| ... | @@ -419,9 +419,32 @@ fn mainArgs( | ... | @@ -419,9 +419,32 @@ fn mainArgs( |
| 419 | }, | 419 | }, |
| 420 | .targets => { | 420 | .targets => { |
| 421 | dev.check(.targets_command); | 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 | const host = std.zig.resolveTargetQueryOrFatal(io, .{}); | 438 | const host = std.zig.resolveTargetQueryOrFatal(io, .{}); |
| 423 | var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer); | 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 | return stdout_writer.interface.flush(); | 448 | return stdout_writer.interface.flush(); |
| 426 | }, | 449 | }, |
| 427 | .version => { | 450 | .version => { |
| ... | @@ -431,16 +454,31 @@ fn mainArgs( | ... | @@ -431,16 +454,31 @@ fn mainArgs( |
| 431 | }, | 454 | }, |
| 432 | .env => { | 455 | .env => { |
| 433 | dev.check(.env_command); | 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 | const host = std.zig.resolveTargetQueryOrFatal(io, .{}); | 473 | const host = std.zig.resolveTargetQueryOrFatal(io, .{}); |
| 435 | var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer); | 474 | var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer); |
| 436 | try @import("print_env.zig").cmdEnv( | 475 | try @import("print_env.zig").cmdEnv( |
| 437 | arena, | 476 | arena, |
| 438 | io, | | |
| 439 | &stdout_writer.interface, | 477 | &stdout_writer.interface, |
| 440 | args, | | |
| 441 | preopens, | | |
| 442 | &host, | 478 | &host, |
| 443 | environ_map, | 479 | environ_map, |
| | 480 | &dirs, |
| | 481 | self_exe_path, |
| 444 | ); | 482 | ); |
| 445 | return stdout_writer.interface.flush(); | 483 | return stdout_writer.interface.flush(); |
| 446 | }, | 484 | }, |
| ... | @@ -3813,9 +3851,14 @@ fn buildOutputType( | ... | @@ -3813,9 +3851,14 @@ fn buildOutputType( |
| 3813 | }) { | 3851 | }) { |
| 3814 | dev.checkAny(&.{ .run_command, .test_command }); | 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 | if (test_exec_args.items.len == 0 and target.ofmt == .c and emit_bin_resolved != .no) { | 3859 | if (test_exec_args.items.len == 0 and target.ofmt == .c and emit_bin_resolved != .no) { |
| 3817 | // Default to using `zig run` to execute the produced .c code from `zig test`. | 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 | // Skip passing `-ofmt`, we want the default for the target, not `.c` anymore. | 3862 | // Skip passing `-ofmt`, we want the default for the target, not `.c` anymore. |
| 3820 | | 3863 | |
| 3821 | var prev_has_cflags = false; | 3864 | var prev_has_cflags = false; |
| ... | @@ -3896,7 +3939,7 @@ fn buildOutputType( | ... | @@ -3896,7 +3939,7 @@ fn buildOutputType( |
| 3896 | arena, | 3939 | arena, |
| 3897 | io, | 3940 | io, |
| 3898 | test_exec_args.items, | 3941 | test_exec_args.items, |
| 3899 | self_exe_path, | 3942 | self_exe_path_or_argv0, |
| 3900 | arg_mode, | 3943 | arg_mode, |
| 3901 | target, | 3944 | target, |
| 3902 | &comp_destroyed, | 3945 | &comp_destroyed, |
| ... | @@ -4287,7 +4330,10 @@ fn serve( | ... | @@ -4287,7 +4330,10 @@ fn serve( |
| 4287 | in: *Io.Reader, | 4330 | in: *Io.Reader, |
| 4288 | out: *Io.Writer, | 4331 | out: *Io.Writer, |
| 4289 | test_exec_args: []const ?[]const u8, | 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 | arg_mode: ArgMode, | 4337 | arg_mode: ArgMode, |
| 4292 | all_args: []const []const u8, | 4338 | all_args: []const []const u8, |
| 4293 | runtime_args_start: ?usize, | 4339 | runtime_args_start: ?usize, |
| ... | @@ -4400,7 +4446,7 @@ fn serve( | ... | @@ -4400,7 +4446,7 @@ fn serve( |
| 4400 | comp, | 4446 | comp, |
| 4401 | gpa, | 4447 | gpa, |
| 4402 | test_exec_args, | 4448 | test_exec_args, |
| 4403 | self_exe_path.?, | 4449 | self_exe_path, |
| 4404 | arg_mode, | 4450 | arg_mode, |
| 4405 | all_args, | 4451 | all_args, |
| 4406 | runtime_args_start, | 4452 | runtime_args_start, |
| ... | @@ -4585,9 +4631,8 @@ fn runOrTest( | ... | @@ -4585,9 +4631,8 @@ fn runOrTest( |
| 4585 | const cmd = try std.mem.join(arena, " ", argv.items); | 4631 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4586 | fatal("the following command failed to execve with '{t}':\n{s}", .{ err, cmd }); | 4632 | fatal("the following command failed to execve with '{t}':\n{s}", .{ err, cmd }); |
| 4587 | } else if (!process.can_spawn) { | 4633 | } else if (!process.can_spawn) { |
| 4588 | const cmd = try std.mem.join(arena, " ", argv.items); | 4634 | fatal("the following command cannot be executed ({t} does not support spawning a child process):\n{f}", .{ |
| 4589 | fatal("the following command cannot be executed ({t} does not support spawning a child process):\n{s}", .{ | 4635 | native_os, std.zig.SubprocessCommand{ .argv = argv.items }, |
| 4590 | native_os, cmd, | | |
| 4591 | }); | 4636 | }); |
| 4592 | } | 4637 | } |
| 4593 | const term_result = (term: { | 4638 | const term_result = (term: { |
| ... | @@ -4667,7 +4712,10 @@ fn runOrTestHotSwap( | ... | @@ -4667,7 +4712,10 @@ fn runOrTestHotSwap( |
| 4667 | comp: *Compilation, | 4712 | comp: *Compilation, |
| 4668 | gpa: Allocator, | 4713 | gpa: Allocator, |
| 4669 | test_exec_args: []const ?[]const u8, | 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 | arg_mode: ArgMode, | 4719 | arg_mode: ArgMode, |
| 4672 | all_args: []const []const u8, | 4720 | all_args: []const []const u8, |
| 4673 | runtime_args_start: ?usize, | 4721 | runtime_args_start: ?usize, |
| ... | @@ -4675,6 +4723,11 @@ fn runOrTestHotSwap( | ... | @@ -4675,6 +4723,11 @@ fn runOrTestHotSwap( |
| 4675 | const io = comp.io; | 4723 | const io = comp.io; |
| 4676 | const lf = comp.bin_file.?; | 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 | const exe_path = switch (builtin.target.os.tag) { | 4731 | const exe_path = switch (builtin.target.os.tag) { |
| 4679 | // On Windows it seems impossible to perform an atomic rename of a file that is currently | 4732 | // On Windows it seems impossible to perform an atomic rename of a file that is currently |
| 4680 | // running in a process. Therefore, we do the opposite. We create a copy of the file in | 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,7 +4753,7 @@ fn runOrTestHotSwap( |
| 4700 | // when testing pass the zig_exe_path to argv | 4753 | // when testing pass the zig_exe_path to argv |
| 4701 | if (arg_mode == .zig_test) | 4754 | if (arg_mode == .zig_test) |
| 4702 | try argv.appendSlice(&[_][]const u8{ | 4755 | try argv.appendSlice(&[_][]const u8{ |
| 4703 | exe_path, self_exe_path, | 4756 | exe_path, self_exe_path_or_argv0, |
| 4704 | }) | 4757 | }) |
| 4705 | // when running just pass the current exe | 4758 | // when running just pass the current exe |
| 4706 | else | 4759 | else |
| ... | @@ -4713,7 +4766,7 @@ fn runOrTestHotSwap( | ... | @@ -4713,7 +4766,7 @@ fn runOrTestHotSwap( |
| 4713 | try argv.append(a); | 4766 | try argv.append(a); |
| 4714 | } else { | 4767 | } else { |
| 4715 | try argv.appendSlice(&[_][]const u8{ | 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,6 +4775,12 @@ fn runOrTestHotSwap( |
| 4722 | try argv.appendSlice(all_args[i..]); | 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 | const child = try std.process.spawn(io, .{ | 4784 | const child = try std.process.spawn(io, .{ |
| 4726 | .argv = argv.items, | 4785 | .argv = argv.items, |
| 4727 | .stdin = .inherit, | 4786 | .stdin = .inherit, |
| ... | @@ -4902,6 +4961,12 @@ fn jitCmdInner( | ... | @@ -4902,6 +4961,12 @@ fn jitCmdInner( |
| 4902 | thread_limit: usize, | 4961 | thread_limit: usize, |
| 4903 | options: JitCmdOptions, | 4962 | options: JitCmdOptions, |
| 4904 | ) !void { | 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 | const target_query: std.Target.Query = .{}; | 4970 | const target_query: std.Target.Query = .{}; |
| 4906 | const resolved_target: Module.ResolvedTarget = .{ | 4971 | const resolved_target: Module.ResolvedTarget = .{ |
| 4907 | .result = std.zig.resolveTargetQueryOrFatal(io, target_query), | 4972 | .result = std.zig.resolveTargetQueryOrFatal(io, target_query), |
| ... | @@ -5074,13 +5139,6 @@ fn jitCmdInner( | ... | @@ -5074,13 +5139,6 @@ fn jitCmdInner( |
| 5074 | fatal("the following command failed to execve with {t}:\n{s}", .{ err, cmd }); | 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 | const term = t: { | 5142 | const term = t: { |
| 5085 | _ = try io.lockStderr(&.{}, .no_color); | 5143 | _ = try io.lockStderr(&.{}, .no_color); |
| 5086 | defer io.unlockStderr(); | 5144 | defer io.unlockStderr(); |