Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows: make more windows tests pass #9370

Merged
merged 31 commits into from Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4091ec5
run-eval.test.ts
paperdave Mar 11, 2024
b3c1a9f
transpiler-cache.test.ts
paperdave Mar 11, 2024
170d143
node net
paperdave Mar 11, 2024
5d31095
some open things
paperdave Mar 12, 2024
b1ed3ea
Merge remote-tracking branch 'origin/main' into dave/win/2024-03-11
paperdave Mar 12, 2024
9d768e6
a
paperdave Mar 12, 2024
5b8653a
a
paperdave Mar 12, 2024
aa1c989
yikes
paperdave Mar 12, 2024
c1c83be
Merge branch 'main' into dave/win/2024-03-11
paperdave Mar 12, 2024
ad61bd5
incredible
paperdave Mar 13, 2024
77cf557
run it back
paperdave Mar 13, 2024
5ad751c
a
paperdave Mar 13, 2024
09c2036
Merge remote-tracking branch 'origin/main' into dave/win/2024-03-11
paperdave Mar 13, 2024
94196e8
this code is what i like to call, incorrect
paperdave Mar 13, 2024
aa05154
ok its all worng
paperdave Mar 13, 2024
b81e639
remove an assertion that is wrong again
paperdave Mar 13, 2024
e7b980e
Merge remote-tracking branch 'origin/main' into dave/win/2024-03-11
paperdave Mar 13, 2024
3869964
Merge remote-tracking branch 'origin/main' into dave/win/2024-03-11
paperdave Mar 13, 2024
1d61dd2
update test things and rebase
paperdave Mar 13, 2024
a7b65ad
performance test
paperdave Mar 14, 2024
3ce3538
mark filesink with mkfifo as todo. see #8166
paperdave Mar 14, 2024
42356ce
Merge branch 'main' into dave/win/2024-03-11
Jarred-Sumner Mar 16, 2024
835dfb2
Merge branch 'main' into dave/win/2024-03-11
Jarred-Sumner Mar 16, 2024
2d60e06
Merge branch 'main' into dave/win/2024-03-11
Jarred-Sumner Mar 18, 2024
8f1b5c4
Merge branch 'main' into dave/win/2024-03-11
Jarred-Sumner Mar 19, 2024
9c2dc5d
Merge remote-tracking branch 'origin/main' into dave/win/2024-03-11
paperdave Mar 21, 2024
a35961c
hehe
paperdave Mar 21, 2024
e7c27b4
not done
paperdave Mar 21, 2024
642c63c
awa
paperdave Mar 22, 2024
9949621
Merge remote-tracking branch 'origin/main' into dave/win/2024-03-11
paperdave Mar 22, 2024
fbdb862
fs test pass
paperdave Mar 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 39 additions & 31 deletions CMakeLists.txt
Expand Up @@ -5,37 +5,6 @@ cmake_policy(SET CMP0067 NEW)
set(Bun_VERSION "1.0.35")
set(WEBKIT_TAG 089023cc9078b3aa173869fd6685f3e7bed2a994)

if(APPLE AND DEFINED ENV{CI})
if(ARCH STREQUAL "x86_64")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14")
else()
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0")
endif()
endif()

if(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
execute_process(COMMAND xcrun --show-sdk-path OUTPUT_VARIABLE SDKROOT)
string(STRIP ${SDKROOT} SDKROOT)
message(STATUS "Using SDKROOT: ${SDKROOT}")
SET(CMAKE_OSX_SYSROOT ${SDKROOT})

execute_process(COMMAND xcrun --sdk macosx --show-sdk-version OUTPUT_VARIABLE MACOSX_DEPLOYMENT_TARGET)
string(STRIP ${MACOSX_DEPLOYMENT_TARGET} MACOSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET ${MACOSX_DEPLOYMENT_TARGET})

# Check if current version of macOS is less than the deployment target and if so, raise an error
execute_process(COMMAND sw_vers -productVersion OUTPUT_VARIABLE MACOS_VERSION)
string(STRIP ${MACOS_VERSION} MACOS_VERSION)

if(MACOS_VERSION VERSION_LESS ${MACOSX_DEPLOYMENT_TARGET})
message(WARNING "\nThe current version of macOS (${MACOS_VERSION}) is less than the deployment target (${MACOSX_DEPLOYMENT_TARGET}).\nThis makes icucore fail to run at start.\nTo fix this, please either:\n- Upgrade to the latest version of macOS\n- Use `xcode-select` to switch to an SDK version <= ${MACOS_VERSION}")
endif()
endif()

if(APPLE)
message(STATUS "Building for macOS v${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()

set(BUN_WORKDIR "${CMAKE_CURRENT_BINARY_DIR}")
message(STATUS "Configuring Bun ${Bun_VERSION} in ${BUN_WORKDIR}")

Expand Down Expand Up @@ -80,6 +49,45 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
endif()
endif()

# --- MacOS SDK ---
if(APPLE AND DEFINED ENV{CI})
if(ARCH STREQUAL "x86_64")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14")
else()
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0")
endif()
endif()

if(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
execute_process(COMMAND xcrun --show-sdk-path OUTPUT_VARIABLE SDKROOT)
string(STRIP ${SDKROOT} SDKROOT)
message(STATUS "MacOS SDK path: ${SDKROOT}")
SET(CMAKE_OSX_SYSROOT ${SDKROOT})

execute_process(COMMAND xcrun --sdk macosx --show-sdk-version OUTPUT_VARIABLE MACOSX_DEPLOYMENT_TARGET)
string(STRIP ${MACOSX_DEPLOYMENT_TARGET} MACOSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET ${MACOSX_DEPLOYMENT_TARGET})

# Check if current version of macOS is less than the deployment target and if so, raise an error
execute_process(COMMAND sw_vers -productVersion OUTPUT_VARIABLE MACOS_VERSION)
string(STRIP ${MACOS_VERSION} MACOS_VERSION)

if(MACOS_VERSION VERSION_LESS ${MACOSX_DEPLOYMENT_TARGET})
message(WARNING
"The current version of macOS (${MACOS_VERSION}) is less than the deployment target (${MACOSX_DEPLOYMENT_TARGET}).\n"
"The build will be incompatible with your current device due to mismatches in `icucore` versions.\n"
"To fix this, please either:\n"
" - Upgrade to at least macOS ${MACOSX_DEPLOYMENT_TARGET}\n"
" - Use `xcode-select` to switch to an SDK version <= ${MACOS_VERSION}\n"
" - Set CMAKE_OSX_DEPLOYMENT_TARGET=${MACOS_VERSION} (make sure to build all dependencies with this variable set too)"
)
endif()
endif()

if(APPLE)
message(STATUS "Building for macOS v${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()

# --- LLVM ---
# This detection is a little overkill, but it ensures that the set LLVM_VERSION matches under
# any case possible. Sorry for the complexity...
Expand Down
14 changes: 9 additions & 5 deletions packages/bun-usockets/src/eventing/libuv.c
Expand Up @@ -91,6 +91,10 @@ void us_poll_start(struct us_poll_t *p, struct us_loop_t *loop, int events) {
((events & LIBUS_SOCKET_WRITABLE) ? POLL_TYPE_POLLING_OUT : 0);

uv_poll_init_socket(loop->uv_loop, p->uv_p, p->fd);
// This unref is okay in the context of Bun's event loop, because sockets have
// a `Async.KeepAlive` associated with them, which is used instead of the
// usockets internals. usockets doesnt have a notion of ref-counted handles.
uv_unref((uv_handle_t *)p->uv_p);
uv_poll_start(p->uv_p, events, poll_cb);
}

Expand Down Expand Up @@ -211,7 +215,7 @@ struct us_poll_t *us_create_poll(struct us_loop_t *loop, int fallthrough,
return p;
}

/* If we update our block position we have to updarte the uv_poll data to point
/* If we update our block position we have to update the uv_poll data to point
* to us */
struct us_poll_t *us_poll_resize(struct us_poll_t *p, struct us_loop_t *loop,
unsigned int ext_size) {
Expand All @@ -225,8 +229,8 @@ struct us_poll_t *us_poll_resize(struct us_poll_t *p, struct us_loop_t *loop,
// timer
struct us_timer_t *us_create_timer(struct us_loop_t *loop, int fallthrough,
unsigned int ext_size) {
struct us_internal_callback_t *cb = us_calloc(1,
sizeof(struct us_internal_callback_t) + sizeof(uv_timer_t) + ext_size);
struct us_internal_callback_t *cb = us_calloc(
1, sizeof(struct us_internal_callback_t) + sizeof(uv_timer_t) + ext_size);

cb->loop = loop;
cb->cb_expects_the_loop = 0; // never read?
Expand Down Expand Up @@ -288,8 +292,8 @@ struct us_loop_t *us_timer_loop(struct us_timer_t *t) {
struct us_internal_async *us_internal_create_async(struct us_loop_t *loop,
int fallthrough,
unsigned int ext_size) {
struct us_internal_callback_t *cb = us_calloc(1,
sizeof(struct us_internal_callback_t) + sizeof(uv_async_t) + ext_size);
struct us_internal_callback_t *cb = us_calloc(
1, sizeof(struct us_internal_callback_t) + sizeof(uv_async_t) + ext_size);

cb->loop = loop;
return (struct us_internal_async *)cb;
Expand Down
3 changes: 3 additions & 0 deletions scripts/env.sh
Expand Up @@ -43,4 +43,7 @@ mkdir -p $BUN_DEPS_OUT_DIR
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "C Compiler: ${CC}"
echo "C++ Compiler: ${CXX}"
if [[ $(uname -s) == 'Darwin' ]]; then
echo "OSX Deployment Target: ${CMAKE_OSX_DEPLOYMENT_TARGET}"
fi
fi
2 changes: 2 additions & 0 deletions src/async/windows_event_loop.zig
Expand Up @@ -259,12 +259,14 @@ pub const FilePoll = struct {
pub fn deactivate(this: *FilePoll, loop: *Loop) void {
std.debug.assert(this.flags.contains(.has_incremented_poll_count));
loop.active_handles -= @as(u32, @intFromBool(this.flags.contains(.has_incremented_poll_count)));
log("deactivate - {d}", .{loop.active_handles});
this.flags.remove(.has_incremented_poll_count);
}

/// Only intended to be used from EventLoop.Pollable
pub fn activate(this: *FilePoll, loop: *Loop) void {
loop.active_handles += @as(u32, @intFromBool(!this.flags.contains(.closed) and !this.flags.contains(.has_incremented_poll_count)));
log("activate - {d}", .{loop.active_handles});
this.flags.insert(.has_incremented_poll_count);
}

Expand Down
9 changes: 5 additions & 4 deletions src/bun.js/RuntimeTranspilerCache.zig
Expand Up @@ -543,8 +543,9 @@ pub const RuntimeTranspilerCache = struct {

const cache_dir_fd = brk: {
if (std.fs.path.dirname(cache_file_path)) |dirname| {
const dir = try std.fs.cwd().makeOpenPath(dirname, .{ .access_sub_paths = true });
break :brk bun.toLibUVOwnedFD(dir.fd);
var dir = try std.fs.cwd().makeOpenPath(dirname, .{ .access_sub_paths = true });
paperdave marked this conversation as resolved.
Show resolved Hide resolved
errdefer dir.close();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

break :brk try bun.toLibUVOwnedFD(dir.fd);
}

break :brk bun.toFD(std.fs.cwd().fd);
Expand Down Expand Up @@ -597,7 +598,7 @@ pub const RuntimeTranspilerCache = struct {
debug("get(\"{s}\") = {s}", .{ source.path.text, @errorName(err) });
return false;
};
if (comptime bun.Environment.allow_assert) {
if (comptime bun.Environment.isDebug) {
if (bun_debug_restore_from_cache) {
debug("get(\"{s}\") = {d} bytes, restored", .{ source.path.text, this.entry.?.output_code.byteSlice().len });
} else {
Expand All @@ -606,7 +607,7 @@ pub const RuntimeTranspilerCache = struct {
}
bun.Analytics.Features.transpiler_cache = true;

if (comptime bun.Environment.allow_assert) {
if (comptime bun.Environment.isDebug) {
if (!bun_debug_restore_from_cache) {
if (this.entry) |*entry| {
entry.deinit(this.sourcemap_allocator, this.output_code_allocator);
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/javascript.zig
Expand Up @@ -1219,7 +1219,7 @@ pub const VirtualMachine = struct {
.source_mappings = undefined,
.macros = MacroMap.init(allocator),
.macro_entry_points = @TypeOf(vm.macro_entry_points).init(allocator),
.origin_timer = std.time.Timer.start() catch @panic("Please don't mess with timers."),
.origin_timer = std.time.Timer.start() catch @panic("Timers are not supported on this system."),
.origin_timestamp = getOriginTimestamp(),
.ref_strings = JSC.RefString.Map.init(allocator),
.ref_strings_mutex = Lock.init(),
Expand Down
13 changes: 7 additions & 6 deletions src/bun.js/module_loader.zig
Expand Up @@ -2064,19 +2064,20 @@ pub const ModuleLoader = struct {
else => {
var stack_buf = std.heap.stackFallback(4096, jsc_vm.allocator);
const allocator = stack_buf.get();
var buf = MutableString.init2048(allocator) catch unreachable;
var buf = MutableString.init2048(allocator) catch bun.outOfMemory();
defer buf.deinit();
var writer = buf.writer();
if (!jsc_vm.origin.isEmpty()) {
writer.writeAll("export default `") catch unreachable;
writer.writeAll("export default `") catch bun.outOfMemory();
// TODO: escape backtick char, though we might already do that
JSC.API.Bun.getPublicPath(specifier, jsc_vm.origin, @TypeOf(&writer), &writer);
writer.writeAll("`;\n") catch unreachable;
writer.writeAll("`;\n") catch bun.outOfMemory();
} else {
writer.writeAll("export default ") catch unreachable;
buf = js_printer.quoteForJSON(specifier, buf, true) catch @panic("out of memory");
// search keywords: "export default \"{}\";"
writer.writeAll("export default ") catch bun.outOfMemory();
buf = js_printer.quoteForJSON(specifier, buf, true) catch bun.outOfMemory();
writer = buf.writer();
writer.writeAll(";\n") catch unreachable;
writer.writeAll(";\n") catch bun.outOfMemory();
}

const public_url = bun.String.createUTF8(buf.toOwnedSliceLeaky());
Expand Down
25 changes: 18 additions & 7 deletions src/bun.js/node/node_fs.zig
Expand Up @@ -3779,7 +3779,7 @@ pub const NodeFS = struct {
.path => |path_| {
const path = path_.sliceZ(&this.sync_error_buf);

const fd = switch (Syscall.open(path, @intFromEnum(FileSystemFlags.a), 0o000666)) {
const fd = switch (Syscall.open(path, @intFromEnum(FileSystemFlags.a), 0o666)) {
.result => |result| result,
.err => |err| return .{ .err = err },
};
Expand Down Expand Up @@ -5148,7 +5148,7 @@ pub const NodeFS = struct {

pub fn readFileWithOptions(this: *NodeFS, args: Arguments.ReadFile, comptime _: Flavor, comptime string_type: StringType) Maybe(Return.ReadFileWithOptions) {
var path: [:0]const u8 = undefined;
const fd: FileDescriptor = bun.toLibUVOwnedFD(switch (args.path) {
const fd_maybe_windows: FileDescriptor = switch (args.path) {
.path => brk: {
path = args.path.path.sliceZ(&this.sync_error_buf);
if (this.vm) |vm| {
Expand Down Expand Up @@ -5180,7 +5180,7 @@ pub const NodeFS = struct {
}
}

break :brk switch (Syscall.open(
break :brk switch (bun.sys.open(
path,
os.O.RDONLY | os.O.NOCTTY,
0,
Expand All @@ -5192,7 +5192,18 @@ pub const NodeFS = struct {
};
},
.fd => |fd| fd,
});
};
const fd = bun.toLibUVOwnedFD(fd_maybe_windows) catch {
if (args.path == .path)
_ = Syscall.close(fd_maybe_windows);

return .{
.err = .{
.errno = @intFromEnum(os.E.MFILE),
.syscall = .open,
},
};
};

defer {
if (args.path == .path)
Expand All @@ -5211,6 +5222,7 @@ pub const NodeFS = struct {
_ = Syscall.setFileOffset(fd, args.offset);
}
// For certain files, the size might be 0 but the file might still have contents.
// https://github.com/oven-sh/bun/issues/1220
paperdave marked this conversation as resolved.
Show resolved Hide resolved
const size = @as(
u64,
@max(
Expand Down Expand Up @@ -5248,7 +5260,6 @@ pub const NodeFS = struct {
},
}
} else {
// https://github.com/oven-sh/bun/issues/1220
while (true) {
switch (Syscall.read(fd, buf.items.ptr[total..buf.capacity])) {
.err => |err| return .{
Expand Down Expand Up @@ -5557,7 +5568,7 @@ pub const NodeFS = struct {
else
std.os.O.RDONLY;

const fd = switch (Syscall.open(path, flags, 0)) {
const fd = switch (bun.sys.open(path, flags, 0)) {
.err => |err| return .{ .err = err.withPath(path) },
.result => |fd_| fd_,
};
Expand Down Expand Up @@ -5807,7 +5818,7 @@ pub const NodeFS = struct {

fn _truncate(this: *NodeFS, path: PathLike, len: JSC.WebCore.Blob.SizeType, flags: i32, comptime _: Flavor) Maybe(Return.Truncate) {
if (comptime Environment.isWindows) {
const file = Syscall.open(
const file = bun.sys.open(
path.sliceZ(&this.sync_error_buf),
os.O.WRONLY | flags,
0o644,
Expand Down
16 changes: 14 additions & 2 deletions src/bun.js/webcore/blob.zig
Expand Up @@ -2298,7 +2298,13 @@ pub const Blob = struct {
open_source_flags,
0,
)) {
.result => |result| bun.toLibUVOwnedFD(result),
.result => |result| switch (bun.sys.toLibUVOwnedFD(result, .open, .close_on_fail)) {
.result => |result_fd| result_fd,
.err => |errno| {
this.system_error = errno.toSystemError();
return bun.errnoToZigErr(errno.errno);
},
},
.err => |errno| {
this.system_error = errno.toSystemError();
return bun.errnoToZigErr(errno.errno);
Expand All @@ -2314,7 +2320,13 @@ pub const Blob = struct {
open_destination_flags,
JSC.Node.default_permission,
)) {
.result => |result| bun.toLibUVOwnedFD(result),
.result => |result| switch (bun.sys.toLibUVOwnedFD(result, .open, .close_on_fail)) {
.result => |result_fd| result_fd,
.err => |errno| {
this.system_error = errno.toSystemError();
return bun.errnoToZigErr(errno.errno);
},
},
.err => |errno| {
switch (mkdirIfNotExists(this, errno, dest, dest)) {
.@"continue" => continue,
Expand Down