diff options
author | 2023-08-28 04:39:16 -0700 | |
---|---|---|
committer | 2023-08-28 04:39:16 -0700 | |
commit | e2a17344dc543c9c652cfe2b14cd2709dd6cfd22 (patch) | |
tree | fe93965d39886494aee12dca71bdcf2a991d806f /src/cli | |
parent | efe987e8d12e824dde840b56cbb704feabe26ed1 (diff) | |
download | bun-e2a17344dc543c9c652cfe2b14cd2709dd6cfd22.tar.gz bun-e2a17344dc543c9c652cfe2b14cd2709dd6cfd22.tar.zst bun-e2a17344dc543c9c652cfe2b14cd2709dd6cfd22.zip |
just kernel32 things (#4354)
* just kernel32 things
* more
* Update linux_c.zig
* Update windows_c.zig
* Add workaround
Workaround https://github.com/ziglang/zig/issues/16980
* Rename http.zig to bun_dev_http_server.zig
* Rename usages
* more
* more
* more
* thanks tigerbeetle
* Rename `JSC.Node.Syscall` -> `bun.sys`
* more
* woops
* more!
* hmm
* it says there are only 37 errors, but that's not true
* populate argv
* it says 32 errors!
* 24 errors
* fix regular build
* 12 left!
* Still 12 left!
* more
* 2 errors left...
* 1 more error
* Add link to Tigerbeetle
* Fix the remainign error
* Fix test timeout
* Update syscall.zig
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/build_command.zig | 6 | ||||
-rw-r--r-- | src/cli/bunx_command.zig | 8 | ||||
-rw-r--r-- | src/cli/create_command.zig | 63 | ||||
-rw-r--r-- | src/cli/dev_command.zig | 7 | ||||
-rw-r--r-- | src/cli/init_command.zig | 23 | ||||
-rw-r--r-- | src/cli/install_completions_command.zig | 11 | ||||
-rw-r--r-- | src/cli/run_command.zig | 31 | ||||
-rw-r--r-- | src/cli/test_command.zig | 6 | ||||
-rw-r--r-- | src/cli/upgrade_command.zig | 8 |
9 files changed, 103 insertions, 60 deletions
diff --git a/src/cli/build_command.zig b/src/cli/build_command.zig index f87d88930..cb7d1ce94 100644 --- a/src/cli/build_command.zig +++ b/src/cli/build_command.zig @@ -411,7 +411,7 @@ pub const BuildCommand = struct { }, .encoding = .buffer, .mode = if (f.is_executable) 0o755 else 0o644, - .dirfd = @as(bun.FileDescriptor, @intCast(root_dir.dir.fd)), + .dirfd = bun.toFD(root_dir.dir.fd), .file = .{ .path = JSC.Node.PathLike{ .string = JSC.PathString.init(rel_path), @@ -431,12 +431,12 @@ pub const BuildCommand = struct { rel_path = filepath_buf[0 .. primary.len + 2]; rel_path = value.pathname; - try f.moveTo(root_path, bun.constStrToU8(rel_path), root_dir.dir.fd); + try f.moveTo(root_path, bun.constStrToU8(rel_path), bun.toFD(root_dir.dir.fd)); }, .copy => |value| { rel_path = value.pathname; - try f.copyTo(root_path, bun.constStrToU8(rel_path), root_dir.dir.fd); + try f.copyTo(root_path, bun.constStrToU8(rel_path), bun.toFD(root_dir.dir.fd)); }, .noop => {}, .pending => unreachable, diff --git a/src/cli/bunx_command.zig b/src/cli/bunx_command.zig index 84c7e1bba..9bf7e1d11 100644 --- a/src/cli/bunx_command.zig +++ b/src/cli/bunx_command.zig @@ -97,7 +97,7 @@ pub const BunxCommand = struct { "{s}/node_modules/{s}/package.json", .{ tempdir_name, package_name }, ) catch unreachable; - return try getBinNameFromSubpath(bundler, std.os.AT.FDCWD, subpath_z); + return try getBinNameFromSubpath(bundler, std.fs.cwd().fd, subpath_z); } /// Check the enclosing package.json for a matching "bin" @@ -141,10 +141,10 @@ pub const BunxCommand = struct { var requests_buf = bun.PackageManager.UpdateRequest.Array.init(0) catch unreachable; var run_in_bun = ctx.debug.run_in_bun; - var passthrough_list = try std.ArrayList(string).initCapacity(ctx.allocator, std.os.argv.len -| 1); + var passthrough_list = try std.ArrayList(string).initCapacity(ctx.allocator, bun.argv().len -| 1); var package_name_for_update_request = [1]string{""}; { - var argv = std.os.argv[1..]; + var argv = bun.argv()[1..]; var found_subcommand_name = false; @@ -286,7 +286,7 @@ pub const BunxCommand = struct { } // 2. The "bin" is possibly not the same as the package name, so we load the package.json to figure out what "bin" to use - if (getBinName(&this_bundler, root_dir_info.getFileDescriptor(), bunx_cache_dir, initial_bin_name)) |package_name_for_bin| { + if (getBinName(&this_bundler, bun.fdcast(root_dir_info.getFileDescriptor()), bunx_cache_dir, initial_bin_name)) |package_name_for_bin| { // if we check the bin name and its actually the same, we don't need to check $PATH here again if (!strings.eqlLong(package_name_for_bin, initial_bin_name, true)) { absolute_in_cache_dir = std.fmt.bufPrint(&absolute_in_cache_dir_buf, "{s}/node_modules/.bin/{s}", .{ bunx_cache_dir, package_name_for_bin }) catch unreachable; diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index 284de1fd5..8264bf771 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -554,7 +554,7 @@ pub const CreateCommand = struct { progress.refresh(); package_json_contents = plucker.contents; - package_json_file = std.fs.File{ .handle = plucker.fd }; + package_json_file = std.fs.File{ .handle = bun.fdcast(plucker.fd) }; } } }, @@ -615,9 +615,13 @@ pub const CreateCommand = struct { var infile = try entry.dir.dir.openFile(entry.basename, .{ .mode = .read_only }); defer infile.close(); - // Assumption: you only really care about making sure something that was executable is still executable - const stat = infile.stat() catch continue; - _ = C.fchmod(outfile.handle, stat.mode); + if (comptime Environment.isPosix) { + // Assumption: you only really care about making sure something that was executable is still executable + const stat = infile.stat() catch continue; + _ = C.fchmod(outfile.handle, stat.mode); + } else { + bun.todo(@src(), void{}); + } CopyFile.copyFile(infile.handle, outfile.handle) catch |err| { Output.prettyErrorln("<r><red>{s}<r>: copying file {s}", .{ @errorName(err), entry.path }); @@ -633,24 +637,33 @@ pub const CreateCommand = struct { read_package_json: { if (package_json_file) |pkg| { - const stat = pkg.stat() catch |err| { - node.end(); + const size = brk: { + if (comptime Environment.isWindows) { + break :brk try pkg.getEndPos(); + } - progress.refresh(); + const stat = pkg.stat() catch |err| { + node.end(); - package_json_file = null; - Output.prettyErrorln("Error reading package.json: <r><red>{s}", .{@errorName(err)}); - break :read_package_json; - }; + progress.refresh(); - if (stat.kind != .file or stat.size == 0) { - package_json_file = null; - node.end(); + package_json_file = null; + Output.prettyErrorln("Error reading package.json: <r><red>{s}", .{@errorName(err)}); + break :read_package_json; + }; - progress.refresh(); - break :read_package_json; - } - package_json_contents = try MutableString.init(ctx.allocator, stat.size); + if (stat.kind != .file or stat.size == 0) { + package_json_file = null; + node.end(); + + progress.refresh(); + break :read_package_json; + } + + break :brk stat.size; + }; + + package_json_contents = try MutableString.init(ctx.allocator, size); package_json_contents.list.expandToCapacity(); _ = pkg.preadAll(package_json_contents.list.items, 0) catch |err| { @@ -1717,36 +1730,36 @@ pub const Example = struct { { var folders = [3]std.fs.IterableDir{ .{ - .dir = .{ .fd = 0 }, + .dir = .{ .fd = bun.fdcast(bun.invalid_fd) }, }, .{ - .dir = .{ .fd = 0 }, + .dir = .{ .fd = bun.fdcast(bun.invalid_fd) }, }, - .{ .dir = .{ .fd = 0 } }, + .{ .dir = .{ .fd = bun.fdcast(bun.invalid_fd) } }, }; if (env_loader.map.get("BUN_CREATE_DIR")) |home_dir| { var parts = [_]string{home_dir}; var outdir_path = filesystem.absBuf(&parts, &home_dir_buf); - folders[0] = std.fs.cwd().openIterableDir(outdir_path, .{}) catch .{ .dir = .{ .fd = 0 } }; + folders[0] = std.fs.cwd().openIterableDir(outdir_path, .{}) catch .{ .dir = .{ .fd = bun.fdcast(bun.invalid_fd) } }; } { var parts = [_]string{ filesystem.top_level_dir, BUN_CREATE_DIR }; var outdir_path = filesystem.absBuf(&parts, &home_dir_buf); - folders[1] = std.fs.cwd().openIterableDir(outdir_path, .{}) catch .{ .dir = .{ .fd = 0 } }; + folders[1] = std.fs.cwd().openIterableDir(outdir_path, .{}) catch .{ .dir = .{ .fd = bun.fdcast(bun.invalid_fd) } }; } if (env_loader.map.get("HOME")) |home_dir| { var parts = [_]string{ home_dir, BUN_CREATE_DIR }; var outdir_path = filesystem.absBuf(&parts, &home_dir_buf); - folders[2] = std.fs.cwd().openIterableDir(outdir_path, .{}) catch .{ .dir = .{ .fd = 0 } }; + folders[2] = std.fs.cwd().openIterableDir(outdir_path, .{}) catch .{ .dir = .{ .fd = bun.fdcast(bun.invalid_fd) } }; } // subfolders with package.json for (folders) |folder__| { const folder_ = folder__.dir; - if (folder_.fd != 0) { + if (folder_.fd != bun.fdcast(bun.invalid_fd)) { const folder: std.fs.Dir = folder_; var iter = (std.fs.IterableDir{ .dir = folder }).iterate(); diff --git a/src/cli/dev_command.zig b/src/cli/dev_command.zig index 9fb846fe7..91c9fda3d 100644 --- a/src/cli/dev_command.zig +++ b/src/cli/dev_command.zig @@ -1,8 +1,11 @@ -const Server = @import("../http.zig").Server; const Command = @import("../cli.zig").Command; -const Global = @import("root").bun.Global; + pub const DevCommand = struct { pub fn exec(ctx: Command.Context) !void { + if (comptime @import("root").bun.Environment.isWindows) unreachable; + + const Server = @import("../bun_dev_http_server.zig").Server; + const Global = @import("root").bun.Global; Global.configureAllocator(.{ .long_running = true }); try Server.start(ctx.allocator, ctx.args, @TypeOf(ctx.debug), ctx.debug); } diff --git a/src/cli/init_command.zig b/src/cli/init_command.zig index 6f1fced54..8d65461a7 100644 --- a/src/cli/init_command.zig +++ b/src/cli/init_command.zig @@ -110,12 +110,25 @@ pub const InitCommand = struct { initializeStore(); read_package_json: { if (package_json_file) |pkg| { - const stat = pkg.stat() catch break :read_package_json; + const size = brk: { + if (comptime bun.Environment.isWindows) { + const end = pkg.getEndPos() catch break :read_package_json; + if (end == 0) { + break :read_package_json; + } + + break :brk end; + } + const stat = pkg.stat() catch break :read_package_json; - if (stat.kind != .file or stat.size == 0) { - break :read_package_json; - } - package_json_contents = try MutableString.init(alloc, stat.size); + if (stat.kind != .file or stat.size == 0) { + break :read_package_json; + } + + break :brk stat.size; + }; + + package_json_contents = try MutableString.init(alloc, size); package_json_contents.list.expandToCapacity(); _ = pkg.preadAll(package_json_contents.list.items, 0) catch { diff --git a/src/cli/install_completions_command.zig b/src/cli/install_completions_command.zig index 7e19d12f1..1d67a7b39 100644 --- a/src/cli/install_completions_command.zig +++ b/src/cli/install_completions_command.zig @@ -45,6 +45,11 @@ pub const InstallCompletionsCommand = struct { pub fn testPath(_: string) !std.fs.Dir {} fn installBunxSymlink(allocator: std.mem.Allocator, cwd: []const u8) !void { + if (comptime Environment.isWindows) { + bun.todo(@src(), {}); + return; + } + var buf: [bun.MAX_PATH_BYTES]u8 = undefined; const bunx_name = if (Environment.isDebug) "bunx-debug" else "bunx"; @@ -133,10 +138,10 @@ pub const InstallCompletionsCommand = struct { var completions_dir: string = ""; var output_dir: std.fs.IterableDir = found: { - for (std.os.argv, 0..) |arg, i| { + for (bun.argv(), 0..) |arg, i| { if (strings.eqlComptime(std.mem.span(arg), "completions")) { - if (std.os.argv.len > i + 1) { - const input = std.mem.span(std.os.argv[i + 1]); + if (bun.argv().len > i + 1) { + const input = std.mem.span(bun.argv()[i + 1]); if (!std.fs.path.isAbsolute(input)) { completions_dir = resolve_path.joinAbs( diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index ba05e1ddf..17eb13dcb 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -50,6 +50,10 @@ pub const RunCommand = struct { }; pub fn findShell(PATH: string, cwd: string) ?string { + if (comptime Environment.isWindows) { + return "C:\\Windows\\System32\\cmd.exe"; + } + inline for (shells_to_search) |shell| { if (which(&path_buf, PATH, cwd, shell)) |shell_| { return shell_; @@ -58,8 +62,7 @@ pub const RunCommand = struct { const Try = struct { pub fn shell(str: stringZ) bool { - std.os.accessZ(str, std.os.X_OK) catch return false; - return true; + return bun.sys.isExecutableFilePath(str); } }; @@ -341,7 +344,7 @@ pub const RunCommand = struct { const result = child_process.spawnAndWait() catch |err| { if (err == error.AccessDenied) { - { + if (comptime Environment.isPosix) { var stat = std.mem.zeroes(std.c.Stat); const rc = bun.C.stat(executable[0.. :0].ptr, &stat); if (rc == 0) { @@ -408,16 +411,21 @@ pub const RunCommand = struct { var self_exe_bin_path_buf: [bun.MAX_PATH_BYTES + 1]u8 = undefined; fn createFakeTemporaryNodeExecutable(PATH: *std.ArrayList(u8), optional_bun_path: *string) !void { + if (comptime Environment.isWindows) { + bun.todo(@src(), {}); + return; + } + var retried = false; - if (!strings.endsWithComptime(std.mem.span(std.os.argv[0]), "node")) { + if (!strings.endsWithComptime(std.mem.span(bun.argv()[0]), "node")) { var argv0 = @as([*:0]const u8, @ptrCast(optional_bun_path.ptr)); // if we are already an absolute path, use that // if the user started the application via a shebang, it's likely that the path is absolute already - if (std.os.argv[0][0] == '/') { - optional_bun_path.* = bun.span(std.os.argv[0]); - argv0 = std.os.argv[0]; + if (bun.argv()[0][0] == '/') { + optional_bun_path.* = bun.span(bun.argv()[0]); + argv0 = bun.argv()[0]; } else if (optional_bun_path.len == 0) { // otherwise, ask the OS for the absolute path var self = std.fs.selfExePath(&self_exe_bin_path_buf) catch unreachable; @@ -429,7 +437,7 @@ pub const RunCommand = struct { } if (optional_bun_path.len == 0) { - argv0 = std.os.argv[0]; + argv0 = bun.argv()[0]; } while (true) { @@ -445,7 +453,8 @@ pub const RunCommand = struct { continue; }; } - _ = bun.C.chmod(bun_node_dir ++ "/node", 0o777); + if (comptime Environment.isPosix) + _ = bun.C.chmod(bun_node_dir ++ "/node", 0o777); break; } } @@ -723,7 +732,7 @@ pub const RunCommand = struct { bun.copy(u8, path_buf[dir_slice.len..], base); path_buf[dir_slice.len + base.len] = 0; var slice = path_buf[0 .. dir_slice.len + base.len :0]; - std.os.accessZ(slice, std.os.X_OK) catch continue; + if (!(bun.sys.isExecutableFilePath(slice))) continue; // we need to dupe because the string pay point to a pointer that only exists in the current scope _ = try results.getOrPut(this_bundler.fs.filename_store.append(@TypeOf(base), base) catch continue); } @@ -953,7 +962,7 @@ pub const RunCommand = struct { shebang = std.mem.trim(u8, shebang, " \r\n\t"); if (shebang.len == 0) break :possibly_open_with_bun_js; if (strings.hasPrefixComptime(shebang, "#!")) { - const first_arg: string = if (std.os.argv.len > 0) bun.span(std.os.argv[0]) else ""; + const first_arg: string = if (bun.argv().len > 0) bun.span(bun.argv()[0]) else ""; const filename = std.fs.path.basename(first_arg); // are we attempting to run the script with bun? if (!strings.contains(shebang, filename)) { diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index 53dd4c3c5..0af54f61b 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -401,7 +401,7 @@ const Scanner = struct { if (@as(FileSystem.RealFS.EntriesOption.Tag, root.*) == .entries) { var iter = root.entries.data.iterator(); const fd = root.entries.fd; - std.debug.assert(fd != 0); + std.debug.assert(fd != bun.invalid_fd); while (iter.next()) |entry| { this.next(entry.value_ptr.*, fd); } @@ -409,8 +409,8 @@ const Scanner = struct { } while (this.dirs_to_scan.readItem()) |entry| { - var dir = std.fs.Dir{ .fd = entry.relative_dir }; - std.debug.assert(dir.fd != 0); + var dir = std.fs.Dir{ .fd = bun.fdcast(entry.relative_dir) }; + std.debug.assert(bun.toFD(dir.fd) != bun.invalid_fd); var parts2 = &[_]string{ entry.dir_path, entry.name.slice() }; var path2 = this.fs.absBuf(parts2, &this.open_dir_buf); diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index 79a7777f3..c48e32aca 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -408,14 +408,14 @@ pub const UpgradeCommand = struct { const use_canary = brk: { const default_use_canary = Environment.is_canary; - if (default_use_canary and strings.containsAny(bun.span(std.os.argv), "--stable")) + if (default_use_canary and strings.containsAny(bun.span(bun.argv()), "--stable")) break :brk false; break :brk strings.eqlComptime(env_loader.map.get("BUN_CANARY") orelse "0", "1") or - strings.containsAny(bun.span(std.os.argv), "--canary") or default_use_canary; + strings.containsAny(bun.span(bun.argv()), "--canary") or default_use_canary; }; - const use_profile = strings.containsAny(bun.span(std.os.argv), "--profile"); + const use_profile = strings.containsAny(bun.span(bun.argv()), "--profile"); if (!use_canary) { var refresher = std.Progress{}; @@ -532,7 +532,7 @@ pub const UpgradeCommand = struct { tmpdir_path_buf[tmpdir_path.len] = 0; var tmpdir_z = tmpdir_path_buf[0..tmpdir_path.len :0]; - std.os.chdirZ(tmpdir_z) catch {}; + _ = bun.sys.chdir(tmpdir_z); const tmpname = "bun.zip"; const exe = |