| ... | ... | @@ -419,9 +419,32 @@ fn mainArgs( |
| 419 | 419 | }, |
| 420 | 420 | .targets => { |
| 421 | 421 | dev.check(.targets_command); |
| 422 | const self_exe_path = switch (native_os) { |
| 423 | .wasi => {}, |
| 424 | else => process.executablePathAlloc(io, arena) catch |err| fatal("unable to find zig self exe path: {t}", .{err}), |
| 425 | }; |
| 426 | var dirs: std.zig.Directories = .init( |
| 427 | arena, |
| 428 | io, |
| 429 | EnvVar.ZIG_LIB_DIR.get(environ_map), |
| 430 | EnvVar.ZIG_GLOBAL_CACHE_DIR.get(environ_map), |
| 431 | .global, |
| 432 | preopens, |
| 433 | self_exe_path, |
| 434 | environ_map, |
| 435 | try std.zig.getResolvedCwd(io, arena), |
| 436 | ); |
| 437 | defer dirs.deinit(io); |
| 422 | 438 | const host = std.zig.resolveTargetQueryOrFatal(io, .{}); |
| 423 | 439 | var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer); |
| 424 | | try @import("print_targets.zig").cmdTargets(arena, io, cmd_args, &stdout_writer.interface, &host); |
| 440 | try @import("print_targets.zig").cmdTargets( |
| 441 | arena, |
| 442 | io, |
| 443 | &dirs, |
| 444 | cmd_args, |
| 445 | &stdout_writer.interface, |
| 446 | &host, |
| 447 | ); |
| 425 | 448 | return stdout_writer.interface.flush(); |
| 426 | 449 | }, |
| 427 | 450 | .version => { |
| ... | ... | @@ -431,16 +454,31 @@ fn mainArgs( |
| 431 | 454 | }, |
| 432 | 455 | .env => { |
| 433 | 456 | dev.check(.env_command); |
| 457 | const self_exe_path = switch (native_os) { |
| 458 | .wasi => args[0], |
| 459 | else => process.executablePathAlloc(io, arena) catch |err| fatal("unable to find zig self exe path: {t}", .{err}), |
| 460 | }; |
| 461 | var dirs: std.zig.Directories = .init( |
| 462 | arena, |
| 463 | io, |
| 464 | EnvVar.ZIG_LIB_DIR.get(environ_map), |
| 465 | EnvVar.ZIG_GLOBAL_CACHE_DIR.get(environ_map), |
| 466 | .global, |
| 467 | preopens, |
| 468 | if (native_os != .wasi) self_exe_path, |
| 469 | environ_map, |
| 470 | try std.zig.getResolvedCwd(io, arena), |
| 471 | ); |
| 472 | defer dirs.deinit(io); |
| 434 | 473 | const host = std.zig.resolveTargetQueryOrFatal(io, .{}); |
| 435 | 474 | var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer); |
| 436 | 475 | try @import("print_env.zig").cmdEnv( |
| 437 | 476 | arena, |
| 438 | | io, |
| 439 | 477 | &stdout_writer.interface, |
| 440 | | args, |
| 441 | | preopens, |
| 442 | 478 | &host, |
| 443 | 479 | environ_map, |
| 480 | &dirs, |
| 481 | self_exe_path, |
| 444 | 482 | ); |
| 445 | 483 | return stdout_writer.interface.flush(); |
| 446 | 484 | }, |
| ... | ... | @@ -3813,9 +3851,14 @@ fn buildOutputType( |
| 3813 | 3851 | }) { |
| 3814 | 3852 | dev.checkAny(&.{ .run_command, .test_command }); |
| 3815 | 3853 | |
| 3854 | const self_exe_path_or_argv0 = switch (native_os) { |
| 3855 | .wasi => all_args[0], // Will error because of `!process.can_spawn` |
| 3856 | else => self_exe_path, |
| 3857 | }; |
| 3858 | |
| 3816 | 3859 | if (test_exec_args.items.len == 0 and target.ofmt == .c and emit_bin_resolved != .no) { |
| 3817 | 3860 | // Default to using `zig run` to execute the produced .c code from `zig test`. |
| 3818 | | try test_exec_args.appendSlice(arena, &.{ self_exe_path, "run" }); |
| 3861 | try test_exec_args.appendSlice(arena, &.{ self_exe_path_or_argv0, "run" }); |
| 3819 | 3862 | // Skip passing `-ofmt`, we want the default for the target, not `.c` anymore. |
| 3820 | 3863 | |
| 3821 | 3864 | var prev_has_cflags = false; |
| ... | ... | @@ -3896,7 +3939,7 @@ fn buildOutputType( |
| 3896 | 3939 | arena, |
| 3897 | 3940 | io, |
| 3898 | 3941 | test_exec_args.items, |
| 3899 | | self_exe_path, |
| 3942 | self_exe_path_or_argv0, |
| 3900 | 3943 | arg_mode, |
| 3901 | 3944 | target, |
| 3902 | 3945 | &comp_destroyed, |
| ... | ... | @@ -4287,7 +4330,10 @@ fn serve( |
| 4287 | 4330 | in: *Io.Reader, |
| 4288 | 4331 | out: *Io.Writer, |
| 4289 | 4332 | test_exec_args: []const ?[]const u8, |
| 4290 | | self_exe_path: ?[]const u8, |
| 4333 | self_exe_path: switch (native_os) { |
| 4334 | .wasi => void, |
| 4335 | else => []const u8, |
| 4336 | }, |
| 4291 | 4337 | arg_mode: ArgMode, |
| 4292 | 4338 | all_args: []const []const u8, |
| 4293 | 4339 | runtime_args_start: ?usize, |
| ... | ... | @@ -4400,7 +4446,7 @@ fn serve( |
| 4400 | 4446 | comp, |
| 4401 | 4447 | gpa, |
| 4402 | 4448 | test_exec_args, |
| 4403 | | self_exe_path.?, |
| 4449 | self_exe_path, |
| 4404 | 4450 | arg_mode, |
| 4405 | 4451 | all_args, |
| 4406 | 4452 | runtime_args_start, |
| ... | ... | @@ -4585,9 +4631,8 @@ fn runOrTest( |
| 4585 | 4631 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4586 | 4632 | fatal("the following command failed to execve with '{t}':\n{s}", .{ err, cmd }); |
| 4587 | 4633 | } else if (!process.can_spawn) { |
| 4588 | | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4589 | | fatal("the following command cannot be executed ({t} does not support spawning a child process):\n{s}", .{ |
| 4590 | | native_os, cmd, |
| 4634 | fatal("the following command cannot be executed ({t} does not support spawning a child process):\n{f}", .{ |
| 4635 | native_os, std.zig.SubprocessCommand{ .argv = argv.items }, |
| 4591 | 4636 | }); |
| 4592 | 4637 | } |
| 4593 | 4638 | const term_result = (term: { |
| ... | ... | @@ -4667,7 +4712,10 @@ fn runOrTestHotSwap( |
| 4667 | 4712 | comp: *Compilation, |
| 4668 | 4713 | gpa: Allocator, |
| 4669 | 4714 | test_exec_args: []const ?[]const u8, |
| 4670 | | self_exe_path: []const u8, |
| 4715 | self_exe_path: switch (native_os) { |
| 4716 | .wasi => void, |
| 4717 | else => []const u8, |
| 4718 | }, |
| 4671 | 4719 | arg_mode: ArgMode, |
| 4672 | 4720 | all_args: []const []const u8, |
| 4673 | 4721 | runtime_args_start: ?usize, |
| ... | ... | @@ -4675,6 +4723,11 @@ fn runOrTestHotSwap( |
| 4675 | 4723 | const io = comp.io; |
| 4676 | 4724 | const lf = comp.bin_file.?; |
| 4677 | 4725 | |
| 4726 | const self_exe_path_or_argv0 = switch (native_os) { |
| 4727 | .wasi => all_args[0], // Will error because of `!process.can_spawn` |
| 4728 | else => self_exe_path, |
| 4729 | }; |
| 4730 | |
| 4678 | 4731 | const exe_path = switch (builtin.target.os.tag) { |
| 4679 | 4732 | // On Windows it seems impossible to perform an atomic rename of a file that is currently |
| 4680 | 4733 | // running in a process. Therefore, we do the opposite. We create a copy of the file in |
| ... | ... | @@ -4700,7 +4753,7 @@ fn runOrTestHotSwap( |
| 4700 | 4753 | // when testing pass the zig_exe_path to argv |
| 4701 | 4754 | if (arg_mode == .zig_test) |
| 4702 | 4755 | try argv.appendSlice(&[_][]const u8{ |
| 4703 | | exe_path, self_exe_path, |
| 4756 | exe_path, self_exe_path_or_argv0, |
| 4704 | 4757 | }) |
| 4705 | 4758 | // when running just pass the current exe |
| 4706 | 4759 | else |
| ... | ... | @@ -4713,7 +4766,7 @@ fn runOrTestHotSwap( |
| 4713 | 4766 | try argv.append(a); |
| 4714 | 4767 | } else { |
| 4715 | 4768 | try argv.appendSlice(&[_][]const u8{ |
| 4716 | | exe_path, self_exe_path, |
| 4769 | exe_path, self_exe_path_or_argv0, |
| 4717 | 4770 | }); |
| 4718 | 4771 | } |
| 4719 | 4772 | } |
| ... | ... | @@ -4722,6 +4775,12 @@ fn runOrTestHotSwap( |
| 4722 | 4775 | try argv.appendSlice(all_args[i..]); |
| 4723 | 4776 | } |
| 4724 | 4777 | |
| 4778 | if (!process.can_spawn) { |
| 4779 | fatal("the following command cannot be executed ({t} does not support spawning a child process):\n{f}", .{ |
| 4780 | native_os, std.zig.SubprocessCommand{ .argv = argv.items }, |
| 4781 | }); |
| 4782 | } |
| 4783 | |
| 4725 | 4784 | const child = try std.process.spawn(io, .{ |
| 4726 | 4785 | .argv = argv.items, |
| 4727 | 4786 | .stdin = .inherit, |
| ... | ... | @@ -4902,6 +4961,12 @@ fn jitCmdInner( |
| 4902 | 4961 | thread_limit: usize, |
| 4903 | 4962 | options: JitCmdOptions, |
| 4904 | 4963 | ) !void { |
| 4964 | if (!std.process.can_spawn) { |
| 4965 | fatal("The {s} command cannot be executed ({t} does not support spawning a child process)", .{ |
| 4966 | options.cmd_name, native_os, |
| 4967 | }); |
| 4968 | } |
| 4969 | |
| 4905 | 4970 | const target_query: std.Target.Query = .{}; |
| 4906 | 4971 | const resolved_target: Module.ResolvedTarget = .{ |
| 4907 | 4972 | .result = std.zig.resolveTargetQueryOrFatal(io, target_query), |
| ... | ... | @@ -5074,13 +5139,6 @@ fn jitCmdInner( |
| 5074 | 5139 | fatal("the following command failed to execve with {t}:\n{s}", .{ err, cmd }); |
| 5075 | 5140 | } |
| 5076 | 5141 | |
| 5077 | | if (!process.can_spawn) { |
| 5078 | | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5079 | | fatal("the following command cannot be executed ({t} does not support spawning a child process):\n{s}", .{ |
| 5080 | | native_os, cmd, |
| 5081 | | }); |
| 5082 | | } |
| 5083 | | |
| 5084 | 5142 | const term = t: { |
| 5085 | 5143 | _ = try io.lockStderr(&.{}, .no_color); |
| 5086 | 5144 | defer io.unlockStderr(); |