From f62940bbdaa7df8738093d78ca490567caf052d2 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 5 Jun 2025 05:11:28 -0700 Subject: [PATCH 1/4] A couple small zig cleanup things (#20196) --- src/bun.js/node/dir_iterator.zig | 2 +- src/deps/uws/Response.zig | 82 ++++++++++++++++---------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/bun.js/node/dir_iterator.zig b/src/bun.js/node/dir_iterator.zig index f355260054..c9ba26706b 100644 --- a/src/bun.js/node/dir_iterator.zig +++ b/src/bun.js/node/dir_iterator.zig @@ -52,7 +52,7 @@ pub fn NewIterator(comptime use_windows_ospath: bool) type { .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris => struct { dir: Dir, seek: i64, - buf: [8192]u8, // TODO align(@alignOf(os.system.dirent)), + buf: [8192]u8 align(@alignOf(std.posix.system.dirent)), index: usize, end_index: usize, received_eof: bool = false, diff --git a/src/deps/uws/Response.zig b/src/deps/uws/Response.zig index 9c2ff2dc1a..21f77d234a 100644 --- a/src/deps/uws/Response.zig +++ b/src/deps/uws/Response.zig @@ -44,7 +44,7 @@ pub fn NewResponse(ssl_flag: i32) type { } pub fn prepareForSendfile(res: *Response) void { - return c.uws_res_prepare_for_sendfile(ssl_flag, res.downcast()); + c.uws_res_prepare_for_sendfile(ssl_flag, res.downcast()); } pub fn uncork(_: *Response) void { @@ -316,9 +316,9 @@ pub const AnyResponse = union(enum) { }; } pub fn flushHeaders(this: AnyResponse) void { - return switch (this) { + switch (this) { inline else => |resp| resp.flushHeaders(), - }; + } } pub fn getWriteOffset(this: AnyResponse) u64 { return switch (this) { @@ -333,9 +333,9 @@ pub const AnyResponse = union(enum) { } pub fn writeContinue(this: AnyResponse) void { - return switch (this) { + switch (this) { inline else => |resp| resp.writeContinue(), - }; + } } pub fn state(this: AnyResponse) State { @@ -359,25 +359,25 @@ pub const AnyResponse = union(enum) { } pub fn onData(this: AnyResponse, comptime UserDataType: type, comptime handler: fn (UserDataType, []const u8, bool) void, optional_data: UserDataType) void { - return switch (this) { + switch (this) { inline .SSL, .TCP => |resp, ssl| resp.onData(UserDataType, struct { pub fn onDataCallback(user_data: UserDataType, _: *uws.NewApp(ssl == .SSL).Response, data: []const u8, last: bool) void { @call(.always_inline, handler, .{ user_data, data, last }); } }.onDataCallback, optional_data), - }; + } } pub fn writeStatus(this: AnyResponse, status: []const u8) void { - return switch (this) { + switch (this) { inline else => |resp| resp.writeStatus(status), - }; + } } pub fn writeHeader(this: AnyResponse, key: []const u8, value: []const u8) void { - return switch (this) { + switch (this) { inline else => |resp| resp.writeHeader(key, value), - }; + } } pub fn write(this: AnyResponse, data: []const u8) WriteResult { @@ -387,9 +387,9 @@ pub const AnyResponse = union(enum) { } pub fn end(this: AnyResponse, data: []const u8, close_connection: bool) void { - return switch (this) { + switch (this) { inline else => |resp| resp.end(data, close_connection), - }; + } } pub fn shouldCloseConnection(this: AnyResponse) bool { @@ -405,27 +405,27 @@ pub const AnyResponse = union(enum) { } pub fn pause(this: AnyResponse) void { - return switch (this) { + switch (this) { inline else => |resp| resp.pause(), - }; + } } pub fn @"resume"(this: AnyResponse) void { - return switch (this) { + switch (this) { inline else => |resp| resp.@"resume"(), - }; + } } pub fn writeHeaderInt(this: AnyResponse, key: []const u8, value: u64) void { - return switch (this) { + switch (this) { inline else => |resp| resp.writeHeaderInt(key, value), - }; + } } pub fn endWithoutBody(this: AnyResponse, close_connection: bool) void { - return switch (this) { + switch (this) { inline else => |resp| resp.endWithoutBody(close_connection), - }; + } } pub fn onWritable(this: AnyResponse, comptime UserDataType: type, comptime handler: fn (UserDataType, u64, AnyResponse) bool, optional_data: UserDataType) void { @@ -438,10 +438,10 @@ pub const AnyResponse = union(enum) { return handler(user_data, offset, .{ .TCP = resp }); } }; - return switch (this) { + switch (this) { .SSL => |resp| resp.onWritable(UserDataType, wrapper.ssl_handler, optional_data), .TCP => |resp| resp.onWritable(UserDataType, wrapper.tcp_handler, optional_data), - }; + } } pub fn onTimeout(this: AnyResponse, comptime UserDataType: type, comptime handler: fn (UserDataType, AnyResponse) void, optional_data: UserDataType) void { @@ -454,10 +454,10 @@ pub const AnyResponse = union(enum) { } }; - return switch (this) { + switch (this) { .SSL => |resp| resp.onTimeout(UserDataType, wrapper.ssl_handler, optional_data), .TCP => |resp| resp.onTimeout(UserDataType, wrapper.tcp_handler, optional_data), - }; + } } pub fn onAborted(this: AnyResponse, comptime UserDataType: type, comptime handler: fn (UserDataType, AnyResponse) void, optional_data: UserDataType) void { @@ -469,51 +469,51 @@ pub const AnyResponse = union(enum) { handler(user_data, .{ .TCP = resp }); } }; - return switch (this) { + switch (this) { .SSL => |resp| resp.onAborted(UserDataType, wrapper.ssl_handler, optional_data), .TCP => |resp| resp.onAborted(UserDataType, wrapper.tcp_handler, optional_data), - }; + } } pub fn clearAborted(this: AnyResponse) void { - return switch (this) { + switch (this) { inline else => |resp| resp.clearAborted(), - }; + } } pub fn clearTimeout(this: AnyResponse) void { - return switch (this) { + switch (this) { inline else => |resp| resp.clearTimeout(), - }; + } } pub fn clearOnWritable(this: AnyResponse) void { - return switch (this) { + switch (this) { inline else => |resp| resp.clearOnWritable(), - }; + } } pub fn clearOnData(this: AnyResponse) void { - return switch (this) { + switch (this) { inline else => |resp| resp.clearOnData(), - }; + } } pub fn endStream(this: AnyResponse, close_connection: bool) void { - return switch (this) { + switch (this) { inline else => |resp| resp.endStream(close_connection), - }; + } } pub fn corked(this: AnyResponse, comptime handler: anytype, args_tuple: anytype) void { - return switch (this) { + switch (this) { inline else => |resp| resp.corked(handler, args_tuple), - }; + } } pub fn runCorkedWithType(this: AnyResponse, comptime UserDataType: type, comptime handler: fn (UserDataType) void, optional_data: UserDataType) void { - return switch (this) { + switch (this) { inline else => |resp| resp.runCorkedWithType(UserDataType, handler, optional_data), - }; + } } pub fn upgrade( From 6a79b9ef879fa57476a99f807033fafa7d6189d9 Mon Sep 17 00:00:00 2001 From: 190n Date: Thu, 5 Jun 2025 17:12:40 -0700 Subject: [PATCH 2/4] Work around compiler crash in uws.WebSocket (#20211) --- src/deps/uws/Response.zig | 1 + src/deps/uws/WebSocket.zig | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/deps/uws/Response.zig b/src/deps/uws/Response.zig index 21f77d234a..3ac7211bf6 100644 --- a/src/deps/uws/Response.zig +++ b/src/deps/uws/Response.zig @@ -11,6 +11,7 @@ /// - Maintains zero-cost abstractions over the underlying µWebSockets API pub fn NewResponse(ssl_flag: i32) type { // making this opaque crashes Zig 0.14.0 when built in Debug or ReleaseSafe + // TODO: change to opaque when we have https://github.com/ziglang/zig/pull/23197 return struct { const Response = @This(); const ssl = ssl_flag == 1; diff --git a/src/deps/uws/WebSocket.zig b/src/deps/uws/WebSocket.zig index 97b9d1f5a1..eeda19652e 100644 --- a/src/deps/uws/WebSocket.zig +++ b/src/deps/uws/WebSocket.zig @@ -1,5 +1,6 @@ pub fn NewWebSocket(comptime ssl_flag: c_int) type { - return opaque { + // TODO: change to opaque when we have https://github.com/ziglang/zig/pull/23197 + return struct { const WebSocket = @This(); pub fn raw(this: *WebSocket) *RawWebSocket { From 1b092f156bc93faf995f02b26e44b4f035001d96 Mon Sep 17 00:00:00 2001 From: 190n Date: Thu, 5 Jun 2025 17:14:43 -0700 Subject: [PATCH 3/4] Make DebugData.magic enum nonexhaustive (#20212) --- src/ptr/ref_count.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ptr/ref_count.zig b/src/ptr/ref_count.zig index 48a117b2df..0fa0d49d48 100644 --- a/src/ptr/ref_count.zig +++ b/src/ptr/ref_count.zig @@ -428,7 +428,7 @@ pub fn DebugData(thread_safe: bool) type { const Debug = @This(); const Count = if (thread_safe) std.atomic.Value(u32) else u32; - magic: enum(u128) { valid = 0x2f84e51d } align(@alignOf(u32)), + magic: enum(u128) { valid = 0x2f84e51d, _ } align(@alignOf(u32)), lock: if (thread_safe) std.debug.SafetyLock else bun.Mutex, next_id: u32, map: std.AutoHashMapUnmanaged(TrackedRef.Id, TrackedRef), From f59050fc2370098557c65d756985644ea4706b0c Mon Sep 17 00:00:00 2001 From: 190n Date: Thu, 5 Jun 2025 17:15:02 -0700 Subject: [PATCH 4/4] Exit early if V8 tests fail to compile (#20215) --- test/v8/v8.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/v8/v8.test.ts b/test/v8/v8.test.ts index 920fce868c..0cdcc276e1 100644 --- a/test/v8/v8.test.ts +++ b/test/v8/v8.test.ts @@ -78,7 +78,8 @@ async function build( if (exitCode !== 0) { console.error(err); console.log(out); - throw new Error(`build failed: ${exitCode}`); + console.error(`build failed: ${exitCode}, bailing out`); + process.exit(1); } return {