| ... | ... | @@ -42,7 +42,6 @@ test { |
| 42 | 42 | const thread_stack_size = 60 << 20; |
| 43 | 43 | |
| 44 | 44 | pub const std_options: std.Options = .{ |
| 45 | | .wasiCwd = wasi_cwd, |
| 46 | 45 | .logFn = log, |
| 47 | 46 | |
| 48 | 47 | .log_level = switch (builtin.mode) { |
| ... | ... | @@ -51,6 +50,7 @@ pub const std_options: std.Options = .{ |
| 51 | 50 | .ReleaseSmall => .err, |
| 52 | 51 | }, |
| 53 | 52 | }; |
| 53 | pub const std_options_cwd = if (native_os == .wasi) wasi_cwd else null; |
| 54 | 54 | |
| 55 | 55 | pub const panic = crash_report.panic; |
| 56 | 56 | pub const debug = crash_report.debug; |
| ... | ... | @@ -208,7 +208,15 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const [:0]const u8, env_ma |
| 208 | 208 | fatal("expected command argument", .{}); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | | if (process.can_replace and std.zig.EnvVar.ZIG_IS_DETECTING_LIBC_PATHS.isSet(env_map)) { |
| 211 | var threaded: Io.Threaded = .init(gpa, .{ |
| 212 | .argv0 = if (@hasField(Io.Threaded.Argv0, "value")) .{ .value = args[0] } else .{}, |
| 213 | }); |
| 214 | defer threaded.deinit(); |
| 215 | threaded_impl_ptr = &threaded; |
| 216 | threaded.stack_size = thread_stack_size; |
| 217 | const io = threaded.io(); |
| 218 | |
| 219 | if (process.can_replace and EnvVar.ZIG_IS_DETECTING_LIBC_PATHS.isSet(env_map)) { |
| 212 | 220 | dev.check(.cc_command); |
| 213 | 221 | // In this case we have accidentally invoked ourselves as "the system C compiler" |
| 214 | 222 | // to figure out where libc is installed. This is essentially infinite recursion |
| ... | ... | @@ -217,7 +225,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const [:0]const u8, env_ma |
| 217 | 225 | // However it's possible Zig is installed as *that* C compiler as well, which is |
| 218 | 226 | // why we have this additional environment variable here to check. |
| 219 | 227 | |
| 220 | | const inf_loop_env_key: std.zig.EnvVar = .ZIG_IS_TRYING_TO_NOT_CALL_ITSELF; |
| 228 | const inf_loop_env_key: EnvVar = .ZIG_IS_TRYING_TO_NOT_CALL_ITSELF; |
| 221 | 229 | if (inf_loop_env_key.isSet(env_map)) { |
| 222 | 230 | fatal("{s}", .{ |
| 223 | 231 | "The compilation links against libc, but Zig is unable to provide a libc " ++ |
| ... | ... | @@ -233,42 +241,34 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const [:0]const u8, env_ma |
| 233 | 241 | // CC environment variable. We detect and support this scenario here because of |
| 234 | 242 | // the ZIG_IS_DETECTING_LIBC_PATHS environment variable. |
| 235 | 243 | if (mem.eql(u8, args[1], "cc")) { |
| 236 | | return process.replace(.{ .argv = args[1..], .env_map = env_map }); |
| 244 | return process.replace(io, .{ .argv = args[1..], .env_map = env_map }); |
| 237 | 245 | } else { |
| 238 | 246 | const modified_args = try arena.dupe([]const u8, args); |
| 239 | 247 | modified_args[0] = "cc"; |
| 240 | | return process.replace(.{ .argv = modified_args, .env_map = env_map }); |
| 248 | return process.replace(io, .{ .argv = modified_args, .env_map = env_map }); |
| 241 | 249 | } |
| 242 | 250 | } |
| 243 | 251 | |
| 244 | | var threaded: Io.Threaded = .init(gpa, .{ |
| 245 | | .argv0 = if (@hasField(Io.Threaded.Argv0, "value")) .{ .value = args[0] } else .{}, |
| 246 | | }); |
| 247 | | defer threaded.deinit(); |
| 248 | | threaded_impl_ptr = &threaded; |
| 249 | | threaded.stack_size = thread_stack_size; |
| 250 | | const io = threaded.io(); |
| 251 | | |
| 252 | 252 | const cmd = args[1]; |
| 253 | 253 | const cmd_args = args[2..]; |
| 254 | 254 | if (mem.eql(u8, cmd, "build-exe")) { |
| 255 | 255 | dev.check(.build_exe_command); |
| 256 | | return buildOutputType(gpa, arena, io, args, .{ .build = .Exe }); |
| 256 | return buildOutputType(gpa, arena, io, args, .{ .build = .Exe }, env_map); |
| 257 | 257 | } else if (mem.eql(u8, cmd, "build-lib")) { |
| 258 | 258 | dev.check(.build_lib_command); |
| 259 | | return buildOutputType(gpa, arena, io, args, .{ .build = .Lib }); |
| 259 | return buildOutputType(gpa, arena, io, args, .{ .build = .Lib }, env_map); |
| 260 | 260 | } else if (mem.eql(u8, cmd, "build-obj")) { |
| 261 | 261 | dev.check(.build_obj_command); |
| 262 | | return buildOutputType(gpa, arena, io, args, .{ .build = .Obj }); |
| 262 | return buildOutputType(gpa, arena, io, args, .{ .build = .Obj }, env_map); |
| 263 | 263 | } else if (mem.eql(u8, cmd, "test")) { |
| 264 | 264 | dev.check(.test_command); |
| 265 | | return buildOutputType(gpa, arena, io, args, .zig_test); |
| 265 | return buildOutputType(gpa, arena, io, args, .zig_test, env_map); |
| 266 | 266 | } else if (mem.eql(u8, cmd, "test-obj")) { |
| 267 | 267 | dev.check(.test_command); |
| 268 | | return buildOutputType(gpa, arena, io, args, .zig_test_obj); |
| 268 | return buildOutputType(gpa, arena, io, args, .zig_test_obj, env_map); |
| 269 | 269 | } else if (mem.eql(u8, cmd, "run")) { |
| 270 | 270 | dev.check(.run_command); |
| 271 | | return buildOutputType(gpa, arena, io, args, .run); |
| 271 | return buildOutputType(gpa, arena, io, args, .run, env_map); |
| 272 | 272 | } else if (mem.eql(u8, cmd, "dlltool") or |
| 273 | 273 | mem.eql(u8, cmd, "ranlib") or |
| 274 | 274 | mem.eql(u8, cmd, "lib") or |
| ... | ... | @@ -278,7 +278,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const [:0]const u8, env_ma |
| 278 | 278 | return process.exit(try llvmArMain(arena, args)); |
| 279 | 279 | } else if (mem.eql(u8, cmd, "build")) { |
| 280 | 280 | dev.check(.build_command); |
| 281 | | return cmdBuild(gpa, arena, io, cmd_args); |
| 281 | return cmdBuild(gpa, arena, io, cmd_args, env_map); |
| 282 | 282 | } else if (mem.eql(u8, cmd, "clang") or |
| 283 | 283 | mem.eql(u8, cmd, "-cc1") or mem.eql(u8, cmd, "-cc1as")) |
| 284 | 284 | { |
| ... | ... | @@ -292,16 +292,16 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const [:0]const u8, env_ma |
| 292 | 292 | return process.exit(try lldMain(arena, args, true)); |
| 293 | 293 | } else if (mem.eql(u8, cmd, "cc")) { |
| 294 | 294 | dev.check(.cc_command); |
| 295 | | return buildOutputType(gpa, arena, io, args, .cc); |
| 295 | return buildOutputType(gpa, arena, io, args, .cc, env_map); |
| 296 | 296 | } else if (mem.eql(u8, cmd, "c++")) { |
| 297 | 297 | dev.check(.cc_command); |
| 298 | | return buildOutputType(gpa, arena, io, args, .cpp); |
| 298 | return buildOutputType(gpa, arena, io, args, .cpp, env_map); |
| 299 | 299 | } else if (mem.eql(u8, cmd, "translate-c")) { |
| 300 | 300 | dev.check(.translate_c_command); |
| 301 | | return buildOutputType(gpa, arena, io, args, .translate_c); |
| 301 | return buildOutputType(gpa, arena, io, args, .translate_c, env_map); |
| 302 | 302 | } else if (mem.eql(u8, cmd, "rc")) { |
| 303 | 303 | const use_server = cmd_args.len > 0 and std.mem.eql(u8, cmd_args[0], "--zig-integration"); |
| 304 | | return jitCmd(gpa, arena, io, cmd_args, .{ |
| 304 | return jitCmd(gpa, arena, io, cmd_args, env_map, .{ |
| 305 | 305 | .cmd_name = "resinator", |
| 306 | 306 | .root_src_path = "resinator/main.zig", |
| 307 | 307 | .depend_on_aro = true, |
| ... | ... | @@ -312,20 +312,20 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const [:0]const u8, env_ma |
| 312 | 312 | dev.check(.fmt_command); |
| 313 | 313 | return @import("fmt.zig").run(gpa, arena, io, cmd_args); |
| 314 | 314 | } else if (mem.eql(u8, cmd, "objcopy")) { |
| 315 | | return jitCmd(gpa, arena, io, cmd_args, .{ |
| 315 | return jitCmd(gpa, arena, io, cmd_args, env_map, .{ |
| 316 | 316 | .cmd_name = "objcopy", |
| 317 | 317 | .root_src_path = "objcopy.zig", |
| 318 | 318 | }); |
| 319 | 319 | } else if (mem.eql(u8, cmd, "fetch")) { |
| 320 | | return cmdFetch(gpa, arena, io, cmd_args); |
| 320 | return cmdFetch(gpa, arena, io, cmd_args, env_map); |
| 321 | 321 | } else if (mem.eql(u8, cmd, "libc")) { |
| 322 | | return jitCmd(gpa, arena, io, cmd_args, .{ |
| 322 | return jitCmd(gpa, arena, io, cmd_args, env_map, .{ |
| 323 | 323 | .cmd_name = "libc", |
| 324 | 324 | .root_src_path = "libc.zig", |
| 325 | 325 | .prepend_zig_lib_dir_path = true, |
| 326 | 326 | }); |
| 327 | 327 | } else if (mem.eql(u8, cmd, "std")) { |
| 328 | | return jitCmd(gpa, arena, io, cmd_args, .{ |
| 328 | return jitCmd(gpa, arena, io, cmd_args, env_map, .{ |
| 329 | 329 | .cmd_name = "std", |
| 330 | 330 | .root_src_path = "std-docs.zig", |
| 331 | 331 | .prepend_zig_lib_dir_path = true, |
| ... | ... | @@ -355,10 +355,11 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const [:0]const u8, env_ma |
| 355 | 355 | args, |
| 356 | 356 | if (native_os == .wasi) wasi_preopens, |
| 357 | 357 | &host, |
| 358 | env_map, |
| 358 | 359 | ); |
| 359 | 360 | return stdout_writer.interface.flush(); |
| 360 | 361 | } else if (mem.eql(u8, cmd, "reduce")) { |
| 361 | | return jitCmd(gpa, arena, io, cmd_args, .{ |
| 362 | return jitCmd(gpa, arena, io, cmd_args, env_map, .{ |
| 362 | 363 | .cmd_name = "reduce", |
| 363 | 364 | .root_src_path = "reduce.zig", |
| 364 | 365 | }); |
| ... | ... | @@ -803,6 +804,7 @@ fn buildOutputType( |
| 803 | 804 | io: Io, |
| 804 | 805 | all_args: []const []const u8, |
| 805 | 806 | arg_mode: ArgMode, |
| 807 | env_map: *process.Environ.Map, |
| 806 | 808 | ) !void { |
| 807 | 809 | var provided_name: ?[]const u8 = null; |
| 808 | 810 | var root_src_file: ?[]const u8 = null; |
| ... | ... | @@ -815,9 +817,9 @@ fn buildOutputType( |
| 815 | 817 | var debug_compile_errors = false; |
| 816 | 818 | var debug_incremental = false; |
| 817 | 819 | var verbose_link = (native_os != .wasi or builtin.link_libc) and |
| 818 | | EnvVar.ZIG_VERBOSE_LINK.isSet(); |
| 820 | EnvVar.ZIG_VERBOSE_LINK.isSet(env_map); |
| 819 | 821 | var verbose_cc = (native_os != .wasi or builtin.link_libc) and |
| 820 | | EnvVar.ZIG_VERBOSE_CC.isSet(); |
| 822 | EnvVar.ZIG_VERBOSE_CC.isSet(env_map); |
| 821 | 823 | var verbose_air = false; |
| 822 | 824 | var verbose_intern_pool = false; |
| 823 | 825 | var verbose_generic_instances = false; |
| ... | ... | @@ -889,9 +891,9 @@ fn buildOutputType( |
| 889 | 891 | var runtime_args_start: ?usize = null; |
| 890 | 892 | var test_filters: std.ArrayList([]const u8) = .empty; |
| 891 | 893 | var test_runner_path: ?[]const u8 = null; |
| 892 | | var override_local_cache_dir: ?[]const u8 = try EnvVar.ZIG_LOCAL_CACHE_DIR.get(arena); |
| 893 | | var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena); |
| 894 | | var override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena); |
| 894 | var override_local_cache_dir: ?[]const u8 = EnvVar.ZIG_LOCAL_CACHE_DIR.get(env_map); |
| 895 | var override_global_cache_dir: ?[]const u8 = EnvVar.ZIG_GLOBAL_CACHE_DIR.get(env_map); |
| 896 | var override_lib_dir: ?[]const u8 = EnvVar.ZIG_LIB_DIR.get(env_map); |
| 895 | 897 | var clang_preprocessor_mode: Compilation.ClangPreprocessorMode = .no; |
| 896 | 898 | var subsystem: ?std.zig.Subsystem = null; |
| 897 | 899 | var major_subsystem_version: ?u16 = null; |
| ... | ... | @@ -988,7 +990,7 @@ fn buildOutputType( |
| 988 | 990 | .framework_dirs = .{}, |
| 989 | 991 | .rpath_list = .{}, |
| 990 | 992 | .each_lib_rpath = null, |
| 991 | | .libc_paths_file = try EnvVar.ZIG_LIBC.get(arena), |
| 993 | .libc_paths_file = EnvVar.ZIG_LIBC.get(env_map), |
| 992 | 994 | .native_system_include_paths = &.{}, |
| 993 | 995 | }; |
| 994 | 996 | defer create_module.link_inputs.deinit(gpa); |
| ... | ... | @@ -997,9 +999,9 @@ fn buildOutputType( |
| 997 | 999 | // if set, default the color setting to .off or .on, respectively |
| 998 | 1000 | // explicit --color arguments will still override this setting. |
| 999 | 1001 | // Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162 |
| 1000 | | var color: Color = if (native_os == .wasi or EnvVar.NO_COLOR.isSet()) |
| 1002 | var color: Color = if (native_os == .wasi or EnvVar.NO_COLOR.isSet(env_map)) |
| 1001 | 1003 | .off |
| 1002 | | else if (EnvVar.CLICOLOR_FORCE.isSet()) |
| 1004 | else if (EnvVar.CLICOLOR_FORCE.isSet(env_map)) |
| 1003 | 1005 | .on |
| 1004 | 1006 | else |
| 1005 | 1007 | .auto; |
| ... | ... | @@ -3097,6 +3099,7 @@ fn buildOutputType( |
| 3097 | 3099 | }, |
| 3098 | 3100 | if (native_os == .wasi) wasi_preopens, |
| 3099 | 3101 | self_exe_path, |
| 3102 | env_map, |
| 3100 | 3103 | ); |
| 3101 | 3104 | defer dirs.deinit(io); |
| 3102 | 3105 | |
| ... | ... | @@ -3108,7 +3111,7 @@ fn buildOutputType( |
| 3108 | 3111 | create_module.opts.emit_bin = emit_bin != .no; |
| 3109 | 3112 | create_module.opts.any_c_source_files = create_module.c_source_files.items.len != 0; |
| 3110 | 3113 | |
| 3111 | | const main_mod = try createModule(gpa, arena, io, &create_module, 0, null, color); |
| 3114 | const main_mod = try createModule(gpa, arena, io, &create_module, 0, null, color, env_map); |
| 3112 | 3115 | for (create_module.modules.keys(), create_module.modules.values()) |key, cli_mod| { |
| 3113 | 3116 | if (cli_mod.resolved == null) |
| 3114 | 3117 | fatal("module '{s}' declared but not used", .{key}); |
| ... | ... | @@ -3585,6 +3588,7 @@ fn buildOutputType( |
| 3585 | 3588 | .global_cc_argv = try cc_argv.toOwnedSlice(arena), |
| 3586 | 3589 | .file_system_inputs = &file_system_inputs, |
| 3587 | 3590 | .debug_compiler_runtime_libs = debug_compiler_runtime_libs, |
| 3591 | .environ_map = env_map, |
| 3588 | 3592 | }) catch |err| switch (err) { |
| 3589 | 3593 | error.CreateFail => switch (create_diag) { |
| 3590 | 3594 | .cross_libc_unavailable => { |
| ... | ... | @@ -3648,6 +3652,7 @@ fn buildOutputType( |
| 3648 | 3652 | arg_mode, |
| 3649 | 3653 | all_args, |
| 3650 | 3654 | runtime_args_start, |
| 3655 | env_map, |
| 3651 | 3656 | ); |
| 3652 | 3657 | return cleanExit(io); |
| 3653 | 3658 | }, |
| ... | ... | @@ -3674,6 +3679,7 @@ fn buildOutputType( |
| 3674 | 3679 | arg_mode, |
| 3675 | 3680 | all_args, |
| 3676 | 3681 | runtime_args_start, |
| 3682 | env_map, |
| 3677 | 3683 | ); |
| 3678 | 3684 | return cleanExit(io); |
| 3679 | 3685 | }, |
| ... | ... | @@ -3686,7 +3692,7 @@ fn buildOutputType( |
| 3686 | 3692 | defer root_prog_node.end(); |
| 3687 | 3693 | |
| 3688 | 3694 | if (arg_mode == .translate_c) { |
| 3689 | | return cmdTranslateC(comp, arena, null, null, root_prog_node); |
| 3695 | return cmdTranslateC(comp, arena, null, null, root_prog_node, env_map); |
| 3690 | 3696 | } |
| 3691 | 3697 | |
| 3692 | 3698 | updateModule(comp, color, root_prog_node) catch |err| switch (err) { |
| ... | ... | @@ -3754,6 +3760,7 @@ fn buildOutputType( |
| 3754 | 3760 | all_args, |
| 3755 | 3761 | runtime_args_start, |
| 3756 | 3762 | create_module.resolved_options.link_libc, |
| 3763 | env_map, |
| 3757 | 3764 | ); |
| 3758 | 3765 | } |
| 3759 | 3766 | |
| ... | ... | @@ -3809,6 +3816,7 @@ fn createModule( |
| 3809 | 3816 | index: usize, |
| 3810 | 3817 | parent: ?*Package.Module, |
| 3811 | 3818 | color: std.zig.Color, |
| 3819 | env_map: *process.Environ.Map, |
| 3812 | 3820 | ) Allocator.Error!*Package.Module { |
| 3813 | 3821 | const cli_mod = &create_module.modules.values()[index]; |
| 3814 | 3822 | if (cli_mod.resolved) |m| return m; |
| ... | ... | @@ -3988,7 +3996,7 @@ fn createModule( |
| 3988 | 3996 | resolved_target.is_native_os and resolved_target.is_native_abi and |
| 3989 | 3997 | create_module.want_native_include_dirs) |
| 3990 | 3998 | { |
| 3991 | | var paths = std.zig.system.NativePaths.detect(arena, io, target) catch |err| |
| 3999 | var paths = std.zig.system.NativePaths.detect(arena, io, target, env_map) catch |err| |
| 3992 | 4000 | fatal("unable to detect native system paths: {t}", .{err}); |
| 3993 | 4001 | for (paths.warnings.items) |warning| { |
| 3994 | 4002 | warn("{s}", .{warning}); |
| ... | ... | @@ -4015,6 +4023,7 @@ fn createModule( |
| 4015 | 4023 | create_module.libc_installation = LibCInstallation.findNative(arena, io, .{ |
| 4016 | 4024 | .verbose = true, |
| 4017 | 4025 | .target = target, |
| 4026 | .env_map = env_map, |
| 4018 | 4027 | }) catch |err| { |
| 4019 | 4028 | fatal("unable to find native libc installation: {t}", .{err}); |
| 4020 | 4029 | }; |
| ... | ... | @@ -4119,7 +4128,7 @@ fn createModule( |
| 4119 | 4128 | for (cli_mod.deps) |dep| { |
| 4120 | 4129 | const dep_index = create_module.modules.getIndex(dep.value) orelse |
| 4121 | 4130 | fatal("module '{s}' depends on non-existent module '{s}'", .{ name, dep.key }); |
| 4122 | | const dep_mod = try createModule(gpa, arena, io, create_module, dep_index, mod, color); |
| 4131 | const dep_mod = try createModule(gpa, arena, io, create_module, dep_index, mod, color, env_map); |
| 4123 | 4132 | try mod.deps.put(arena, dep.key, dep_mod); |
| 4124 | 4133 | } |
| 4125 | 4134 | |
| ... | ... | @@ -4128,9 +4137,7 @@ fn createModule( |
| 4128 | 4137 | |
| 4129 | 4138 | fn saveState(comp: *Compilation, incremental: bool) void { |
| 4130 | 4139 | if (incremental) { |
| 4131 | | comp.saveState() catch |err| { |
| 4132 | | warn("unable to save incremental compilation state: {s}", .{@errorName(err)}); |
| 4133 | | }; |
| 4140 | comp.saveState() catch |err| warn("unable to save incremental compilation state: {t}", .{err}); |
| 4134 | 4141 | } |
| 4135 | 4142 | } |
| 4136 | 4143 | |
| ... | ... | @@ -4143,6 +4150,7 @@ fn serve( |
| 4143 | 4150 | arg_mode: ArgMode, |
| 4144 | 4151 | all_args: []const []const u8, |
| 4145 | 4152 | runtime_args_start: ?usize, |
| 4153 | env_map: *process.Environ.Map, |
| 4146 | 4154 | ) !void { |
| 4147 | 4155 | const gpa = comp.gpa; |
| 4148 | 4156 | const io = comp.io; |
| ... | ... | @@ -4190,7 +4198,7 @@ fn serve( |
| 4190 | 4198 | defer arena_instance.deinit(); |
| 4191 | 4199 | const arena = arena_instance.allocator(); |
| 4192 | 4200 | var output: Compilation.CImportResult = undefined; |
| 4193 | | try cmdTranslateC(comp, arena, &output, file_system_inputs, main_progress_node); |
| 4201 | try cmdTranslateC(comp, arena, &output, file_system_inputs, main_progress_node, env_map); |
| 4194 | 4202 | defer output.deinit(gpa); |
| 4195 | 4203 | |
| 4196 | 4204 | if (file_system_inputs.items.len != 0) { |
| ... | ... | @@ -4390,6 +4398,7 @@ fn runOrTest( |
| 4390 | 4398 | all_args: []const []const u8, |
| 4391 | 4399 | runtime_args_start: ?usize, |
| 4392 | 4400 | link_libc: bool, |
| 4401 | env_map: *process.Environ.Map, |
| 4393 | 4402 | ) !void { |
| 4394 | 4403 | const raw_emit_bin = comp.emit_bin orelse return; |
| 4395 | 4404 | const exe_path = switch (comp.cache_use) { |
| ... | ... | @@ -4426,77 +4435,90 @@ fn runOrTest( |
| 4426 | 4435 | if (runtime_args_start) |i| { |
| 4427 | 4436 | try argv.appendSlice(all_args[i..]); |
| 4428 | 4437 | } |
| 4429 | | var env_map = try process.getEnvMap(arena); |
| 4430 | 4438 | try env_map.put("ZIG_EXE", self_exe_path); |
| 4431 | 4439 | |
| 4432 | 4440 | // We do not execve for tests because if the test fails we want to print |
| 4433 | 4441 | // the error message and invocation below. |
| 4434 | 4442 | if (process.can_replace and arg_mode == .run) { |
| 4435 | | // execv releases the locks; no need to destroy the Compilation here. |
| 4443 | // process replacement releases the locks; no need to destroy the Compilation here. |
| 4436 | 4444 | _ = try io.lockStderr(&.{}, .no_color); |
| 4437 | | const err = process.execve(gpa, argv.items, &env_map); |
| 4445 | const err = process.replace(io, .{ .argv = argv.items, .env_map = env_map }); |
| 4438 | 4446 | io.unlockStderr(); |
| 4439 | 4447 | try warnAboutForeignBinaries(io, arena, arg_mode, target, link_libc); |
| 4440 | 4448 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4441 | 4449 | fatal("the following command failed to execve with '{t}':\n{s}", .{ err, cmd }); |
| 4442 | | } else if (process.can_spawn) { |
| 4443 | | var child = std.process.Child.init(argv.items, gpa); |
| 4444 | | child.env_map = &env_map; |
| 4445 | | child.stdin_behavior = .inherit; |
| 4446 | | child.stdout_behavior = .inherit; |
| 4447 | | child.stderr_behavior = .inherit; |
| 4448 | | |
| 4450 | } else if (!process.can_spawn) { |
| 4451 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4452 | fatal("the following command cannot be executed ({t} does not support spawning a child process):\n{s}", .{ |
| 4453 | native_os, cmd, |
| 4454 | }); |
| 4455 | } |
| 4456 | const term_result = (term: { |
| 4449 | 4457 | // Here we release all the locks associated with the Compilation so |
| 4450 | 4458 | // that whatever this child process wants to do won't deadlock. |
| 4451 | 4459 | comp.destroy(); |
| 4452 | 4460 | comp_destroyed.* = true; |
| 4453 | 4461 | |
| 4454 | | const term_result = t: { |
| 4455 | | _ = try io.lockStderr(&.{}, .no_color); |
| 4456 | | defer io.unlockStderr(); |
| 4457 | | break :t child.spawnAndWait(io); |
| 4458 | | }; |
| 4459 | | const term = term_result catch |err| { |
| 4460 | | try warnAboutForeignBinaries(io, arena, arg_mode, target, link_libc); |
| 4461 | | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4462 | | fatal("the following command failed with '{s}':\n{s}", .{ @errorName(err), cmd }); |
| 4463 | | }; |
| 4464 | | switch (arg_mode) { |
| 4465 | | .run, .build => { |
| 4466 | | switch (term) { |
| 4467 | | .Exited => |code| { |
| 4468 | | if (code == 0) { |
| 4469 | | return cleanExit(io); |
| 4470 | | } else { |
| 4471 | | process.exit(code); |
| 4472 | | } |
| 4473 | | }, |
| 4474 | | else => { |
| 4475 | | process.exit(1); |
| 4476 | | }, |
| 4477 | | } |
| 4478 | | }, |
| 4479 | | .zig_test => { |
| 4480 | | switch (term) { |
| 4481 | | .Exited => |code| { |
| 4482 | | if (code == 0) { |
| 4483 | | return cleanExit(io); |
| 4484 | | } else { |
| 4485 | | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4486 | | fatal("the following test command failed with exit code {d}:\n{s}", .{ code, cmd }); |
| 4487 | | } |
| 4488 | | }, |
| 4489 | | else => { |
| 4490 | | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4491 | | fatal("the following test command crashed:\n{s}", .{cmd}); |
| 4492 | | }, |
| 4493 | | } |
| 4494 | | }, |
| 4495 | | else => unreachable, |
| 4496 | | } |
| 4497 | | } else { |
| 4462 | _ = try io.lockStderr(&.{}, .no_color); |
| 4463 | defer io.unlockStderr(); |
| 4464 | |
| 4465 | var child = std.process.spawn(io, .{ |
| 4466 | .argv = argv.items, |
| 4467 | .env_map = env_map, |
| 4468 | .stdin = .inherit, |
| 4469 | .stdout = .inherit, |
| 4470 | .stderr = .inherit, |
| 4471 | }) catch |err| break :term err; |
| 4472 | defer child.kill(io); |
| 4473 | |
| 4474 | break :term child.wait(io); |
| 4475 | }); |
| 4476 | |
| 4477 | const term = term_result catch |err| { |
| 4478 | try warnAboutForeignBinaries(io, arena, arg_mode, target, link_libc); |
| 4498 | 4479 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4499 | | fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd }); |
| 4480 | fatal("the following command failed with {t}:\n{s}", .{ err, cmd }); |
| 4481 | }; |
| 4482 | switch (arg_mode) { |
| 4483 | .run, .build => { |
| 4484 | switch (term) { |
| 4485 | .exited => |code| { |
| 4486 | if (code == 0) { |
| 4487 | return cleanExit(io); |
| 4488 | } else { |
| 4489 | process.exit(code); |
| 4490 | } |
| 4491 | }, |
| 4492 | .signal => |sig| { |
| 4493 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4494 | fatal("the following command terminated with signal {t}:\n{s}", .{ sig, cmd }); |
| 4495 | }, |
| 4496 | else => { |
| 4497 | process.exit(1); |
| 4498 | }, |
| 4499 | } |
| 4500 | }, |
| 4501 | .zig_test => { |
| 4502 | switch (term) { |
| 4503 | .exited => |code| { |
| 4504 | if (code == 0) { |
| 4505 | return cleanExit(io); |
| 4506 | } else { |
| 4507 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4508 | fatal("the following test command failed with exit code {d}:\n{s}", .{ code, cmd }); |
| 4509 | } |
| 4510 | }, |
| 4511 | .signal => |sig| { |
| 4512 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4513 | fatal("the following test command terminated with signal {t}:\n{s}", .{ sig, cmd }); |
| 4514 | }, |
| 4515 | else => { |
| 4516 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4517 | fatal("the following test command crashed:\n{s}", .{cmd}); |
| 4518 | }, |
| 4519 | } |
| 4520 | }, |
| 4521 | else => unreachable, |
| 4500 | 4522 | } |
| 4501 | 4523 | } |
| 4502 | 4524 | |
| ... | ... | @@ -4559,13 +4581,13 @@ fn runOrTestHotSwap( |
| 4559 | 4581 | try argv.appendSlice(all_args[i..]); |
| 4560 | 4582 | } |
| 4561 | 4583 | |
| 4562 | | var child = try std.process.spwan(io, .{ |
| 4584 | var child = try std.process.spawn(io, .{ |
| 4563 | 4585 | .argv = argv.items, |
| 4564 | 4586 | .stdin = .inherit, |
| 4565 | 4587 | .stdout = .inherit, |
| 4566 | 4588 | .stderr = .inherit, |
| 4567 | 4589 | }); |
| 4568 | | return child.id; |
| 4590 | return child.id.?; |
| 4569 | 4591 | } |
| 4570 | 4592 | |
| 4571 | 4593 | const UpdateModuleError = Compilation.UpdateError || error{ |
| ... | ... | @@ -4597,6 +4619,7 @@ fn cmdTranslateC( |
| 4597 | 4619 | fancy_output: ?*Compilation.CImportResult, |
| 4598 | 4620 | file_system_inputs: ?*std.ArrayList(u8), |
| 4599 | 4621 | prog_node: std.Progress.Node, |
| 4622 | env_map: *process.Environ.Map, |
| 4600 | 4623 | ) !void { |
| 4601 | 4624 | dev.check(.translate_c_command); |
| 4602 | 4625 | |
| ... | ... | @@ -4630,6 +4653,7 @@ fn cmdTranslateC( |
| 4630 | 4653 | translated_basename, |
| 4631 | 4654 | comp.root_mod, |
| 4632 | 4655 | prog_node, |
| 4656 | env_map, |
| 4633 | 4657 | ); |
| 4634 | 4658 | |
| 4635 | 4659 | if (result.errors.errorMessageCount() != 0) { |
| ... | ... | @@ -4677,10 +4701,11 @@ pub fn translateC( |
| 4677 | 4701 | arena: Allocator, |
| 4678 | 4702 | io: Io, |
| 4679 | 4703 | argv: []const []const u8, |
| 4704 | env_map: *process.Environ.Map, |
| 4680 | 4705 | prog_node: std.Progress.Node, |
| 4681 | 4706 | capture: ?*[]u8, |
| 4682 | 4707 | ) !void { |
| 4683 | | try jitCmd(gpa, arena, io, argv, .{ |
| 4708 | try jitCmd(gpa, arena, io, argv, env_map, .{ |
| 4684 | 4709 | .cmd_name = "translate-c", |
| 4685 | 4710 | .root_src_path = "translate-c/main.zig", |
| 4686 | 4711 | .depend_on_aro = true, |
| ... | ... | @@ -4837,21 +4862,21 @@ test sanitizeExampleName { |
| 4837 | 4862 | try std.testing.expectEqualStrings("test_project", try sanitizeExampleName(arena, "test project")); |
| 4838 | 4863 | } |
| 4839 | 4864 | |
| 4840 | | fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !void { |
| 4865 | fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8, env_map: *process.Environ.Map) !void { |
| 4841 | 4866 | dev.check(.build_command); |
| 4842 | 4867 | |
| 4843 | 4868 | var build_file: ?[]const u8 = null; |
| 4844 | | var override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena); |
| 4845 | | var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena); |
| 4846 | | var override_local_cache_dir: ?[]const u8 = try EnvVar.ZIG_LOCAL_CACHE_DIR.get(arena); |
| 4847 | | var override_build_runner: ?[]const u8 = try EnvVar.ZIG_BUILD_RUNNER.get(arena); |
| 4869 | var override_lib_dir: ?[]const u8 = EnvVar.ZIG_LIB_DIR.get(env_map); |
| 4870 | var override_global_cache_dir: ?[]const u8 = EnvVar.ZIG_GLOBAL_CACHE_DIR.get(env_map); |
| 4871 | var override_local_cache_dir: ?[]const u8 = EnvVar.ZIG_LOCAL_CACHE_DIR.get(env_map); |
| 4872 | var override_build_runner: ?[]const u8 = EnvVar.ZIG_BUILD_RUNNER.get(env_map); |
| 4848 | 4873 | var child_argv = std.array_list.Managed([]const u8).init(arena); |
| 4849 | 4874 | var reference_trace: ?u32 = null; |
| 4850 | 4875 | var debug_compile_errors = false; |
| 4851 | 4876 | var verbose_link = (native_os != .wasi or builtin.link_libc) and |
| 4852 | | EnvVar.ZIG_VERBOSE_LINK.isSet(); |
| 4877 | EnvVar.ZIG_VERBOSE_LINK.isSet(env_map); |
| 4853 | 4878 | var verbose_cc = (native_os != .wasi or builtin.link_libc) and |
| 4854 | | EnvVar.ZIG_VERBOSE_CC.isSet(); |
| 4879 | EnvVar.ZIG_VERBOSE_CC.isSet(env_map); |
| 4855 | 4880 | var verbose_air = false; |
| 4856 | 4881 | var verbose_intern_pool = false; |
| 4857 | 4882 | var verbose_generic_instances = false; |
| ... | ... | @@ -5048,7 +5073,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) |
| 5048 | 5073 | } |
| 5049 | 5074 | |
| 5050 | 5075 | const work_around_btrfs_bug = native_os == .linux and |
| 5051 | | EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); |
| 5076 | EnvVar.ZIG_BTRFS_WORKAROUND.isSet(env_map); |
| 5052 | 5077 | const root_prog_node = std.Progress.start(io, .{ |
| 5053 | 5078 | .disable_printing = (color == .off), |
| 5054 | 5079 | .root_name = "Compile Build Script", |
| ... | ... | @@ -5108,6 +5133,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) |
| 5108 | 5133 | } }, |
| 5109 | 5134 | {}, |
| 5110 | 5135 | self_exe_path, |
| 5136 | env_map, |
| 5111 | 5137 | ); |
| 5112 | 5138 | defer dirs.deinit(io); |
| 5113 | 5139 | |
| ... | ... | @@ -5210,7 +5236,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) |
| 5210 | 5236 | job_queue.read_only = true; |
| 5211 | 5237 | cleanup_build_dir = job_queue.global_cache.handle; |
| 5212 | 5238 | } else { |
| 5213 | | try http_client.initDefaultProxies(arena); |
| 5239 | try http_client.initDefaultProxies(arena, env_map); |
| 5214 | 5240 | } |
| 5215 | 5241 | |
| 5216 | 5242 | try job_queue.all_fetches.ensureUnusedCapacity(gpa, 1); |
| ... | ... | @@ -5364,6 +5390,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) |
| 5364 | 5390 | .cache_mode = .whole, |
| 5365 | 5391 | .reference_trace = reference_trace, |
| 5366 | 5392 | .debug_compile_errors = debug_compile_errors, |
| 5393 | .environ_map = env_map, |
| 5367 | 5394 | }) catch |err| switch (err) { |
| 5368 | 5395 | error.CreateFail => fatal("failed to create compilation: {f}", .{create_diag}), |
| 5369 | 5396 | else => fatal("failed to create compilation: {s}", .{@errorName(err)}), |
| ... | ... | @@ -5385,81 +5412,81 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) |
| 5385 | 5412 | }); |
| 5386 | 5413 | } |
| 5387 | 5414 | |
| 5388 | | if (process.can_spawn) { |
| 5389 | | var child = std.process.Child.init(child_argv.items, gpa); |
| 5390 | | child.stdin_behavior = .inherit; |
| 5391 | | child.stdout_behavior = .inherit; |
| 5392 | | child.stderr_behavior = .inherit; |
| 5393 | | |
| 5394 | | const term = t: { |
| 5395 | | _ = try io.lockStderr(&.{}, .no_color); |
| 5396 | | defer io.unlockStderr(); |
| 5397 | | break :t child.spawnAndWait(io) catch |err| |
| 5398 | | fatal("failed to spawn build runner {s}: {t}", .{ child_argv.items[0], err }); |
| 5399 | | }; |
| 5400 | | |
| 5401 | | switch (term) { |
| 5402 | | .Exited => |code| { |
| 5403 | | if (code == 0) return cleanExit(io); |
| 5404 | | // Indicates that the build runner has reported compile errors |
| 5405 | | // and this parent process does not need to report any further |
| 5406 | | // diagnostics. |
| 5407 | | if (code == 2) process.exit(2); |
| 5408 | | |
| 5409 | | if (code == 3) { |
| 5410 | | if (!dev.env.supports(.fetch_command)) process.exit(3); |
| 5411 | | // Indicates the configure phase failed due to missing lazy |
| 5412 | | // dependencies and stdout contains the hashes of the ones |
| 5413 | | // that are missing. |
| 5414 | | const s = fs.path.sep_str; |
| 5415 | | const tmp_sub_path = "tmp" ++ s ++ results_tmp_file_nonce; |
| 5416 | | const stdout = dirs.local_cache.handle.readFileAlloc(io, tmp_sub_path, arena, .limited(50 * 1024 * 1024)) catch |err| { |
| 5417 | | fatal("unable to read results of configure phase from '{f}{s}': {s}", .{ |
| 5418 | | dirs.local_cache, tmp_sub_path, @errorName(err), |
| 5415 | if (!process.can_spawn) { |
| 5416 | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5417 | fatal("the following command cannot be executed ({t} does not support spawning a child process):\n{s}", .{ native_os, cmd }); |
| 5418 | } |
| 5419 | switch (term: { |
| 5420 | _ = try io.lockStderr(&.{}, .no_color); |
| 5421 | defer io.unlockStderr(); |
| 5422 | var child = std.process.spawn(io, .{ |
| 5423 | .argv = child_argv.items, |
| 5424 | }) catch |err| fatal("failed to spawn build runner {s}: {t}", .{ child_argv.items[0], err }); |
| 5425 | defer child.kill(io); |
| 5426 | break :term child.wait(io) catch |err| |
| 5427 | fatal("failed to wait build runner {s}: {t}", .{ child_argv.items[0], err }); |
| 5428 | }) { |
| 5429 | .exited => |code| { |
| 5430 | if (code == 0) return cleanExit(io); |
| 5431 | // Indicates that the build runner has reported compile errors |
| 5432 | // and this parent process does not need to report any further |
| 5433 | // diagnostics. |
| 5434 | if (code == 2) process.exit(2); |
| 5435 | |
| 5436 | if (code == 3) { |
| 5437 | if (!dev.env.supports(.fetch_command)) process.exit(3); |
| 5438 | // Indicates the configure phase failed due to missing lazy |
| 5439 | // dependencies and stdout contains the hashes of the ones |
| 5440 | // that are missing. |
| 5441 | const s = fs.path.sep_str; |
| 5442 | const tmp_sub_path = "tmp" ++ s ++ results_tmp_file_nonce; |
| 5443 | const stdout = dirs.local_cache.handle.readFileAlloc(io, tmp_sub_path, arena, .limited(50 * 1024 * 1024)) catch |err| { |
| 5444 | fatal("unable to read results of configure phase from '{f}{s}': {t}", .{ |
| 5445 | dirs.local_cache, tmp_sub_path, err, |
| 5446 | }); |
| 5447 | }; |
| 5448 | dirs.local_cache.handle.deleteFile(io, tmp_sub_path) catch {}; |
| 5449 | |
| 5450 | var it = mem.splitScalar(u8, stdout, '\n'); |
| 5451 | var any_errors = false; |
| 5452 | while (it.next()) |hash| { |
| 5453 | if (hash.len == 0) continue; |
| 5454 | if (hash.len > Package.Hash.max_len) { |
| 5455 | std.log.err("invalid digest (length {d} exceeds maximum): '{s}'", .{ |
| 5456 | hash.len, hash, |
| 5419 | 5457 | }); |
| 5420 | | }; |
| 5421 | | dirs.local_cache.handle.deleteFile(io, tmp_sub_path) catch {}; |
| 5422 | | |
| 5423 | | var it = mem.splitScalar(u8, stdout, '\n'); |
| 5424 | | var any_errors = false; |
| 5425 | | while (it.next()) |hash| { |
| 5426 | | if (hash.len == 0) continue; |
| 5427 | | if (hash.len > Package.Hash.max_len) { |
| 5428 | | std.log.err("invalid digest (length {d} exceeds maximum): '{s}'", .{ |
| 5429 | | hash.len, hash, |
| 5430 | | }); |
| 5431 | | any_errors = true; |
| 5432 | | continue; |
| 5433 | | } |
| 5434 | | try unlazy_set.put(arena, .fromSlice(hash), {}); |
| 5458 | any_errors = true; |
| 5459 | continue; |
| 5435 | 5460 | } |
| 5436 | | if (any_errors) process.exit(3); |
| 5437 | | if (system_pkg_dir_path) |p| { |
| 5438 | | // In this mode, the system needs to provide these packages; they |
| 5439 | | // cannot be fetched by Zig. |
| 5440 | | for (unlazy_set.keys()) |*hash| { |
| 5441 | | std.log.err("lazy dependency package not found: {s}" ++ s ++ "{s}", .{ |
| 5442 | | p, hash.toSlice(), |
| 5443 | | }); |
| 5444 | | } |
| 5445 | | std.log.info("remote package fetching disabled due to --system mode", .{}); |
| 5446 | | std.log.info("dependencies might be avoidable depending on build configuration", .{}); |
| 5447 | | process.exit(3); |
| 5461 | try unlazy_set.put(arena, .fromSlice(hash), {}); |
| 5462 | } |
| 5463 | if (any_errors) process.exit(3); |
| 5464 | if (system_pkg_dir_path) |p| { |
| 5465 | // In this mode, the system needs to provide these packages; they |
| 5466 | // cannot be fetched by Zig. |
| 5467 | for (unlazy_set.keys()) |*hash| { |
| 5468 | std.log.err("lazy dependency package not found: {s}" ++ s ++ "{s}", .{ |
| 5469 | p, hash.toSlice(), |
| 5470 | }); |
| 5448 | 5471 | } |
| 5449 | | continue; |
| 5472 | std.log.info("remote package fetching disabled due to --system mode", .{}); |
| 5473 | std.log.info("dependencies might be avoidable depending on build configuration", .{}); |
| 5474 | process.exit(3); |
| 5450 | 5475 | } |
| 5476 | continue; |
| 5477 | } |
| 5451 | 5478 | |
| 5452 | | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5453 | | fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd }); |
| 5454 | | }, |
| 5455 | | else => { |
| 5456 | | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5457 | | fatal("the following build command crashed:\n{s}", .{cmd}); |
| 5458 | | }, |
| 5459 | | } |
| 5460 | | } else { |
| 5461 | | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5462 | | fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd }); |
| 5479 | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5480 | fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd }); |
| 5481 | }, |
| 5482 | .signal => |sig| { |
| 5483 | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5484 | fatal("the following build command terminated with signal {t}:\n{s}", .{ sig, cmd }); |
| 5485 | }, |
| 5486 | else => { |
| 5487 | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5488 | fatal("the following build command crashed:\n{s}", .{cmd}); |
| 5489 | }, |
| 5463 | 5490 | } |
| 5464 | 5491 | } |
| 5465 | 5492 | } |
| ... | ... | @@ -5482,6 +5509,7 @@ fn jitCmd( |
| 5482 | 5509 | arena: Allocator, |
| 5483 | 5510 | io: Io, |
| 5484 | 5511 | args: []const []const u8, |
| 5512 | env_map: *process.Environ.Map, |
| 5485 | 5513 | options: JitCmdOptions, |
| 5486 | 5514 | ) !void { |
| 5487 | 5515 | dev.check(.jit_command); |
| ... | ... | @@ -5503,13 +5531,13 @@ fn jitCmd( |
| 5503 | 5531 | const self_exe_path = process.executablePathAlloc(io, arena) catch |err| |
| 5504 | 5532 | fatal("unable to find self exe path: {t}", .{err}); |
| 5505 | 5533 | |
| 5506 | | const optimize_mode: std.builtin.OptimizeMode = if (EnvVar.ZIG_DEBUG_CMD.isSet()) |
| 5534 | const optimize_mode: std.builtin.OptimizeMode = if (EnvVar.ZIG_DEBUG_CMD.isSet(env_map)) |
| 5507 | 5535 | .Debug |
| 5508 | 5536 | else |
| 5509 | 5537 | .ReleaseFast; |
| 5510 | 5538 | const strip = optimize_mode != .Debug; |
| 5511 | | const override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena); |
| 5512 | | const override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena); |
| 5539 | const override_lib_dir: ?[]const u8 = EnvVar.ZIG_LIB_DIR.get(env_map); |
| 5540 | const override_global_cache_dir: ?[]const u8 = EnvVar.ZIG_GLOBAL_CACHE_DIR.get(env_map); |
| 5513 | 5541 | |
| 5514 | 5542 | // This `init` calls `fatal` on error. |
| 5515 | 5543 | var dirs: Compilation.Directories = .init( |
| ... | ... | @@ -5520,6 +5548,7 @@ fn jitCmd( |
| 5520 | 5548 | .global, |
| 5521 | 5549 | if (native_os == .wasi) wasi_preopens, |
| 5522 | 5550 | self_exe_path, |
| 5551 | env_map, |
| 5523 | 5552 | ); |
| 5524 | 5553 | defer dirs.deinit(io); |
| 5525 | 5554 | |
| ... | ... | @@ -5593,6 +5622,7 @@ fn jitCmd( |
| 5593 | 5622 | .self_exe_path = self_exe_path, |
| 5594 | 5623 | .thread_limit = thread_limit, |
| 5595 | 5624 | .cache_mode = .whole, |
| 5625 | .environ_map = env_map, |
| 5596 | 5626 | }) catch |err| switch (err) { |
| 5597 | 5627 | error.CreateFail => fatal("failed to create compilation: {f}", .{create_diag}), |
| 5598 | 5628 | else => fatal("failed to create compilation: {s}", .{@errorName(err)}), |
| ... | ... | @@ -5639,31 +5669,33 @@ fn jitCmd( |
| 5639 | 5669 | child_argv.appendSliceAssumeCapacity(args); |
| 5640 | 5670 | |
| 5641 | 5671 | if (process.can_replace and options.capture == null) { |
| 5642 | | if (EnvVar.ZIG_DEBUG_CMD.isSet()) { |
| 5672 | if (EnvVar.ZIG_DEBUG_CMD.isSet(env_map)) { |
| 5643 | 5673 | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5644 | 5674 | std.debug.print("{s}\n", .{cmd}); |
| 5645 | 5675 | } |
| 5646 | | const err = process.execv(gpa, child_argv.items); |
| 5676 | const err = process.replace(io, .{ .argv = child_argv.items, .env_map = env_map }); |
| 5647 | 5677 | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5648 | 5678 | fatal("the following command failed to execve with '{t}':\n{s}", .{ err, cmd }); |
| 5649 | 5679 | } |
| 5650 | 5680 | |
| 5651 | 5681 | if (!process.can_spawn) { |
| 5652 | 5682 | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5653 | | fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ |
| 5654 | | @tagName(native_os), cmd, |
| 5683 | fatal("the following command cannot be executed ({t} does not support spawning a child process):\n{s}", .{ |
| 5684 | native_os, cmd, |
| 5655 | 5685 | }); |
| 5656 | 5686 | } |
| 5657 | 5687 | |
| 5658 | | var child = std.process.Child.init(child_argv.items, gpa); |
| 5659 | | child.stdin_behavior = .inherit; |
| 5660 | | child.stdout_behavior = if (options.capture == null) .inherit else .pipe; |
| 5661 | | child.stderr_behavior = .inherit; |
| 5662 | | |
| 5663 | | const term = t: { |
| 5688 | switch (t: { |
| 5664 | 5689 | _ = try io.lockStderr(&.{}, .no_color); |
| 5665 | 5690 | defer io.unlockStderr(); |
| 5666 | | try child.spawn(io); |
| 5691 | |
| 5692 | var child = std.process.spawn(io, .{ |
| 5693 | .argv = child_argv.items, |
| 5694 | .stdin = .inherit, |
| 5695 | .stdout = if (options.capture == null) .inherit else .pipe, |
| 5696 | .stderr = .inherit, |
| 5697 | }) catch |err| fatal("failed to spawn {s}: {t}", .{ child_argv.items[0], err }); |
| 5698 | defer child.kill(io); |
| 5667 | 5699 | |
| 5668 | 5700 | if (options.capture) |ptr| { |
| 5669 | 5701 | var stdout_reader = child.stdout.?.readerStreaming(io, &.{}); |
| ... | ... | @@ -5671,9 +5703,8 @@ fn jitCmd( |
| 5671 | 5703 | } |
| 5672 | 5704 | |
| 5673 | 5705 | break :t try child.wait(io); |
| 5674 | | }; |
| 5675 | | switch (term) { |
| 5676 | | .Exited => |code| { |
| 5706 | }) { |
| 5707 | .exited => |code| { |
| 5677 | 5708 | if (code == 0) { |
| 5678 | 5709 | if (options.capture != null) return; |
| 5679 | 5710 | return cleanExit(io); |
| ... | ... | @@ -5681,6 +5712,10 @@ fn jitCmd( |
| 5681 | 5712 | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5682 | 5713 | fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd }); |
| 5683 | 5714 | }, |
| 5715 | .signal => |sig| { |
| 5716 | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5717 | fatal("the following build command terminated with signal {t}:\n{s}", .{ sig, cmd }); |
| 5718 | }, |
| 5684 | 5719 | else => { |
| 5685 | 5720 | const cmd = try std.mem.join(arena, " ", child_argv.items); |
| 5686 | 5721 | fatal("the following build command crashed:\n{s}", .{cmd}); |
| ... | ... | @@ -5796,7 +5831,7 @@ pub fn lldMain( |
| 5796 | 5831 | return @intFromBool(!ok); |
| 5797 | 5832 | } |
| 5798 | 5833 | |
| 5799 | | const ArgIteratorResponseFile = process.ArgIteratorGeneral(.{ .comments = true, .single_quotes = true }); |
| 5834 | const ArgIteratorResponseFile = process.Args.IteratorGeneral(.{ .comments = true, .single_quotes = true }); |
| 5800 | 5835 | |
| 5801 | 5836 | /// Initialize the arguments from a Response File. "*.rsp" |
| 5802 | 5837 | fn initArgIteratorResponseFile(allocator: Allocator, io: Io, resp_file_path: []const u8) !ArgIteratorResponseFile { |
| ... | ... | @@ -6872,14 +6907,15 @@ fn cmdFetch( |
| 6872 | 6907 | arena: Allocator, |
| 6873 | 6908 | io: Io, |
| 6874 | 6909 | args: []const []const u8, |
| 6910 | env_map: *process.Environ.Map, |
| 6875 | 6911 | ) !void { |
| 6876 | 6912 | dev.check(.fetch_command); |
| 6877 | 6913 | |
| 6878 | 6914 | const color: Color = .auto; |
| 6879 | 6915 | const work_around_btrfs_bug = native_os == .linux and |
| 6880 | | EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); |
| 6916 | EnvVar.ZIG_BTRFS_WORKAROUND.isSet(env_map); |
| 6881 | 6917 | var opt_path_or_url: ?[]const u8 = null; |
| 6882 | | var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena); |
| 6918 | var override_global_cache_dir: ?[]const u8 = EnvVar.ZIG_GLOBAL_CACHE_DIR.get(env_map); |
| 6883 | 6919 | var debug_hash: bool = false; |
| 6884 | 6920 | var save: union(enum) { |
| 6885 | 6921 | no, |
| ... | ... | @@ -6925,7 +6961,7 @@ fn cmdFetch( |
| 6925 | 6961 | var http_client: std.http.Client = .{ .allocator = gpa, .io = io }; |
| 6926 | 6962 | defer http_client.deinit(); |
| 6927 | 6963 | |
| 6928 | | try http_client.initDefaultProxies(arena); |
| 6964 | try http_client.initDefaultProxies(arena, env_map); |
| 6929 | 6965 | |
| 6930 | 6966 | var root_prog_node = std.Progress.start(io, .{ |
| 6931 | 6967 | .root_name = "Fetch", |
| ... | ... | @@ -6933,7 +6969,7 @@ fn cmdFetch( |
| 6933 | 6969 | defer root_prog_node.end(); |
| 6934 | 6970 | |
| 6935 | 6971 | var global_cache_directory: Directory = l: { |
| 6936 | | const p = override_global_cache_dir orelse try introspect.resolveGlobalCacheDir(arena); |
| 6972 | const p = override_global_cache_dir orelse try introspect.resolveGlobalCacheDir(arena, env_map); |
| 6937 | 6973 | break :l .{ |
| 6938 | 6974 | .handle = try Io.Dir.cwd().createDirPathOpen(io, p, .{}), |
| 6939 | 6975 | .path = p, |