mirror of
https://github.com/oven-sh/bun
synced 2026-02-03 15:38:46 +00:00
Compare commits
14 Commits
dylan/byte
...
pfg/zig-01
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2bca43f5d | ||
|
|
43b2c0e43a | ||
|
|
bf5a316913 | ||
|
|
84d559f76b | ||
|
|
9dadf094c4 | ||
|
|
3932382848 | ||
|
|
fcef27cebd | ||
|
|
e38e0c8cd0 | ||
|
|
3ffbeda127 | ||
|
|
188f946ee5 | ||
|
|
91cd7c1fa8 | ||
|
|
255c5a760f | ||
|
|
da48da4ae3 | ||
|
|
b178ccd011 |
@@ -63,7 +63,6 @@ const BunBuildOptions = struct {
|
||||
/// `./build/codegen` or equivalent
|
||||
codegen_path: []const u8,
|
||||
no_llvm: bool,
|
||||
override_no_export_cpp_apis: bool,
|
||||
|
||||
cached_options_module: ?*Module = null,
|
||||
windows_shim: ?WindowsShim = null,
|
||||
@@ -96,7 +95,6 @@ const BunBuildOptions = struct {
|
||||
opts.addOption(bool, "enable_asan", this.enable_asan);
|
||||
opts.addOption([]const u8, "reported_nodejs_version", b.fmt("{}", .{this.reported_nodejs_version}));
|
||||
opts.addOption(bool, "zig_self_hosted_backend", this.no_llvm);
|
||||
opts.addOption(bool, "override_no_export_cpp_apis", this.override_no_export_cpp_apis);
|
||||
|
||||
const mod = opts.createModule();
|
||||
this.cached_options_module = mod;
|
||||
@@ -208,7 +206,6 @@ pub fn build(b: *Build) !void {
|
||||
const obj_format = b.option(ObjectFormat, "obj_format", "Output file for object files") orelse .obj;
|
||||
|
||||
const no_llvm = b.option(bool, "no_llvm", "Experiment with Zig self hosted backends. No stability guaranteed") orelse false;
|
||||
const override_no_export_cpp_apis = b.option(bool, "override-no-export-cpp-apis", "Override the default export_cpp_apis logic to disable exports") orelse false;
|
||||
|
||||
var build_options = BunBuildOptions{
|
||||
.target = target,
|
||||
@@ -220,7 +217,6 @@ pub fn build(b: *Build) !void {
|
||||
.codegen_path = codegen_path,
|
||||
.codegen_embed = codegen_embed,
|
||||
.no_llvm = no_llvm,
|
||||
.override_no_export_cpp_apis = override_no_export_cpp_apis,
|
||||
|
||||
.version = try Version.parse(bun_version),
|
||||
.canary_revision = canary: {
|
||||
@@ -480,7 +476,6 @@ fn addMultiCheck(
|
||||
.codegen_path = root_build_options.codegen_path,
|
||||
.no_llvm = root_build_options.no_llvm,
|
||||
.enable_asan = root_build_options.enable_asan,
|
||||
.override_no_export_cpp_apis = root_build_options.override_no_export_cpp_apis,
|
||||
};
|
||||
|
||||
var obj = addBunObject(b, &options);
|
||||
|
||||
@@ -572,6 +572,7 @@ src/json_parser.zig
|
||||
src/libarchive/libarchive-bindings.zig
|
||||
src/libarchive/libarchive.zig
|
||||
src/linear_fifo.zig
|
||||
src/linked_list.zig
|
||||
src/linker.zig
|
||||
src/linux.zig
|
||||
src/logger.zig
|
||||
|
||||
@@ -20,7 +20,7 @@ else()
|
||||
unsupported(CMAKE_SYSTEM_NAME)
|
||||
endif()
|
||||
|
||||
set(ZIG_COMMIT "0a0120fa92cd7f6ab244865688b351df634f0707")
|
||||
set(ZIG_COMMIT "2a158f8fa65c657eb8b80591d37dc1f07a2489d8")
|
||||
optionx(ZIG_TARGET STRING "The zig target to use" DEFAULT ${DEFAULT_ZIG_TARGET})
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
|
||||
@@ -10,5 +10,6 @@ tar --no-xattrs \
|
||||
-zcf "$out" \
|
||||
build/debug/codegen \
|
||||
src/bun.js/bindings/GeneratedBindings.zig \
|
||||
src/bun.js/bindings/GeneratedJS2Native.zig
|
||||
src/bun.js/bindings/GeneratedJS2Native.zig \
|
||||
vendor/zstd
|
||||
echo "-> $out"
|
||||
|
||||
@@ -145,7 +145,7 @@ pub fn raiseIgnoringPanicHandler(sig: bun.SignalCode) noreturn {
|
||||
if (bun.Environment.os != .windows) {
|
||||
var sa: std.c.Sigaction = .{
|
||||
.handler = .{ .handler = std.posix.SIG.DFL },
|
||||
.mask = std.posix.empty_sigset,
|
||||
.mask = std.posix.sigemptyset(),
|
||||
.flags = std.posix.SA.RESETHAND,
|
||||
};
|
||||
_ = std.c.sigaction(@intFromEnum(sig), &sa, null);
|
||||
|
||||
@@ -4,7 +4,7 @@ const std = @import("std");
|
||||
/// Single allocation only.
|
||||
///
|
||||
pub const MaxHeapAllocator = struct {
|
||||
array_list: std.ArrayListAligned(u8, @alignOf(std.c.max_align_t)),
|
||||
array_list: std.ArrayListAligned(u8, .fromByteUnits(@alignOf(std.c.max_align_t))),
|
||||
|
||||
fn alloc(ptr: *anyopaque, len: usize, alignment: std.mem.Alignment, _: usize) ?[*]u8 {
|
||||
bun.assert(alignment.toByteUnits() <= @alignOf(std.c.max_align_t));
|
||||
|
||||
@@ -1824,7 +1824,7 @@ const DeferredRequest = struct {
|
||||
/// is very silly. This contributes to ~6kb of the initial DevServer allocation.
|
||||
const max_preallocated = 16;
|
||||
|
||||
pub const List = std.SinglyLinkedList(DeferredRequest);
|
||||
pub const List = bun.SinglyLinkedList(DeferredRequest);
|
||||
pub const Node = List.Node;
|
||||
|
||||
route_bundle_index: RouteBundle.Index,
|
||||
|
||||
@@ -928,8 +928,8 @@ const WaiterThreadPosix = struct {
|
||||
}
|
||||
|
||||
if (comptime Environment.isLinux) {
|
||||
var current_mask = std.posix.empty_sigset;
|
||||
std.os.linux.sigaddset(¤t_mask, std.posix.SIG.CHLD);
|
||||
var current_mask = std.posix.sigemptyset();
|
||||
std.posix.sigaddset(¤t_mask, std.posix.SIG.CHLD);
|
||||
const act = std.posix.Sigaction{
|
||||
.handler = .{ .handler = &wakeup },
|
||||
.mask = current_mask,
|
||||
@@ -964,7 +964,7 @@ const WaiterThreadPosix = struct {
|
||||
|
||||
_ = std.posix.poll(&polls, std.math.maxInt(i32)) catch 0;
|
||||
} else {
|
||||
var mask = std.posix.empty_sigset;
|
||||
var mask = std.posix.sigemptyset();
|
||||
var signal: c_int = std.posix.SIG.CHLD;
|
||||
const rc = std.c.sigwait(&mask, &signal);
|
||||
_ = rc;
|
||||
|
||||
@@ -270,7 +270,6 @@ pub const FileSystemRouter = struct {
|
||||
};
|
||||
|
||||
this.arena.deinit();
|
||||
this.router.deinit();
|
||||
globalThis.allocator().destroy(this.arena);
|
||||
|
||||
this.arena = arena;
|
||||
@@ -398,7 +397,6 @@ pub const FileSystemRouter = struct {
|
||||
dir.deref();
|
||||
}
|
||||
|
||||
this.router.deinit();
|
||||
this.arena.deinit();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2408,12 +2408,10 @@ pub fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool,
|
||||
|
||||
comptime {
|
||||
const export_prefix = "Bun__HTTPRequestContext" ++ (if (debug_mode) "Debug" else "") ++ (if (ThisServer.ssl_enabled) "TLS" else "");
|
||||
if (bun.Environment.export_cpp_apis) {
|
||||
@export(&JSC.toJSHostFn(onResolve), .{ .name = export_prefix ++ "__onResolve" });
|
||||
@export(&JSC.toJSHostFn(onReject), .{ .name = export_prefix ++ "__onReject" });
|
||||
@export(&JSC.toJSHostFn(onResolveStream), .{ .name = export_prefix ++ "__onResolveStream" });
|
||||
@export(&JSC.toJSHostFn(onRejectStream), .{ .name = export_prefix ++ "__onRejectStream" });
|
||||
}
|
||||
@export(&JSC.toJSHostFn(onResolve), .{ .name = export_prefix ++ "__onResolve" });
|
||||
@export(&JSC.toJSHostFn(onReject), .{ .name = export_prefix ++ "__onReject" });
|
||||
@export(&JSC.toJSHostFn(onResolveStream), .{ .name = export_prefix ++ "__onResolveStream" });
|
||||
@export(&JSC.toJSHostFn(onRejectStream), .{ .name = export_prefix ++ "__onRejectStream" });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6602,6 +6602,8 @@ pub fn zigDeleteTree(self: std.fs.Dir, sub_path: []const u8, kind_hint: std.fs.F
|
||||
error.BadPathName,
|
||||
error.NetworkNotFound,
|
||||
error.DeviceBusy,
|
||||
error.ProcessNotFound,
|
||||
error.PermissionDenied,
|
||||
=> |e| return e,
|
||||
};
|
||||
stack.appendAssumeCapacity(.{
|
||||
@@ -6637,6 +6639,7 @@ pub fn zigDeleteTree(self: std.fs.Dir, sub_path: []const u8, kind_hint: std.fs.F
|
||||
error.BadPathName,
|
||||
error.NetworkNotFound,
|
||||
error.Unexpected,
|
||||
error.PermissionDenied,
|
||||
=> |e| return e,
|
||||
}
|
||||
}
|
||||
@@ -6694,6 +6697,8 @@ pub fn zigDeleteTree(self: std.fs.Dir, sub_path: []const u8, kind_hint: std.fs.F
|
||||
error.BadPathName,
|
||||
error.NetworkNotFound,
|
||||
error.DeviceBusy,
|
||||
error.PermissionDenied,
|
||||
error.ProcessNotFound,
|
||||
=> |e| return e,
|
||||
};
|
||||
} else {
|
||||
@@ -6718,6 +6723,7 @@ pub fn zigDeleteTree(self: std.fs.Dir, sub_path: []const u8, kind_hint: std.fs.F
|
||||
error.FileBusy,
|
||||
error.BadPathName,
|
||||
error.NetworkNotFound,
|
||||
error.PermissionDenied,
|
||||
error.Unexpected,
|
||||
=> |e| return e,
|
||||
}
|
||||
@@ -6750,6 +6756,7 @@ fn zigDeleteTreeOpenInitialSubpath(self: std.fs.Dir, sub_path: []const u8, kind_
|
||||
error.NotDir,
|
||||
error.FileNotFound,
|
||||
error.AccessDenied,
|
||||
error.PermissionDenied,
|
||||
error.SymLinkLoop,
|
||||
error.ProcessFdQuotaExceeded,
|
||||
error.NameTooLong,
|
||||
@@ -6762,6 +6769,7 @@ fn zigDeleteTreeOpenInitialSubpath(self: std.fs.Dir, sub_path: []const u8, kind_
|
||||
error.BadPathName,
|
||||
error.DeviceBusy,
|
||||
error.NetworkNotFound,
|
||||
error.ProcessNotFound,
|
||||
=> |e| return e,
|
||||
};
|
||||
} else {
|
||||
@@ -6775,6 +6783,7 @@ fn zigDeleteTreeOpenInitialSubpath(self: std.fs.Dir, sub_path: []const u8, kind_
|
||||
|
||||
error.FileNotFound,
|
||||
error.AccessDenied,
|
||||
error.PermissionDenied,
|
||||
error.InvalidUtf8,
|
||||
error.InvalidWtf8,
|
||||
error.SymLinkLoop,
|
||||
@@ -6845,6 +6854,8 @@ fn zigDeleteTreeMinStackSizeWithKindHint(self: std.fs.Dir, sub_path: []const u8,
|
||||
error.BadPathName,
|
||||
error.NetworkNotFound,
|
||||
error.DeviceBusy,
|
||||
error.ProcessNotFound,
|
||||
error.PermissionDenied,
|
||||
=> |e| return e,
|
||||
};
|
||||
if (cleanup_dir_parent) |*d| d.close();
|
||||
@@ -6877,6 +6888,7 @@ fn zigDeleteTreeMinStackSizeWithKindHint(self: std.fs.Dir, sub_path: []const u8,
|
||||
error.FileBusy,
|
||||
error.BadPathName,
|
||||
error.NetworkNotFound,
|
||||
error.PermissionDenied,
|
||||
error.Unexpected,
|
||||
=> |e| return e,
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ pub fn Bun__Process__editWindowsEnvVar(k: bun.String, v: bun.String) callconv(.C
|
||||
}
|
||||
|
||||
comptime {
|
||||
if (Environment.export_cpp_apis and Environment.isWindows) {
|
||||
if (Environment.isWindows) {
|
||||
@export(&Bun__Process__editWindowsEnvVar, .{ .name = "Bun__Process__editWindowsEnvVar" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,7 +439,7 @@ pub const PathWatcherManager = struct {
|
||||
return .{
|
||||
.err = .{
|
||||
.errno = @truncate(@intFromEnum(switch (err) {
|
||||
error.AccessDenied => bun.sys.E.ACCES,
|
||||
error.AccessDenied, error.PermissionDenied => bun.sys.E.ACCES,
|
||||
error.SystemResources => bun.sys.E.NOMEM,
|
||||
error.Unexpected,
|
||||
error.InvalidUtf8,
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
//! Web APIs implemented in Zig live here
|
||||
|
||||
comptime {
|
||||
if (bun.Environment.export_cpp_apis) {
|
||||
_ = &@import("webcore/prompt.zig");
|
||||
}
|
||||
_ = &@import("webcore/prompt.zig");
|
||||
_ = &@import("webcore/TextEncoder.zig");
|
||||
}
|
||||
|
||||
|
||||
@@ -593,19 +593,17 @@ pub fn JSSink(comptime SinkType: type, comptime abi_name: []const u8) type {
|
||||
}
|
||||
|
||||
comptime {
|
||||
if (bun.Environment.export_cpp_apis) {
|
||||
@export(&finalize, .{ .name = abi_name ++ "__finalize" });
|
||||
@export(&jsWrite, .{ .name = abi_name ++ "__write" });
|
||||
@export(&jsGetInternalFd, .{ .name = abi_name ++ "__getInternalFd" });
|
||||
@export(&close, .{ .name = abi_name ++ "__close" });
|
||||
@export(&jsFlush, .{ .name = abi_name ++ "__flush" });
|
||||
@export(&jsStart, .{ .name = abi_name ++ "__start" });
|
||||
@export(&jsEnd, .{ .name = abi_name ++ "__end" });
|
||||
@export(&jsConstruct, .{ .name = abi_name ++ "__construct" });
|
||||
@export(&endWithSink, .{ .name = abi_name ++ "__endWithSink" });
|
||||
@export(&updateRef, .{ .name = abi_name ++ "__updateRef" });
|
||||
@export(&memoryCost, .{ .name = abi_name ++ "__memoryCost" });
|
||||
}
|
||||
@export(&finalize, .{ .name = abi_name ++ "__finalize" });
|
||||
@export(&jsWrite, .{ .name = abi_name ++ "__write" });
|
||||
@export(&jsGetInternalFd, .{ .name = abi_name ++ "__getInternalFd" });
|
||||
@export(&close, .{ .name = abi_name ++ "__close" });
|
||||
@export(&jsFlush, .{ .name = abi_name ++ "__flush" });
|
||||
@export(&jsStart, .{ .name = abi_name ++ "__start" });
|
||||
@export(&jsEnd, .{ .name = abi_name ++ "__end" });
|
||||
@export(&jsConstruct, .{ .name = abi_name ++ "__construct" });
|
||||
@export(&endWithSink, .{ .name = abi_name ++ "__endWithSink" });
|
||||
@export(&updateRef, .{ .name = abi_name ++ "__updateRef" });
|
||||
@export(&memoryCost, .{ .name = abi_name ++ "__memoryCost" });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -185,6 +185,8 @@ pub const comptime_string_map = @import("./comptime_string_map.zig");
|
||||
pub const ComptimeStringMap = comptime_string_map.ComptimeStringMap;
|
||||
pub const ComptimeStringMap16 = comptime_string_map.ComptimeStringMap16;
|
||||
pub const ComptimeStringMapWithKeyType = comptime_string_map.ComptimeStringMapWithKeyType;
|
||||
// Old version of SinglyLinkedList
|
||||
pub const SinglyLinkedList = @import("./linked_list.zig").SinglyLinkedList;
|
||||
|
||||
pub const glob = @import("./glob.zig");
|
||||
pub const patch = @import("./patch.zig");
|
||||
@@ -2858,7 +2860,7 @@ pub fn runtimeEmbedFile(
|
||||
abs_path,
|
||||
std.math.maxInt(usize),
|
||||
null,
|
||||
@alignOf(u8),
|
||||
.fromByteUnits(@alignOf(u8)),
|
||||
'\x00',
|
||||
) catch |e| {
|
||||
Output.panic(
|
||||
|
||||
@@ -404,7 +404,7 @@ const AbortHandler = struct {
|
||||
if (Environment.isPosix) {
|
||||
const action = std.posix.Sigaction{
|
||||
.handler = .{ .sigaction = AbortHandler.posixSignalHandler },
|
||||
.mask = std.posix.empty_sigset,
|
||||
.mask = std.posix.sigemptyset(),
|
||||
.flags = std.posix.SA.SIGINFO | std.posix.SA.RESTART | std.posix.SA.RESETHAND,
|
||||
};
|
||||
std.posix.sigaction(std.posix.SIG.INT, &action, null);
|
||||
|
||||
@@ -1489,10 +1489,8 @@ zigInternal.dedent();
|
||||
zigInternal.line("};");
|
||||
zigInternal.line();
|
||||
zigInternal.line("comptime {");
|
||||
zigInternal.line(` if (bun.Environment.export_cpp_apis) {`);
|
||||
zigInternal.line(' for (@typeInfo(binding_internals).@"struct".decls) |decl| {');
|
||||
zigInternal.line(" _ = &@field(binding_internals, decl.name);");
|
||||
zigInternal.line(" }");
|
||||
zigInternal.line(' for (@typeInfo(binding_internals).@"struct".decls) |decl| {');
|
||||
zigInternal.line(" _ = &@field(binding_internals, decl.name);");
|
||||
zigInternal.line(" }");
|
||||
zigInternal.line("}");
|
||||
|
||||
|
||||
@@ -24,9 +24,10 @@ pub fn main() !void {
|
||||
|
||||
const in = brk: {
|
||||
const in_path = args.next() orelse @panic("missing argument");
|
||||
const in = try std.fs.openFileAbsolute(in_path, .{});
|
||||
std.log.info("in_path: {s}", .{in_path});
|
||||
const in = try std.fs.cwd().openFile(in_path, .{});
|
||||
defer in.close();
|
||||
break :brk try in.readToEndAllocOptions(gpa, std.math.maxInt(u32), null, 1, 0);
|
||||
break :brk try in.readToEndAllocOptions(gpa, std.math.maxInt(u32), null, .fromByteUnits(1), 0);
|
||||
};
|
||||
defer gpa.free(in);
|
||||
|
||||
|
||||
@@ -843,7 +843,7 @@ pub fn resetOnPosix() void {
|
||||
if (bun.Environment.enable_asan) return;
|
||||
var act = std.posix.Sigaction{
|
||||
.handler = .{ .sigaction = handleSegfaultPosix },
|
||||
.mask = std.posix.empty_sigset,
|
||||
.mask = std.posix.sigemptyset(),
|
||||
.flags = (std.posix.SA.SIGINFO | std.posix.SA.RESTART | std.posix.SA.RESETHAND),
|
||||
};
|
||||
updatePosixSegfaultHandler(&act) catch {};
|
||||
@@ -877,7 +877,7 @@ pub fn resetSegfaultHandler() void {
|
||||
|
||||
var act = std.posix.Sigaction{
|
||||
.handler = .{ .handler = std.posix.SIG.DFL },
|
||||
.mask = std.posix.empty_sigset,
|
||||
.mask = std.posix.sigemptyset(),
|
||||
.flags = 0,
|
||||
};
|
||||
// To avoid a double-panic, do nothing if an error happens here.
|
||||
@@ -1439,7 +1439,7 @@ fn report(url: []const u8) void {
|
||||
null,
|
||||
null,
|
||||
1, // true
|
||||
0,
|
||||
.{},
|
||||
null,
|
||||
null,
|
||||
&startup_info,
|
||||
@@ -1497,7 +1497,7 @@ fn crash() noreturn {
|
||||
},
|
||||
else => {
|
||||
// Install default handler so that the tkill below will terminate.
|
||||
const sigact = std.posix.Sigaction{ .handler = .{ .handler = std.posix.SIG.DFL }, .mask = std.posix.empty_sigset, .flags = 0 };
|
||||
const sigact = std.posix.Sigaction{ .handler = .{ .handler = std.posix.SIG.DFL }, .mask = std.posix.sigemptyset(), .flags = 0 };
|
||||
inline for (.{
|
||||
std.posix.SIG.SEGV,
|
||||
std.posix.SIG.ILL,
|
||||
|
||||
@@ -27,10 +27,6 @@ pub const isX64 = @import("builtin").target.cpu.arch == .x86_64;
|
||||
pub const isMusl = builtin.target.abi.isMusl();
|
||||
pub const allow_assert = isDebug or isTest or std.builtin.Mode.ReleaseSafe == @import("builtin").mode;
|
||||
pub const show_crash_trace = isDebug or isTest or enable_asan;
|
||||
/// All calls to `@export` should be gated behind this check, so that code
|
||||
/// generators that compile Zig code know not to reference and compile a ton of
|
||||
/// unused code.
|
||||
pub const export_cpp_apis = if (build_options.override_no_export_cpp_apis) false else (@import("builtin").output_mode == .Obj or isTest);
|
||||
|
||||
pub const build_options = @import("build_options");
|
||||
|
||||
|
||||
@@ -223,10 +223,10 @@ const LinuxImpl = struct {
|
||||
else
|
||||
undefined;
|
||||
|
||||
const rc = linux.futex_wait(
|
||||
@as(*const i32, @ptrCast(&ptr.raw)),
|
||||
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAIT,
|
||||
@as(i32, @bitCast(expect)),
|
||||
const rc = linux.futex_4arg(
|
||||
&ptr.raw,
|
||||
.{ .cmd = .WAIT, .private = true },
|
||||
expect,
|
||||
if (timeout != null) &ts else null,
|
||||
);
|
||||
|
||||
@@ -245,10 +245,10 @@ const LinuxImpl = struct {
|
||||
}
|
||||
|
||||
fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
|
||||
const rc = linux.futex_wake(
|
||||
@as(*const i32, @ptrCast(&ptr.raw)),
|
||||
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAKE,
|
||||
std.math.cast(i32, max_waiters) orelse std.math.maxInt(i32),
|
||||
const rc = linux.futex_3arg(
|
||||
&ptr.raw,
|
||||
.{ .cmd = .WAKE, .private = true },
|
||||
max_waiters,
|
||||
);
|
||||
|
||||
switch (linux.E.init(rc)) {
|
||||
|
||||
@@ -785,7 +785,7 @@ fn launcher(comptime mode: LauncherMode, bun_ctx: anytype) mode.RetType() {
|
||||
null,
|
||||
null,
|
||||
1, // true
|
||||
if (is_standalone) 0 else w.CREATE_UNICODE_ENVIRONMENT,
|
||||
.{ .create_unicode_environment = !is_standalone },
|
||||
if (is_standalone) null else @constCast(bun_ctx.environment),
|
||||
null,
|
||||
&startup_info,
|
||||
|
||||
@@ -27,7 +27,7 @@ const LEXER_DEBUGGER_WORKAROUND = false;
|
||||
|
||||
const HashMapPool = struct {
|
||||
const HashMap = std.HashMap(u64, void, IdentityContext, 80);
|
||||
const LinkedList = std.SinglyLinkedList(HashMap);
|
||||
const LinkedList = bun.SinglyLinkedList(HashMap);
|
||||
threadlocal var list: LinkedList = undefined;
|
||||
threadlocal var loaded: bool = false;
|
||||
|
||||
|
||||
124
src/linked_list.zig
Normal file
124
src/linked_list.zig
Normal file
@@ -0,0 +1,124 @@
|
||||
// TODO(zig-upgrade): Migrate to the new intrusive list
|
||||
|
||||
/// A singly-linked list is headed by a single forward pointer. The elements
|
||||
/// are singly-linked for minimum space and pointer manipulation overhead at
|
||||
/// the expense of O(n) removal for arbitrary elements. New elements can be
|
||||
/// added to the list after an existing element or at the head of the list.
|
||||
/// A singly-linked list may only be traversed in the forward direction.
|
||||
/// Singly-linked lists are ideal for applications with large datasets and
|
||||
/// few or no removals or for implementing a LIFO queue.
|
||||
pub fn SinglyLinkedList(comptime T: type) type {
|
||||
return struct {
|
||||
const Self = @This();
|
||||
|
||||
/// Node inside the linked list wrapping the actual data.
|
||||
pub const Node = struct {
|
||||
next: ?*Node = null,
|
||||
data: T,
|
||||
|
||||
pub const Data = T;
|
||||
|
||||
/// Insert a new node after the current one.
|
||||
///
|
||||
/// Arguments:
|
||||
/// new_node: Pointer to the new node to insert.
|
||||
pub fn insertAfter(node: *Node, new_node: *Node) void {
|
||||
new_node.next = node.next;
|
||||
node.next = new_node;
|
||||
}
|
||||
|
||||
/// Remove a node from the list.
|
||||
///
|
||||
/// Arguments:
|
||||
/// node: Pointer to the node to be removed.
|
||||
/// Returns:
|
||||
/// node removed
|
||||
pub fn removeNext(node: *Node) ?*Node {
|
||||
const next_node = node.next orelse return null;
|
||||
node.next = next_node.next;
|
||||
return next_node;
|
||||
}
|
||||
|
||||
/// Iterate over the singly-linked list from this node, until the final node is found.
|
||||
/// This operation is O(N).
|
||||
pub fn findLast(node: *Node) *Node {
|
||||
var it = node;
|
||||
while (true) {
|
||||
it = it.next orelse return it;
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterate over each next node, returning the count of all nodes except the starting one.
|
||||
/// This operation is O(N).
|
||||
pub fn countChildren(node: *const Node) usize {
|
||||
var count: usize = 0;
|
||||
var it: ?*const Node = node.next;
|
||||
while (it) |n| : (it = n.next) {
|
||||
count += 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/// Reverse the list starting from this node in-place.
|
||||
/// This operation is O(N).
|
||||
pub fn reverse(indirect: *?*Node) void {
|
||||
if (indirect.* == null) {
|
||||
return;
|
||||
}
|
||||
var current: *Node = indirect.*.?;
|
||||
while (current.next) |next| {
|
||||
current.next = next.next;
|
||||
next.next = indirect.*;
|
||||
indirect.* = next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
first: ?*Node = null,
|
||||
|
||||
/// Insert a new node at the head.
|
||||
///
|
||||
/// Arguments:
|
||||
/// new_node: Pointer to the new node to insert.
|
||||
pub fn prepend(list: *Self, new_node: *Node) void {
|
||||
new_node.next = list.first;
|
||||
list.first = new_node;
|
||||
}
|
||||
|
||||
/// Remove a node from the list.
|
||||
///
|
||||
/// Arguments:
|
||||
/// node: Pointer to the node to be removed.
|
||||
pub fn remove(list: *Self, node: *Node) void {
|
||||
if (list.first == node) {
|
||||
list.first = node.next;
|
||||
} else {
|
||||
var current_elm = list.first.?;
|
||||
while (current_elm.next != node) {
|
||||
current_elm = current_elm.next.?;
|
||||
}
|
||||
current_elm.next = node.next;
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove and return the first node in the list.
|
||||
///
|
||||
/// Returns:
|
||||
/// A pointer to the first node in the list.
|
||||
pub fn popFirst(list: *Self) ?*Node {
|
||||
const first = list.first orelse return null;
|
||||
list.first = first.next;
|
||||
return first;
|
||||
}
|
||||
|
||||
/// Iterate over all nodes, returning the count.
|
||||
/// This operation is O(N).
|
||||
pub fn len(list: Self) usize {
|
||||
if (list.first) |n| {
|
||||
return 1 + n.countChildren();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -26,7 +26,7 @@ pub fn main() void {
|
||||
if (Environment.isPosix) {
|
||||
var act: std.posix.Sigaction = .{
|
||||
.handler = .{ .handler = std.posix.SIG.IGN },
|
||||
.mask = std.posix.empty_sigset,
|
||||
.mask = std.posix.sigemptyset(),
|
||||
.flags = 0,
|
||||
};
|
||||
std.posix.sigaction(std.posix.SIG.PIPE, &act, null);
|
||||
|
||||
@@ -369,7 +369,7 @@ pub fn MultiArrayList(comptime T: type) type {
|
||||
|
||||
const other_bytes = gpa.alignedAlloc(
|
||||
u8,
|
||||
@alignOf(Elem),
|
||||
.fromByteUnits(@alignOf(Elem)),
|
||||
capacityInBytes(new_len),
|
||||
) catch {
|
||||
const self_slice = self.slice();
|
||||
@@ -444,7 +444,7 @@ pub fn MultiArrayList(comptime T: type) type {
|
||||
assert(new_capacity >= self.len);
|
||||
const new_bytes = try gpa.alignedAlloc(
|
||||
u8,
|
||||
@alignOf(Elem),
|
||||
.fromByteUnits(@alignOf(Elem)),
|
||||
capacityInBytes(new_capacity),
|
||||
);
|
||||
if (self.len == 0) {
|
||||
|
||||
@@ -57,14 +57,6 @@ pub fn init(
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(this: *Router) void {
|
||||
if (comptime Environment.isWindows) {
|
||||
for (this.routes.list.items(.filepath)) |abs_path| {
|
||||
this.allocator.free(abs_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getEntryPoints(this: *const Router) []const string {
|
||||
return this.routes.list.items(.filepath);
|
||||
}
|
||||
|
||||
14
src/sync.zig
14
src/sync.zig
@@ -1106,7 +1106,7 @@ else
|
||||
struct {
|
||||
mutex: Mutex,
|
||||
notified: bool,
|
||||
waiters: std.SinglyLinkedList(Event),
|
||||
waiters: bun.SinglyLinkedList(Event),
|
||||
|
||||
pub fn init() Condvar {
|
||||
return .{
|
||||
@@ -1189,10 +1189,10 @@ else
|
||||
const Futex = switch (@import("builtin").os.tag) {
|
||||
.linux => struct {
|
||||
fn wait(ptr: *const i32, cmp: i32) void {
|
||||
switch (system.getErrno(system.futex_wait(
|
||||
switch (system.getErrno(system.futex_4arg(
|
||||
ptr,
|
||||
system.FUTEX.PRIVATE_FLAG | system.FUTEX.WAIT,
|
||||
cmp,
|
||||
.{ .cmd = .WAIT, .private = true },
|
||||
@bitCast(cmp),
|
||||
null,
|
||||
))) {
|
||||
0 => {},
|
||||
@@ -1203,10 +1203,10 @@ const Futex = switch (@import("builtin").os.tag) {
|
||||
}
|
||||
|
||||
fn wake(ptr: *const i32) void {
|
||||
switch (system.getErrno(system.futex_wake(
|
||||
switch (system.getErrno(system.futex_3arg(
|
||||
ptr,
|
||||
system.FUTEX.PRIVATE_FLAG | system.FUTEX.WAKE,
|
||||
@as(i32, 1),
|
||||
.{ .cmd = .WAKE, .private = true },
|
||||
1,
|
||||
))) {
|
||||
0 => {},
|
||||
std.posix.EFAULT => {},
|
||||
|
||||
@@ -20,7 +20,7 @@ const IdentityContext = @import("../identity_context.zig").IdentityContext;
|
||||
|
||||
const HashMapPool = struct {
|
||||
const HashMap = std.HashMap(u64, void, IdentityContext, 80);
|
||||
const LinkedList = std.SinglyLinkedList(HashMap);
|
||||
const LinkedList = bun.SinglyLinkedList(HashMap);
|
||||
threadlocal var list: LinkedList = undefined;
|
||||
threadlocal var loaded: bool = false;
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ pub fn init(this: *INotifyWatcher, _: []const u8) !void {
|
||||
|
||||
// TODO: convert to bun.sys.Error
|
||||
this.fd = .fromNative(try std.posix.inotify_init1(IN.CLOEXEC));
|
||||
this.eventlist_bytes = &(try bun.default_allocator.alignedAlloc(EventListBytes, @alignOf(Event), 1))[0];
|
||||
this.eventlist_bytes = &(try bun.default_allocator.alignedAlloc(EventListBytes, .fromByteUnits(@alignOf(Event)), 1))[0];
|
||||
log("{} init", .{this.fd});
|
||||
}
|
||||
|
||||
|
||||
@@ -3758,6 +3758,18 @@ pub fn becomeWatcherManager(allocator: std.mem.Allocator) noreturn {
|
||||
}
|
||||
}
|
||||
|
||||
pub extern "kernel32" fn GetEnvironmentStringsW() callconv(.winapi) ?LPWSTR;
|
||||
|
||||
pub extern "kernel32" fn FreeEnvironmentStringsW(
|
||||
penv: LPWSTR,
|
||||
) callconv(.winapi) BOOL;
|
||||
|
||||
pub extern "kernel32" fn GetEnvironmentVariableW(
|
||||
lpName: ?LPCWSTR,
|
||||
lpBuffer: ?[*]WCHAR,
|
||||
nSize: DWORD,
|
||||
) callconv(.winapi) DWORD;
|
||||
|
||||
pub fn spawnWatcherChild(
|
||||
allocator: std.mem.Allocator,
|
||||
procinfo: *std.os.windows.PROCESS_INFORMATION,
|
||||
@@ -3783,7 +3795,10 @@ pub fn spawnWatcherChild(
|
||||
return error.Win32Error;
|
||||
}
|
||||
|
||||
const flags: DWORD = c.CREATE_UNICODE_ENVIRONMENT | c.EXTENDED_STARTUPINFO_PRESENT;
|
||||
const flags: std.os.windows.CreateProcessFlags = .{
|
||||
.create_unicode_environment = true,
|
||||
.extended_startupinfo_present = true,
|
||||
};
|
||||
|
||||
const image_path = exePathW();
|
||||
var wbuf: WPathBuffer = undefined;
|
||||
@@ -3792,9 +3807,9 @@ pub fn spawnWatcherChild(
|
||||
|
||||
const image_pathZ = wbuf[0..image_path.len :0];
|
||||
|
||||
const kernelenv = kernel32.GetEnvironmentStringsW();
|
||||
const kernelenv = GetEnvironmentStringsW();
|
||||
defer if (kernelenv) |envptr| {
|
||||
_ = kernel32.FreeEnvironmentStringsW(envptr);
|
||||
_ = FreeEnvironmentStringsW(envptr);
|
||||
};
|
||||
|
||||
var size: usize = 0;
|
||||
|
||||
Reference in New Issue
Block a user