diff --git a/misctools/features.zig b/misctools/features.zig index 7bedbd042e0925..0541a1e1536a58 100644 --- a/misctools/features.zig +++ b/misctools/features.zig @@ -10,7 +10,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const Features = @import("../src/analytics/analytics_thread.zig").Features; // zig run --main-pkg-path ../ ./features.zig diff --git a/misctools/http_bench.zig b/misctools/http_bench.zig index 3cd147d2eaa81c..97a6815987f7ba 100644 --- a/misctools/http_bench.zig +++ b/misctools/http_bench.zig @@ -8,7 +8,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const clap = @import("../src/deps/zig-clap/clap.zig"); const URL = @import("../src/url.zig").URL; diff --git a/misctools/machbench.zig b/misctools/machbench.zig index d664788eab4b61..e2c2cdd2c73fe6 100644 --- a/misctools/machbench.zig +++ b/misctools/machbench.zig @@ -9,7 +9,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const clap = @import("../src/deps/zig-clap/clap.zig"); const URL = @import("../src/url.zig").URL; diff --git a/misctools/readlink-getfd.zig b/misctools/readlink-getfd.zig index 4522fdc6402c1b..119b4eb7426e60 100644 --- a/misctools/readlink-getfd.zig +++ b/misctools/readlink-getfd.zig @@ -10,7 +10,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; // zig build-exe -Doptimize=ReleaseFast --main-pkg-path ../ ./readlink-getfd.zig pub fn main() anyerror!void { diff --git a/misctools/readlink-realpath.zig b/misctools/readlink-realpath.zig index 827db30dc72f93..9bf317af601b83 100644 --- a/misctools/readlink-realpath.zig +++ b/misctools/readlink-realpath.zig @@ -10,7 +10,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; // zig build-exe -Doptimize=ReleaseFast --main-pkg-path ../ ./readlink-getfd.zig pub fn main() anyerror!void { diff --git a/misctools/tgz.zig b/misctools/tgz.zig index 6a3f9b5722dda3..f1df243127637e 100644 --- a/misctools/tgz.zig +++ b/misctools/tgz.zig @@ -10,7 +10,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const Archive = @import("../src/libarchive/libarchive.zig").Archive; const Zlib = @import("../src/zlib.zig"); diff --git a/root.zig b/root.zig index 4778a56d1b0713..f844d3fcf783dc 100644 --- a/root.zig +++ b/root.zig @@ -10,4 +10,4 @@ pub const completions = struct { }; pub const JavaScriptCore = @import("./src/jsc.zig"); -pub const C = @import("./src/c.zig"); +pub const C = @import("./src/C.zig"); diff --git a/src/c.zig b/src/C.zig similarity index 97% rename from src/c.zig rename to src/C.zig index 1541b9872eaf0e..e975c5c16bf213 100644 --- a/src/c.zig +++ b/src/C.zig @@ -1,18 +1,18 @@ const std = @import("std"); const bun = @import("root").bun; -const Environment = @import("./env.zig"); +const C = @import("root").C; +const Environment = bun.Environment; pub const translated = @import("translated-c-headers"); const PlatformSpecific = switch (Environment.os) { - .mac => @import("./darwin_c.zig"), - .linux => @import("./linux_c.zig"), - .windows => @import("./windows_c.zig"), + .mac => @import("C/darwin.zig"), + .linux => @import("C/linux.zig"), + .windows => @import("C/windows.zig"), else => struct {}, }; pub usingnamespace PlatformSpecific; -const C = std.c; const builtin = @import("builtin"); const posix = std.posix; const mem = std.mem; @@ -25,8 +25,8 @@ const mode_t = bun.Mode; const libc_stat = bun.Stat; const zeroes = mem.zeroes; -pub const darwin = @import("./darwin_c.zig"); -pub const linux = @import("./linux_c.zig"); +pub const darwin = @import("C/darwin.zig"); +pub const linux = @import("C/linux.zig"); pub extern "c" fn chmod([*c]const u8, mode_t) c_int; pub extern "c" fn fchmod(std.c.fd_t, mode_t) c_int; pub extern "c" fn fchmodat(c_int, [*c]const u8, mode_t, c_int) c_int; @@ -50,7 +50,7 @@ pub fn lstat_absolute(path: [:0]const u8) !Stat { } var st = zeroes(libc_stat); - switch (errno(bun.C.lstat(path.ptr, &st))) { + switch (errno(C.lstat(path.ptr, &st))) { .SUCCESS => {}, .NOENT => return error.FileNotFound, // .EINVAL => unreachable, @@ -167,9 +167,9 @@ pub fn copyFileZSlowWithHandle(in_handle: bun.FileDescriptor, to_dir: bun.FileDe }; const src_len = bun.windows.GetFinalPathNameByHandleW(in_handle.cast(), &buf1, buf1.len, 0); if (src_len == 0) { - return Maybe(void).errno(bun.C.E.BUSY, .GetFinalPathNameByHandle); + return Maybe(void).errno(C.E.BUSY, .GetFinalPathNameByHandle); } else if (src_len >= buf1.len) { - return Maybe(void).errno(bun.C.E.NAMETOOLONG, .GetFinalPathNameByHandle); + return Maybe(void).errno(C.E.NAMETOOLONG, .GetFinalPathNameByHandle); } const src = buf1[0..src_len :0]; return bun.copyFile(src, dest); @@ -501,5 +501,5 @@ pub const geteuid = translated.geteuid; pub const getpwuid_r = translated.getpwuid_r; export fn Bun__errnoName(err: c_int) ?[*:0]const u8 { - return @tagName(bun.C.SystemErrno.init(err) orelse return null); + return @tagName(C.SystemErrno.init(err) orelse return null); } diff --git a/src/darwin_c.zig b/src/C/darwin.zig similarity index 100% rename from src/darwin_c.zig rename to src/C/darwin.zig diff --git a/src/linux_c.zig b/src/C/linux.zig similarity index 99% rename from src/linux_c.zig rename to src/C/linux.zig index d29d846da37f0a..5f104703a200c3 100644 --- a/src/linux_c.zig +++ b/src/C/linux.zig @@ -1,5 +1,6 @@ const std = @import("std"); const bun = @import("root").bun; +const C = @import("root").C; pub extern "C" fn memmem(haystack: [*]const u8, haystacklen: usize, needle: [*]const u8, needlelen: usize) ?[*]const u8; pub const SystemErrno = enum(u8) { SUCCESS = 0, @@ -619,14 +620,14 @@ const posix_spawn_file_actions_addchdir_np_type = *const fn (actions: *posix_spa /// When not available, these functions will return 0. pub fn posix_spawn_file_actions_addfchdir_np(actions: *posix_spawn_file_actions_t, filedes: std.posix.fd_t) c_int { - const function = bun.C.dlsym(posix_spawn_file_actions_addfchdir_np_type, "posix_spawn_file_actions_addfchdir_np") orelse + const function = C.dlsym(posix_spawn_file_actions_addfchdir_np_type, "posix_spawn_file_actions_addfchdir_np") orelse return 0; return function(actions, filedes); } /// When not available, these functions will return 0. pub fn posix_spawn_file_actions_addchdir_np(actions: *posix_spawn_file_actions_t, path: [*:0]const u8) c_int { - const function = bun.C.dlsym(posix_spawn_file_actions_addchdir_np_type, "posix_spawn_file_actions_addchdir_np") orelse + const function = C.dlsym(posix_spawn_file_actions_addchdir_np_type, "posix_spawn_file_actions_addchdir_np") orelse return 0; return function(actions, path); } diff --git a/src/windows_c.zig b/src/C/windows.zig similarity index 99% rename from src/windows_c.zig rename to src/C/windows.zig index df725226c65c49..1c2adc78ab0753 100644 --- a/src/windows_c.zig +++ b/src/C/windows.zig @@ -1,5 +1,6 @@ const std = @import("std"); const bun = @import("root").bun; +const C = @import("root").C; const builtin = @import("builtin"); const win32 = std.os.windows; const posix = std.posix; @@ -1067,7 +1068,7 @@ pub const UV_EUNATCH = -uv.UV_EUNATCH; pub const off_t = i64; pub fn preallocate_file(_: posix.fd_t, _: off_t, _: off_t) !void {} -const uv = @import("./deps/libuv.zig"); +const uv = @import("../deps/libuv.zig"); pub const E = enum(u16) { SUCCESS = 0, @@ -1437,7 +1438,7 @@ pub fn moveOpenedFileAt( var rename_info_buf: [struct_buf_len]u8 align(@alignOf(w.FILE_RENAME_INFORMATION_EX)) = undefined; const struct_len = @sizeOf(w.FILE_RENAME_INFORMATION_EX) - 1 + new_file_name.len * 2; - if (struct_len > struct_buf_len) return Maybe(void).errno(bun.C.E.NAMETOOLONG, .NtSetInformationFile); + if (struct_len > struct_buf_len) return Maybe(void).errno(C.E.NAMETOOLONG, .NtSetInformationFile); const rename_info = @as(*w.FILE_RENAME_INFORMATION_EX, @ptrCast(&rename_info_buf)); var io_status_block: w.IO_STATUS_BLOCK = undefined; diff --git a/src/Global.zig b/src/Global.zig index f935d3b958c3a9..0e90c32c3e0e89 100644 --- a/src/Global.zig +++ b/src/Global.zig @@ -6,6 +6,7 @@ const use_mimalloc = bun.use_mimalloc; const StringTypes = @import("./string_types.zig"); const Mimalloc = bun.Mimalloc; const bun = @import("root").bun; +const C = @import("root").C; const version_string = Environment.version_string; @@ -119,7 +120,7 @@ pub fn exit(code: u32) noreturn { Bun__onExit(); std.os.windows.kernel32.ExitProcess(code); }, - else => bun.C.quick_exit(@bitCast(code)), + else => C.quick_exit(@bitCast(code)), } } diff --git a/src/StandaloneModuleGraph.zig b/src/StandaloneModuleGraph.zig index aae3c32a178269..ff59386afbafdb 100644 --- a/src/StandaloneModuleGraph.zig +++ b/src/StandaloneModuleGraph.zig @@ -2,6 +2,7 @@ //! But this incurred a fixed 350ms overhead on every build, which is unacceptable //! so we give up on codesigning support on macOS for now until we can find a better solution const bun = @import("root").bun; +const C = @import("root").C; const std = @import("std"); const Schema = bun.Schema.Api; const strings = bun.strings; @@ -638,7 +639,7 @@ pub const StandaloneModuleGraph = struct { // the final 8 bytes in the file are the length of the module graph with padding, excluding the trailer and offsets _ = Syscall.write(cloned_executable_fd, std.mem.asBytes(&total_byte_count)); if (comptime !Environment.isWindows) { - _ = bun.C.fchmod(cloned_executable_fd.int(), 0o777); + _ = C.fchmod(cloned_executable_fd.int(), 0o777); } if (Environment.isWindows and inject_options.windows_hide_console) { @@ -709,14 +710,14 @@ pub const StandaloneModuleGraph = struct { break :brk outfile_buf_u16[0..outfile_w.len :0]; }; - bun.C.moveOpenedFileAtLoose(fd, bun.toFD(root_dir.fd), outfile_slice, true).unwrap() catch |err| { + C.moveOpenedFileAtLoose(fd, bun.toFD(root_dir.fd), outfile_slice, true).unwrap() catch |err| { if (err == error.EISDIR) { Output.errGeneric("{} is a directory. Please choose a different --outfile or delete the directory", .{bun.fmt.utf16(outfile_slice)}); } else { Output.err(err, "failed to move executable to result path", .{}); } - _ = bun.C.deleteOpenedFile(fd); + _ = C.deleteOpenedFile(fd); Global.exit(1); }; @@ -761,7 +762,7 @@ pub const StandaloneModuleGraph = struct { } } - bun.C.moveFileZWithHandle( + C.moveFileZWithHandle( fd, bun.FD.cwd(), bun.sliceTo(&(try std.posix.toPosixPath(temp_location)), 0), diff --git a/src/analytics/analytics_thread.zig b/src/analytics/analytics_thread.zig index d8c77de1eda461..841e99ae122d98 100644 --- a/src/analytics/analytics_thread.zig +++ b/src/analytics/analytics_thread.zig @@ -8,7 +8,7 @@ const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const FeatureFlags = bun.FeatureFlags; -const C = bun.C; +const C = @import("root").C; const sync = @import("../sync.zig"); const std = @import("std"); diff --git a/src/async/posix_event_loop.zig b/src/async/posix_event_loop.zig index 2dfb108952fae8..3cec39f65062d9 100644 --- a/src/async/posix_event_loop.zig +++ b/src/async/posix_event_loop.zig @@ -3,6 +3,7 @@ const Output = bun.Output; const JSC = bun.JSC; const uws = bun.uws; const Environment = bun.Environment; +const C = @import("root").C; const std = @import("std"); pub const Loop = uws.Loop; @@ -902,7 +903,7 @@ pub const FilePoll = struct { &timeout, ); - if (bun.C.getErrno(rc) == .INTR) continue; + if (C.getErrno(rc) == .INTR) continue; break :rc rc; } }; @@ -919,7 +920,7 @@ pub const FilePoll = struct { // indicate the error condition. } - const errno = bun.C.getErrno(rc); + const errno = C.getErrno(rc); if (errno != .SUCCESS) { this.deactivate(loop); @@ -1071,7 +1072,7 @@ pub const FilePoll = struct { // indicate the error condition. } - const errno = bun.C.getErrno(rc); + const errno = C.getErrno(rc); switch (rc) { std.math.minInt(@TypeOf(rc))...-1 => return JSC.Maybe(void).errnoSys(@intFromEnum(errno), .kevent).?, else => {}, diff --git a/src/bake/DevServer.zig b/src/bake/DevServer.zig index 096220b9c7fc52..bfb7e973a22af2 100644 --- a/src/bake/DevServer.zig +++ b/src/bake/DevServer.zig @@ -6,6 +6,53 @@ //! adjusting imports) must always rebundle only that one file. //! //! All work is held in-memory, using manually managed data-oriented design. + +const std = @import("std"); +const Allocator = std.mem.Allocator; +const Mutex = bun.Mutex; +const ArrayListUnmanaged = std.ArrayListUnmanaged; +const AutoArrayHashMapUnmanaged = std.AutoArrayHashMapUnmanaged; + +const bun = @import("root").bun; +const Environment = bun.Environment; +const assert = bun.assert; +const DynamicBitSetUnmanaged = bun.bit_set.DynamicBitSetUnmanaged; + +const bake = bun.bake; +const FrameworkRouter = bake.FrameworkRouter; +const Route = FrameworkRouter.Route; +const OpaqueFileId = FrameworkRouter.OpaqueFileId; + +const Log = bun.logger.Log; +const Output = bun.Output; + +const Transpiler = bun.transpiler.Transpiler; +const BundleV2 = bun.bundle_v2.BundleV2; + +const Define = bun.options.Define; +const OutputFile = bun.options.OutputFile; + +const uws = bun.uws; +const App = uws.NewApp(false); +const AnyWebSocket = uws.AnyWebSocket; +const Request = uws.Request; +const Response = App.Response; + +const MimeType = bun.http.MimeType; + +const JSC = bun.JSC; +const Watcher = bun.JSC.Watcher; +const JSValue = JSC.JSValue; +const VirtualMachine = JSC.VirtualMachine; +const JSModuleLoader = JSC.JSModuleLoader; +const EventLoopHandle = JSC.EventLoopHandle; +const JSInternalPromise = JSC.JSInternalPromise; + +const ThreadlocalArena = @import("../allocators/mimalloc_arena.zig").Arena; +const Chunk = bun.bundle_v2.Chunk; + +const C = @import("root").C; + pub const DevServer = @This(); pub const debug = bun.Output.Scoped(.Bake, false); pub const igLog = bun.Output.scoped(.IncrementalGraph, false); @@ -4258,7 +4305,7 @@ pub fn onFileUpdate(dev: *DevServer, events: []Watcher.Event, changed_files: []? pub fn onWatchError(_: *DevServer, err: bun.sys.Error) void { // TODO: how to recover? the watcher can't just ... crash???????? - Output.err(@as(bun.C.E, @enumFromInt(err.errno)), "Watcher crashed", .{}); + Output.err(@as(C.E, @enumFromInt(err.errno)), "Watcher crashed", .{}); if (bun.Environment.isDebug) { bun.todoPanic(@src(), "Watcher crash", .{}); } @@ -4443,47 +4490,3 @@ pub const EntryPointList = struct { } } }; - -const std = @import("std"); -const Allocator = std.mem.Allocator; -const Mutex = bun.Mutex; -const ArrayListUnmanaged = std.ArrayListUnmanaged; -const AutoArrayHashMapUnmanaged = std.AutoArrayHashMapUnmanaged; - -const bun = @import("root").bun; -const Environment = bun.Environment; -const assert = bun.assert; -const DynamicBitSetUnmanaged = bun.bit_set.DynamicBitSetUnmanaged; - -const bake = bun.bake; -const FrameworkRouter = bake.FrameworkRouter; -const Route = FrameworkRouter.Route; -const OpaqueFileId = FrameworkRouter.OpaqueFileId; - -const Log = bun.logger.Log; -const Output = bun.Output; - -const Transpiler = bun.transpiler.Transpiler; -const BundleV2 = bun.bundle_v2.BundleV2; - -const Define = bun.options.Define; -const OutputFile = bun.options.OutputFile; - -const uws = bun.uws; -const App = uws.NewApp(false); -const AnyWebSocket = uws.AnyWebSocket; -const Request = uws.Request; -const Response = App.Response; - -const MimeType = bun.http.MimeType; - -const JSC = bun.JSC; -const Watcher = bun.JSC.Watcher; -const JSValue = JSC.JSValue; -const VirtualMachine = JSC.VirtualMachine; -const JSModuleLoader = JSC.JSModuleLoader; -const EventLoopHandle = JSC.EventLoopHandle; -const JSInternalPromise = JSC.JSInternalPromise; - -const ThreadlocalArena = @import("../allocators/mimalloc_arena.zig").Arena; -const Chunk = bun.bundle_v2.Chunk; diff --git a/src/bun.js/RuntimeTranspilerCache.zig b/src/bun.js/RuntimeTranspilerCache.zig index 3eac90cbf6aeae..dac6b9f60d569d 100644 --- a/src/bun.js/RuntimeTranspilerCache.zig +++ b/src/bun.js/RuntimeTranspilerCache.zig @@ -13,6 +13,7 @@ const expected_version = 13; const bun = @import("root").bun; +const C = @import("root").C; const std = @import("std"); const Output = bun.Output; const JSC = bun.JSC; @@ -245,7 +246,7 @@ pub const RuntimeTranspilerCache = struct { } bun.assert(end_position == @as(i64, @intCast(sourcemap.len + output_bytes.len + Metadata.size))); - bun.C.preallocate_file(tmpfile.fd.cast(), 0, @intCast(end_position)) catch {}; + C.preallocate_file(tmpfile.fd.cast(), 0, @intCast(end_position)) catch {}; while (position < end_position) { const written = try bun.sys.pwritev(tmpfile.fd, vecs, position).unwrap(); if (written <= 0) { diff --git a/src/bun.js/api/bun/dns_resolver.zig b/src/bun.js/api/bun/dns_resolver.zig index 1ae5ccd9262333..6b5286318a8c31 100644 --- a/src/bun.js/api/bun/dns_resolver.zig +++ b/src/bun.js/api/bun/dns_resolver.zig @@ -2,6 +2,7 @@ const Bun = @This(); const default_allocator = bun.default_allocator; const bun = @import("root").bun; const Environment = bun.Environment; +const C = @import("root").C; const Global = bun.Global; const strings = bun.strings; @@ -44,7 +45,7 @@ const LibInfo = struct { const RTLD_LAZY = 1; const RTLD_LOCAL = 4; - handle = bun.C.dlopen("libinfo.dylib", RTLD_LAZY | RTLD_LOCAL); + handle = C.dlopen("libinfo.dylib", RTLD_LAZY | RTLD_LOCAL); if (handle == null) Output.debug("libinfo.dylib not found", .{}); return handle; @@ -54,7 +55,7 @@ const LibInfo = struct { pub fn get() ?*const GetaddrinfoAsyncStart { bun.Environment.onlyMac(); - return bun.C.dlsymWithHandle(*const GetaddrinfoAsyncStart, "getaddrinfo_async_start", getHandle); + return C.dlsymWithHandle(*const GetaddrinfoAsyncStart, "getaddrinfo_async_start", getHandle); } }.get; @@ -62,14 +63,14 @@ const LibInfo = struct { pub fn get() ?*const GetaddrinfoAsyncHandleReply { bun.Environment.onlyMac(); - return bun.C.dlsymWithHandle(*const GetaddrinfoAsyncHandleReply, "getaddrinfo_async_handle_reply", getHandle); + return C.dlsymWithHandle(*const GetaddrinfoAsyncHandleReply, "getaddrinfo_async_handle_reply", getHandle); } }.get; pub fn get() ?*const GetaddrinfoAsyncCancel { bun.Environment.onlyMac(); - return bun.C.dlsymWithHandle(*const GetaddrinfoAsyncCancel, "getaddrinfo_async_cancel", getHandle); + return C.dlsymWithHandle(*const GetaddrinfoAsyncCancel, "getaddrinfo_async_cancel", getHandle); } pub fn lookup(this: *DNSResolver, query: GetAddrInfo, globalThis: *JSC.JSGlobalObject) JSC.JSValue { @@ -115,7 +116,7 @@ const LibInfo = struct { ); if (errno != 0) { - request.head.promise.rejectTask(globalThis, globalThis.createErrorInstance("getaddrinfo_async_start error: {s}", .{@tagName(bun.C.getErrno(errno))})); + request.head.promise.rejectTask(globalThis, globalThis.createErrorInstance("getaddrinfo_async_start error: {s}", .{@tagName(C.getErrno(errno))})); if (request.cache.pending_cache) this.pending_host_cache_native.available.set(request.cache.pos_in_pending); this.vm.allocator.destroy(request); @@ -1395,7 +1396,7 @@ pub const InternalDNS = struct { // https://github.com/nodejs/node/issues/33816 // https://github.com/aio-libs/aiohttp/issues/5357 // https://github.com/libuv/libuv/issues/2225 - .flags = if (Environment.isPosix) bun.C.netdb.AI_ADDRCONFIG else 0, + .flags = if (Environment.isPosix) C.netdb.AI_ADDRCONFIG else 0, .next = null, .protocol = 0, .socktype = std.c.SOCK.STREAM, diff --git a/src/bun.js/api/bun/process.zig b/src/bun.js/api/bun/process.zig index 0c353110daf6a5..2bdcf46a204b23 100644 --- a/src/bun.js/api/bun/process.zig +++ b/src/bun.js/api/bun/process.zig @@ -1,5 +1,6 @@ const bun = @import("root").bun; const std = @import("std"); +const C = @import("root").C; const PosixSpawn = bun.spawn; const Environment = bun.Environment; const JSC = bun.JSC; @@ -496,7 +497,7 @@ pub const Process = struct { .waiter_thread, .fd => { const err = std.c.kill(this.pid, signal); if (err != 0) { - const errno_ = bun.C.getErrno(err); + const errno_ = C.getErrno(err); // if the process was already killed don't throw if (errno_ != .SRCH) @@ -510,7 +511,7 @@ pub const Process = struct { .uv => |*handle| { if (handle.kill(signal).toError(.kill)) |err| { // if the process was already killed don't throw - if (err.errno != @intFromEnum(bun.C.E.SRCH)) { + if (err.errno != @intFromEnum(C.E.SRCH)) { return .{ .err = err }; } } @@ -1135,7 +1136,7 @@ pub const PosixSpawnResult = struct { pidfd_flags, ); while (true) { - switch (bun.C.getErrno(rc)) { + switch (C.getErrno(rc)) { .SUCCESS => return JSC.Maybe(PidFDType){ .result = @intCast(rc) }, .INTR => { rc = std.os.linux.pidfd_open( @@ -1216,13 +1217,13 @@ pub fn spawnProcessPosix( var attr = try PosixSpawn.Attr.init(); defer attr.deinit(); - var flags: i32 = bun.C.POSIX_SPAWN_SETSIGDEF | bun.C.POSIX_SPAWN_SETSIGMASK; + var flags: i32 = C.POSIX_SPAWN_SETSIGDEF | C.POSIX_SPAWN_SETSIGMASK; if (comptime Environment.isMac) { - flags |= bun.C.POSIX_SPAWN_CLOEXEC_DEFAULT; + flags |= C.POSIX_SPAWN_CLOEXEC_DEFAULT; if (options.use_execve_on_macos) { - flags |= bun.C.POSIX_SPAWN_SETEXEC; + flags |= C.POSIX_SPAWN_SETEXEC; if (options.stdin == .buffer or options.stdout == .buffer or options.stderr == .buffer) { Output.panic("Internal error: stdin, stdout, and stderr cannot be buffered when use_execve_on_macos is true", .{}); @@ -1231,7 +1232,7 @@ pub fn spawnProcessPosix( } if (options.detached) { - flags |= bun.C.POSIX_SPAWN_SETSID; + flags |= C.POSIX_SPAWN_SETSID; } if (options.cwd.len > 0) { @@ -1825,9 +1826,9 @@ pub const sync = struct { chunks: std.ArrayList([]u8) = .{ .items = &.{}, .allocator = bun.default_allocator, .capacity = 0 }, pipe: *uv.Pipe, - err: bun.C.E = .SUCCESS, + err: C.E = .SUCCESS, context: *SyncWindowsProcess, - onDoneCallback: *const fn (*SyncWindowsProcess, tag: bun.FDTag, chunks: []const []u8, err: bun.C.E) void = &SyncWindowsProcess.onReaderDone, + onDoneCallback: *const fn (*SyncWindowsProcess, tag: bun.FDTag, chunks: []const []u8, err: C.E) void = &SyncWindowsProcess.onReaderDone, tag: bun.FDTag = .none, pub usingnamespace bun.New(@This()); @@ -1840,7 +1841,7 @@ pub const sync = struct { this.chunks.append(@constCast(data)) catch bun.outOfMemory(); } - fn onError(this: *SyncWindowsPipeReader, err: bun.C.E) void { + fn onError(this: *SyncWindowsPipeReader, err: C.E) void { this.err = err; this.pipe.close(onClose); } @@ -1867,7 +1868,7 @@ pub const sync = struct { const SyncWindowsProcess = struct { stderr: []const []u8 = &.{}, stdout: []const []u8 = &.{}, - err: bun.C.E = .SUCCESS, + err: C.E = .SUCCESS, waiting_count: u8 = 1, process: *Process, status: ?Status = null, @@ -1881,7 +1882,7 @@ pub const sync = struct { this.process.deref(); } - pub fn onReaderDone(this: *SyncWindowsProcess, tag: bun.FDTag, chunks: []const []u8, err: bun.C.E) void { + pub fn onReaderDone(this: *SyncWindowsProcess, tag: bun.FDTag, chunks: []const []u8, err: C.E) void { switch (tag) { .stderr => { this.stderr = chunks; @@ -2171,7 +2172,7 @@ pub const sync = struct { } const rc = std.c.poll(poll_fds.ptr, @intCast(poll_fds.len), -1); - switch (bun.C.getErrno(rc)) { + switch (C.getErrno(rc)) { .SUCCESS => {}, .AGAIN, .INTR => continue, else => |err| return .{ .err = bun.sys.Error.fromCode(err, .poll) }, diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig index 7a2fef50eb0484..d72a242d44d478 100644 --- a/src/bun.js/api/bun/socket.zig +++ b/src/bun.js/api/bun/socket.zig @@ -1,5 +1,6 @@ const default_allocator = bun.default_allocator; const bun = @import("root").bun; +const C = @import("root").C; const Environment = bun.Environment; const Global = bun.Global; @@ -693,10 +694,10 @@ pub const Listener = struct { hostname_or_unix.deinit(); } - const errno = @intFromEnum(bun.C.getErrno(@as(c_int, -1))); + const errno = @intFromEnum(C.getErrno(@as(c_int, -1))); if (errno != 0) { err.put(globalObject, ZigString.static("errno"), JSValue.jsNumber(errno)); - if (bun.C.SystemErrno.init(errno)) |str| { + if (C.SystemErrno.init(errno)) |str| { err.put(globalObject, ZigString.static("code"), ZigString.init(@tagName(str)).toJS(globalObject)); } } @@ -793,7 +794,7 @@ pub const Listener = struct { log("Failed to listen {d}", .{errno}); if (errno != 0) { err.put(globalObject, ZigString.static("errno"), JSValue.jsNumber(errno)); - if (bun.C.SystemErrno.init(errno)) |str| { + if (C.SystemErrno.init(errno)) |str| { err.put(globalObject, ZigString.static("code"), ZigString.init(@tagName(str)).toJS(globalObject)); } } @@ -1267,7 +1268,7 @@ pub const Listener = struct { SocketType.dataSetCached(socket.getThisValue(globalObject), globalObject, default_data); socket.flags.allow_half_open = socket_config.allowHalfOpen; socket.doConnect(connection) catch { - socket.handleConnectError(@intFromEnum(if (port == null) bun.C.SystemErrno.ENOENT else bun.C.SystemErrno.ECONNREFUSED)); + socket.handleConnectError(@intFromEnum(if (port == null) C.SystemErrno.ENOENT else C.SystemErrno.ECONNREFUSED)); return promise_value; }; @@ -1615,9 +1616,9 @@ fn NewSocket(comptime ssl: bool) type { .syscall = bun.String.static("connect"), // For some reason errno is 0 which causes this to be success. // Unix socket emits ENOENT - .code = if (errno == @intFromEnum(bun.C.SystemErrno.ENOENT)) bun.String.static("ENOENT") else bun.String.static("ECONNREFUSED"), + .code = if (errno == @intFromEnum(C.SystemErrno.ENOENT)) bun.String.static("ENOENT") else bun.String.static("ECONNREFUSED"), // .code = bun.String.static(@tagName(bun.sys.getErrno(errno))), - // .code = bun.String.static(@tagName(@as(bun.C.E, @enumFromInt(errno)))), + // .code = bun.String.static(@tagName(@as(C.E, @enumFromInt(errno)))), }; vm.eventLoop().enter(); defer { @@ -2261,7 +2262,7 @@ fn NewSocket(comptime ssl: bool) type { if (written > 0) { if (remaining_in_buffered_data.len > 0) { var input_buffer = this.buffered_data_for_node_net.slice(); - bun.C.memmove(input_buffer.ptr, input_buffer.ptr[written..], remaining_in_buffered_data.len); + C.memmove(input_buffer.ptr, input_buffer.ptr[written..], remaining_in_buffered_data.len); this.buffered_data_for_node_net.len = @truncate(remaining_in_buffered_data.len); } } @@ -2289,7 +2290,7 @@ fn NewSocket(comptime ssl: bool) type { const len = @as(usize, @intCast(this.buffered_data_for_node_net.len)) - wrote; bun.debugAssert(len <= this.buffered_data_for_node_net.len); bun.debugAssert(len <= this.buffered_data_for_node_net.cap); - bun.C.memmove(this.buffered_data_for_node_net.ptr, this.buffered_data_for_node_net.ptr[wrote..], len); + C.memmove(this.buffered_data_for_node_net.ptr, this.buffered_data_for_node_net.ptr[wrote..], len); this.buffered_data_for_node_net.len = @truncate(len); } } @@ -2425,7 +2426,7 @@ fn NewSocket(comptime ssl: bool) type { if (written > 0) { if (this.buffered_data_for_node_net.len > written) { const remaining = this.buffered_data_for_node_net.slice()[written..]; - bun.C.memmove(this.buffered_data_for_node_net.ptr, remaining.ptr, remaining.len); + C.memmove(this.buffered_data_for_node_net.ptr, remaining.ptr, remaining.len); this.buffered_data_for_node_net.len = @truncate(remaining.len); } else { this.buffered_data_for_node_net.deinitWithAllocator(bun.default_allocator); @@ -3718,7 +3719,7 @@ pub const DuplexUpgradeContext = struct { } } else { if (this.tls) |tls| { - tls.handleConnectError(@intFromEnum(bun.C.SystemErrno.ECONNREFUSED)); + tls.handleConnectError(@intFromEnum(C.SystemErrno.ECONNREFUSED)); } } } @@ -3751,7 +3752,7 @@ pub const DuplexUpgradeContext = struct { bun.outOfMemory(); }, else => { - const errno = @intFromEnum(bun.C.SystemErrno.ECONNREFUSED); + const errno = @intFromEnum(C.SystemErrno.ECONNREFUSED); if (this.tls) |tls| { const socket = TLSSocket.Socket.fromDuplex(&this.upgrade); @@ -4116,10 +4117,10 @@ pub const WindowsNamedPipeContext = if (Environment.isWindows) struct { errdefer { switch (socket) { .tls => |tls| { - tls.handleConnectError(@intFromEnum(bun.C.SystemErrno.ENOENT)); + tls.handleConnectError(@intFromEnum(C.SystemErrno.ENOENT)); }, .tcp => |tcp| { - tcp.handleConnectError(@intFromEnum(bun.C.SystemErrno.ENOENT)); + tcp.handleConnectError(@intFromEnum(C.SystemErrno.ENOENT)); }, .none => {}, } @@ -4136,10 +4137,10 @@ pub const WindowsNamedPipeContext = if (Environment.isWindows) struct { errdefer { switch (socket) { .tls => |tls| { - tls.handleConnectError(@intFromEnum(bun.C.SystemErrno.ENOENT)); + tls.handleConnectError(@intFromEnum(C.SystemErrno.ENOENT)); }, .tcp => |tcp| { - tcp.handleConnectError(@intFromEnum(bun.C.SystemErrno.ENOENT)); + tcp.handleConnectError(@intFromEnum(C.SystemErrno.ENOENT)); }, .none => {}, } @@ -4334,7 +4335,7 @@ pub fn jsCreateSocketPair(global: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JS var fds_: [2]std.c.fd_t = .{ 0, 0 }; const rc = std.c.socketpair(std.posix.AF.UNIX, std.posix.SOCK.STREAM, 0, &fds_); if (rc != 0) { - const err = bun.sys.Error.fromCode(bun.C.getErrno(rc), .socketpair); + const err = bun.sys.Error.fromCode(C.getErrno(rc), .socketpair); return global.throwValue(err.toJSC(global)); } diff --git a/src/bun.js/api/bun/spawn.zig b/src/bun.js/api/bun/spawn.zig index 0f937974b6badf..f98da200ace084 100644 --- a/src/bun.js/api/bun/spawn.zig +++ b/src/bun.js/api/bun/spawn.zig @@ -2,6 +2,7 @@ const JSC = bun.JSC; const bun = @import("root").bun; const string = bun.string; const std = @import("std"); +const C = @import("root").C; const Output = bun.Output; fn _getSystem() type { @@ -9,7 +10,7 @@ fn _getSystem() type { // the "usingnamespace" is evaluating in dead branches return brk: { if (comptime bun.Environment.isLinux) { - const Type = bun.C.linux; + const Type = C.linux; break :brk struct { pub usingnamespace std.posix.system; pub usingnamespace Type; @@ -137,14 +138,14 @@ pub const BunSpawn = struct { var flags: c_int = 0; if (self.detached) { - flags |= bun.C.POSIX_SPAWN_SETSID; + flags |= C.POSIX_SPAWN_SETSID; } return @intCast(flags); } pub fn set(self: *Attr, flags: u16) !void { - self.detached = (flags & bun.C.POSIX_SPAWN_SETSID) != 0; + self.detached = (flags & C.POSIX_SPAWN_SETSID) != 0; } pub fn resetSignals(this: *Attr) !void { @@ -388,7 +389,7 @@ pub const PosixSpawn = struct { }); // Unlike most syscalls, posix_spawn returns 0 on success and an errno on failure. - // That is why bun.C.getErrno() is not used here, since that checks for -1. + // That is why C.getErrno() is not used here, since that checks for -1. if (rc == 0) { return Maybe(pid_t){ .result = pid }; } diff --git a/src/bun.js/api/bun/spawn/stdio.zig b/src/bun.js/api/bun/spawn/stdio.zig index 8a989d1ab0e35d..b1f684253730da 100644 --- a/src/bun.js/api/bun/spawn/stdio.zig +++ b/src/bun.js/api/bun/spawn/stdio.zig @@ -11,6 +11,7 @@ const JSGlobalObject = JSC.JSGlobalObject; const posix = std.posix; const Output = bun.Output; const os = std.os; +const C = @import("root").C; const uv = bun.windows.libuv; pub const Stdio = union(enum) { @@ -47,7 +48,7 @@ pub const Stdio = union(enum) { stdin_used_as_out, out_used_as_stdin, blob_used_as_out, - uv_pipe: bun.C.E, + uv_pipe: C.E, pub fn toStr(this: *const @This()) []const u8 { return switch (this.*) { diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 686bdaf49f67ad..e936a0ff29e5d3 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -1,6 +1,7 @@ const Bun = @This(); const default_allocator = bun.default_allocator; const bun = @import("root").bun; +const C = @import("root").C; const Environment = bun.Environment; const AnyBlob = bun.JSC.WebCore.AnyBlob; const Global = bun.Global; @@ -2592,7 +2593,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp const val = linux.sendfile(this.sendfile.socket_fd.cast(), this.sendfile.fd.cast(), &signed_offset, this.sendfile.remain); this.sendfile.offset = @as(Blob.SizeType, @intCast(signed_offset)); - const errcode = bun.C.getErrno(val); + const errcode = C.getErrno(val); this.sendfile.remain -|= @as(Blob.SizeType, @intCast(this.sendfile.offset -| start)); @@ -2607,7 +2608,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp } else { var sbytes: std.posix.off_t = adjusted_count; const signed_offset = @as(i64, @bitCast(@as(u64, this.sendfile.offset))); - const errcode = bun.C.getErrno(std.c.sendfile( + const errcode = C.getErrno(std.c.sendfile( this.sendfile.fd.cast(), this.sendfile.socket_fd.cast(), signed_offset, @@ -6826,7 +6827,7 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp if (comptime Environment.isLinux) { const rc: i32 = -1; const code = Sys.getErrno(rc); - if (code == bun.C.E.ACCES) { + if (code == C.E.ACCES) { error_instance = (JSC.SystemError{ .message = bun.String.init(std.fmt.bufPrint(&output_buf, "permission denied {s}:{d}", .{ tcp.hostname orelse "0.0.0.0", tcp.port }) catch "Failed to start server"), .code = bun.String.static("EACCES"), diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig index 7bc75dc56af277..cb87ab65fc4107 100644 --- a/src/bun.js/base.zig +++ b/src/bun.js/base.zig @@ -9,7 +9,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const JavaScript = @import("./javascript.zig"); const JSC = bun.JSC; const WebCore = @import("./webcore.zig"); diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 1d88a6d235db0b..e36512b7f3fb8b 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -1,5 +1,6 @@ const std = @import("std"); const bun = @import("root").bun; +const C = @import("root").C; const string = bun.string; const Output = bun.Output; const C_API = bun.JSC.C; @@ -1747,7 +1748,7 @@ pub const SystemError = extern struct { pub const name = "SystemError"; pub const namespace = ""; - pub fn getErrno(this: *const SystemError) bun.C.E { + pub fn getErrno(this: *const SystemError) C.E { // The inverse in bun.sys.Error.toSystemError() return @enumFromInt(this.errno * -1); } diff --git a/src/bun.js/config.zig b/src/bun.js/config.zig index c8fbeddbd4543f..55a36893cbb80b 100644 --- a/src/bun.js/config.zig +++ b/src/bun.js/config.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const Fs = @import("../fs.zig"); diff --git a/src/bun.js/ipc.zig b/src/bun.js/ipc.zig index cfa4150f4f6ac8..782cf36adfdfcc 100644 --- a/src/bun.js/ipc.zig +++ b/src/bun.js/ipc.zig @@ -6,6 +6,7 @@ const strings = bun.strings; const string = bun.string; const Output = bun.Output; const MutableString = bun.MutableString; +const C = @import("root").C; const std = @import("std"); const Allocator = std.mem.Allocator; const JSC = bun.JSC; @@ -601,7 +602,7 @@ const NamedPipeIPCData = struct { const stream = this.writer.getStream() orelse { this.close(false); - return JSC.Maybe(void).errno(bun.C.E.PIPE, .pipe); + return JSC.Maybe(void).errno(C.E.PIPE, .pipe); }; const readStartResult = stream.readStart(instance, NewNamedPipeIPCHandler(Context).onReadAlloc, NewNamedPipeIPCHandler(Context).onReadError, NewNamedPipeIPCHandler(Context).onRead); @@ -824,7 +825,7 @@ fn NewNamedPipeIPCHandler(comptime Context: type) type { return available.ptr[0..suggested_size]; } - fn onReadError(this: *Context, err: bun.C.E) void { + fn onReadError(this: *Context, err: C.E) void { log("NewNamedPipeIPCHandler#onReadError {}", .{err}); if (this.ipc()) |ipc_data| { ipc_data.close(true); diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 41d5c1ba2fff69..940286e1b34388 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -13,7 +13,7 @@ const default_allocator = bun.default_allocator; const StoredFileDescriptorType = bun.StoredFileDescriptorType; const ErrorableString = bun.JSC.ErrorableString; const Arena = @import("../allocators/mimalloc_arena.zig").Arena; -const C = bun.C; +const C = @import("root").C; const Exception = bun.JSC.Exception; const Allocator = std.mem.Allocator; @@ -4638,7 +4638,7 @@ pub fn NewHotReloader(comptime Ctx: type, comptime EventLoopType: type, comptime _: *@This(), err: bun.sys.Error, ) void { - Output.err(@as(bun.C.E, @enumFromInt(err.errno)), "Watcher crashed", .{}); + Output.err(@as(C.E, @enumFromInt(err.errno)), "Watcher crashed", .{}); if (bun.Environment.isDebug) { @panic("Watcher crash"); } diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index cfc603014746cb..db34865bf576ec 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -12,7 +12,7 @@ const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const StoredFileDescriptorType = bun.StoredFileDescriptorType; const Arena = @import("../allocators/mimalloc_arena.zig").Arena; -const C = bun.C; +const C = @import("root").C; const Allocator = std.mem.Allocator; const IdentityContext = @import("../identity_context.zig").IdentityContext; @@ -2051,7 +2051,7 @@ pub const ModuleLoader = struct { .sqlite_embedded, .sqlite => { const sqlite_module_source_code_string = brk: { if (jsc_vm.hot_reload == .hot) { - break :brk + break :brk \\// Generated code \\import {Database} from 'bun:sqlite'; \\const {path} = import.meta; @@ -2071,7 +2071,7 @@ pub const ModuleLoader = struct { ; } - break :brk + break :brk \\// Generated code \\import {Database} from 'bun:sqlite'; \\export const db = new Database(import.meta.path); @@ -2102,7 +2102,7 @@ pub const ModuleLoader = struct { if (comptime Environment.isMac) { switch (bun.sys.open( &(std.posix.toPosixPath(path.text) catch break :auto_watch), - bun.C.O_EVTONLY, + C.O_EVTONLY, 0, )) { .err => break :auto_watch, diff --git a/src/bun.js/node/dir_iterator.zig b/src/bun.js/node/dir_iterator.zig index 7b6b89286ed162..1e25f8e7483f77 100644 --- a/src/bun.js/node/dir_iterator.zig +++ b/src/bun.js/node/dir_iterator.zig @@ -13,6 +13,7 @@ const Dir = std.fs.Dir; const JSC = bun.JSC; const PathString = JSC.PathString; const bun = @import("root").bun; +const C = @import("root").C; const IteratorError = error{ AccessDenied, SystemResources } || posix.UnexpectedError; const mem = std.mem; @@ -270,7 +271,7 @@ pub fn NewIterator(comptime use_windows_ospath: bool) type { bun.sys.syslog("NtQueryDirectoryFile({}) = {s}", .{ bun.toFD(self.dir.fd), @tagName(rc) }); return .{ .err = .{ - .errno = @intFromEnum(bun.C.SystemErrno.ENOTDIR), + .errno = @intFromEnum(C.SystemErrno.ENOTDIR), .syscall = .NtQueryDirectoryFile, }, }; @@ -296,7 +297,7 @@ pub fn NewIterator(comptime use_windows_ospath: bool) type { return .{ .err = .{ - .errno = @intFromEnum(bun.C.SystemErrno.EUNKNOWN), + .errno = @intFromEnum(C.SystemErrno.EUNKNOWN), .syscall = .NtQueryDirectoryFile, }, }; diff --git a/src/bun.js/node/fs_events.zig b/src/bun.js/node/fs_events.zig index 9953527a6ebfb6..71b1bdabaf47a7 100644 --- a/src/bun.js/node/fs_events.zig +++ b/src/bun.js/node/fs_events.zig @@ -1,5 +1,6 @@ const std = @import("std"); const bun = @import("root").bun; +const C = @import("root").C; const Environment = bun.Environment; const Mutex = bun.Mutex; const sync = @import("../../sync.zig"); @@ -191,7 +192,7 @@ var fsevents_cf: ?CoreFoundation = null; var fsevents_cs: ?CoreServices = null; fn InitLibrary() void { - const fsevents_cf_handle = bun.C.dlopen("/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation", RTLD_LAZY | RTLD_LOCAL); + const fsevents_cf_handle = C.dlopen("/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation", RTLD_LAZY | RTLD_LOCAL); if (fsevents_cf_handle == null) @panic("Cannot Load CoreFoundation"); fsevents_cf = CoreFoundation{ @@ -210,7 +211,7 @@ fn InitLibrary() void { .RunLoopDefaultMode = dlsym(fsevents_cf_handle, *CFStringRef, "kCFRunLoopDefaultMode") orelse @panic("Cannot Load CoreFoundation"), }; - const fsevents_cs_handle = bun.C.dlopen("/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices", RTLD_LAZY | RTLD_LOCAL); + const fsevents_cs_handle = C.dlopen("/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices", RTLD_LAZY | RTLD_LOCAL); if (fsevents_cs_handle == null) @panic("Cannot Load CoreServices"); fsevents_cs = CoreServices{ diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index d0500f31cb0ab6..e0086f2e946474 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -3,13 +3,13 @@ // The top-level functions assume the arguments are already validated const std = @import("std"); const bun = @import("root").bun; +const C = @import("root").C; const strings = bun.strings; const windows = bun.windows; const string = bun.string; const JSC = bun.JSC; const PathString = JSC.PathString; const Environment = bun.Environment; -const C = bun.C; const Flavor = JSC.Node.Flavor; const system = std.posix.system; const Maybe = JSC.Maybe; @@ -1865,7 +1865,7 @@ pub const Arguments = struct { const stat = bun.sys.stat(old_path.sliceZ(&buf)); // if there's an error node defaults to file. - break :link_type if (stat == .result and bun.C.S.ISDIR(@intCast(stat.result.mode))) .dir else .file; + break :link_type if (stat == .result and C.S.ISDIR(@intCast(stat.result.mode))) .dir else .file; }; return Symlink{ @@ -3465,7 +3465,7 @@ pub const NodeFS = struct { // https://manpages.debian.org/testing/manpages-dev/ioctl_ficlone.2.en.html if (args.mode.isForceClone()) { - if (ret.errnoSysP(bun.C.linux.ioctl_ficlone(dest_fd, src_fd), .ioctl_ficlone, dest)) |err| { + if (ret.errnoSysP(C.linux.ioctl_ficlone(dest_fd, src_fd), .ioctl_ficlone, dest)) |err| { _ = Syscall.close(dest_fd); // This is racey, but it's the best we can do _ = bun.sys.unlink(dest); @@ -3478,7 +3478,7 @@ pub const NodeFS = struct { // If we know it's a regular file and ioctl_ficlone is available, attempt to use it. if (posix.S.ISREG(stat_.mode) and bun.can_use_ioctl_ficlone()) { - const rc = bun.C.linux.ioctl_ficlone(dest_fd, src_fd); + const rc = C.linux.ioctl_ficlone(dest_fd, src_fd); if (rc == 0) { _ = C.fchmod(dest_fd.cast(), stat_.mode); _ = Syscall.close(dest_fd); @@ -3974,7 +3974,7 @@ pub const NodeFS = struct { }; } - // bun.C.getErrno(rc) returns SUCCESS if rc is -1 so we call std.c._errno() directly + // C.getErrno(rc) returns SUCCESS if rc is -1 so we call std.c._errno() directly const errno = @as(std.c.E, @enumFromInt(std.c._errno().*)); return .{ .err = Syscall.Error{ @@ -5112,7 +5112,7 @@ pub const NodeFS = struct { if (Environment.isLinux) { preallocate: { // Worthwhile after 6 MB at least on ext4 linux - if (buf.len >= bun.C.preallocate_length) { + if (buf.len >= C.preallocate_length) { const offset: usize = if (args.file == .path) // on mac, it's relatively positioned 0 @@ -5129,7 +5129,7 @@ pub const NodeFS = struct { } }; - bun.C.preallocate_file( + C.preallocate_file( fd.cast(), @as(std.posix.off_t, @intCast(offset)), @as(std.posix.off_t, @intCast(buf.len)), @@ -5307,7 +5307,7 @@ pub const NodeFS = struct { pub fn rmdir(this: *NodeFS, args: Arguments.RmDir, comptime _: Flavor) Maybe(Return.Rmdir) { if (args.recursive) { std.fs.cwd().deleteTree(args.path.slice()) catch |err| { - const errno: bun.C.E = switch (err) { + const errno: C.E = switch (err) { error.AccessDenied => .PERM, error.FileTooBig => .FBIG, error.SymLinkLoop => .LOOP, @@ -6086,7 +6086,7 @@ pub const NodeFS = struct { var size: usize = @intCast(@max(stat_.size, 0)); if (posix.S.ISREG(stat_.mode) and bun.can_use_ioctl_ficlone()) { - const rc = bun.C.linux.ioctl_ficlone(dest_fd, src_fd); + const rc = C.linux.ioctl_ficlone(dest_fd, src_fd); if (rc == 0) { _ = C.fchmod(dest_fd.cast(), stat_.mode); _ = Syscall.close(dest_fd); diff --git a/src/bun.js/node/node_fs_watcher.zig b/src/bun.js/node/node_fs_watcher.zig index 05cf2b498709b5..40d2d063fa467b 100644 --- a/src/bun.js/node/node_fs_watcher.zig +++ b/src/bun.js/node/node_fs_watcher.zig @@ -1,6 +1,7 @@ const std = @import("std"); const JSC = bun.JSC; const bun = @import("root").bun; +const C = @import("root").C; const Fs = @import("../../fs.zig"); const Path = @import("../../resolver/resolve_path.zig"); const Encoder = JSC.WebCore.Encoder; @@ -196,7 +197,7 @@ pub const FSWatcher = struct { }; pub const FSWatchTaskWindows = struct { - event: Event = .{ .@"error" = .{ .errno = @intFromEnum(bun.C.SystemErrno.EINVAL), .syscall = .watch } }, + event: Event = .{ .@"error" = .{ .errno = @intFromEnum(C.SystemErrno.EINVAL), .syscall = .watch } }, ctx: *FSWatcher, /// Unused: To match the API of the posix version diff --git a/src/bun.js/node/node_os.zig b/src/bun.js/node/node_os.zig index fc60648fee1385..edba0c629bb1ff 100644 --- a/src/bun.js/node/node_os.zig +++ b/src/bun.js/node/node_os.zig @@ -1,7 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); const bun = @import("root").bun; -const C = bun.C; +const C = @import("root").C; const string = bun.string; const strings = bun.strings; const JSC = bun.JSC; @@ -186,7 +186,7 @@ fn cpusImplLinux(globalThis: *JSC.JSGlobalObject) !JSC.JSValue { extern fn bun_sysconf__SC_CLK_TCK() isize; fn cpusImplDarwin(globalThis: *JSC.JSGlobalObject) !JSC.JSValue { - const local_bindings = @import("../../darwin_c.zig"); + const local_bindings = C.darwin; const c = std.c; // Fetch the CPU info structure @@ -333,23 +333,23 @@ pub fn homedir(global: *JSC.JSGlobalObject) !bun.String { defer if (string_bytes.ptr != &stack_string_bytes) bun.default_allocator.free(string_bytes); - var pw: bun.C.passwd = undefined; - var result: ?*bun.C.passwd = null; + var pw: C.passwd = undefined; + var result: ?*C.passwd = null; const ret = while (true) { - const ret = bun.C.getpwuid_r( - bun.C.geteuid(), + const ret = C.getpwuid_r( + C.geteuid(), &pw, string_bytes.ptr, string_bytes.len, &result, ); - if (ret == @intFromEnum(bun.C.E.INTR)) + if (ret == @intFromEnum(C.E.INTR)) continue; // If the system call wants more memory, double it. - if (ret == @intFromEnum(bun.C.E.RANGE)) { + if (ret == @intFromEnum(C.E.RANGE)) { const len = string_bytes.len; bun.default_allocator.free(string_bytes); string_bytes = ""; diff --git a/src/bun.js/node/node_util_binding.zig b/src/bun.js/node/node_util_binding.zig index cbcf25f09b3746..b402153f716ab4 100644 --- a/src/bun.js/node/node_util_binding.zig +++ b/src/bun.js/node/node_util_binding.zig @@ -1,5 +1,6 @@ const std = @import("std"); const bun = @import("root").bun; +const C = @import("root").C; const Allocator = std.mem.Allocator; const Environment = bun.Environment; const JSC = bun.JSC; @@ -34,74 +35,74 @@ pub fn internalErrorName(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFr if (err_int == -3013) return bun.String.static("EAI_BADHINTS").toJS(globalThis); if (err_int == -3014) return bun.String.static("EAI_PROTOCOL").toJS(globalThis); - if (err_int == -bun.C.UV_E2BIG) return bun.String.static("E2BIG").toJS(globalThis); - if (err_int == -bun.C.UV_EACCES) return bun.String.static("EACCES").toJS(globalThis); - if (err_int == -bun.C.UV_EADDRINUSE) return bun.String.static("EADDRINUSE").toJS(globalThis); - if (err_int == -bun.C.UV_EADDRNOTAVAIL) return bun.String.static("EADDRNOTAVAIL").toJS(globalThis); - if (err_int == -bun.C.UV_EAFNOSUPPORT) return bun.String.static("EAFNOSUPPORT").toJS(globalThis); - if (err_int == -bun.C.UV_EAGAIN) return bun.String.static("EAGAIN").toJS(globalThis); - if (err_int == -bun.C.UV_EALREADY) return bun.String.static("EALREADY").toJS(globalThis); - if (err_int == -bun.C.UV_EBADF) return bun.String.static("EBADF").toJS(globalThis); - if (err_int == -bun.C.UV_EBUSY) return bun.String.static("EBUSY").toJS(globalThis); - if (err_int == -bun.C.UV_ECANCELED) return bun.String.static("ECANCELED").toJS(globalThis); - if (err_int == -bun.C.UV_ECHARSET) return bun.String.static("ECHARSET").toJS(globalThis); - if (err_int == -bun.C.UV_ECONNABORTED) return bun.String.static("ECONNABORTED").toJS(globalThis); - if (err_int == -bun.C.UV_ECONNREFUSED) return bun.String.static("ECONNREFUSED").toJS(globalThis); - if (err_int == -bun.C.UV_ECONNRESET) return bun.String.static("ECONNRESET").toJS(globalThis); - if (err_int == -bun.C.UV_EDESTADDRREQ) return bun.String.static("EDESTADDRREQ").toJS(globalThis); - if (err_int == -bun.C.UV_EEXIST) return bun.String.static("EEXIST").toJS(globalThis); - if (err_int == -bun.C.UV_EFAULT) return bun.String.static("EFAULT").toJS(globalThis); - if (err_int == -bun.C.UV_EHOSTUNREACH) return bun.String.static("EHOSTUNREACH").toJS(globalThis); - if (err_int == -bun.C.UV_EINTR) return bun.String.static("EINTR").toJS(globalThis); - if (err_int == -bun.C.UV_EINVAL) return bun.String.static("EINVAL").toJS(globalThis); - if (err_int == -bun.C.UV_EIO) return bun.String.static("EIO").toJS(globalThis); - if (err_int == -bun.C.UV_EISCONN) return bun.String.static("EISCONN").toJS(globalThis); - if (err_int == -bun.C.UV_EISDIR) return bun.String.static("EISDIR").toJS(globalThis); - if (err_int == -bun.C.UV_ELOOP) return bun.String.static("ELOOP").toJS(globalThis); - if (err_int == -bun.C.UV_EMFILE) return bun.String.static("EMFILE").toJS(globalThis); - if (err_int == -bun.C.UV_EMSGSIZE) return bun.String.static("EMSGSIZE").toJS(globalThis); - if (err_int == -bun.C.UV_ENAMETOOLONG) return bun.String.static("ENAMETOOLONG").toJS(globalThis); - if (err_int == -bun.C.UV_ENETDOWN) return bun.String.static("ENETDOWN").toJS(globalThis); - if (err_int == -bun.C.UV_ENETUNREACH) return bun.String.static("ENETUNREACH").toJS(globalThis); - if (err_int == -bun.C.UV_ENFILE) return bun.String.static("ENFILE").toJS(globalThis); - if (err_int == -bun.C.UV_ENOBUFS) return bun.String.static("ENOBUFS").toJS(globalThis); - if (err_int == -bun.C.UV_ENODEV) return bun.String.static("ENODEV").toJS(globalThis); - if (err_int == -bun.C.UV_ENOENT) return bun.String.static("ENOENT").toJS(globalThis); - if (err_int == -bun.C.UV_ENOMEM) return bun.String.static("ENOMEM").toJS(globalThis); - if (err_int == -bun.C.UV_ENONET) return bun.String.static("ENONET").toJS(globalThis); - if (err_int == -bun.C.UV_ENOSPC) return bun.String.static("ENOSPC").toJS(globalThis); - if (err_int == -bun.C.UV_ENOSYS) return bun.String.static("ENOSYS").toJS(globalThis); - if (err_int == -bun.C.UV_ENOTCONN) return bun.String.static("ENOTCONN").toJS(globalThis); - if (err_int == -bun.C.UV_ENOTDIR) return bun.String.static("ENOTDIR").toJS(globalThis); - if (err_int == -bun.C.UV_ENOTEMPTY) return bun.String.static("ENOTEMPTY").toJS(globalThis); - if (err_int == -bun.C.UV_ENOTSOCK) return bun.String.static("ENOTSOCK").toJS(globalThis); - if (err_int == -bun.C.UV_ENOTSUP) return bun.String.static("ENOTSUP").toJS(globalThis); - if (err_int == -bun.C.UV_EPERM) return bun.String.static("EPERM").toJS(globalThis); - if (err_int == -bun.C.UV_EPIPE) return bun.String.static("EPIPE").toJS(globalThis); - if (err_int == -bun.C.UV_EPROTO) return bun.String.static("EPROTO").toJS(globalThis); - if (err_int == -bun.C.UV_EPROTONOSUPPORT) return bun.String.static("EPROTONOSUPPORT").toJS(globalThis); - if (err_int == -bun.C.UV_EPROTOTYPE) return bun.String.static("EPROTOTYPE").toJS(globalThis); - if (err_int == -bun.C.UV_EROFS) return bun.String.static("EROFS").toJS(globalThis); - if (err_int == -bun.C.UV_ESHUTDOWN) return bun.String.static("ESHUTDOWN").toJS(globalThis); - if (err_int == -bun.C.UV_ESPIPE) return bun.String.static("ESPIPE").toJS(globalThis); - if (err_int == -bun.C.UV_ESRCH) return bun.String.static("ESRCH").toJS(globalThis); - if (err_int == -bun.C.UV_ETIMEDOUT) return bun.String.static("ETIMEDOUT").toJS(globalThis); - if (err_int == -bun.C.UV_ETXTBSY) return bun.String.static("ETXTBSY").toJS(globalThis); - if (err_int == -bun.C.UV_EXDEV) return bun.String.static("EXDEV").toJS(globalThis); - if (err_int == -bun.C.UV_EFBIG) return bun.String.static("EFBIG").toJS(globalThis); - if (err_int == -bun.C.UV_ENOPROTOOPT) return bun.String.static("ENOPROTOOPT").toJS(globalThis); - if (err_int == -bun.C.UV_ERANGE) return bun.String.static("ERANGE").toJS(globalThis); - if (err_int == -bun.C.UV_ENXIO) return bun.String.static("ENXIO").toJS(globalThis); - if (err_int == -bun.C.UV_EMLINK) return bun.String.static("EMLINK").toJS(globalThis); - if (err_int == -bun.C.UV_EHOSTDOWN) return bun.String.static("EHOSTDOWN").toJS(globalThis); - if (err_int == -bun.C.UV_EREMOTEIO) return bun.String.static("EREMOTEIO").toJS(globalThis); - if (err_int == -bun.C.UV_ENOTTY) return bun.String.static("ENOTTY").toJS(globalThis); - if (err_int == -bun.C.UV_EFTYPE) return bun.String.static("EFTYPE").toJS(globalThis); - if (err_int == -bun.C.UV_EILSEQ) return bun.String.static("EILSEQ").toJS(globalThis); - if (err_int == -bun.C.UV_EOVERFLOW) return bun.String.static("EOVERFLOW").toJS(globalThis); - if (err_int == -bun.C.UV_ESOCKTNOSUPPORT) return bun.String.static("ESOCKTNOSUPPORT").toJS(globalThis); - if (err_int == -bun.C.UV_ENODATA) return bun.String.static("ENODATA").toJS(globalThis); - if (err_int == -bun.C.UV_EUNATCH) return bun.String.static("EUNATCH").toJS(globalThis); + if (err_int == -C.UV_E2BIG) return bun.String.static("E2BIG").toJS(globalThis); + if (err_int == -C.UV_EACCES) return bun.String.static("EACCES").toJS(globalThis); + if (err_int == -C.UV_EADDRINUSE) return bun.String.static("EADDRINUSE").toJS(globalThis); + if (err_int == -C.UV_EADDRNOTAVAIL) return bun.String.static("EADDRNOTAVAIL").toJS(globalThis); + if (err_int == -C.UV_EAFNOSUPPORT) return bun.String.static("EAFNOSUPPORT").toJS(globalThis); + if (err_int == -C.UV_EAGAIN) return bun.String.static("EAGAIN").toJS(globalThis); + if (err_int == -C.UV_EALREADY) return bun.String.static("EALREADY").toJS(globalThis); + if (err_int == -C.UV_EBADF) return bun.String.static("EBADF").toJS(globalThis); + if (err_int == -C.UV_EBUSY) return bun.String.static("EBUSY").toJS(globalThis); + if (err_int == -C.UV_ECANCELED) return bun.String.static("ECANCELED").toJS(globalThis); + if (err_int == -C.UV_ECHARSET) return bun.String.static("ECHARSET").toJS(globalThis); + if (err_int == -C.UV_ECONNABORTED) return bun.String.static("ECONNABORTED").toJS(globalThis); + if (err_int == -C.UV_ECONNREFUSED) return bun.String.static("ECONNREFUSED").toJS(globalThis); + if (err_int == -C.UV_ECONNRESET) return bun.String.static("ECONNRESET").toJS(globalThis); + if (err_int == -C.UV_EDESTADDRREQ) return bun.String.static("EDESTADDRREQ").toJS(globalThis); + if (err_int == -C.UV_EEXIST) return bun.String.static("EEXIST").toJS(globalThis); + if (err_int == -C.UV_EFAULT) return bun.String.static("EFAULT").toJS(globalThis); + if (err_int == -C.UV_EHOSTUNREACH) return bun.String.static("EHOSTUNREACH").toJS(globalThis); + if (err_int == -C.UV_EINTR) return bun.String.static("EINTR").toJS(globalThis); + if (err_int == -C.UV_EINVAL) return bun.String.static("EINVAL").toJS(globalThis); + if (err_int == -C.UV_EIO) return bun.String.static("EIO").toJS(globalThis); + if (err_int == -C.UV_EISCONN) return bun.String.static("EISCONN").toJS(globalThis); + if (err_int == -C.UV_EISDIR) return bun.String.static("EISDIR").toJS(globalThis); + if (err_int == -C.UV_ELOOP) return bun.String.static("ELOOP").toJS(globalThis); + if (err_int == -C.UV_EMFILE) return bun.String.static("EMFILE").toJS(globalThis); + if (err_int == -C.UV_EMSGSIZE) return bun.String.static("EMSGSIZE").toJS(globalThis); + if (err_int == -C.UV_ENAMETOOLONG) return bun.String.static("ENAMETOOLONG").toJS(globalThis); + if (err_int == -C.UV_ENETDOWN) return bun.String.static("ENETDOWN").toJS(globalThis); + if (err_int == -C.UV_ENETUNREACH) return bun.String.static("ENETUNREACH").toJS(globalThis); + if (err_int == -C.UV_ENFILE) return bun.String.static("ENFILE").toJS(globalThis); + if (err_int == -C.UV_ENOBUFS) return bun.String.static("ENOBUFS").toJS(globalThis); + if (err_int == -C.UV_ENODEV) return bun.String.static("ENODEV").toJS(globalThis); + if (err_int == -C.UV_ENOENT) return bun.String.static("ENOENT").toJS(globalThis); + if (err_int == -C.UV_ENOMEM) return bun.String.static("ENOMEM").toJS(globalThis); + if (err_int == -C.UV_ENONET) return bun.String.static("ENONET").toJS(globalThis); + if (err_int == -C.UV_ENOSPC) return bun.String.static("ENOSPC").toJS(globalThis); + if (err_int == -C.UV_ENOSYS) return bun.String.static("ENOSYS").toJS(globalThis); + if (err_int == -C.UV_ENOTCONN) return bun.String.static("ENOTCONN").toJS(globalThis); + if (err_int == -C.UV_ENOTDIR) return bun.String.static("ENOTDIR").toJS(globalThis); + if (err_int == -C.UV_ENOTEMPTY) return bun.String.static("ENOTEMPTY").toJS(globalThis); + if (err_int == -C.UV_ENOTSOCK) return bun.String.static("ENOTSOCK").toJS(globalThis); + if (err_int == -C.UV_ENOTSUP) return bun.String.static("ENOTSUP").toJS(globalThis); + if (err_int == -C.UV_EPERM) return bun.String.static("EPERM").toJS(globalThis); + if (err_int == -C.UV_EPIPE) return bun.String.static("EPIPE").toJS(globalThis); + if (err_int == -C.UV_EPROTO) return bun.String.static("EPROTO").toJS(globalThis); + if (err_int == -C.UV_EPROTONOSUPPORT) return bun.String.static("EPROTONOSUPPORT").toJS(globalThis); + if (err_int == -C.UV_EPROTOTYPE) return bun.String.static("EPROTOTYPE").toJS(globalThis); + if (err_int == -C.UV_EROFS) return bun.String.static("EROFS").toJS(globalThis); + if (err_int == -C.UV_ESHUTDOWN) return bun.String.static("ESHUTDOWN").toJS(globalThis); + if (err_int == -C.UV_ESPIPE) return bun.String.static("ESPIPE").toJS(globalThis); + if (err_int == -C.UV_ESRCH) return bun.String.static("ESRCH").toJS(globalThis); + if (err_int == -C.UV_ETIMEDOUT) return bun.String.static("ETIMEDOUT").toJS(globalThis); + if (err_int == -C.UV_ETXTBSY) return bun.String.static("ETXTBSY").toJS(globalThis); + if (err_int == -C.UV_EXDEV) return bun.String.static("EXDEV").toJS(globalThis); + if (err_int == -C.UV_EFBIG) return bun.String.static("EFBIG").toJS(globalThis); + if (err_int == -C.UV_ENOPROTOOPT) return bun.String.static("ENOPROTOOPT").toJS(globalThis); + if (err_int == -C.UV_ERANGE) return bun.String.static("ERANGE").toJS(globalThis); + if (err_int == -C.UV_ENXIO) return bun.String.static("ENXIO").toJS(globalThis); + if (err_int == -C.UV_EMLINK) return bun.String.static("EMLINK").toJS(globalThis); + if (err_int == -C.UV_EHOSTDOWN) return bun.String.static("EHOSTDOWN").toJS(globalThis); + if (err_int == -C.UV_EREMOTEIO) return bun.String.static("EREMOTEIO").toJS(globalThis); + if (err_int == -C.UV_ENOTTY) return bun.String.static("ENOTTY").toJS(globalThis); + if (err_int == -C.UV_EFTYPE) return bun.String.static("EFTYPE").toJS(globalThis); + if (err_int == -C.UV_EILSEQ) return bun.String.static("EILSEQ").toJS(globalThis); + if (err_int == -C.UV_EOVERFLOW) return bun.String.static("EOVERFLOW").toJS(globalThis); + if (err_int == -C.UV_ESOCKTNOSUPPORT) return bun.String.static("ESOCKTNOSUPPORT").toJS(globalThis); + if (err_int == -C.UV_ENODATA) return bun.String.static("ENODATA").toJS(globalThis); + if (err_int == -C.UV_EUNATCH) return bun.String.static("EUNATCH").toJS(globalThis); var fmtstring = bun.String.createFormat("Unknown system error {d}", .{err_int}) catch bun.outOfMemory(); return fmtstring.transferToJS(globalThis); diff --git a/src/bun.js/node/path_watcher.zig b/src/bun.js/node/path_watcher.zig index 4dd3aae1788bba..cfc8450b7add0f 100644 --- a/src/bun.js/node/path_watcher.zig +++ b/src/bun.js/node/path_watcher.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const C = @import("root").C; const UnboundedQueue = @import("../unbounded_queue.zig").UnboundedQueue; const Path = @import("../../resolver/resolve_path.zig"); @@ -96,7 +97,7 @@ pub const PathWatcherManager = struct { .windows => bun.sys.openDirAtWindowsA(bun.FD.cwd(), path, .{ .iterable = true, .read_only = true }), }) { .err => |e| { - if (e.errno == @intFromEnum(bun.C.E.NOTDIR)) { + if (e.errno == @intFromEnum(C.E.NOTDIR)) { const file = switch (bun.sys.open(path, 0, 0)) { .err => |file_err| return .{ .err = file_err.withPath(path) }, .result => |r| r, @@ -448,11 +449,11 @@ pub const PathWatcherManager = struct { return .{ .err = .{ .errno = @truncate(@intFromEnum(switch (err) { - error.AccessDenied => bun.C.E.ACCES, - error.SystemResources => bun.C.E.NOMEM, + error.AccessDenied => C.E.ACCES, + error.SystemResources => C.E.NOMEM, error.Unexpected, error.InvalidUtf8, - => bun.C.E.INVAL, + => C.E.INVAL, })), .syscall = .watch, }, @@ -481,7 +482,7 @@ pub const PathWatcherManager = struct { manager._decrementPathRef(entry_path_z); return switch (err) { error.OutOfMemory => .{ .err = .{ - .errno = @truncate(@intFromEnum(bun.C.E.NOMEM)), + .errno = @truncate(@intFromEnum(C.E.NOMEM)), .syscall = .watch, } }, }; @@ -554,8 +555,8 @@ pub const PathWatcherManager = struct { .result = DirectoryRegisterTask.schedule(this, watcher, path) catch |err| return .{ .err = .{ .errno = @truncate(@intFromEnum(switch (err) { - error.OutOfMemory => bun.C.E.NOMEM, - error.UnexpectedFailure => bun.C.E.INVAL, + error.OutOfMemory => C.E.NOMEM, + error.UnexpectedFailure => C.E.INVAL, })), }, }, @@ -954,16 +955,16 @@ pub fn watch( default_manager = PathWatcherManager.init(vm) catch |e| { return .{ .err = .{ .errno = @truncate(@intFromEnum(switch (e) { - error.SystemResources, error.LockedMemoryLimitExceeded, error.OutOfMemory => bun.C.E.NOMEM, + error.SystemResources, error.LockedMemoryLimitExceeded, error.OutOfMemory => C.E.NOMEM, error.ProcessFdQuotaExceeded, error.SystemFdQuotaExceeded, error.ThreadQuotaExceeded, - => bun.C.E.MFILE, + => C.E.MFILE, - error.Unexpected => bun.C.E.NOMEM, + error.Unexpected => C.E.NOMEM, - error.KQueueError => bun.C.E.INVAL, + error.KQueueError => C.E.INVAL, })), .syscall = .watch, } }; @@ -990,29 +991,29 @@ pub fn watch( error.BadPathName, error.InvalidUtf8, error.InvalidWtf8, - => bun.C.E.INVAL, + => C.E.INVAL, error.OutOfMemory, error.SystemResources, - => bun.C.E.NOMEM, + => C.E.NOMEM, error.FileNotFound, error.NetworkNotFound, error.NoDevice, - => bun.C.E.NOENT, + => C.E.NOENT, - error.DeviceBusy => bun.C.E.BUSY, - error.AccessDenied => bun.C.E.PERM, - error.InvalidHandle => bun.C.E.BADF, - error.SymLinkLoop => bun.C.E.LOOP, - error.NotDir => bun.C.E.NOTDIR, + error.DeviceBusy => C.E.BUSY, + error.AccessDenied => C.E.PERM, + error.InvalidHandle => C.E.BADF, + error.SymLinkLoop => C.E.LOOP, + error.NotDir => C.E.NOTDIR, error.ProcessFdQuotaExceeded, error.SystemFdQuotaExceeded, error.UserResourceLimitReached, - => bun.C.E.MFILE, + => C.E.MFILE, - else => bun.C.E.INVAL, + else => C.E.INVAL, })), .syscall = .watch, } }; diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 302e11fd5e2d7d..cc062ac69953ff 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -1,6 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); const bun = @import("root").bun; +const C = @import("root").C; const meta = bun.meta; const windows = bun.windows; const heap_allocator = bun.default_allocator; @@ -12,7 +13,6 @@ const path_handler = bun.path; const strings = bun.strings; const string = bun.string; -const C = bun.C; const L = strings.literal; const Environment = bun.Environment; const Fs = @import("../../fs.zig"); @@ -1692,7 +1692,7 @@ pub fn StatType(comptime Big: bool) type { return @truncate(this.mode); } - const S = if (Environment.isWindows) bun.C.S else posix.system.S; + const S = if (Environment.isWindows) C.S else posix.system.S; pub fn isBlockDevice(this: *This) JSC.JSValue { return JSC.JSValue.jsBoolean(S.ISBLK(@intCast(this.modeInternal()))); diff --git a/src/bun.js/node/win_watcher.zig b/src/bun.js/node/win_watcher.zig index 93a96faf4a01fa..40a4427e70fe5c 100644 --- a/src/bun.js/node/win_watcher.zig +++ b/src/bun.js/node/win_watcher.zig @@ -1,5 +1,6 @@ const std = @import("std"); const bun = @import("root").bun; +const C = @import("root").C; const windows = bun.windows; const uv = windows.libuv; const Path = @import("../../resolver/resolve_path.zig"); @@ -183,7 +184,7 @@ pub const PathWatcher = struct { var outbuf: bun.PathBuffer = undefined; const event_path = switch (bun.sys.readlink(path, &outbuf)) { .err => |err| brk: { - if (err.errno == @intFromEnum(bun.C.E.NOENT)) { + if (err.errno == @intFromEnum(C.E.NOENT)) { return .{ .err = .{ .errno = err.errno, .syscall = .open, diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index 53d4c87113c973..33800401686ab0 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -1,6 +1,7 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; +const C = @import("root").C; const MimeType = http.MimeType; const ZigURL = @import("../../url.zig").URL; const http = bun.http; @@ -877,7 +878,7 @@ pub const Blob = struct { // it might return EPERM when the parent directory doesn't exist // #6336 if (result.err.getErrno() == .PERM) { - result.err.errno = @intCast(@intFromEnum(bun.C.E.NOENT)); + result.err.errno = @intCast(@intFromEnum(C.E.NOENT)); } result.err = result.err.withPathLike(destination_blob.store.?.data.file.pathlike); @@ -2206,7 +2207,7 @@ pub const Blob = struct { .result => |fd| fd, .err => |err| { if (comptime @hasField(This, "mkdirp_if_not_exists")) { - if (err.errno == @intFromEnum(bun.C.E.NOENT)) { + if (err.errno == @intFromEnum(C.E.NOENT)) { switch (mkdirIfNotExists(this, err, path, path_string.slice())) { .@"continue" => continue, .fail => { @@ -2583,7 +2584,7 @@ pub const Blob = struct { _ = bun.sys.close(result); return .{ .err = .{ - .errno = @as(c_int, @intCast(@intFromEnum(bun.C.SystemErrno.EMFILE))), + .errno = @as(c_int, @intCast(@intFromEnum(C.SystemErrno.EMFILE))), .syscall = .open, .path = pathlike.path.slice(), }, @@ -2742,8 +2743,8 @@ pub const Blob = struct { if (rc.errno()) |errno| { this.throw(.{ // #6336 - .errno = if (errno == @intFromEnum(bun.C.SystemErrno.EPERM)) - @as(c_int, @intCast(@intFromEnum(bun.C.SystemErrno.ENOENT))) + .errno = if (errno == @intFromEnum(C.SystemErrno.EPERM)) + @as(c_int, @intCast(@intFromEnum(C.SystemErrno.ENOENT))) else errno, .syscall = .copyfile, @@ -2850,7 +2851,7 @@ pub const Blob = struct { var destination = &this.destination_file_store.data.file; if (destination.pathlike != .path) { this.throw(.{ - .errno = @as(c_int, @intCast(@intFromEnum(bun.C.SystemErrno.EINVAL))), + .errno = @as(c_int, @intCast(@intFromEnum(C.SystemErrno.EINVAL))), .syscall = .mkdir, }); return; @@ -2887,12 +2888,12 @@ pub const Blob = struct { }; const unsupported_directory_error = SystemError{ - .errno = @as(c_int, @intCast(@intFromEnum(bun.C.SystemErrno.EISDIR))), + .errno = @as(c_int, @intCast(@intFromEnum(C.SystemErrno.EISDIR))), .message = bun.String.static("That doesn't work on folders"), .syscall = bun.String.static("fstat"), }; const unsupported_non_regular_file_error = SystemError{ - .errno = @as(c_int, @intCast(@intFromEnum(bun.C.SystemErrno.ENOTSUP))), + .errno = @as(c_int, @intCast(@intFromEnum(C.SystemErrno.ENOTSUP))), .message = bun.String.static("Non-regular files aren't supported yet"), .syscall = bun.String.static("fstat"), }; @@ -3152,10 +3153,10 @@ pub const Blob = struct { const written = switch (comptime use) { .copy_file_range => linux.copy_file_range(src_fd.cast(), null, dest_fd.cast(), null, remain, 0), .sendfile => linux.sendfile(dest_fd.cast(), src_fd.cast(), null, remain), - .splice => bun.C.splice(src_fd.cast(), null, dest_fd.cast(), null, remain, 0), + .splice => C.splice(src_fd.cast(), null, dest_fd.cast(), null, remain, 0), }; - switch (bun.C.getErrno(written)) { + switch (C.getErrno(written)) { .SUCCESS => {}, .NOSYS, .XDEV => { @@ -3333,7 +3334,7 @@ pub const Blob = struct { if (this.doClonefile()) { if (this.max_length != Blob.max_size and this.max_length < @as(SizeType, @intCast(stat_.?.size))) { // If this fails...well, there's not much we can do about it. - _ = bun.C.truncate( + _ = C.truncate( this.destination_file_store.pathlike.path.sliceZ(&path_buf), @as(std.posix.off_t, @intCast(this.max_length)), ); @@ -3399,10 +3400,10 @@ pub const Blob = struct { } if (posix.S.ISREG(stat.mode) and - this.max_length > bun.C.preallocate_length and + this.max_length > C.preallocate_length and this.max_length != Blob.max_size) { - bun.C.preallocate_file(this.destination_fd.cast(), 0, this.max_length) catch {}; + C.preallocate_file(this.destination_fd.cast(), 0, this.max_length) catch {}; } } @@ -3868,7 +3869,7 @@ pub const Blob = struct { // We say regular files and pipes exist. // This is mostly meant for "Can we use this in new Response(file)?" - return JSValue.jsBoolean(bun.isRegularFile(store.data.file.mode) or bun.C.S.ISFIFO(store.data.file.mode)); + return JSValue.jsBoolean(bun.isRegularFile(store.data.file.mode) or C.S.ISFIFO(store.data.file.mode)); } pub fn isS3(this: *const Blob) bool { diff --git a/src/bun.js/webcore/blob/ReadFile.zig b/src/bun.js/webcore/blob/ReadFile.zig index 2add4b0053e365..a324147008e21c 100644 --- a/src/bun.js/webcore/blob/ReadFile.zig +++ b/src/bun.js/webcore/blob/ReadFile.zig @@ -1,4 +1,5 @@ const bun = @import("root").bun; +const C = @import("root").C; const JSC = bun.JSC; const std = @import("std"); const Blob = JSC.WebCore.Blob; @@ -711,8 +712,8 @@ pub const ReadFileUV = struct { } // Out of memory we can't read more than 4GB at a time (ULONG) on Windows if (this.size > @as(usize, std.math.maxInt(bun.windows.ULONG))) { - this.errno = bun.errnoToZigErr(bun.C.E.NOMEM); - this.system_error = bun.sys.Error.fromCode(bun.C.E.NOMEM, .read).toSystemError(); + this.errno = bun.errnoToZigErr(C.E.NOMEM); + this.system_error = bun.sys.Error.fromCode(C.E.NOMEM, .read).toSystemError(); this.onFinish(); return; } diff --git a/src/bun.js/webcore/blob/WriteFile.zig b/src/bun.js/webcore/blob/WriteFile.zig index 9560fc4cd2f18f..6f0d03fd729be7 100644 --- a/src/bun.js/webcore/blob/WriteFile.zig +++ b/src/bun.js/webcore/blob/WriteFile.zig @@ -1,4 +1,5 @@ const bun = @import("root").bun; +const C = @import("root").C; const JSC = bun.JSC; const std = @import("std"); const Blob = JSC.WebCore.Blob; @@ -287,7 +288,7 @@ pub const WriteFile = struct { // seemed to have zero performance impact in // microbenchmarks. if (!this.could_block and this.bytes_blob.sharedView().len > 1024) { - bun.C.preallocate_file(fd.cast(), 0, @intCast(this.bytes_blob.sharedView().len)) catch {}; // we don't care if it fails. + C.preallocate_file(fd.cast(), 0, @intCast(this.bytes_blob.sharedView().len)) catch {}; // we don't care if it fails. } } @@ -434,7 +435,7 @@ pub const WriteFileWindows = struct { &this.io_request, &(std.posix.toPosixPath(path) catch { this.throw(bun.sys.Error{ - .errno = @intFromEnum(bun.C.E.NAMETOOLONG), + .errno = @intFromEnum(C.E.NAMETOOLONG), .syscall = .open, }); return; diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index 9cfa4dc51e6d56..99d2a38ab6cfe6 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -1,6 +1,7 @@ const std = @import("std"); const Api = @import("../../api/schema.zig").Api; const bun = @import("root").bun; +const C = @import("root").C; const MimeType = HTTPClient.MimeType; const ZigURL = @import("../../url.zig").URL; const HTTPClient = bun.http; @@ -30,7 +31,7 @@ const JSInternalPromise = JSC.JSInternalPromise; const JSPromise = JSC.JSPromise; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; -const E = bun.C.E; +const E = C.E; const VirtualMachine = JSC.VirtualMachine; const Task = JSC.Task; const JSPrinter = bun.js_printer; @@ -609,7 +610,7 @@ pub const StreamStart = union(Tag) { if (!path.isString()) { return .{ .err = Syscall.Error{ - .errno = @intFromEnum(bun.C.SystemErrno.EINVAL), + .errno = @intFromEnum(C.SystemErrno.EINVAL), .syscall = .write, }, }; @@ -627,7 +628,7 @@ pub const StreamStart = union(Tag) { if (!fd_value.isAnyInt()) { return .{ .err = Syscall.Error{ - .errno = @intFromEnum(bun.C.SystemErrno.EBADF), + .errno = @intFromEnum(C.SystemErrno.EBADF), .syscall = .write, }, }; @@ -645,7 +646,7 @@ pub const StreamStart = union(Tag) { } else { return .{ .err = Syscall.Error{ - .errno = @intFromEnum(bun.C.SystemErrno.EBADF), + .errno = @intFromEnum(C.SystemErrno.EBADF), .syscall = .write, }, }; @@ -3586,7 +3587,7 @@ pub const FileSink = struct { .fd => |fd_| brk: { if (comptime Environment.isPosix and FeatureFlags.nonblocking_stdout_and_stderr_on_posix) { if (bun.FDTag.get(fd_) != .none) { - const rc = bun.C.open_as_nonblocking_tty(@intCast(fd_.cast()), bun.O.WRONLY); + const rc = C.open_as_nonblocking_tty(@intCast(fd_.cast()), bun.O.WRONLY); if (rc > -1) { isatty = true; is_nonblocking_tty = true; @@ -3974,7 +3975,7 @@ pub const FileReader = struct { const fd = if (file.pathlike == .fd) if (file.pathlike.fd.isStdio()) brk: { if (comptime Environment.isPosix) { - const rc = bun.C.open_as_nonblocking_tty(file.pathlike.fd.int(), bun.O.RDONLY); + const rc = C.open_as_nonblocking_tty(file.pathlike.fd.int(), bun.O.RDONLY); if (rc > -1) { is_nonblocking_tty = true; file.is_atty = true; @@ -4017,7 +4018,7 @@ pub const FileReader = struct { { // var termios = std.mem.zeroes(std.posix.termios); // _ = std.c.tcgetattr(fd.cast(), &termios); - // bun.C.cfmakeraw(&termios); + // C.cfmakeraw(&termios); // _ = std.c.tcsetattr(fd.cast(), std.posix.TCSA.NOW, &termios); file.is_atty = true; } diff --git a/src/bun.zig b/src/bun.zig index 5ae74eae5cc12e..423f561336dbfa 100644 --- a/src/bun.zig +++ b/src/bun.zig @@ -8,6 +8,7 @@ const builtin = @import("builtin"); const std = @import("std"); const bun = @This(); +const C = @import("root").C; pub const Environment = @import("env.zig"); @@ -102,7 +103,6 @@ pub const JSOOM = OOM || JSError; pub const detectCI = @import("./ci_info.zig").detectCI; -pub const C = @import("root").C; pub const sha = @import("./sha.zig"); pub const FeatureFlags = @import("feature_flags.zig"); pub const meta = @import("./meta.zig"); diff --git a/src/bun_js.zig b/src/bun_js.zig index 3c25404f899c4e..608904a904d387 100644 --- a/src/bun_js.zig +++ b/src/bun_js.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const lex = bun.js_lexer; diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index 55ce5fe86e1c21..b6970d5457a2ce 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -43,6 +43,7 @@ // const Transpiler = bun.Transpiler; const bun = @import("root").bun; +const C = @import("root").C; const string = bun.string; const Output = bun.Output; const Global = bun.Global; @@ -53,7 +54,6 @@ const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const StoredFileDescriptorType = bun.StoredFileDescriptorType; const FeatureFlags = bun.FeatureFlags; -const C = bun.C; const std = @import("std"); const lex = @import("../js_lexer.zig"); const Logger = @import("../logger.zig"); @@ -4011,7 +4011,7 @@ pub const ParseTask = struct { result: ?*OnBeforeParseResult = null, - const headers = bun.C.translated; + const headers = C.translated; comptime { bun.assert(@sizeOf(OnBeforeParseArguments) == @sizeOf(headers.OnBeforeParseArguments)); diff --git a/src/bunfig.zig b/src/bunfig.zig index 8ca56ec0ee8c7f..1011d7750b3ca8 100644 --- a/src/bunfig.zig +++ b/src/bunfig.zig @@ -9,7 +9,7 @@ const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const URL = @import("./url.zig").URL; -const C = bun.C; +const C = @import("root").C; const options = @import("./options.zig"); const logger = bun.logger; const js_ast = bun.JSAst; diff --git a/src/c-headers-for-zig.h b/src/c-headers-for-zig.h index 42c03aca64326e..d7dd76599357dd 100644 --- a/src/c-headers-for-zig.h +++ b/src/c-headers-for-zig.h @@ -1,5 +1,5 @@ // This file is run through translate-c and exposed to Zig code -// under the namespace bun.C.translated. Prefer adding includes +// under the namespace C.translated. Prefer adding includes // to this file instead of manually porting struct definitions // into Zig code. By using automatic translation, differences // in platforms can be avoided. diff --git a/src/cache.zig b/src/cache.zig index 96ecf3484c45de..7f9c6f2f0e157b 100644 --- a/src/cache.zig +++ b/src/cache.zig @@ -9,7 +9,7 @@ const MutableString = bun.MutableString; const stringZ = bun.stringZ; const FeatureFlags = bun.FeatureFlags; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const js_ast = bun.JSAst; const logger = bun.logger; diff --git a/src/cli.zig b/src/cli.zig index dda794d31958e1..31beb585d4c590 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -8,7 +8,7 @@ const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const FeatureFlags = bun.FeatureFlags; -const C = bun.C; +const C = @import("root").C; const root = @import("root"); const std = @import("std"); const lex = bun.js_lexer; diff --git a/src/cli/build_command.zig b/src/cli/build_command.zig index 073bceb1296d82..48f66797e182be 100644 --- a/src/cli/build_command.zig +++ b/src/cli/build_command.zig @@ -9,7 +9,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const lex = bun.js_lexer; const logger = bun.logger; diff --git a/src/cli/bunx_command.zig b/src/cli/bunx_command.zig index dcd75f5647bef9..2d21affa3477fc 100644 --- a/src/cli/bunx_command.zig +++ b/src/cli/bunx_command.zig @@ -9,7 +9,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const cli = @import("../cli.zig"); const Command = cli.Command; @@ -478,7 +478,7 @@ pub const BunxCommand = struct { // where a user can replace the directory with malicious code. // // If this format changes, please update cache clearing code in package_manager_command.zig - const uid = if (bun.Environment.isPosix) bun.C.getuid() else bun.windows.userUniqueId(); + const uid = if (bun.Environment.isPosix) C.getuid() else bun.windows.userUniqueId(); PATH = switch (PATH.len > 0) { inline else => |path_is_nonzero| try std.fmt.allocPrint( ctx.allocator, diff --git a/src/cli/colon_list_type.zig b/src/cli/colon_list_type.zig index e76652925069c6..1d1ae2e907d80c 100644 --- a/src/cli/colon_list_type.zig +++ b/src/cli/colon_list_type.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); pub fn ColonListType(comptime t: type, comptime value_resolver: anytype) type { diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index 2723e33f5a718a..c06e1c5cdc7819 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const Progress = bun.Progress; diff --git a/src/cli/discord_command.zig b/src/cli/discord_command.zig index 06fff1238f8926..5c0375c3c612d4 100644 --- a/src/cli/discord_command.zig +++ b/src/cli/discord_command.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const open = @import("../open.zig"); diff --git a/src/cli/exec_command.zig b/src/cli/exec_command.zig index 0711d7b1e34674..c89e2663388a5a 100644 --- a/src/cli/exec_command.zig +++ b/src/cli/exec_command.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const open = @import("../open.zig"); const Command = bun.CLI.Command; diff --git a/src/cli/init_command.zig b/src/cli/init_command.zig index 01d4d3112acd2e..b160320d823f02 100644 --- a/src/cli/init_command.zig +++ b/src/cli/init_command.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const open = @import("../open.zig"); const CLI = @import("../cli.zig"); diff --git a/src/cli/install_completions_command.zig b/src/cli/install_completions_command.zig index ed9e5d02ace5cf..e11e0736e4149d 100644 --- a/src/cli/install_completions_command.zig +++ b/src/cli/install_completions_command.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const lex = bun.js_lexer; diff --git a/src/cli/pack_command.zig b/src/cli/pack_command.zig index 8918c2123314bc..15f8e4589215d5 100644 --- a/src/cli/pack_command.zig +++ b/src/cli/pack_command.zig @@ -1,5 +1,6 @@ const std = @import("std"); const bun = @import("root").bun; +const C = @import("root").C; const Global = bun.Global; const Output = bun.Output; const Command = bun.CLI.Command; @@ -2395,7 +2396,7 @@ pub const bindings = struct { }, else => { const pathname = archive_entry.pathname(); - const kind = bun.C.kindFromMode(archive_entry.filetype()); + const kind = C.kindFromMode(archive_entry.filetype()); const perm = archive_entry.perm(); var entry_info: EntryInfo = .{ diff --git a/src/cli/package_manager_command.zig b/src/cli/package_manager_command.zig index 8a246ec74bafd3..cee91864078400 100644 --- a/src/cli/package_manager_command.zig +++ b/src/cli/package_manager_command.zig @@ -1,6 +1,7 @@ const std = @import("std"); const Progress = std.Progress; const bun = @import("root").bun; +const C = @import("root").C; const Global = bun.Global; const Output = bun.Output; const string = bun.string; @@ -273,7 +274,7 @@ pub const PackageManagerCommand = struct { // This is to match 'bunx_command.BunxCommand.exec's logic const prefix = try std.fmt.allocPrint(ctx.allocator, "bunx-{d}-", .{ - if (bun.Environment.isPosix) bun.C.getuid() else bun.windows.userUniqueId(), + if (bun.Environment.isPosix) C.getuid() else bun.windows.userUniqueId(), }); var deleted: usize = 0; diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index 4ae3c93ed1c564..78643fd4706e8b 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -8,7 +8,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const uws = bun.uws; const JSC = bun.JSC; diff --git a/src/cli/shell_completions.zig b/src/cli/shell_completions.zig index 4df3eb70b831d6..7f5620f3fd9acb 100644 --- a/src/cli/shell_completions.zig +++ b/src/cli/shell_completions.zig @@ -8,7 +8,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; pub const Shell = enum { unknown, diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index 050a83880cadc9..31d7d2c58dca96 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const OOM = bun.OOM; @@ -933,7 +933,7 @@ pub const CommandLineReporter = struct { if (comptime reporters.lcov) { try lcov_buffered_writer.flush(); lcov_file.close(); - bun.C.moveFileZ( + C.moveFileZ( bun.toFD(std.fs.cwd()), lcov_name, bun.toFD(std.fs.cwd()), diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index f39e4b906ed790..3947e0bb82fef9 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const Progress = bun.Progress; diff --git a/src/compile_target.zig b/src/compile_target.zig index 82f0731dd369a2..690e95652cb3f5 100644 --- a/src/compile_target.zig +++ b/src/compile_target.zig @@ -5,6 +5,7 @@ /// It stores the downloaded binary into the bun install cache. /// const bun = @import("root").bun; +const C = @import("root").C; const std = @import("std"); const Environment = bun.Environment; const strings = bun.strings; @@ -73,23 +74,23 @@ pub fn toNPMRegistryURLWithURL(this: *const CompileTarget, buf: []u8, registry_u return switch (this.os) { inline else => |os| switch (this.arch) { inline else => |arch| switch (this.libc) { - inline else => |libc| switch (this.baseline) { - // https://registry.npmjs.org/@oven/bun-linux-x64/-/bun-linux-x64-0.1.6.tgz - inline else => |is_baseline| try std.fmt.bufPrint(buf, comptime "{s}/@oven/bun-" ++ - os.npmName() ++ "-" ++ arch.npmName() ++ - libc.npmName() ++ - (if (is_baseline) "-baseline" else "") ++ - "/-/bun-" ++ - os.npmName() ++ "-" ++ arch.npmName() ++ - libc.npmName() ++ - (if (is_baseline) "-baseline" else "") ++ - "-" ++ - "{d}.{d}.{d}.tgz", .{ - registry_url, - this.version.major, - this.version.minor, - this.version.patch, - }), + inline else => |libc| switch (this.baseline) { + // https://registry.npmjs.org/@oven/bun-linux-x64/-/bun-linux-x64-0.1.6.tgz + inline else => |is_baseline| try std.fmt.bufPrint(buf, comptime "{s}/@oven/bun-" ++ + os.npmName() ++ "-" ++ arch.npmName() ++ + libc.npmName() ++ + (if (is_baseline) "-baseline" else "") ++ + "/-/bun-" ++ + os.npmName() ++ "-" ++ arch.npmName() ++ + libc.npmName() ++ + (if (is_baseline) "-baseline" else "") ++ + "-" ++ + "{d}.{d}.{d}.tgz", .{ + registry_url, + this.version.major, + this.version.minor, + this.version.patch, + }), }, }, }, @@ -297,7 +298,7 @@ pub fn downloadToPath(this: *const CompileTarget, env: *bun.DotEnv.Loader, alloc var did_retry = false; while (true) { - bun.C.moveFileZ(bun.toFD(tmpdir), if (this.os == .windows) "bun.exe" else "bun", bun.invalid_fd, dest_z) catch |err| { + C.moveFileZ(bun.toFD(tmpdir), if (this.os == .windows) "bun.exe" else "bun", bun.invalid_fd, dest_z) catch |err| { if (!did_retry) { did_retry = true; const dirname = bun.path.dirname(dest_z, .loose); diff --git a/src/copy_file.zig b/src/copy_file.zig index 1d66e8ed047edd..0f2c11eac98aa6 100644 --- a/src/copy_file.zig +++ b/src/copy_file.zig @@ -5,6 +5,7 @@ const std = @import("std"); const posix = std.posix; const math = std.math; const bun = @import("root").bun; +const C = @import("root").C; const strings = bun.strings; const Environment = bun.Environment; @@ -75,10 +76,10 @@ pub fn copyFileWithState(in: InputType, out: InputType, copy_file_state: *CopyFi if (can_use_ioctl_ficlone() and !copy_file_state.has_seen_exdev and !copy_file_state.has_ioctl_ficlone_failed) { // We only check once if the ioctl is supported, and cache the result. // EXT4 does not support FICLONE. - const rc = bun.C.linux.ioctl_ficlone(bun.toFD(out), bun.toFD(in)); + const rc = C.linux.ioctl_ficlone(bun.toFD(out), bun.toFD(in)); // the ordering is flipped but it is consistent with other system calls. bun.sys.syslog("ioctl_ficlone({d}, {d}) = {d}", .{ in, out, rc }); - switch (bun.C.getErrno(rc)) { + switch (C.getErrno(rc)) { .SUCCESS => return CopyFileReturnType.success, .XDEV => { copy_file_state.has_seen_exdev = true; @@ -214,7 +215,7 @@ pub fn copyFileRange(in: fd_t, out: fd_t, len: usize, flags: u32, copy_file_stat while (true) { const rc = std.os.linux.copy_file_range(in, null, out, null, len, flags); bun.sys.syslog("copy_file_range({d}, {d}, {d}) = {d}", .{ in, out, len, rc }); - switch (bun.C.getErrno(rc)) { + switch (C.getErrno(rc)) { .SUCCESS => return .{ .result = @intCast(rc) }, // these may not be regular files, try fallback .INVAL => { @@ -245,7 +246,7 @@ pub fn copyFileRange(in: fd_t, out: fd_t, len: usize, flags: u32, copy_file_stat while (!copy_file_state.has_sendfile_failed) { const rc = std.os.linux.sendfile(@intCast(out), @intCast(in), null, len); bun.sys.syslog("sendfile({d}, {d}, {d}) = {d}", .{ in, out, len, rc }); - switch (bun.C.getErrno(rc)) { + switch (C.getErrno(rc)) { .SUCCESS => return .{ .result = @intCast(rc) }, .INTR => continue, // these may not be regular files, try fallback diff --git a/src/css_scanner.zig b/src/css_scanner.zig index 03ad54e3bb6e92..061a2bdf4aba4f 100644 --- a/src/css_scanner.zig +++ b/src/css_scanner.zig @@ -12,7 +12,7 @@ const StoredFileDescriptorType = bun.StoredFileDescriptorType; const FeatureFlags = bun.FeatureFlags; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const options = @import("./options.zig"); const import_record = @import("import_record.zig"); const logger = bun.logger; diff --git a/src/defines-table.zig b/src/defines-table.zig index 8fdfeda58e52f2..4f9219fd582291 100644 --- a/src/defines-table.zig +++ b/src/defines-table.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const defines = @import("./defines.zig"); diff --git a/src/defines.zig b/src/defines.zig index f038248505ab35..d6e01459e97f8d 100644 --- a/src/defines.zig +++ b/src/defines.zig @@ -13,7 +13,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const Ref = @import("ast/base.zig").Ref; const GlobalDefinesKey = @import("./defines-table.zig").GlobalDefinesKey; diff --git a/src/deps/libuv.zig b/src/deps/libuv.zig index 071b1862b12313..a6104736a7109a 100644 --- a/src/deps/libuv.zig +++ b/src/deps/libuv.zig @@ -1,4 +1,5 @@ const bun = @import("root").bun; +const C = @import("root").C; const Maybe = bun.JSC.Maybe; const WORD = c_ushort; @@ -634,7 +635,7 @@ pub const Loop = extern struct { return loop_alive; } - pub fn init(ptr: *Loop) ?bun.C.E { + pub fn init(ptr: *Loop) ?C.E { if (uv_loop_init(ptr).errEnum()) |err| return err; return null; } @@ -2573,78 +2574,78 @@ pub fn uv_is_closed(handle: *const uv_handle_t) bool { return (handle.flags & UV_HANDLE_CLOSED != 0); } -pub fn translateUVErrorToE(code_in: anytype) bun.C.E { +pub fn translateUVErrorToE(code_in: anytype) C.E { const code: c_int = @intCast(code_in); return switch (code) { - UV_EPERM => bun.C.E.PERM, - UV_ENOENT => bun.C.E.NOENT, - UV_ESRCH => bun.C.E.SRCH, - UV_EINTR => bun.C.E.INTR, - UV_EIO => bun.C.E.IO, - UV_ENXIO => bun.C.E.NXIO, - UV_E2BIG => bun.C.E.@"2BIG", - UV_EBADF => bun.C.E.BADF, - UV_EAGAIN => bun.C.E.AGAIN, - UV_ENOMEM => bun.C.E.NOMEM, - UV_EACCES => bun.C.E.ACCES, - UV_EFAULT => bun.C.E.FAULT, - UV_EBUSY => bun.C.E.BUSY, - UV_EEXIST => bun.C.E.EXIST, - UV_EXDEV => bun.C.E.XDEV, - UV_ENODEV => bun.C.E.NODEV, - UV_ENOTDIR => bun.C.E.NOTDIR, - UV_EISDIR => bun.C.E.ISDIR, - UV_EINVAL => bun.C.E.INVAL, - UV_ENFILE => bun.C.E.NFILE, - UV_EMFILE => bun.C.E.MFILE, - UV_ENOTTY => bun.C.E.NOTTY, - UV_ETXTBSY => bun.C.E.TXTBSY, - UV_EFBIG => bun.C.E.FBIG, - UV_ENOSPC => bun.C.E.NOSPC, - UV_ESPIPE => bun.C.E.SPIPE, - UV_EROFS => bun.C.E.ROFS, - UV_EMLINK => bun.C.E.MLINK, - UV_EPIPE => bun.C.E.PIPE, - UV_ERANGE => bun.C.E.RANGE, - UV_ENAMETOOLONG => bun.C.E.NAMETOOLONG, - UV_ENOSYS => bun.C.E.NOSYS, - UV_ENOTEMPTY => bun.C.E.NOTEMPTY, - UV_ELOOP => bun.C.E.LOOP, - UV_EUNATCH => bun.C.E.UNATCH, - UV_ENODATA => bun.C.E.NODATA, - UV_ENONET => bun.C.E.NONET, - UV_EPROTO => bun.C.E.PROTO, - UV_EOVERFLOW => bun.C.E.OVERFLOW, - UV_EILSEQ => bun.C.E.ILSEQ, - UV_ENOTSOCK => bun.C.E.NOTSOCK, - UV_EDESTADDRREQ => bun.C.E.DESTADDRREQ, - UV_EMSGSIZE => bun.C.E.MSGSIZE, - UV_EPROTOTYPE => bun.C.E.PROTOTYPE, - UV_ENOPROTOOPT => bun.C.E.NOPROTOOPT, - UV_EPROTONOSUPPORT => bun.C.E.PROTONOSUPPORT, - UV_ESOCKTNOSUPPORT => bun.C.E.SOCKTNOSUPPORT, - UV_ENOTSUP => bun.C.E.NOTSUP, - UV_EAFNOSUPPORT => bun.C.E.AFNOSUPPORT, - UV_EADDRINUSE => bun.C.E.ADDRINUSE, - UV_EADDRNOTAVAIL => bun.C.E.ADDRNOTAVAIL, - UV_ENETDOWN => bun.C.E.NETDOWN, - UV_ENETUNREACH => bun.C.E.NETUNREACH, - UV_ECONNABORTED => bun.C.E.CONNABORTED, - UV_ECONNRESET => bun.C.E.CONNRESET, - UV_ENOBUFS => bun.C.E.NOBUFS, - UV_EISCONN => bun.C.E.ISCONN, - UV_ENOTCONN => bun.C.E.NOTCONN, - UV_ESHUTDOWN => bun.C.E.SHUTDOWN, - UV_ETIMEDOUT => bun.C.E.TIMEDOUT, - UV_ECONNREFUSED => bun.C.E.CONNREFUSED, - UV_EHOSTDOWN => bun.C.E.HOSTDOWN, - UV_EHOSTUNREACH => bun.C.E.HOSTUNREACH, - UV_EALREADY => bun.C.E.ALREADY, - UV_EREMOTEIO => bun.C.E.REMOTEIO, - UV_ECANCELED => bun.C.E.CANCELED, - UV_ECHARSET => bun.C.E.CHARSET, - UV_EOF => bun.C.E.EOF, + UV_EPERM => C.E.PERM, + UV_ENOENT => C.E.NOENT, + UV_ESRCH => C.E.SRCH, + UV_EINTR => C.E.INTR, + UV_EIO => C.E.IO, + UV_ENXIO => C.E.NXIO, + UV_E2BIG => C.E.@"2BIG", + UV_EBADF => C.E.BADF, + UV_EAGAIN => C.E.AGAIN, + UV_ENOMEM => C.E.NOMEM, + UV_EACCES => C.E.ACCES, + UV_EFAULT => C.E.FAULT, + UV_EBUSY => C.E.BUSY, + UV_EEXIST => C.E.EXIST, + UV_EXDEV => C.E.XDEV, + UV_ENODEV => C.E.NODEV, + UV_ENOTDIR => C.E.NOTDIR, + UV_EISDIR => C.E.ISDIR, + UV_EINVAL => C.E.INVAL, + UV_ENFILE => C.E.NFILE, + UV_EMFILE => C.E.MFILE, + UV_ENOTTY => C.E.NOTTY, + UV_ETXTBSY => C.E.TXTBSY, + UV_EFBIG => C.E.FBIG, + UV_ENOSPC => C.E.NOSPC, + UV_ESPIPE => C.E.SPIPE, + UV_EROFS => C.E.ROFS, + UV_EMLINK => C.E.MLINK, + UV_EPIPE => C.E.PIPE, + UV_ERANGE => C.E.RANGE, + UV_ENAMETOOLONG => C.E.NAMETOOLONG, + UV_ENOSYS => C.E.NOSYS, + UV_ENOTEMPTY => C.E.NOTEMPTY, + UV_ELOOP => C.E.LOOP, + UV_EUNATCH => C.E.UNATCH, + UV_ENODATA => C.E.NODATA, + UV_ENONET => C.E.NONET, + UV_EPROTO => C.E.PROTO, + UV_EOVERFLOW => C.E.OVERFLOW, + UV_EILSEQ => C.E.ILSEQ, + UV_ENOTSOCK => C.E.NOTSOCK, + UV_EDESTADDRREQ => C.E.DESTADDRREQ, + UV_EMSGSIZE => C.E.MSGSIZE, + UV_EPROTOTYPE => C.E.PROTOTYPE, + UV_ENOPROTOOPT => C.E.NOPROTOOPT, + UV_EPROTONOSUPPORT => C.E.PROTONOSUPPORT, + UV_ESOCKTNOSUPPORT => C.E.SOCKTNOSUPPORT, + UV_ENOTSUP => C.E.NOTSUP, + UV_EAFNOSUPPORT => C.E.AFNOSUPPORT, + UV_EADDRINUSE => C.E.ADDRINUSE, + UV_EADDRNOTAVAIL => C.E.ADDRNOTAVAIL, + UV_ENETDOWN => C.E.NETDOWN, + UV_ENETUNREACH => C.E.NETUNREACH, + UV_ECONNABORTED => C.E.CONNABORTED, + UV_ECONNRESET => C.E.CONNRESET, + UV_ENOBUFS => C.E.NOBUFS, + UV_EISCONN => C.E.ISCONN, + UV_ENOTCONN => C.E.NOTCONN, + UV_ESHUTDOWN => C.E.SHUTDOWN, + UV_ETIMEDOUT => C.E.TIMEDOUT, + UV_ECONNREFUSED => C.E.CONNREFUSED, + UV_EHOSTDOWN => C.E.HOSTDOWN, + UV_EHOSTUNREACH => C.E.HOSTUNREACH, + UV_EALREADY => C.E.ALREADY, + UV_EREMOTEIO => C.E.REMOTEIO, + UV_ECANCELED => C.E.CANCELED, + UV_ECHARSET => C.E.CHARSET, + UV_EOF => C.E.EOF, else => @enumFromInt(-code), }; } @@ -2679,84 +2680,84 @@ pub const ReturnCode = enum(c_int) { return null; } - pub inline fn errno(this: ReturnCode) ?@TypeOf(@intFromEnum(bun.C.E.ACCES)) { + pub inline fn errno(this: ReturnCode) ?@TypeOf(@intFromEnum(C.E.ACCES)) { return if (this.int() < 0) switch (this.int()) { - UV_EPERM => @intFromEnum(bun.C.E.PERM), - UV_ENOENT => @intFromEnum(bun.C.E.NOENT), - UV_ESRCH => @intFromEnum(bun.C.E.SRCH), - UV_EINTR => @intFromEnum(bun.C.E.INTR), - UV_EIO => @intFromEnum(bun.C.E.IO), - UV_ENXIO => @intFromEnum(bun.C.E.NXIO), - UV_E2BIG => @intFromEnum(bun.C.E.@"2BIG"), - UV_EBADF => @intFromEnum(bun.C.E.BADF), - UV_EAGAIN => @intFromEnum(bun.C.E.AGAIN), - UV_ENOMEM => @intFromEnum(bun.C.E.NOMEM), - UV_EACCES => @intFromEnum(bun.C.E.ACCES), - UV_EFAULT => @intFromEnum(bun.C.E.FAULT), - UV_EBUSY => @intFromEnum(bun.C.E.BUSY), - UV_EEXIST => @intFromEnum(bun.C.E.EXIST), - UV_EXDEV => @intFromEnum(bun.C.E.XDEV), - UV_ENODEV => @intFromEnum(bun.C.E.NODEV), - UV_ENOTDIR => @intFromEnum(bun.C.E.NOTDIR), - UV_EISDIR => @intFromEnum(bun.C.E.ISDIR), - UV_EINVAL => @intFromEnum(bun.C.E.INVAL), - UV_ENFILE => @intFromEnum(bun.C.E.NFILE), - UV_EMFILE => @intFromEnum(bun.C.E.MFILE), - UV_ENOTTY => @intFromEnum(bun.C.E.NOTTY), - UV_ETXTBSY => @intFromEnum(bun.C.E.TXTBSY), - UV_EFBIG => @intFromEnum(bun.C.E.FBIG), - UV_ENOSPC => @intFromEnum(bun.C.E.NOSPC), - UV_ESPIPE => @intFromEnum(bun.C.E.SPIPE), - UV_EROFS => @intFromEnum(bun.C.E.ROFS), - UV_EMLINK => @intFromEnum(bun.C.E.MLINK), - UV_EPIPE => @intFromEnum(bun.C.E.PIPE), - UV_ERANGE => @intFromEnum(bun.C.E.RANGE), - UV_ENAMETOOLONG => @intFromEnum(bun.C.E.NAMETOOLONG), - UV_ENOSYS => @intFromEnum(bun.C.E.NOSYS), - UV_ENOTEMPTY => @intFromEnum(bun.C.E.NOTEMPTY), - UV_ELOOP => @intFromEnum(bun.C.E.LOOP), - UV_EUNATCH => @intFromEnum(bun.C.E.UNATCH), - UV_ENODATA => @intFromEnum(bun.C.E.NODATA), - UV_ENONET => @intFromEnum(bun.C.E.NONET), - UV_EPROTO => @intFromEnum(bun.C.E.PROTO), - UV_EOVERFLOW => @intFromEnum(bun.C.E.OVERFLOW), - UV_EILSEQ => @intFromEnum(bun.C.E.ILSEQ), - UV_ENOTSOCK => @intFromEnum(bun.C.E.NOTSOCK), - UV_EDESTADDRREQ => @intFromEnum(bun.C.E.DESTADDRREQ), - UV_EMSGSIZE => @intFromEnum(bun.C.E.MSGSIZE), - UV_EPROTOTYPE => @intFromEnum(bun.C.E.PROTOTYPE), - UV_ENOPROTOOPT => @intFromEnum(bun.C.E.NOPROTOOPT), - UV_EPROTONOSUPPORT => @intFromEnum(bun.C.E.PROTONOSUPPORT), - UV_ESOCKTNOSUPPORT => @intFromEnum(bun.C.E.SOCKTNOSUPPORT), - UV_ENOTSUP => @intFromEnum(bun.C.E.NOTSUP), - UV_EAFNOSUPPORT => @intFromEnum(bun.C.E.AFNOSUPPORT), - UV_EADDRINUSE => @intFromEnum(bun.C.E.ADDRINUSE), - UV_EADDRNOTAVAIL => @intFromEnum(bun.C.E.ADDRNOTAVAIL), - UV_ENETDOWN => @intFromEnum(bun.C.E.NETDOWN), - UV_ENETUNREACH => @intFromEnum(bun.C.E.NETUNREACH), - UV_ECONNABORTED => @intFromEnum(bun.C.E.CONNABORTED), - UV_ECONNRESET => @intFromEnum(bun.C.E.CONNRESET), - UV_ENOBUFS => @intFromEnum(bun.C.E.NOBUFS), - UV_EISCONN => @intFromEnum(bun.C.E.ISCONN), - UV_ENOTCONN => @intFromEnum(bun.C.E.NOTCONN), - UV_ESHUTDOWN => @intFromEnum(bun.C.E.SHUTDOWN), - UV_ETIMEDOUT => @intFromEnum(bun.C.E.TIMEDOUT), - UV_ECONNREFUSED => @intFromEnum(bun.C.E.CONNREFUSED), - UV_EHOSTDOWN => @intFromEnum(bun.C.E.HOSTDOWN), - UV_EHOSTUNREACH => @intFromEnum(bun.C.E.HOSTUNREACH), - UV_EALREADY => @intFromEnum(bun.C.E.ALREADY), - UV_EREMOTEIO => @intFromEnum(bun.C.E.REMOTEIO), - UV_ECANCELED => @intFromEnum(bun.C.E.CANCELED), - UV_ECHARSET => @intFromEnum(bun.C.E.CHARSET), - UV_EOF => @intFromEnum(bun.C.E.EOF), + UV_EPERM => @intFromEnum(C.E.PERM), + UV_ENOENT => @intFromEnum(C.E.NOENT), + UV_ESRCH => @intFromEnum(C.E.SRCH), + UV_EINTR => @intFromEnum(C.E.INTR), + UV_EIO => @intFromEnum(C.E.IO), + UV_ENXIO => @intFromEnum(C.E.NXIO), + UV_E2BIG => @intFromEnum(C.E.@"2BIG"), + UV_EBADF => @intFromEnum(C.E.BADF), + UV_EAGAIN => @intFromEnum(C.E.AGAIN), + UV_ENOMEM => @intFromEnum(C.E.NOMEM), + UV_EACCES => @intFromEnum(C.E.ACCES), + UV_EFAULT => @intFromEnum(C.E.FAULT), + UV_EBUSY => @intFromEnum(C.E.BUSY), + UV_EEXIST => @intFromEnum(C.E.EXIST), + UV_EXDEV => @intFromEnum(C.E.XDEV), + UV_ENODEV => @intFromEnum(C.E.NODEV), + UV_ENOTDIR => @intFromEnum(C.E.NOTDIR), + UV_EISDIR => @intFromEnum(C.E.ISDIR), + UV_EINVAL => @intFromEnum(C.E.INVAL), + UV_ENFILE => @intFromEnum(C.E.NFILE), + UV_EMFILE => @intFromEnum(C.E.MFILE), + UV_ENOTTY => @intFromEnum(C.E.NOTTY), + UV_ETXTBSY => @intFromEnum(C.E.TXTBSY), + UV_EFBIG => @intFromEnum(C.E.FBIG), + UV_ENOSPC => @intFromEnum(C.E.NOSPC), + UV_ESPIPE => @intFromEnum(C.E.SPIPE), + UV_EROFS => @intFromEnum(C.E.ROFS), + UV_EMLINK => @intFromEnum(C.E.MLINK), + UV_EPIPE => @intFromEnum(C.E.PIPE), + UV_ERANGE => @intFromEnum(C.E.RANGE), + UV_ENAMETOOLONG => @intFromEnum(C.E.NAMETOOLONG), + UV_ENOSYS => @intFromEnum(C.E.NOSYS), + UV_ENOTEMPTY => @intFromEnum(C.E.NOTEMPTY), + UV_ELOOP => @intFromEnum(C.E.LOOP), + UV_EUNATCH => @intFromEnum(C.E.UNATCH), + UV_ENODATA => @intFromEnum(C.E.NODATA), + UV_ENONET => @intFromEnum(C.E.NONET), + UV_EPROTO => @intFromEnum(C.E.PROTO), + UV_EOVERFLOW => @intFromEnum(C.E.OVERFLOW), + UV_EILSEQ => @intFromEnum(C.E.ILSEQ), + UV_ENOTSOCK => @intFromEnum(C.E.NOTSOCK), + UV_EDESTADDRREQ => @intFromEnum(C.E.DESTADDRREQ), + UV_EMSGSIZE => @intFromEnum(C.E.MSGSIZE), + UV_EPROTOTYPE => @intFromEnum(C.E.PROTOTYPE), + UV_ENOPROTOOPT => @intFromEnum(C.E.NOPROTOOPT), + UV_EPROTONOSUPPORT => @intFromEnum(C.E.PROTONOSUPPORT), + UV_ESOCKTNOSUPPORT => @intFromEnum(C.E.SOCKTNOSUPPORT), + UV_ENOTSUP => @intFromEnum(C.E.NOTSUP), + UV_EAFNOSUPPORT => @intFromEnum(C.E.AFNOSUPPORT), + UV_EADDRINUSE => @intFromEnum(C.E.ADDRINUSE), + UV_EADDRNOTAVAIL => @intFromEnum(C.E.ADDRNOTAVAIL), + UV_ENETDOWN => @intFromEnum(C.E.NETDOWN), + UV_ENETUNREACH => @intFromEnum(C.E.NETUNREACH), + UV_ECONNABORTED => @intFromEnum(C.E.CONNABORTED), + UV_ECONNRESET => @intFromEnum(C.E.CONNRESET), + UV_ENOBUFS => @intFromEnum(C.E.NOBUFS), + UV_EISCONN => @intFromEnum(C.E.ISCONN), + UV_ENOTCONN => @intFromEnum(C.E.NOTCONN), + UV_ESHUTDOWN => @intFromEnum(C.E.SHUTDOWN), + UV_ETIMEDOUT => @intFromEnum(C.E.TIMEDOUT), + UV_ECONNREFUSED => @intFromEnum(C.E.CONNREFUSED), + UV_EHOSTDOWN => @intFromEnum(C.E.HOSTDOWN), + UV_EHOSTUNREACH => @intFromEnum(C.E.HOSTUNREACH), + UV_EALREADY => @intFromEnum(C.E.ALREADY), + UV_EREMOTEIO => @intFromEnum(C.E.REMOTEIO), + UV_ECANCELED => @intFromEnum(C.E.CANCELED), + UV_ECHARSET => @intFromEnum(C.E.CHARSET), + UV_EOF => @intFromEnum(C.E.EOF), else => null, } else null; } - pub inline fn errEnum(this: ReturnCode) ?bun.C.E { + pub inline fn errEnum(this: ReturnCode) ?C.E { return if (this.int() < 0) (translateUVErrorToE(this.int())) else @@ -2794,14 +2795,14 @@ pub const ReturnCodeI64 = enum(i64) { return null; } - pub inline fn errno(this: ReturnCodeI64) ?@TypeOf(@intFromEnum(bun.C.E.ACCES)) { + pub inline fn errno(this: ReturnCodeI64) ?@TypeOf(@intFromEnum(C.E.ACCES)) { return if (@intFromEnum(this) < 0) @as(u16, @intCast(-@intFromEnum(this))) else null; } - pub inline fn errEnum(this: ReturnCodeI64) ?bun.C.E { + pub inline fn errEnum(this: ReturnCodeI64) ?C.E { return if (@intFromEnum(this) < 0) (translateUVErrorToE(@intFromEnum(this))) else @@ -2852,7 +2853,7 @@ fn StreamMixin(comptime Type: type) type { this: *Type, context: anytype, comptime alloc_cb: *const (fn (@TypeOf(context), suggested_size: usize) []u8), - comptime error_cb: *const (fn (@TypeOf(context), err: bun.C.E) void), + comptime error_cb: *const (fn (@TypeOf(context), err: C.E) void), comptime read_cb: *const (fn (@TypeOf(context), data: []const u8) void), ) Maybe(void) { const Context = @TypeOf(context); @@ -2867,7 +2868,7 @@ fn StreamMixin(comptime Type: type) type { if (nreads == 0) return; // EAGAIN or EWOULDBLOCK if (nreads < 0) { req.readStop(); - error_cb(context_data, ReturnCodeI64.init(nreads).errEnum() orelse bun.C.E.CANCELED); + error_cb(context_data, ReturnCodeI64.init(nreads).errEnum() orelse C.E.CANCELED); } else { read_cb(context_data, buffer.slice()); } diff --git a/src/deps/uws.zig b/src/deps/uws.zig index 3555261098d13c..9fcfc1aabe59cd 100644 --- a/src/deps/uws.zig +++ b/src/deps/uws.zig @@ -1,5 +1,6 @@ pub const is_bindgen = false; const bun = @import("root").bun; +const C = @import("root").C; const Api = bun.ApiSchema; const std = @import("std"); const Environment = bun.Environment; @@ -664,7 +665,7 @@ pub const WindowsNamedPipe = if (Environment.isWindows) struct { } } - fn onReadError(this: *WindowsNamedPipe, err: bun.C.E) void { + fn onReadError(this: *WindowsNamedPipe, err: C.E) void { log("onReadError", .{}); if (err == .EOF) { // we received FIN but we dont allow half-closed connections right now @@ -855,7 +856,7 @@ pub const WindowsNamedPipe = if (Environment.isWindows) struct { }) catch { return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.PIPE), + .errno = @intFromEnum(C.E.PIPE), .syscall = .connect, }, }; @@ -903,7 +904,7 @@ pub const WindowsNamedPipe = if (Environment.isWindows) struct { }) catch { return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.PIPE), + .errno = @intFromEnum(C.E.PIPE), .syscall = .connect, }, }; @@ -941,7 +942,7 @@ pub const WindowsNamedPipe = if (Environment.isWindows) struct { }) catch { return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.PIPE), + .errno = @intFromEnum(C.E.PIPE), .syscall = .connect, }, }; @@ -984,7 +985,7 @@ pub const WindowsNamedPipe = if (Environment.isWindows) struct { return false; } const stream = this.writer.getStream() orelse { - this.onError(bun.sys.Error.fromCode(bun.C.E.PIPE, .read)); + this.onError(bun.sys.Error.fromCode(C.E.PIPE, .read)); return false; }; diff --git a/src/env_loader.zig b/src/env_loader.zig index 63646845276287..bc06c8162fa07c 100644 --- a/src/env_loader.zig +++ b/src/env_loader.zig @@ -10,7 +10,7 @@ const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const CodePoint = bun.CodePoint; -const C = bun.C; +const C = @import("root").C; const CodepointIterator = @import("./string_immutable.zig").CodepointIterator; const Analytics = @import("./analytics/analytics_thread.zig"); const Fs = @import("./fs.zig"); diff --git a/src/fd.zig b/src/fd.zig index 508cbf39ec83fa..ebc3b0b1ed4fec 100644 --- a/src/fd.zig +++ b/src/fd.zig @@ -2,6 +2,7 @@ const std = @import("std"); const posix = std.posix; const bun = @import("root").bun; +const C = @import("root").C; const env = bun.Environment; const JSC = bun.JSC; const JSValue = JSC.JSValue; @@ -242,7 +243,7 @@ pub const FDImpl = packed struct { const fd = this.encode(); bun.assert(fd != bun.invalid_fd); bun.assert(fd.cast() >= 0); - break :result switch (bun.C.getErrno(bun.sys.syscall.close(fd.cast()))) { + break :result switch (C.getErrno(bun.sys.syscall.close(fd.cast()))) { .BADF => bun.sys.Error{ .errno = @intFromEnum(posix.E.BADF), .syscall = .close, .fd = fd }, else => null, }; @@ -251,7 +252,7 @@ pub const FDImpl = packed struct { const fd = this.encode(); bun.assert(fd != bun.invalid_fd); bun.assert(fd.cast() >= 0); - break :result switch (bun.C.getErrno(bun.sys.syscall.@"close$NOCANCEL"(fd.cast()))) { + break :result switch (C.getErrno(bun.sys.syscall.@"close$NOCANCEL"(fd.cast()))) { .BADF => bun.sys.Error{ .errno = @intFromEnum(posix.E.BADF), .syscall = .close, .fd = fd }, else => null, }; diff --git a/src/fs.zig b/src/fs.zig index fa20e43a5272aa..1bb78e31682c81 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -11,7 +11,7 @@ const FileDescriptor = bun.FileDescriptor; const FeatureFlags = bun.FeatureFlags; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const sync = @import("sync.zig"); const Mutex = bun.Mutex; const Semaphore = sync.Semaphore; diff --git a/src/glob/GlobWalker.zig b/src/glob/GlobWalker.zig index 6498fbb7d4c9a9..19c1b31b6b739e 100644 --- a/src/glob/GlobWalker.zig +++ b/src/glob/GlobWalker.zig @@ -22,6 +22,7 @@ // THE SOFTWARE. const std = @import("std"); const bun = @import("root").bun; +const C = @import("root").C; const eqlComptime = @import("../string_immutable.zig").eqlComptime; const expect = std.testing.expect; @@ -35,7 +36,6 @@ const Arena = std.heap.ArenaAllocator; const ArrayList = std.ArrayListUnmanaged; const ArrayListManaged = std.ArrayList; const BunString = bun.String; -const C = @import("../c.zig"); const CodepointIterator = @import("../string_immutable.zig").PackedCodepointIterator; const Codepoint = CodepointIterator.Cursor.CodePointType; const Dirent = @import("../bun.js/node/types.zig").Dirent; @@ -290,7 +290,7 @@ pub const DirEntryAccessor = struct { } // TODO do we want to propagate ENOTDIR through the 'Maybe' to match the SyscallAccessor? // The glob implementation specifically checks for this error when dealing with symlinks - // return .{ .err = Syscall.Error.fromCode(bun.C.E.NOTDIR, Syscall.Tag.open) }; + // return .{ .err = Syscall.Error.fromCode(C.E.NOTDIR, Syscall.Tag.open) }; const res = FS.instance.fs.readDirectory(path, null, 0, false) catch |err| { return err; }; @@ -475,12 +475,12 @@ pub fn GlobWalker_( const path = try this.walker.arena.allocator().dupeZ(u8, path_without_special_syntax); const fd = switch (try Accessor.open(path)) { .err => |e| { - if (e.getErrno() == bun.C.E.NOTDIR) { + if (e.getErrno() == C.E.NOTDIR) { this.iter_state = .{ .matched = path }; return Maybe(void).success; } // Doesn't exist - if (e.getErrno() == bun.C.E.NOENT) { + if (e.getErrno() == C.E.NOENT) { this.iter_state = .get_next; return Maybe(void).success; } @@ -669,7 +669,7 @@ pub fn GlobWalker_( const stat_result: bun.Stat = switch (Accessor.statat(fd, pathz)) { .err => |e_| { var e: bun.sys.Error = e_; - if (e.getErrno() == bun.C.E.NOENT) { + if (e.getErrno() == C.E.NOENT) { this.iter_state = .get_next; return Maybe(void).success; } @@ -743,7 +743,7 @@ pub fn GlobWalker_( this.iter_state = .get_next; const maybe_dir_fd: ?Accessor.Handle = switch (try Accessor.openat(this.cwd_fd, symlink_full_path_z)) { .err => |err| brk: { - if (@as(usize, @intCast(err.errno)) == @as(usize, @intFromEnum(bun.C.E.NOTDIR))) { + if (@as(usize, @intCast(err.errno)) == @as(usize, @intFromEnum(C.E.NOTDIR))) { break :brk null; } if (this.walker.error_on_broken_symlinks) return .{ .err = this.walker.handleSysErrWithPath(err, symlink_full_path_z) }; diff --git a/src/http.zig b/src/http.zig index 3b4451c0cce36d..a81d97a948592b 100644 --- a/src/http.zig +++ b/src/http.zig @@ -9,7 +9,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const FeatureFlags = bun.FeatureFlags; const stringZ = bun.stringZ; -const C = bun.C; +const C = @import("root").C; const Loc = bun.logger.Loc; const Log = bun.logger.Log; const DotEnv = @import("./env_loader.zig"); @@ -177,7 +177,7 @@ pub const Sendfile = struct { std.os.linux.sendfile(socket.fd().cast(), this.fd.cast(), &signed_offset, this.remain); this.offset = @as(u64, @intCast(signed_offset)); - const errcode = bun.C.getErrno(val); + const errcode = C.getErrno(val); this.remain -|= @as(u64, @intCast(this.offset -| begin)); @@ -191,7 +191,7 @@ pub const Sendfile = struct { } else if (Environment.isPosix) { var sbytes: std.posix.off_t = adjusted_count; const signed_offset = @as(i64, @bitCast(@as(u64, this.offset))); - const errcode = bun.C.getErrno(std.c.sendfile( + const errcode = C.getErrno(std.c.sendfile( this.fd.cast(), socket.fd().cast(), signed_offset, diff --git a/src/http/method.zig b/src/http/method.zig index 67103c523e638a..32376d419cf18c 100644 --- a/src/http/method.zig +++ b/src/http/method.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); pub const Method = enum { diff --git a/src/http/mime_type.zig b/src/http/mime_type.zig index a7cf32c5a990b7..cffde31d7a14ff 100644 --- a/src/http/mime_type.zig +++ b/src/http/mime_type.zig @@ -8,7 +8,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const Loader = @import("../options.zig").Loader; const ComptimeStringMap = bun.ComptimeStringMap; diff --git a/src/http/url_path.zig b/src/http/url_path.zig index d1e50072b38419..4536285d167ad9 100644 --- a/src/http/url_path.zig +++ b/src/http/url_path.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const PercentEncoding = @import("../url.zig").PercentEncoding; const std = @import("std"); diff --git a/src/http/websocket.zig b/src/http/websocket.zig index 7ecf4b6d7a018f..172c9f04d49ef3 100644 --- a/src/http/websocket.zig +++ b/src/http/websocket.zig @@ -12,7 +12,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; pub const Opcode = enum(u4) { Continue = 0x0, diff --git a/src/http/websocket_http_client.zig b/src/http/websocket_http_client.zig index 734b795835dffc..de92f10a48c643 100644 --- a/src/http/websocket_http_client.zig +++ b/src/http/websocket_http_client.zig @@ -11,7 +11,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const BoringSSL = bun.BoringSSL; const uws = bun.uws; const JSC = bun.JSC; diff --git a/src/install/bin.zig b/src/install/bin.zig index d0162e63839de4..3f05c66f9f3d78 100644 --- a/src/install/bin.zig +++ b/src/install/bin.zig @@ -7,7 +7,7 @@ const Global = bun.Global; const std = @import("std"); const strings = bun.strings; const Environment = @import("../env.zig"); -const C = @import("../c.zig"); +const C = @import("root").C; const Fs = @import("../fs.zig"); const stringZ = bun.stringZ; const Resolution = @import("./resolution.zig").Resolution; @@ -526,14 +526,14 @@ pub const Bin = extern struct { err: ?anyerror = null, - pub var umask: bun.C.Mode = 0; + pub var umask: C.Mode = 0; var has_set_umask = false; pub fn ensureUmask() void { if (!has_set_umask) { has_set_umask = true; - umask = bun.C.umask(0); + umask = C.umask(0); } } diff --git a/src/install/extract_tarball.zig b/src/install/extract_tarball.zig index e8b8fb0c481d88..d3f5a3e4c20983 100644 --- a/src/install/extract_tarball.zig +++ b/src/install/extract_tarball.zig @@ -1,4 +1,5 @@ const bun = @import("root").bun; +const C = @import("root").C; const default_allocator = bun.default_allocator; const Global = bun.Global; const json_parser = bun.JSON; @@ -341,7 +342,7 @@ fn extract(this: *const ExtractTarball, tgz_bytes: []const u8) !Install.ExtractD return error.InstallFailed; }; - switch (bun.C.moveOpenedFileAt(dir_to_move, bun.toFD(cache_dir.fd), path_to_use, true)) { + switch (C.moveOpenedFileAt(dir_to_move, bun.toFD(cache_dir.fd), path_to_use, true)) { .err => |err| { if (!did_retry) { switch (err.getErrno()) { diff --git a/src/install/install.zig b/src/install/install.zig index 065bb1ff02b0c1..b607c14d99b154 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -16,7 +16,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const uws = @import("../deps/uws.zig"); const JSC = bun.JSC; @@ -13547,9 +13547,9 @@ pub const PackageManager = struct { Global.exit(1); }; - const is_writable = if (stat.uid == bun.C.getuid()) + const is_writable = if (stat.uid == C.getuid()) stat.mode & bun.S.IWUSR > 0 - else if (stat.gid == bun.C.getgid()) + else if (stat.gid == C.getgid()) stat.mode & bun.S.IWGRP > 0 else stat.mode & bun.S.IWOTH > 0; diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index 969a31c1dd136b..28dd817f56744e 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -11,7 +11,7 @@ const Glob = bun.glob; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const JSAst = bun.JSAst; const TextLockfile = @import("./bun.lock.zig"); const OOM = bun.OOM; diff --git a/src/install/patch_install.zig b/src/install/patch_install.zig index 842ca4a01f40b9..4ddde5319f6d5e 100644 --- a/src/install/patch_install.zig +++ b/src/install/patch_install.zig @@ -1,5 +1,6 @@ const bun = @import("root").bun; const std = @import("std"); +const C = @import("root").C; const string = bun.string; const stringZ = bun.stringZ; @@ -425,7 +426,7 @@ pub const PatchTask = struct { const stat: bun.Stat = switch (bun.sys.stat(absolute_patchfile_path)) { .err => |e| { - if (e.getErrno() == bun.C.E.NOENT) { + if (e.getErrno() == C.E.NOENT) { const fmt = "\n\nerror: could not find patch file {s}\n\nPlease make sure it exists.\n\nTo create a new patch file run:\n\n bun patch {s}\n"; const args = .{ this.callback.calc_hash.patchfile_path, diff --git a/src/install/semver.zig b/src/install/semver.zig index a3f9ca2efd4cb3..cde6c184c9c645 100644 --- a/src/install/semver.zig +++ b/src/install/semver.zig @@ -9,7 +9,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const JSC = bun.JSC; const IdentityContext = @import("../identity_context.zig").IdentityContext; const OOM = bun.OOM; diff --git a/src/install/windows-shim/bun_shim_impl.zig b/src/install/windows-shim/bun_shim_impl.zig index c8cf07e09db1b2..5a94750bf279ae 100644 --- a/src/install/windows-shim/bun_shim_impl.zig +++ b/src/install/windows-shim/bun_shim_impl.zig @@ -42,6 +42,7 @@ const builtin = @import("builtin"); const dbg = builtin.mode == .Debug; const std = @import("std"); +const C = @import("root").C; const w = std.os.windows; const assert = std.debug.assert; const fmt16 = std.unicode.fmtUtf16le; @@ -737,7 +738,7 @@ fn launcher(comptime mode: LauncherMode, bun_ctx: anytype) mode.RetType() { // Prepare stdio for the child process, as after this we are going to *immediatly* exit // it is likely that the c-runtime's atexit will not be called as we end the process ourselves. bun.Output.Source.Stdio.restore(); - bun.C.windows_enable_stdio_inheritance(); + C.windows_enable_stdio_inheritance(); } // I attempted to use lower level methods for this, but it really seems diff --git a/src/io/PipeReader.zig b/src/io/PipeReader.zig index 668f7b55fe2f7d..c83234f547257f 100644 --- a/src/io/PipeReader.zig +++ b/src/io/PipeReader.zig @@ -1,4 +1,5 @@ const bun = @import("root").bun; +const C = @import("root").C; const std = @import("std"); const uv = bun.windows.libuv; const Source = @import("./source.zig").Source; @@ -156,7 +157,7 @@ pub fn PosixPipeReader( } if (comptime file_type == .pipe) { - if (bun.Environment.isMac or !bun.C.RWFFlagSupport.isMaybeSupported()) { + if (bun.Environment.isMac or !C.RWFFlagSupport.isMaybeSupported()) { switch (bun.isReadable(fd)) { .ready => {}, .hup => { @@ -251,7 +252,7 @@ pub fn PosixPipeReader( } if (comptime file_type == .pipe) { - if (bun.Environment.isMac or !bun.C.RWFFlagSupport.isMaybeSupported()) { + if (bun.Environment.isMac or !C.RWFFlagSupport.isMaybeSupported()) { switch (bun.isReadable(fd)) { .ready => {}, .hup => { @@ -445,7 +446,7 @@ pub fn WindowsPipeReader( } // ops we should not hit this lets fail with EPIPE bun.assert(false); - return this.onRead(.{ .err = bun.sys.Error.fromCode(bun.C.E.PIPE, .read) }, "", .progress); + return this.onRead(.{ .err = bun.sys.Error.fromCode(C.E.PIPE, .read) }, "", .progress); }, } } @@ -453,7 +454,7 @@ pub fn WindowsPipeReader( pub fn startReading(this: *This) bun.JSC.Maybe(void) { if (this.flags.is_done or !this.flags.is_paused) return .{ .result = {} }; this.flags.is_paused = false; - const source: Source = this.source orelse return .{ .err = bun.sys.Error.fromCode(bun.C.E.BADF, .read) }; + const source: Source = this.source orelse return .{ .err = bun.sys.Error.fromCode(C.E.BADF, .read) }; bun.assert(!source.isClosed()); switch (source) { @@ -1166,7 +1167,7 @@ pub const WindowsBufferedReader = struct { pub fn setRawMode(this: *WindowsBufferedReader, value: bool) bun.JSC.Maybe(void) { const source = this.source orelse return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.BADF), + .errno = @intFromEnum(C.E.BADF), .syscall = .uv_tty_set_mode, }, }; diff --git a/src/io/PipeWriter.zig b/src/io/PipeWriter.zig index 622fda152768a9..12f444760157b2 100644 --- a/src/io/PipeWriter.zig +++ b/src/io/PipeWriter.zig @@ -1,4 +1,5 @@ const bun = @import("root").bun; +const C = @import("root").C; const std = @import("std"); const Async = bun.Async; const JSC = bun.JSC; @@ -82,7 +83,7 @@ pub fn PosixPipeWriter( fn writeToBlockingPipe(fd: bun.FileDescriptor, buf: []const u8) JSC.Maybe(usize) { if (comptime bun.Environment.isLinux) { - if (bun.C.linux.RWFFlagSupport.isMaybeSupported()) { + if (C.linux.RWFFlagSupport.isMaybeSupported()) { return bun.sys.writeNonblocking(fd, buf); } } @@ -1273,7 +1274,7 @@ pub fn WindowsStreamingWriter( } var pipe = this.source orelse { - const err = bun.sys.Error.fromCode(bun.C.E.PIPE, .pipe); + const err = bun.sys.Error.fromCode(C.E.PIPE, .pipe); this.last_write_result = .{ .err = err }; onError(this.parent, err); this.closeWithoutReporting(); diff --git a/src/io/io.zig b/src/io/io.zig index 7a4f36d3c2505b..2504b2dd7dd14f 100644 --- a/src/io/io.zig +++ b/src/io/io.zig @@ -1,4 +1,5 @@ const bun = @import("root").bun; +const C = @import("root").C; const std = @import("std"); const sys = bun.sys; const linux = std.os.linux; @@ -39,7 +40,7 @@ pub const Loop = struct { epoll.data.ptr = @intFromPtr(&loop); const rc = std.os.linux.epoll_ctl(loop.epoll_fd.cast(), std.os.linux.EPOLL.CTL_ADD, loop.waker.getFd().cast(), &epoll); - switch (bun.C.getErrno(rc)) { + switch (C.getErrno(rc)) { .SUCCESS => {}, else => |err| bun.Output.panic("Failed to wait on epoll {s}", .{@tagName(err)}), } @@ -149,7 +150,7 @@ pub const Loop = struct { std.math.maxInt(i32), ); - switch (bun.C.getErrno(rc)) { + switch (C.getErrno(rc)) { .INTR => continue, .SUCCESS => {}, else => |e| bun.Output.panic("epoll_wait: {s}", .{@tagName(e)}), @@ -270,7 +271,7 @@ pub const Loop = struct { null, ); - switch (bun.C.getErrno(rc)) { + switch (C.getErrno(rc)) { .INTR => continue, .SUCCESS => {}, else => |e| bun.Output.panic("kevent64 failed: {s}", .{@tagName(e)}), @@ -613,7 +614,7 @@ pub const Poll = struct { inline else => |t| { var this: *Pollable.Tag.Type(t) = @alignCast(@fieldParentPtr("io_poll", poll)); if (event.events & linux.EPOLL.ERR != 0) { - const errno = bun.C.getErrno(event.events); + const errno = C.getErrno(event.events); log("error() = {s}", .{@tagName(errno)}); this.onIOError(bun.sys.Error.fromCode(errno, .epoll_ctl)); } else { @@ -682,7 +683,7 @@ pub const Poll = struct { } }; -pub const retry = bun.C.E.AGAIN; +pub const retry = C.E.AGAIN; pub const ReadState = @import("./pipes.zig").ReadState; pub const PipeReader = @import("./PipeReader.zig").PipeReader; diff --git a/src/io/io_darwin.zig b/src/io/io_darwin.zig index 71fb60d6613fff..b89e2c810c11bf 100644 --- a/src/io/io_darwin.zig +++ b/src/io/io_darwin.zig @@ -1,4 +1,5 @@ const std = @import("std"); +// const C = @import("root").C; const os = struct { pub usingnamespace std.posix; pub const EINTR = 4; @@ -150,7 +151,7 @@ pub const Waker = struct { // ); // if (errno < 0) { -// return asError(bun.C.getErrno(errno)); +// return asError(C.getErrno(errno)); // } // } @@ -174,7 +175,7 @@ pub const Waker = struct { // null, // ); // if (errno < 0) { -// return asError(bun.C.getErrno(errno)); +// return asError(C.getErrno(errno)); // } // return @as(u64, @intCast(errno)); diff --git a/src/io/source.zig b/src/io/source.zig index 99447a44b82914..1906b4cc7274b6 100644 --- a/src/io/source.zig +++ b/src/io/source.zig @@ -1,5 +1,6 @@ const std = @import("std"); const bun = @import("root").bun; +const C = @import("root").C; const uv = bun.windows.libuv; const log = bun.Output.scoped(.PipeSource, true); @@ -214,7 +215,7 @@ pub const Source = union(enum) { }, else => .{ .err = .{ - .errno = @intFromEnum(bun.C.E.NOTSUP), + .errno = @intFromEnum(C.E.NOTSUP), .syscall = .uv_tty_set_mode, .fd = this.getFd(), }, diff --git a/src/js_ast.zig b/src/js_ast.zig index 6b4fd31d3283d4..69ea41b534f7fb 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -11,7 +11,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; pub const Ref = @import("ast/base.zig").Ref; pub const Index = @import("ast/base.zig").Index; const RefHashCtx = @import("ast/base.zig").RefHashCtx; diff --git a/src/js_lexer.zig b/src/js_lexer.zig index 1560f026213327..7aaa9636c804f3 100644 --- a/src/js_lexer.zig +++ b/src/js_lexer.zig @@ -14,7 +14,7 @@ const CodePoint = bun.CodePoint; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const FeatureFlags = @import("feature_flags.zig"); const JavascriptString = []const u16; const Indentation = bun.js_printer.Options.Indentation; diff --git a/src/js_parser.zig b/src/js_parser.zig index 62e6515a8eb5d0..cf7878f91c1f2f 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -24,7 +24,7 @@ const strings = bun.strings; const MutableString = @import("./string_mutable.zig").MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const G = js_ast.G; const Define = @import("./defines.zig").Define; const DefineData = @import("./defines.zig").DefineData; @@ -7576,7 +7576,7 @@ fn NewParser_( return p.newExpr( // Use libc fmod here to be consistent with what JavaScriptCore does // https://github.com/oven-sh/WebKit/blob/7a0b13626e5db69aa5a32d037431d381df5dfb61/Source/JavaScriptCore/runtime/MathCommon.cpp#L574-L597 - E.Number{ .value = if (comptime Environment.isNative) bun.C.fmod(vals[0], vals[1]) else std.math.mod(f64, vals[0], vals[1]) catch 0 }, + E.Number{ .value = if (comptime Environment.isNative) C.fmod(vals[0], vals[1]) else std.math.mod(f64, vals[0], vals[1]) catch 0 }, v.loc, ); } diff --git a/src/js_printer.zig b/src/js_printer.zig index 8cb2b6327de6c5..85e08a68e56fdb 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -18,7 +18,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const Ref = @import("ast/base.zig").Ref; const StoredFileDescriptorType = bun.StoredFileDescriptorType; const FeatureFlags = bun.FeatureFlags; diff --git a/src/json_parser.zig b/src/json_parser.zig index 47267b62ee56d3..2037ed8b3a9622 100644 --- a/src/json_parser.zig +++ b/src/json_parser.zig @@ -15,7 +15,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const expect = std.testing.expect; const ImportKind = importRecord.ImportKind; const BindingNodeIndex = js_ast.BindingNodeIndex; diff --git a/src/libarchive/libarchive-bindings.zig b/src/libarchive/libarchive-bindings.zig index d9bd69630a80bf..2bd9763c7b671e 100644 --- a/src/libarchive/libarchive-bindings.zig +++ b/src/libarchive/libarchive-bindings.zig @@ -1,5 +1,6 @@ const std = @import("std"); const bun = @import("root").bun; +const C = @import("root").C; const wchar_t = u16; const la_int64_t = i64; const la_ssize_t = isize; @@ -956,7 +957,7 @@ pub const Archive = opaque { .retry => continue, .eof => Return.res(null), .ok => { - const kind = bun.C.kindFromMode(entry.filetype()); + const kind = C.kindFromMode(entry.filetype()); if (this.filter.contains(kind)) continue; diff --git a/src/libarchive/libarchive.zig b/src/libarchive/libarchive.zig index 09f5c495546e12..a59f16f53e17ab 100644 --- a/src/libarchive/libarchive.zig +++ b/src/libarchive/libarchive.zig @@ -2,6 +2,7 @@ pub const lib = @import("./libarchive-bindings.zig"); const bun = @import("root").bun; +const C = @import("root").C; const string = bun.string; const Output = bun.Output; const Global = bun.Global; @@ -11,7 +12,6 @@ const MutableString = bun.MutableString; const FileDescriptorType = bun.FileDescriptor; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; const std = @import("std"); const Archive = lib.Archive; const JSC = bun.JSC; @@ -476,7 +476,7 @@ pub const Archiver = struct { switch (bun.sys.openatWindows(bun.toFD(dir_fd), path, flags)) { .result => |fd| break :brk fd, .err => |e| switch (e.errno) { - @intFromEnum(bun.C.E.PERM), @intFromEnum(bun.C.E.NOENT) => { + @intFromEnum(C.E.PERM), @intFromEnum(C.E.NOENT) => { bun.MakePath.makePath(u16, dir, bun.Dirname.dirname(u16, path_slice) orelse return bun.errnoToZigErr(e.errno)) catch {}; break :brk try bun.sys.openatWindows(bun.toFD(dir_fd), path, flags).unwrap(); }, diff --git a/src/linker.zig b/src/linker.zig index dcaecf25e83c40..b81705d9f1cc4c 100644 --- a/src/linker.zig +++ b/src/linker.zig @@ -10,7 +10,7 @@ const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const FileDescriptorType = bun.FileDescriptor; -const C = bun.C; +const C = @import("root").C; const Ref = @import("./ast/base.zig").Ref; const std = @import("std"); diff --git a/src/logger.zig b/src/logger.zig index d0af8cb71e319f..a8dd33aec6f4e6 100644 --- a/src/logger.zig +++ b/src/logger.zig @@ -11,7 +11,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const JSC = bun.JSC; const fs = @import("fs.zig"); const unicode = std.unicode; diff --git a/src/main.zig b/src/main.zig index d3b73b7ee552c5..3c4e396164e728 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,6 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); const bun = @import("root").bun; +const C = @import("root").C; const Output = bun.Output; const Environment = bun.Environment; @@ -59,7 +60,7 @@ pub const overrides = struct { } if (comptime T == u8 and sentinel == 0) { - return bun.C.strlen(p); + return C.strlen(p); } var i: usize = 0; diff --git a/src/open.zig b/src/open.zig index c14c2895c96288..cd8f263ad72648 100644 --- a/src/open.zig +++ b/src/open.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const DotEnv = @import("env_loader.zig"); diff --git a/src/options.zig b/src/options.zig index 3e965a81b9d0bc..921f5c2bfd6234 100644 --- a/src/options.zig +++ b/src/options.zig @@ -20,7 +20,7 @@ const MutableString = bun.MutableString; const FileDescriptorType = bun.FileDescriptor; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const StoredFileDescriptorType = bun.StoredFileDescriptorType; const JSC = bun.JSC; const Runtime = @import("./runtime.zig").Runtime; @@ -2197,7 +2197,7 @@ pub const OutputFile = struct { } pub fn moveTo(file: *const OutputFile, _: string, rel_path: []u8, dir: FileDescriptorType) !void { - try bun.C.moveFileZ(file.value.move.dir, bun.sliceTo(&(try std.posix.toPosixPath(file.value.move.getPathname())), 0), dir, bun.sliceTo(&(try std.posix.toPosixPath(rel_path)), 0)); + try C.moveFileZ(file.value.move.dir, bun.sliceTo(&(try std.posix.toPosixPath(file.value.move.getPathname())), 0), dir, bun.sliceTo(&(try std.posix.toPosixPath(rel_path)), 0)); } pub fn copyTo(file: *const OutputFile, _: string, rel_path: []u8, dir: FileDescriptorType) !void { diff --git a/src/output.zig b/src/output.zig index ce10ab39502de6..d6ca93f6276b14 100644 --- a/src/output.zig +++ b/src/output.zig @@ -1,4 +1,5 @@ const bun = @import("root").bun; +const C = @import("root").C; const std = @import("std"); const Environment = @import("./env.zig"); const string = bun.string; @@ -243,7 +244,7 @@ pub const Source = struct { } pub fn init() void { - bun.C.bun_initialize_process(); + C.bun_initialize_process(); if (Environment.isWindows) { WindowsStdio.init(); @@ -264,7 +265,7 @@ pub const Source = struct { if (Environment.isWindows) { WindowsStdio.restore(); } else { - bun.C.bun_restore_stdio(); + C.bun_restore_stdio(); } } }; @@ -1108,7 +1109,7 @@ pub inline fn err(error_name: anytype, comptime fmt: []const u8, args: anytype) // enums if (info == .Enum) { - const errno: bun.C.SystemErrno = @enumFromInt(@intFromEnum(info)); + const errno: C.SystemErrno = @enumFromInt(@intFromEnum(info)); break :display_name .{ @tagName(errno), false }; } diff --git a/src/renamer.zig b/src/renamer.zig index c41e4ca66c2f88..d8bc5ed5cf358b 100644 --- a/src/renamer.zig +++ b/src/renamer.zig @@ -8,7 +8,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const Ref = @import("./ast/base.zig").Ref; const RefCtx = @import("./ast/base.zig").RefCtx; diff --git a/src/resolver/data_url.zig b/src/resolver/data_url.zig index 5757cebfe8360d..885f52fb4d7c54 100644 --- a/src/resolver/data_url.zig +++ b/src/resolver/data_url.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const Allocator = std.mem.Allocator; diff --git a/src/resolver/dir_info.zig b/src/resolver/dir_info.zig index 5ff0767b54c0ca..96df811ec442bb 100644 --- a/src/resolver/dir_info.zig +++ b/src/resolver/dir_info.zig @@ -8,7 +8,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const StoredFileDescriptorType = bun.StoredFileDescriptorType; const FeatureFlags = bun.FeatureFlags; diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index c3435c06cb5929..5b5ebb2da7f1fc 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -8,7 +8,7 @@ const MutableString = bun.MutableString; const StoredFileDescriptorType = bun.StoredFileDescriptorType; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const Api = @import("../api/schema.zig").Api; const std = @import("std"); const options = @import("../options.zig"); diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index d427747c82c518..a024763030719b 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -10,7 +10,7 @@ const PathString = bun.PathString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const StoredFileDescriptorType = bun.StoredFileDescriptorType; -const C = bun.C; +const C = @import("root").C; const ast = @import("../import_record.zig"); const logger = bun.logger; const options = @import("../options.zig"); diff --git a/src/resolver/tsconfig_json.zig b/src/resolver/tsconfig_json.zig index c4e40a70569ef4..9b91330c7072bd 100644 --- a/src/resolver/tsconfig_json.zig +++ b/src/resolver/tsconfig_json.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const options = @import("../options.zig"); const logger = bun.logger; diff --git a/src/router.zig b/src/router.zig index 23f61bf3155149..b02f606431d7de 100644 --- a/src/router.zig +++ b/src/router.zig @@ -18,7 +18,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const StoredFileDescriptorType = bun.StoredFileDescriptorType; const DirInfo = @import("./resolver/dir_info.zig"); const Fs = @import("./fs.zig"); diff --git a/src/runtime.zig b/src/runtime.zig index b64cd8b7e9fff0..a5068e1746600d 100644 --- a/src/runtime.zig +++ b/src/runtime.zig @@ -8,7 +8,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const resolve_path = @import("./resolver/resolve_path.zig"); const Fs = @import("./fs.zig"); diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index 6fb90f25ac40e6..c3694e99338cb0 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -20,6 +20,7 @@ const std = @import("std"); const builtin = @import("builtin"); const string = []const u8; const bun = @import("root").bun; +const C = @import("root").C; const posix = std.posix; const Arena = std.heap.ArenaAllocator; const Allocator = std.mem.Allocator; @@ -5688,7 +5689,7 @@ pub const Interpreter = struct { pub fn done(this: *Builtin, exit_code: anytype) void { const code: ExitCode = switch (@TypeOf(exit_code)) { - bun.C.E => @intFromEnum(exit_code), + C.E => @intFromEnum(exit_code), u1, u8, u16 => exit_code, comptime_int => exit_code, else => @compileError("Invalid type: " ++ @typeName(@TypeOf(exit_code))), @@ -5775,7 +5776,7 @@ pub const Interpreter = struct { }, .arraybuf => { if (io.arraybuf.i >= io.arraybuf.buf.array_buffer.byte_len) { - return Maybe(usize).initErr(Syscall.Error.fromCode(bun.C.E.NOSPC, .write)); + return Maybe(usize).initErr(Syscall.Error.fromCode(C.E.NOSPC, .write)); } const len = buf.len; @@ -5801,10 +5802,10 @@ pub const Interpreter = struct { fn taskErrorToString(this: *Builtin, comptime kind: Kind, err: anytype) []const u8 { switch (@TypeOf(err)) { Syscall.Error => return switch (err.getErrno()) { - bun.C.E.NOENT => this.fmtErrorArena(kind, "{s}: No such file or directory\n", .{err.path}), - bun.C.E.NAMETOOLONG => this.fmtErrorArena(kind, "{s}: File name too long\n", .{err.path}), - bun.C.E.ISDIR => this.fmtErrorArena(kind, "{s}: is a directory\n", .{err.path}), - bun.C.E.NOTEMPTY => this.fmtErrorArena(kind, "{s}: Directory not empty\n", .{err.path}), + C.E.NOENT => this.fmtErrorArena(kind, "{s}: No such file or directory\n", .{err.path}), + C.E.NAMETOOLONG => this.fmtErrorArena(kind, "{s}: File name too long\n", .{err.path}), + C.E.ISDIR => this.fmtErrorArena(kind, "{s}: is a directory\n", .{err.path}), + C.E.NOTEMPTY => this.fmtErrorArena(kind, "{s}: Directory not empty\n", .{err.path}), else => this.fmtErrorArena(kind, "{s}\n", .{err.toSystemError().message.byteSlice()}), }, JSC.SystemError => { @@ -6428,7 +6429,7 @@ pub const Interpreter = struct { .path = .{ .string = bun.PathString.init(filepath) }, }; if (node_fs.utimes(args, .callback).asErr()) |err| out: { - if (err.getErrno() == bun.C.E.NOENT) { + if (err.getErrno() == C.E.NOENT) { const perm = 0o664; switch (Syscall.open(filepath, bun.O.CREAT | bun.O.WRONLY, perm)) { .result => |fd| { @@ -7335,7 +7336,7 @@ pub const Interpreter = struct { const errno: usize = @intCast(err.errno); switch (errno) { - @as(usize, @intFromEnum(bun.C.E.NOTDIR)) => { + @as(usize, @intFromEnum(C.E.NOTDIR)) => { if (this.bltn.stderr.needsIO() == null) { const buf = this.bltn.fmtErrorArena(.cd, "not a directory: {s}\n", .{new_cwd_}); _ = this.bltn.writeNoIO(.stderr, buf); @@ -7348,7 +7349,7 @@ pub const Interpreter = struct { this.writeStderrNonBlocking("not a directory: {s}\n", .{new_cwd_}); return Maybe(void).success; }, - @as(usize, @intFromEnum(bun.C.E.NOENT)) => { + @as(usize, @intFromEnum(C.E.NOENT)) => { if (this.bltn.stderr.needsIO() == null) { const buf = this.bltn.fmtErrorArena(.cd, "not a directory: {s}\n", .{new_cwd_}); _ = this.bltn.writeNoIO(.stderr, buf); @@ -7726,10 +7727,10 @@ pub const Interpreter = struct { const fd = switch (ShellSyscall.openat(this.cwd, this.path, bun.O.RDONLY | bun.O.DIRECTORY, 0)) { .err => |e| { switch (e.getErrno()) { - bun.C.E.NOENT => { + C.E.NOENT => { this.err = this.errorWithPath(e, this.path); }, - bun.C.E.NOTDIR => { + C.E.NOTDIR => { this.result_kind = .file; this.addEntry(this.path); }, @@ -8297,7 +8298,7 @@ pub const Interpreter = struct { const fd = switch (ShellSyscall.openat(this.cwd, this.target, bun.O.RDONLY | bun.O.DIRECTORY, 0)) { .err => |e| { switch (e.getErrno()) { - bun.C.E.NOTDIR => { + C.E.NOTDIR => { this.result = .{ .result = null }; }, else => { @@ -8363,7 +8364,7 @@ pub const Interpreter = struct { pub fn moveInDir(this: *@This(), src: [:0]const u8, buf: *bun.PathBuffer) bool { const path_in_dir_ = bun.path.normalizeBuf(ResolvePath.basename(src), buf, .auto); if (path_in_dir_.len + 1 >= buf.len) { - this.err = Syscall.Error.fromCode(bun.C.E.NAMETOOLONG, .rename); + this.err = Syscall.Error.fromCode(C.E.NAMETOOLONG, .rename); return false; } buf[path_in_dir_.len] = 0; @@ -8481,7 +8482,7 @@ pub const Interpreter = struct { const maybe_fd: ?bun.FileDescriptor = switch (check_target.task.result.?) { .err => |e| brk: { switch (e.getErrno()) { - bun.C.E.NOENT => { + C.E.NOENT => { // Means we are renaming entry, not moving to a directory if (this.args.sources.len == 1) break :brk null; @@ -9590,11 +9591,11 @@ pub const Interpreter = struct { .result => return Maybe(void).success, .err => |e| { switch (e.getErrno()) { - bun.C.E.NOENT => { + C.E.NOENT => { if (this.opts.force) return this.verboseDeleted(dir_task, path); return .{ .err = this.errorWithPath(e, path) }; }, - bun.C.E.NOTDIR => { + C.E.NOTDIR => { delete_state.treat_as_dir = false; if (this.removeEntryFile(dir_task, dir_task.path, is_absolute, buf, &delete_state).asErr()) |err| { return .{ .err = this.errorWithPath(err, path) }; @@ -9610,7 +9611,7 @@ pub const Interpreter = struct { } if (!this.opts.recursive) { - return Maybe(void).initErr(Syscall.Error.fromCode(bun.C.E.ISDIR, .TODO).withPath(bun.default_allocator.dupeZ(u8, dir_task.path) catch bun.outOfMemory())); + return Maybe(void).initErr(Syscall.Error.fromCode(C.E.ISDIR, .TODO).withPath(bun.default_allocator.dupeZ(u8, dir_task.path) catch bun.outOfMemory())); } const flags = bun.O.DIRECTORY | bun.O.RDONLY; @@ -9618,11 +9619,11 @@ pub const Interpreter = struct { .result => |fd| fd, .err => |e| { switch (e.getErrno()) { - bun.C.E.NOENT => { + C.E.NOENT => { if (this.opts.force) return this.verboseDeleted(dir_task, path); return .{ .err = this.errorWithPath(e, path) }; }, - bun.C.E.NOTDIR => { + C.E.NOTDIR => { return this.removeEntryFile(dir_task, dir_task.path, is_absolute, buf, &DummyRemoveFile.dummy); }, else => return .{ .err = this.errorWithPath(e, path) }, @@ -9714,7 +9715,7 @@ pub const Interpreter = struct { }, .err => |e| { switch (e.getErrno()) { - bun.C.E.NOENT => { + C.E.NOENT => { if (this.opts.force) { switch (this.verboseDeleted(dir_task, path)) { .err => |e2| return .{ .err = e2 }, @@ -9819,14 +9820,14 @@ pub const Interpreter = struct { }, .err => |e| { switch (e.getErrno()) { - bun.C.E.NOENT => { + C.E.NOENT => { if (this.opts.force) { _ = this.verboseDeleted(dir_task, dir_task.path); return .{ .result = true }; } return .{ .err = this.errorWithPath(e, dir_task.path) }; }, - bun.C.E.NOTDIR => { + C.E.NOTDIR => { state.treat_as_dir = false; continue; }, @@ -9869,17 +9870,17 @@ pub const Interpreter = struct { .err => |e| { debug("unlinkatWithFlags({s}) = {s}", .{ path, @tagName(e.getErrno()) }); switch (e.getErrno()) { - bun.C.E.NOENT => { + C.E.NOENT => { if (this.opts.force) return this.verboseDeleted(parent_dir_task, path); return .{ .err = this.errorWithPath(e, path) }; }, - bun.C.E.ISDIR => { + C.E.ISDIR => { return Handler.onIsDir(vtable, parent_dir_task, path, is_absolute, buf); }, // This might happen if the file is actually a directory - bun.C.E.PERM => { + C.E.PERM => { switch (builtin.os.tag) { // non-Linux POSIX systems and Windows return EPERM when trying to delete a directory, so // we need to handle that case specifically and translate the error @@ -9894,13 +9895,13 @@ pub const Interpreter = struct { .err => |e2| { return switch (e2.getErrno()) { // not empty, process directory as we would normally - bun.C.E.NOTEMPTY => { + C.E.NOTEMPTY => { // this.enqueueNoJoin(parent_dir_task, path, .dir); // return Maybe(void).success; return Handler.onDirNotEmpty(vtable, parent_dir_task, path, is_absolute, buf); }, // actually a file, the error is a permissions error - bun.C.E.NOTDIR => .{ .err = this.errorWithPath(e, path) }, + C.E.NOTDIR => .{ .err = this.errorWithPath(e, path) }, else => .{ .err = this.errorWithPath(e2, path) }, }; }, @@ -10824,7 +10825,7 @@ pub const Interpreter = struct { if (bun.Environment.isWindows) { const attributes = bun.sys.getFileAttributes(path[0..path.len]) orelse { const err: Syscall.Error = .{ - .errno = @intFromEnum(bun.C.SystemErrno.ENOENT), + .errno = @intFromEnum(C.SystemErrno.ENOENT), .syscall = .copyfile, .path = path, }; @@ -10919,7 +10920,7 @@ pub const Interpreter = struct { const tgt_is_dir: bool, const tgt_exists: bool = switch (this.isDir(tgt)) { .result => |is_dir| .{ is_dir, true }, .err => |e| brk: { - if (e.getErrno() == bun.C.E.NOENT) { + if (e.getErrno() == C.E.NOENT) { // If it has a trailing directory separator, its a directory const is_dir = hasTrailingSep(tgt); break :brk .{ is_dir, false }; diff --git a/src/string_immutable.zig b/src/string_immutable.zig index ab1d7964908809..a1a6eaa15748c2 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const C = @import("root").C; const expect = std.testing.expect; const Environment = @import("./env.zig"); const string = bun.string; @@ -469,7 +470,7 @@ pub inline fn lastIndexOfChar(self: []const u8, char: u8) ?usize { if (@inComptime()) { return lastIndexOfCharT(u8, self, char); } - const start = bun.C.memrchr(self.ptr, char, self.len) orelse return null; + const start = C.memrchr(self.ptr, char, self.len) orelse return null; const i = @intFromPtr(start) - @intFromPtr(self.ptr); return @intCast(i); } @@ -505,7 +506,7 @@ pub inline fn indexOf(self: string, str: string) ?usize { if (str_len == 1) return indexOfCharUsize(self, str_ptr[0]); - const start = bun.C.memmem(self_ptr, self_len, str_ptr, str_len) orelse return null; + const start = C.memmem(self_ptr, self_len, str_ptr, str_len) orelse return null; const i = @intFromPtr(start) - @intFromPtr(self_ptr); bun.unsafeAssert(i < self_len); @@ -1109,7 +1110,7 @@ pub fn eqlCaseInsensitiveASCII(a: string, b: string, comptime check_len: bool) b bun.unsafeAssert(b.len > 0); bun.unsafeAssert(a.len > 0); - return bun.C.strncasecmp(a.ptr, b.ptr, a.len) == 0; + return C.strncasecmp(a.ptr, b.ptr, a.len) == 0; } pub fn eqlCaseInsensitiveT(comptime T: type, a: []const T, b: []const u8) bool { @@ -1248,7 +1249,7 @@ pub fn eqlUtf16(comptime self: string, other: []const u16) bool { if (self.len == 0) return true; - return bun.C.memcmp(bun.cast([*]const u8, self.ptr), bun.cast([*]const u8, other.ptr), self.len * @sizeOf(u16)) == 0; + return C.memcmp(bun.cast([*]const u8, self.ptr), bun.cast([*]const u8, other.ptr), self.len * @sizeOf(u16)) == 0; } pub fn toUTF8Alloc(allocator: std.mem.Allocator, js: []const u16) ![]u8 { @@ -1482,7 +1483,7 @@ pub const BOM = enum { pub fn removeAndConvertToUTF8AndFree(bom: BOM, allocator: std.mem.Allocator, bytes: []u8) ![]u8 { switch (bom) { .utf8 => { - bun.C.memmove(bytes.ptr, bytes.ptr + utf8_bytes.len, bytes.len - utf8_bytes.len); + C.memmove(bytes.ptr, bytes.ptr + utf8_bytes.len, bytes.len - utf8_bytes.len); return bytes[0 .. bytes.len - utf8_bytes.len]; }, .utf16_le => { @@ -1495,7 +1496,7 @@ pub const BOM = enum { else => { // TODO: this needs to re-encode, for now we just remove the BOM const bom_bytes = bom.getHeader(); - bun.C.memmove(bytes.ptr, bytes.ptr + bom_bytes.len, bytes.len - bom_bytes.len); + C.memmove(bytes.ptr, bytes.ptr + bom_bytes.len, bytes.len - bom_bytes.len); return bytes[0 .. bytes.len - bom_bytes.len]; }, } @@ -1509,7 +1510,7 @@ pub const BOM = enum { const bytes = list.items; switch (bom) { .utf8 => { - bun.C.memmove(bytes.ptr, bytes.ptr + utf8_bytes.len, bytes.len - utf8_bytes.len); + C.memmove(bytes.ptr, bytes.ptr + utf8_bytes.len, bytes.len - utf8_bytes.len); return bytes[0 .. bytes.len - utf8_bytes.len]; }, .utf16_le => { @@ -1526,7 +1527,7 @@ pub const BOM = enum { else => { // TODO: this needs to re-encode, for now we just remove the BOM const bom_bytes = bom.getHeader(); - bun.C.memmove(bytes.ptr, bytes.ptr + bom_bytes.len, bytes.len - bom_bytes.len); + C.memmove(bytes.ptr, bytes.ptr + bom_bytes.len, bytes.len - bom_bytes.len); return bytes[0 .. bytes.len - bom_bytes.len]; }, } @@ -4247,7 +4248,7 @@ pub fn indexOfNeedsEscape(slice: []const u8, comptime quote_char: u8) ?u32 { } pub fn indexOfCharZ(sliceZ: [:0]const u8, char: u8) ?u63 { - const ptr = bun.C.strchr(sliceZ.ptr, char) orelse return null; + const ptr = C.strchr(sliceZ.ptr, char) orelse return null; const pos = @intFromPtr(ptr) - @intFromPtr(sliceZ.ptr); if (comptime Environment.isDebug) @@ -4270,7 +4271,7 @@ pub fn indexOfCharUsize(slice: []const u8, char: u8) ?usize { return std.mem.indexOfScalar(u8, slice, char); } - const ptr = bun.C.memchr(slice.ptr, char, slice.len) orelse return null; + const ptr = C.memchr(slice.ptr, char, slice.len) orelse return null; const i = @intFromPtr(ptr) - @intFromPtr(slice.ptr); bun.assert(i < slice.len); bun.assert(slice[i] == char); @@ -4285,7 +4286,7 @@ pub fn indexOfCharPos(slice: []const u8, char: u8, start_index: usize) ?usize { if (start_index >= slice.len) return null; - const ptr = bun.C.memchr(slice.ptr + start_index, char, slice.len - start_index) orelse + const ptr = C.memchr(slice.ptr + start_index, char, slice.len - start_index) orelse return null; const i = @intFromPtr(ptr) - @intFromPtr(slice.ptr); bun.assert(i < slice.len); @@ -4921,7 +4922,7 @@ pub fn join(slices: []const string, delimiter: string, allocator: std.mem.Alloca pub fn order(a: []const u8, b: []const u8) std.math.Order { const len = @min(a.len, b.len); - const cmp = if (comptime Environment.isNative) bun.C.memcmp(a.ptr, b.ptr, len) else return std.mem.order(u8, a, b); + const cmp = if (comptime Environment.isNative) C.memcmp(a.ptr, b.ptr, len) else return std.mem.order(u8, a, b); return switch (std.math.sign(cmp)) { 0 => std.math.order(a.len, b.len), 1 => .gt, diff --git a/src/sys.zig b/src/sys.zig index fa7d22c4dff856..a7bb7b8033b2af 100644 --- a/src/sys.zig +++ b/src/sys.zig @@ -2,8 +2,8 @@ // The differences are in error handling const std = @import("std"); const builtin = @import("builtin"); - const bun = @import("root").bun; +const C = @import("root").C; const posix = std.posix; const assertIsValidWindowsPath = bun.strings.assertIsValidWindowsPath; @@ -15,7 +15,6 @@ const libc = std.posix.system; const windows = bun.windows; -const C = bun.C; const Environment = bun.Environment; const JSC = bun.JSC; const MAX_PATH_BYTES = bun.MAX_PATH_BYTES; @@ -275,7 +274,7 @@ pub const Tag = enum(u8) { }; pub const Error = struct { - const E = bun.C.E; + const E = C.E; const retry_errno = if (Environment.isLinux) @as(Int, @intCast(@intFromEnum(E.AGAIN))) @@ -374,12 +373,12 @@ pub const Error = struct { break :brk @as(C.SystemErrno, @enumFromInt(this.errno)); }; - if (bun.tagName(bun.C.SystemErrno, system_errno)) |errname| { + if (bun.tagName(C.SystemErrno, system_errno)) |errname| { return errname; } } else if (this.errno > 0 and this.errno < C.SystemErrno.max) { const system_errno = @as(C.SystemErrno, @enumFromInt(this.errno)); - if (bun.tagName(bun.C.SystemErrno, system_errno)) |errname| { + if (bun.tagName(C.SystemErrno, system_errno)) |errname| { return errname; } } @@ -416,7 +415,7 @@ pub const Error = struct { break :brk @as(C.SystemErrno, @enumFromInt(this.errno)); }; - if (bun.tagName(bun.C.SystemErrno, system_errno)) |errname| { + if (bun.tagName(C.SystemErrno, system_errno)) |errname| { err.code = bun.String.static(errname); if (C.SystemErrno.labels.get(system_errno)) |label| { err.message = bun.String.static(label); @@ -540,11 +539,11 @@ pub fn chdir(path: anytype, destination: anytype) Maybe(void) { if (comptime Type == []u8 or Type == []const u8) { return chdirOSPath( &(std.posix.toPosixPath(path) catch return .{ .err = .{ - .errno = @intFromEnum(bun.C.SystemErrno.EINVAL), + .errno = @intFromEnum(C.SystemErrno.EINVAL), .syscall = .chdir, } }), &(std.posix.toPosixPath(destination) catch return .{ .err = .{ - .errno = @intFromEnum(bun.C.SystemErrno.EINVAL), + .errno = @intFromEnum(C.SystemErrno.EINVAL), .syscall = .chdir, } }), ); @@ -716,7 +715,7 @@ pub fn mkdirA(file_path: []const u8, flags: bun.Mode) Maybe(void) { if (comptime Environment.isMac) { return Maybe(void).errnoSysP(syscall.mkdir(&(std.posix.toPosixPath(file_path) catch return Maybe(void){ .err = .{ - .errno = @intFromEnum(bun.C.E.NOMEM), + .errno = @intFromEnum(C.E.NOMEM), .syscall = .open, }, }), flags), .mkdir, file_path) orelse Maybe(void).success; @@ -725,7 +724,7 @@ pub fn mkdirA(file_path: []const u8, flags: bun.Mode) Maybe(void) { if (comptime Environment.isLinux) { return Maybe(void).errnoSysP(linux.mkdir(&(std.posix.toPosixPath(file_path) catch return Maybe(void){ .err = .{ - .errno = @intFromEnum(bun.C.E.NOMEM), + .errno = @intFromEnum(C.E.NOMEM), .syscall = .open, }, }), flags), .mkdir, file_path) orelse Maybe(void).success; @@ -778,7 +777,7 @@ pub fn fcntl(fd: bun.FileDescriptor, cmd: i32, arg: fnctl_int) Maybe(fnctl_int) unreachable; } -pub fn getErrno(rc: anytype) bun.C.E { +pub fn getErrno(rc: anytype) C.E { if (comptime Environment.isWindows) { if (comptime @TypeOf(rc) == bun.windows.NTSTATUS) { return bun.windows.translateNTStatusToErrno(rc); @@ -788,10 +787,10 @@ pub fn getErrno(rc: anytype) bun.C.E { return e.toE(); } - return bun.C.E.UNKNOWN; + return C.E.UNKNOWN; } - return bun.C.getErrno(rc); + return C.getErrno(rc); } const w = std.os.windows; @@ -829,7 +828,7 @@ pub fn normalizePathWindows( if (buf.len < path.len) { return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.NOMEM), + .errno = @intFromEnum(C.E.NOMEM), .syscall = .open, }, }; @@ -850,7 +849,7 @@ pub fn normalizePathWindows( const base_path = bun.windows.GetFinalPathNameByHandle(base_fd, w.GetFinalPathNameByHandleFormat{}, buf) catch { return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.BADFD), + .errno = @intFromEnum(C.E.BADFD), .syscall = .open, } }; }; @@ -957,7 +956,7 @@ fn openDirAtWindowsNtPath( return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.UNKNOWN), + .errno = @intFromEnum(C.E.UNKNOWN), .syscall = .open, }, }; @@ -1043,7 +1042,7 @@ pub fn openFileAtWindowsNtPath( const path_len_bytes = std.math.cast(u16, path.len * 2) orelse return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.NOMEM), + .errno = @intFromEnum(C.E.NOMEM), .syscall = .open, }, }; @@ -1134,7 +1133,7 @@ pub fn openFileAtWindowsNtPath( if (kernel32.SetFilePointerEx(result, 0, null, FILE_END) == 0) { return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.UNKNOWN), + .errno = @intFromEnum(C.E.UNKNOWN), .syscall = .SetFilePointerEx, }, }; @@ -1156,7 +1155,7 @@ pub fn openFileAtWindowsNtPath( return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.UNKNOWN), + .errno = @intFromEnum(C.E.UNKNOWN), .syscall = .open, }, }; @@ -1331,7 +1330,7 @@ pub fn openatA(dirfd: bun.FileDescriptor, file_path: []const u8, flags: bun.Mode const pathZ = std.posix.toPosixPath(file_path) catch return Maybe(bun.FileDescriptor){ .err = .{ - .errno = @intFromEnum(bun.C.E.NAMETOOLONG), + .errno = @intFromEnum(C.E.NAMETOOLONG), .syscall = .open, }, }; @@ -1724,7 +1723,7 @@ pub fn read(fd: bun.FileDescriptor, buf: []u8) Maybe(usize) { }; } -const socket_flags_nonblock = bun.C.MSG_DONTWAIT | bun.C.MSG_NOSIGNAL; +const socket_flags_nonblock = C.MSG_DONTWAIT | C.MSG_NOSIGNAL; pub fn recvNonBlock(fd: bun.FileDescriptor, buf: []u8) Maybe(usize) { return recv(fd, buf, socket_flags_nonblock); @@ -1876,12 +1875,12 @@ pub const RenameAt2Flags = packed struct { var flags: u32 = 0; if (comptime Environment.isMac) { - if (self.exchange) flags |= bun.C.RENAME_SWAP; - if (self.exclude) flags |= bun.C.RENAME_EXCL; - if (self.nofollow) flags |= bun.C.RENAME_NOFOLLOW_ANY; + if (self.exchange) flags |= C.RENAME_SWAP; + if (self.exclude) flags |= C.RENAME_EXCL; + if (self.nofollow) flags |= C.RENAME_NOFOLLOW_ANY; } else { - if (self.exchange) flags |= bun.C.RENAME_EXCHANGE; - if (self.exclude) flags |= bun.C.RENAME_NOREPLACE; + if (self.exchange) flags |= C.RENAME_EXCHANGE; + if (self.exclude) flags |= C.RENAME_NOREPLACE; } return flags; @@ -1898,9 +1897,9 @@ pub fn renameatConcurrently( switch (renameatConcurrentlyWithoutFallback(from_dir_fd, from, to_dir_fd, to)) { .result => return Maybe(void).success, .err => |e| { - if (opts.move_fallback and e.getErrno() == bun.C.E.XDEV) { + if (opts.move_fallback and e.getErrno() == C.E.XDEV) { bun.Output.debugWarn("renameatConcurrently() failed with E.XDEV, falling back to moveFileZSlowMaybe()", .{}); - return bun.C.moveFileZSlowMaybe(from_dir_fd, from, to_dir_fd, to); + return C.moveFileZSlowMaybe(from_dir_fd, from, to_dir_fd, to); } return .{ .err = e }; }, @@ -1973,7 +1972,7 @@ pub fn renameat2(from_dir: bun.FileDescriptor, from: [:0]const u8, to_dir: bun.F while (true) { const rc = switch (comptime Environment.os) { .linux => std.os.linux.renameat2(@intCast(from_dir.cast()), from.ptr, @intCast(to_dir.cast()), to.ptr, flags.int()), - .mac => bun.C.renameatx_np(@intCast(from_dir.cast()), from.ptr, @intCast(to_dir.cast()), to.ptr, flags.int()), + .mac => C.renameatx_np(@intCast(from_dir.cast()), from.ptr, @intCast(to_dir.cast()), to.ptr, flags.int()), else => @compileError("renameat2() is not implemented on this platform"), }; @@ -1998,7 +1997,7 @@ pub fn renameat(from_dir: bun.FileDescriptor, from: [:0]const u8, to_dir: bun.Fi bun.WPathBufferPool.put(w_buf_to); } - const rc = bun.C.renameAtW( + const rc = C.renameAtW( from_dir, bun.strings.toNTPath(w_buf_from, from), to_dir, @@ -2258,7 +2257,7 @@ pub fn getFdPath(fd: bun.FileDescriptor, out_buffer: *[MAX_PATH_BYTES]u8) Maybe( .windows => { var wide_buf: [windows.PATH_MAX_WIDE]u16 = undefined; const wide_slice = bun.windows.GetFinalPathNameByHandle(fd.cast(), .{}, wide_buf[0..]) catch { - return Maybe([]u8){ .err = .{ .errno = @intFromEnum(bun.C.SystemErrno.EBADF), .syscall = .GetFinalPathNameByHandle } }; + return Maybe([]u8){ .err = .{ .errno = @intFromEnum(C.SystemErrno.EBADF), .syscall = .GetFinalPathNameByHandle } }; }; // Trust that Windows gives us valid UTF-16LE. @@ -2303,7 +2302,7 @@ pub fn mmap( const fail = std.c.MAP_FAILED; if (rc == fail) { return Maybe([]align(mem.page_size) u8){ - .err = .{ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(bun.C.getErrno(@as(i64, @bitCast(@intFromPtr(fail))))))), .syscall = .mmap }, + .err = .{ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(C.getErrno(@as(i64, @bitCast(@intFromPtr(fail))))))), .syscall = .mmap }, }; } @@ -2685,7 +2684,7 @@ pub fn faccessat(dir_: anytype, subpath: anytype) JSC.Maybe(bool) { if (comptime Environment.isLinux) { // avoid loading the libc symbol for this to reduce chances of GLIBC minimum version requirements const rc = linux.faccessat(dir_fd.cast(), subpath, linux.F_OK, 0); - syslog("faccessat({}, {}, O_RDONLY, 0) = {d}", .{ dir_fd, bun.fmt.fmtOSPath(subpath, .{}), if (rc == 0) 0 else @intFromEnum(bun.C.getErrno(rc)) }); + syslog("faccessat({}, {}, O_RDONLY, 0) = {d}", .{ dir_fd, bun.fmt.fmtOSPath(subpath, .{}), if (rc == 0) 0 else @intFromEnum(C.getErrno(rc)) }); if (rc == 0) { return JSC.Maybe(bool){ .result = true }; } @@ -2695,7 +2694,7 @@ pub fn faccessat(dir_: anytype, subpath: anytype) JSC.Maybe(bool) { // on other platforms use faccessat from libc const rc = std.c.faccessat(dir_fd.cast(), subpath, std.posix.F_OK, 0); - syslog("faccessat({}, {}, O_RDONLY, 0) = {d}", .{ dir_fd, bun.fmt.fmtOSPath(subpath, .{}), if (rc == 0) 0 else @intFromEnum(bun.C.getErrno(rc)) }); + syslog("faccessat({}, {}, O_RDONLY, 0) = {d}", .{ dir_fd, bun.fmt.fmtOSPath(subpath, .{}), if (rc == 0) 0 else @intFromEnum(C.getErrno(rc)) }); if (rc == 0) { return JSC.Maybe(bool){ .result = true }; } @@ -2971,7 +2970,7 @@ pub fn dupWithFlags(fd: bun.FileDescriptor, flags: i32) Maybe(bun.FileDescriptor } const ArgType = if (comptime Environment.isLinux) usize else c_int; - const out = syscall.fcntl(fd.cast(), @as(i32, bun.C.F.DUPFD_CLOEXEC), @as(ArgType, 0)); + const out = syscall.fcntl(fd.cast(), @as(i32, C.F.DUPFD_CLOEXEC), @as(ArgType, 0)); log("dup({d}) = {d}", .{ fd.cast(), out }); if (Maybe(bun.FileDescriptor).errnoSysFd(out, .dup, fd)) |err| { return err; @@ -2997,14 +2996,14 @@ pub fn linkat(dir_fd: bun.FileDescriptor, basename: []const u8, dest_dir_fd: bun @intCast(dir_fd), &(std.posix.toPosixPath(basename) catch return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.NOMEM), + .errno = @intFromEnum(C.E.NOMEM), .syscall = .open, }, }), @intCast(dest_dir_fd), &(std.posix.toPosixPath(dest_name) catch return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.NOMEM), + .errno = @intFromEnum(C.E.NOMEM), .syscall = .open, }, }), @@ -3081,7 +3080,7 @@ pub fn linkatTmpfile(tmpfd: bun.FileDescriptor, dirfd: bun.FileDescriptor, name: /// On other platforms, this is just a wrapper around `read(2)`. pub fn readNonblocking(fd: bun.FileDescriptor, buf: []u8) Maybe(usize) { if (Environment.isLinux) { - while (bun.C.linux.RWFFlagSupport.isMaybeSupported()) { + while (C.linux.RWFFlagSupport.isMaybeSupported()) { const iovec = [1]std.posix.iovec{.{ .base = buf.ptr, .len = buf.len, @@ -3102,7 +3101,7 @@ pub fn readNonblocking(fd: bun.FileDescriptor, buf: []u8) Maybe(usize) { if (Maybe(usize).errnoSysFd(rc, .read, fd)) |err| { switch (err.getErrno()) { .OPNOTSUPP, .NOSYS => { - bun.C.linux.RWFFlagSupport.disable(); + C.linux.RWFFlagSupport.disable(); switch (bun.isReadable(fd)) { .hup, .ready => return read(fd, buf), else => return .{ .err = Error.retry }, @@ -3125,7 +3124,7 @@ pub fn readNonblocking(fd: bun.FileDescriptor, buf: []u8) Maybe(usize) { /// On other platforms, this is just a wrapper around `read(2)`. pub fn writeNonblocking(fd: bun.FileDescriptor, buf: []const u8) Maybe(usize) { if (Environment.isLinux) { - while (bun.C.linux.RWFFlagSupport.isMaybeSupported()) { + while (C.linux.RWFFlagSupport.isMaybeSupported()) { const iovec = [1]std.posix.iovec_const{.{ .base = buf.ptr, .len = buf.len, @@ -3146,7 +3145,7 @@ pub fn writeNonblocking(fd: bun.FileDescriptor, buf: []const u8) Maybe(usize) { if (Maybe(usize).errnoSysFd(rc, .write, fd)) |err| { switch (err.getErrno()) { .OPNOTSUPP, .NOSYS => { - bun.C.linux.RWFFlagSupport.disable(); + C.linux.RWFFlagSupport.disable(); switch (bun.isWritable(fd)) { .hup, .ready => return write(fd, buf), else => return .{ .err = Error.retry }, @@ -3302,7 +3301,7 @@ pub const File = struct { defer if (Environment.isPosix) this.close(); // On Windows, close the file before moving it. if (Environment.isWindows) this.close(); - try bun.C.moveFileZWithHandle(this.handle, bun.toFD(std.fs.cwd()), src, bun.toFD(std.fs.cwd()), dest); + try C.moveFileZWithHandle(this.handle, bun.toFD(std.fs.cwd()), src, bun.toFD(std.fs.cwd()), dest); } fn stdIoRead(this: File, buf: []u8) ReadError!usize { @@ -3368,7 +3367,7 @@ pub const File = struct { switch (bun.windows.GetLastError()) { .SUCCESS => {}, else => |err| { - return .{ .err = Error.fromCode((bun.C.SystemErrno.init(err) orelse bun.C.SystemErrno.EUNKNOWN).toE(), .fstat) }; + return .{ .err = Error.fromCode((C.SystemErrno.init(err) orelse C.SystemErrno.EUNKNOWN).toE(), .fstat) }; }, } } @@ -3604,7 +3603,7 @@ pub inline fn toLibUVOwnedFD( } return .{ .err = .{ - .errno = @intFromEnum(bun.C.E.MFILE), + .errno = @intFromEnum(C.E.MFILE), .syscall = syscall_tag, }, }; diff --git a/src/sys_uv.zig b/src/sys_uv.zig index 75557717a15594..add96f746c1ffe 100644 --- a/src/sys_uv.zig +++ b/src/sys_uv.zig @@ -11,7 +11,7 @@ const kernel32 = bun.windows; const linux = posix.linux; const uv = bun.windows.libuv; -const C = bun.C; +const C = @import("root").C; const E = C.E; const Environment = bun.Environment; const FDImpl = bun.FDImpl; diff --git a/src/tagged_pointer.zig b/src/tagged_pointer.zig index f81aa656b3a111..4be4901bca4771 100644 --- a/src/tagged_pointer.zig +++ b/src/tagged_pointer.zig @@ -6,7 +6,7 @@ const Global = bun.Global; const Environment = bun.Environment; const strings = bun.strings; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const typeBaseName = @import("./meta.zig").typeBaseName; const TagSize = u15; diff --git a/src/tmp.zig b/src/tmp.zig index 9b1cd7a2542bdd..8088952025613a 100644 --- a/src/tmp.zig +++ b/src/tmp.zig @@ -1,5 +1,6 @@ -const bun = @import("root").bun; const std = @import("std"); +const bun = @import("root").bun; +const C = @import("root").C; const Environment = bun.Environment; const O = bun.O; @@ -84,6 +85,6 @@ pub const Tmpfile = struct { } } - try bun.C.moveFileZWithHandle(this.fd, this.destination_dir, this.tmpfilename, this.destination_dir, destname); + try C.moveFileZWithHandle(this.fd, this.destination_dir, this.tmpfilename, this.destination_dir, destname); } }; diff --git a/src/toml/toml_parser.zig b/src/toml/toml_parser.zig index 0d07d49714394f..dcafb8c2325473 100644 --- a/src/toml/toml_parser.zig +++ b/src/toml/toml_parser.zig @@ -16,7 +16,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const expect = std.testing.expect; const ImportKind = importRecord.ImportKind; const BindingNodeIndex = js_ast.BindingNodeIndex; diff --git a/src/tracy.zig b/src/tracy.zig index b83c6946abd63d..08925c95c04c16 100644 --- a/src/tracy.zig +++ b/src/tracy.zig @@ -9,6 +9,7 @@ const std = @import("std"); const builtin = @import("builtin"); const build_options = @import("build_options"); const bun = @import("root").bun; +const C = @import("root").C; pub const enable_allocation = false; pub const enable_callstack = false; @@ -492,7 +493,7 @@ fn dlsym(comptime Type: type, comptime symbol: [:0]const u8) ?Type { if (comptime bun.Environment.isLinux) { // use LD_PRELOAD on linux - if (bun.C.dlsym(Type, symbol)) |val| { + if (C.dlsym(Type, symbol)) |val| { return val; } } @@ -537,14 +538,14 @@ fn dlsym(comptime Type: type, comptime symbol: [:0]const u8) ?Type { 0; if (bun.getenvZ("BUN_TRACY_PATH")) |path| { - const handle = bun.C.dlopen(&(std.posix.toPosixPath(path) catch unreachable), RLTD); + const handle = C.dlopen(&(std.posix.toPosixPath(path) catch unreachable), RLTD); if (handle != null) { Handle.handle = handle; break :get; } } inline for (comptime paths_to_try) |path| { - const handle = bun.C.dlopen(path, RLTD); + const handle = C.dlopen(path, RLTD); if (handle != null) { Handle.handle = handle; break; @@ -556,5 +557,5 @@ fn dlsym(comptime Type: type, comptime symbol: [:0]const u8) ?Type { } } - return bun.C.dlsymWithHandle(Type, symbol, Handle.getter); + return C.dlsymWithHandle(Type, symbol, Handle.getter); } diff --git a/src/transpiler.zig b/src/transpiler.zig index 5836e0e20c1447..a06a046aa668b6 100644 --- a/src/transpiler.zig +++ b/src/transpiler.zig @@ -9,7 +9,7 @@ const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const StoredFileDescriptorType = bun.StoredFileDescriptorType; const FeatureFlags = bun.FeatureFlags; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); const lex = bun.js_lexer; const logger = bun.logger; diff --git a/src/url.zig b/src/url.zig index f96325ade9efd4..0319853963a8f5 100644 --- a/src/url.zig +++ b/src/url.zig @@ -10,7 +10,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const JSC = bun.JSC; // This is close to WHATWG URL, but we don't want the validation errors diff --git a/src/watcher.zig b/src/watcher.zig index 1cd75586b57448..97de7d4fc1bc97 100644 --- a/src/watcher.zig +++ b/src/watcher.zig @@ -1,5 +1,6 @@ const std = @import("std"); const bun = @import("root").bun; +const C = @import("root").C; const string = bun.string; const Output = bun.Output; const Global = bun.Global; @@ -57,14 +58,14 @@ const INotify = struct { .result = std.posix.inotify_add_watchZ(this.inotify_fd, pathname, watch_file_mask) catch |err| return .{ .err = .{ .errno = @truncate(@intFromEnum(switch (err) { - error.FileNotFound => bun.C.E.NOENT, - error.AccessDenied => bun.C.E.ACCES, - error.SystemResources => bun.C.E.NOMEM, - error.Unexpected => bun.C.E.INVAL, - error.NotDir => bun.C.E.NOTDIR, - error.NameTooLong => bun.C.E.NAMETOOLONG, - error.UserResourceLimitReached => bun.C.E.MFILE, - error.WatchAlreadyExists => bun.C.E.EXIST, + error.FileNotFound => C.E.NOENT, + error.AccessDenied => C.E.ACCES, + error.SystemResources => C.E.NOMEM, + error.Unexpected => C.E.INVAL, + error.NotDir => C.E.NOTDIR, + error.NameTooLong => C.E.NAMETOOLONG, + error.UserResourceLimitReached => C.E.MFILE, + error.WatchAlreadyExists => C.E.EXIST, })), .syscall = .watch, }, @@ -81,14 +82,14 @@ const INotify = struct { .result = std.posix.inotify_add_watchZ(this.inotify_fd, pathname, watch_dir_mask) catch |err| return .{ .err = .{ .errno = @truncate(@intFromEnum(switch (err) { - error.FileNotFound => bun.C.E.NOENT, - error.AccessDenied => bun.C.E.ACCES, - error.SystemResources => bun.C.E.NOMEM, - error.Unexpected => bun.C.E.INVAL, - error.NotDir => bun.C.E.NOTDIR, - error.NameTooLong => bun.C.E.NAMETOOLONG, - error.UserResourceLimitReached => bun.C.E.MFILE, - error.WatchAlreadyExists => bun.C.E.EXIST, + error.FileNotFound => C.E.NOENT, + error.AccessDenied => C.E.ACCES, + error.SystemResources => C.E.NOMEM, + error.Unexpected => C.E.INVAL, + error.NotDir => C.E.NOTDIR, + error.NameTooLong => C.E.NAMETOOLONG, + error.UserResourceLimitReached => C.E.MFILE, + error.WatchAlreadyExists => C.E.EXIST, })), .syscall = .watch, }, @@ -275,7 +276,7 @@ const WindowsWatcher = struct { const err = w.kernel32.GetLastError(); log("failed to start watching directory: {s}", .{@tagName(err)}); return .{ .err = .{ - .errno = @intFromEnum(bun.C.SystemErrno.init(err) orelse bun.C.SystemErrno.EINVAL), + .errno = @intFromEnum(C.SystemErrno.init(err) orelse C.SystemErrno.EINVAL), .syscall = .watch, } }; } @@ -385,7 +386,7 @@ const WindowsWatcher = struct { } else { log("GetQueuedCompletionStatus failed: {s}", .{@tagName(err)}); return .{ .err = .{ - .errno = @intFromEnum(bun.C.SystemErrno.init(err) orelse bun.C.SystemErrno.EINVAL), + .errno = @intFromEnum(C.SystemErrno.init(err) orelse C.SystemErrno.EINVAL), .syscall = .watch, } }; } @@ -401,7 +402,7 @@ const WindowsWatcher = struct { // TODO close handles? log("shutdown notification in WindowsWatcher.next", .{}); return .{ .err = .{ - .errno = @intFromEnum(bun.C.SystemErrno.ESHUTDOWN), + .errno = @intFromEnum(C.SystemErrno.ESHUTDOWN), .syscall = .watch, } }; } @@ -409,7 +410,7 @@ const WindowsWatcher = struct { } else { log("GetQueuedCompletionStatus returned no overlapped event", .{}); return .{ .err = .{ - .errno = @truncate(@intFromEnum(bun.C.E.INVAL)), + .errno = @truncate(@intFromEnum(C.E.INVAL)), .syscall = .watch, } }; } diff --git a/src/which_npm_client.zig b/src/which_npm_client.zig index 7e90f12d3491bf..0b4e5a6fca6ecb 100644 --- a/src/which_npm_client.zig +++ b/src/which_npm_client.zig @@ -7,7 +7,7 @@ const strings = bun.strings; const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; -const C = bun.C; +const C = @import("root").C; const std = @import("std"); diff --git a/src/windows.zig b/src/windows.zig index b7d7d6860cba40..6103081409e5c1 100644 --- a/src/windows.zig +++ b/src/windows.zig @@ -1,4 +1,5 @@ const bun = @import("root").bun; +const C = @import("root").C; const windows = std.os.windows; const win32 = windows; pub const PATH_MAX_WIDE = windows.PATH_MAX_WIDE; @@ -156,7 +157,7 @@ pub extern "kernel32" fn SetCurrentDirectoryW( pub const SetCurrentDirectory = SetCurrentDirectoryW; pub extern "ntdll" fn RtlNtStatusToDosError(win32.NTSTATUS) callconv(windows.WINAPI) Win32Error; -const SystemErrno = bun.C.SystemErrno; +const SystemErrno = C.SystemErrno; // This was originally copied from Zig's standard library /// Codes are from https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d @@ -3038,15 +3039,15 @@ pub extern "kernel32" fn SetFileInformationByHandle( bufferSize: DWORD, ) BOOL; -pub fn getLastErrno() bun.C.E { - return (bun.C.SystemErrno.init(bun.windows.kernel32.GetLastError()) orelse SystemErrno.EUNKNOWN).toE(); +pub fn getLastErrno() C.E { + return (C.SystemErrno.init(bun.windows.kernel32.GetLastError()) orelse SystemErrno.EUNKNOWN).toE(); } pub fn getLastError() anyerror { return bun.errnoToZigErr(getLastErrno()); } -pub fn translateNTStatusToErrno(err: win32.NTSTATUS) bun.C.E { +pub fn translateNTStatusToErrno(err: win32.NTSTATUS) C.E { return switch (err) { .SUCCESS => .SUCCESS, .ACCESS_DENIED => .PERM,