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 19 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
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
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
13 changes: 7 additions & 6 deletions src/bun.js/module_loader.zig
Expand Up @@ -2018,19 +2018,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 @@ -5124,7 +5124,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 @@ -5156,7 +5156,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 @@ -5168,7 +5168,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 @@ -5187,6 +5198,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 @@ -5224,7 +5236,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 @@ -5533,7 +5544,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 @@ -5783,7 +5794,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
27 changes: 21 additions & 6 deletions src/bun.js/webcore/streams.zig
Expand Up @@ -3384,29 +3384,38 @@ pub const FileReader = struct {

break :brk 0;
})) {
.result => |_fd| if (Environment.isWindows) bun.toLibUVOwnedFD(_fd) else _fd,
.result => |fd| if (Environment.isWindows)
switch (bun.sys.toLibUVOwnedFD(fd, .dup, .close_on_fail)) {
.result => |converted_fd| converted_fd,
.err => |err| return .{ .err = err.withFd(file.pathlike.fd) },
}
else
fd,
.err => |err| {
return .{ .err = err.withFd(file.pathlike.fd) };
},
}
else switch (Syscall.open(file.pathlike.path.sliceZ(&file_buf), std.os.O.RDONLY | std.os.O.NONBLOCK | std.os.O.CLOEXEC, 0)) {
.result => |_fd| _fd,
.result => |fd| fd,
.err => |err| {
return .{ .err = err.withPath(file.pathlike.path.slice()) };
},
};

if (comptime Environment.isPosix) {
if ((file.is_atty orelse false) or (fd.int() < 3 and std.os.isatty(fd.cast())) or (file.pathlike == .fd and bun.FDTag.get(file.pathlike.fd) != .none and std.os.isatty(file.pathlike.fd.cast()))) {
if ((file.is_atty orelse false) or
(fd.int() < 3 and std.os.isatty(fd.cast())) or
(file.pathlike == .fd and
bun.FDTag.get(file.pathlike.fd) != .none and
std.os.isatty(file.pathlike.fd.cast())))
{
// var termios = std.mem.zeroes(std.os.termios);
// _ = std.c.tcgetattr(fd.cast(), &termios);
// bun.C.cfmakeraw(&termios);
// _ = std.c.tcsetattr(fd.cast(), std.os.TCSA.NOW, &termios);
file.is_atty = true;
}
}

if (comptime Environment.isPosix) {
const stat: bun.Stat = switch (Syscall.fstat(fd)) {
.result => |result| result,
.err => |err| {
Expand All @@ -3421,7 +3430,12 @@ pub const FileReader = struct {
}

this.pollable = bun.sys.isPollable(stat.mode) or (file.is_atty orelse false);
this.file_type = if (bun.S.ISFIFO(stat.mode)) .pipe else if (bun.S.ISSOCK(stat.mode)) .socket else .file;
this.file_type = if (bun.S.ISFIFO(stat.mode))
.pipe
else if (bun.S.ISSOCK(stat.mode))
.socket
else
.file;
this.nonblocking = this.pollable and !(file.is_atty orelse false);

if (this.nonblocking and this.file_type == .pipe) {
Expand Down Expand Up @@ -3475,6 +3489,7 @@ pub const FileReader = struct {
return .{ .err = err };
},
.result => |opened| {
std.debug.assert(opened.fd.isValid());
this.fd = opened.fd;
pollable = opened.pollable;
file_type = opened.file_type;
Expand Down
6 changes: 3 additions & 3 deletions src/bun.zig
Expand Up @@ -1880,13 +1880,13 @@ pub inline fn toFD(fd: anytype) FileDescriptor {
/// Accepts either a UV descriptor (i32) or a windows handle (*anyopaque)
///
/// On windows, this file descriptor will always be backed by libuv, so calling .close() is safe.
pub inline fn toLibUVOwnedFD(fd: anytype) FileDescriptor {
pub inline fn toLibUVOwnedFD(fd: anytype) !FileDescriptor {
const T = @TypeOf(fd);
if (Environment.isWindows) {
return (switch (T) {
FDImpl.System => FDImpl.fromSystem(fd).makeLibUVOwned(),
FDImpl.System => try FDImpl.fromSystem(fd).makeLibUVOwned(),
FDImpl.UV => FDImpl.fromUV(fd),
FileDescriptor => FDImpl.decode(fd).makeLibUVOwned(),
FileDescriptor => try FDImpl.decode(fd).makeLibUVOwned(),
FDImpl => fd.makeLibUVOwned(),
else => @compileError("toLibUVOwnedFD() does not support type \"" ++ @typeName(T) ++ "\""),
}).encode();
Expand Down
2 changes: 1 addition & 1 deletion src/cli.zig
Expand Up @@ -1872,7 +1872,7 @@ pub const Command = struct {
const file_pathZ = script_name_buf[0..file_path.len :0];
break :brk bun.openFileZ(file_pathZ, .{ .mode = .read_only });
}
}) catch return false).handle);
}) catch return false).handle) catch return false;
defer _ = bun.sys.close(file);

switch (bun.sys.fstat(file)) {
Expand Down
10 changes: 5 additions & 5 deletions src/cli/install.ps1
Expand Up @@ -219,11 +219,11 @@ function Install-Bun {

$env:IS_BUN_AUTO_UPDATE = "1"
$null = "$(& "${BunBin}\bun.exe" completions)"
# if ($LASTEXITCODE -ne 0) {
# Write-Output "Install Failed - could not finalize installation"
# Write-Output "The command '${BunBin}\bun.exe completions' exited with code ${LASTEXITCODE}`n"
# exit 1
# }
if ($LASTEXITCODE -ne 0) {
Write-Output "Install Failed - could not finalize installation"
Write-Output "The command '${BunBin}\bun.exe completions' exited with code ${LASTEXITCODE}`n"
exit 1
}
$env:IS_BUN_AUTO_UPDATE = $null

$DisplayVersion = if ($BunRevision -like "*-canary.*") {
Expand Down