| author | |
| committer | |
| log | 09dea957ed74f87b7f5f88bc2c760f3f93d0165a |
| tree | 3b517ec2e5efdedc3fbbeaf3f6a6249ccead7325 |
| parent | 053119083c2c93cb1fc4129bc647c03301f4010d |
Introduce introspect.EnvVar which tracks all the environment variables
that are observed by the compiler, so that we can print them with `zig
env`.
The `zig env` command now prints both the resolved values as well as all
the possibly observed environment variables.6 files changed, 108 insertions(+), 91 deletions(-)
src/introspect.zig+45-11| ... | ... | @@ -4,6 +4,7 @@ const mem = std.mem; |
| 4 | 4 | const os = std.os; |
| 5 | 5 | const fs = std.fs; |
| 6 | 6 | const Compilation = @import("Compilation.zig"); |
| 7 | const build_options = @import("build_options"); | |
| 7 | 8 | |
| 8 | 9 | /// Returns the sub_path that worked, or `null` if none did. |
| 9 | 10 | /// The path of the returned Directory is relative to `base`. |
| ... | ... | @@ -80,23 +81,17 @@ pub fn findZigLibDirFromSelfExe( |
| 80 | 81 | |
| 81 | 82 | /// Caller owns returned memory. |
| 82 | 83 | pub fn resolveGlobalCacheDir(allocator: mem.Allocator) ![]u8 { |
| 83 | if (builtin.os.tag == .wasi) { | |
| 84 | if (builtin.os.tag == .wasi) | |
| 84 | 85 | @compileError("on WASI the global cache dir must be resolved with preopens"); |
| 85 | } | |
| 86 | if (std.process.getEnvVarOwned(allocator, "ZIG_GLOBAL_CACHE_DIR")) |value| { | |
| 87 | if (value.len > 0) { | |
| 88 | return value; | |
| 89 | } else { | |
| 90 | allocator.free(value); | |
| 91 | } | |
| 92 | } else |_| {} | |
| 86 | ||
| 87 | if (try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(allocator)) |value| return value; | |
| 93 | 88 | |
| 94 | 89 | const appname = "zig"; |
| 95 | 90 | |
| 96 | 91 | if (builtin.os.tag != .windows) { |
| 97 | if (std.os.getenv("XDG_CACHE_HOME")) |cache_root| { | |
| 92 | if (EnvVar.XDG_CACHE_HOME.getPosix()) |cache_root| { | |
| 98 | 93 | return fs.path.join(allocator, &[_][]const u8{ cache_root, appname }); |
| 99 | } else if (std.os.getenv("HOME")) |home| { | |
| 94 | } else if (EnvVar.HOME.getPosix()) |home| { | |
| 100 | 95 | return fs.path.join(allocator, &[_][]const u8{ home, ".cache", appname }); |
| 101 | 96 | } |
| 102 | 97 | } |
| ... | ... | @@ -146,3 +141,42 @@ pub fn resolvePath( |
| 146 | 141 | pub fn isUpDir(p: []const u8) bool { |
| 147 | 142 | return mem.startsWith(u8, p, "..") and (p.len == 2 or p[2] == fs.path.sep); |
| 148 | 143 | } |
| 144 | ||
| 145 | /// Collects all the environment variables that Zig could possibly inspect, so | |
| 146 | /// that we can do reflection on this and print them with `zig env`. | |
| 147 | pub const EnvVar = enum { | |
| 148 | ZIG_GLOBAL_CACHE_DIR, | |
| 149 | ZIG_LOCAL_CACHE_DIR, | |
| 150 | ZIG_LIB_DIR, | |
| 151 | ZIG_LIBC, | |
| 152 | ZIG_BUILD_RUNNER, | |
| 153 | ZIG_VERBOSE_LINK, | |
| 154 | ZIG_VERBOSE_CC, | |
| 155 | ZIG_BTRFS_WORKAROUND, | |
| 156 | CC, | |
| 157 | NO_COLOR, | |
| 158 | XDG_CACHE_HOME, | |
| 159 | HOME, | |
| 160 | /// https://github.com/ziglang/zig/issues/17585 | |
| 161 | INCLUDE, | |
| 162 | ||
| 163 | pub fn isSet(comptime ev: EnvVar) bool { | |
| 164 | return std.process.hasEnvVarConstant(@tagName(ev)); | |
| 165 | } | |
| 166 | ||
| 167 | pub fn get(ev: EnvVar, arena: mem.Allocator) !?[]u8 { | |
| 168 | // Env vars aren't used in the bootstrap stage. | |
| 169 | if (build_options.only_c) return null; | |
| 170 | ||
| 171 | if (std.process.getEnvVarOwned(arena, @tagName(ev))) |value| { | |
| 172 | return value; | |
| 173 | } else |err| switch (err) { | |
| 174 | error.EnvironmentVariableNotFound => return null, | |
| 175 | else => |e| return e, | |
| 176 | } | |
| 177 | } | |
| 178 | ||
| 179 | pub fn getPosix(comptime ev: EnvVar) ?[:0]const u8 { | |
| 180 | return std.os.getenvZ(@tagName(ev)); | |
| 181 | } | |
| 182 | }; |
src/libc_installation.zig+2-1| ... | ... | @@ -11,6 +11,7 @@ const is_haiku = builtin.target.os.tag == .haiku; |
| 11 | 11 | const log = std.log.scoped(.libc_installation); |
| 12 | 12 | |
| 13 | 13 | const ZigWindowsSDK = @import("windows_sdk.zig").ZigWindowsSDK; |
| 14 | const EnvVar = @import("introspect.zig").EnvVar; | |
| 14 | 15 | |
| 15 | 16 | /// See the render function implementation for documentation of the fields. |
| 16 | 17 | pub const LibCInstallation = struct { |
| ... | ... | @@ -694,7 +695,7 @@ fn appendCcExe(args: *std.ArrayList([]const u8), skip_cc_env_var: bool) !void { |
| 694 | 695 | args.appendAssumeCapacity(default_cc_exe); |
| 695 | 696 | return; |
| 696 | 697 | } |
| 697 | const cc_env_var = std.os.getenvZ("CC") orelse { | |
| 698 | const cc_env_var = EnvVar.CC.getPosix() orelse { | |
| 698 | 699 | args.appendAssumeCapacity(default_cc_exe); |
| 699 | 700 | return; |
| 700 | 701 | }; |
src/main.zig+27-37| ... | ... | @@ -18,6 +18,7 @@ const link = @import("link.zig"); |
| 18 | 18 | const Package = @import("Package.zig"); |
| 19 | 19 | const build_options = @import("build_options"); |
| 20 | 20 | const introspect = @import("introspect.zig"); |
| 21 | const EnvVar = introspect.EnvVar; | |
| 21 | 22 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; |
| 22 | 23 | const wasi_libc = @import("wasi_libc.zig"); |
| 23 | 24 | const BuildId = std.Build.CompileStep.BuildId; |
| ... | ... | @@ -231,14 +232,14 @@ pub fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 231 | 232 | fatal("expected command argument", .{}); |
| 232 | 233 | } |
| 233 | 234 | |
| 234 | if (std.process.can_execv and std.os.getenvZ("ZIG_IS_DETECTING_LIBC_PATHS") != null) { | |
| 235 | if (process.can_execv and std.os.getenvZ("ZIG_IS_DETECTING_LIBC_PATHS") != null) { | |
| 235 | 236 | // In this case we have accidentally invoked ourselves as "the system C compiler" |
| 236 | 237 | // to figure out where libc is installed. This is essentially infinite recursion |
| 237 | 238 | // via child process execution due to the CC environment variable pointing to Zig. |
| 238 | 239 | // Here we ignore the CC environment variable and exec `cc` as a child process. |
| 239 | 240 | // However it's possible Zig is installed as *that* C compiler as well, which is |
| 240 | 241 | // why we have this additional environment variable here to check. |
| 241 | var env_map = try std.process.getEnvMap(arena); | |
| 242 | var env_map = try process.getEnvMap(arena); | |
| 242 | 243 | |
| 243 | 244 | const inf_loop_env_key = "ZIG_IS_TRYING_TO_NOT_CALL_ITSELF"; |
| 244 | 245 | if (env_map.get(inf_loop_env_key) != null) { |
| ... | ... | @@ -254,11 +255,11 @@ pub fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 254 | 255 | // CC environment variable. We detect and support this scenario here because of |
| 255 | 256 | // the ZIG_IS_DETECTING_LIBC_PATHS environment variable. |
| 256 | 257 | if (mem.eql(u8, args[1], "cc")) { |
| 257 | return std.process.execve(arena, args[1..], &env_map); | |
| 258 | return process.execve(arena, args[1..], &env_map); | |
| 258 | 259 | } else { |
| 259 | 260 | const modified_args = try arena.dupe([]const u8, args); |
| 260 | 261 | modified_args[0] = "cc"; |
| 261 | return std.process.execve(arena, modified_args, &env_map); | |
| 262 | return process.execve(arena, modified_args, &env_map); | |
| 262 | 263 | } |
| 263 | 264 | } |
| 264 | 265 | |
| ... | ... | @@ -686,19 +687,6 @@ const Emit = union(enum) { |
| 686 | 687 | } |
| 687 | 688 | }; |
| 688 | 689 | |
| 689 | fn optionalStringEnvVar(arena: Allocator, name: []const u8) !?[]const u8 { | |
| 690 | // Env vars aren't used in the bootstrap stage. | |
| 691 | if (build_options.only_c) { | |
| 692 | return null; | |
| 693 | } | |
| 694 | if (std.process.getEnvVarOwned(arena, name)) |value| { | |
| 695 | return value; | |
| 696 | } else |err| switch (err) { | |
| 697 | error.EnvironmentVariableNotFound => return null, | |
| 698 | else => |e| return e, | |
| 699 | } | |
| 700 | } | |
| 701 | ||
| 702 | 690 | const ArgMode = union(enum) { |
| 703 | 691 | build: std.builtin.OutputMode, |
| 704 | 692 | cc, |
| ... | ... | @@ -797,8 +785,10 @@ fn buildOutputType( |
| 797 | 785 | var no_builtin = false; |
| 798 | 786 | var listen: Listen = .none; |
| 799 | 787 | var debug_compile_errors = false; |
| 800 | var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK"); | |
| 801 | var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and std.process.hasEnvVarConstant("ZIG_VERBOSE_CC"); | |
| 788 | var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and | |
| 789 | EnvVar.ZIG_VERBOSE_LINK.isSet(); | |
| 790 | var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and | |
| 791 | EnvVar.ZIG_VERBOSE_CC.isSet(); | |
| 802 | 792 | var verbose_air = false; |
| 803 | 793 | var verbose_intern_pool = false; |
| 804 | 794 | var verbose_generic_instances = false; |
| ... | ... | @@ -892,15 +882,15 @@ fn buildOutputType( |
| 892 | 882 | var each_lib_rpath: ?bool = null; |
| 893 | 883 | var build_id: ?BuildId = null; |
| 894 | 884 | var sysroot: ?[]const u8 = null; |
| 895 | var libc_paths_file: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIBC"); | |
| 885 | var libc_paths_file: ?[]const u8 = try EnvVar.ZIG_LIBC.get(arena); | |
| 896 | 886 | var machine_code_model: std.builtin.CodeModel = .default; |
| 897 | 887 | var runtime_args_start: ?usize = null; |
| 898 | 888 | var test_filter: ?[]const u8 = null; |
| 899 | 889 | var test_name_prefix: ?[]const u8 = null; |
| 900 | 890 | var test_runner_path: ?[]const u8 = null; |
| 901 | var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR"); | |
| 902 | var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR"); | |
| 903 | var override_lib_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIB_DIR"); | |
| 891 | var override_local_cache_dir: ?[]const u8 = try EnvVar.ZIG_LOCAL_CACHE_DIR.get(arena); | |
| 892 | var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena); | |
| 893 | var override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena); | |
| 904 | 894 | var main_mod_path: ?[]const u8 = null; |
| 905 | 895 | var clang_preprocessor_mode: Compilation.ClangPreprocessorMode = .no; |
| 906 | 896 | var subsystem: ?std.Target.SubSystem = null; |
| ... | ... | @@ -960,7 +950,7 @@ fn buildOutputType( |
| 960 | 950 | // if it exists, default the color setting to .off |
| 961 | 951 | // explicit --color arguments will still override this setting. |
| 962 | 952 | // Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162 |
| 963 | color = if (builtin.os.tag == .wasi or std.process.hasEnvVarConstant("NO_COLOR")) .off else .auto; | |
| 953 | color = if (builtin.os.tag == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto; | |
| 964 | 954 | |
| 965 | 955 | switch (arg_mode) { |
| 966 | 956 | .build, .translate_c, .zig_test, .run => { |
| ... | ... | @@ -4059,18 +4049,18 @@ fn runOrTest( |
| 4059 | 4049 | if (runtime_args_start) |i| { |
| 4060 | 4050 | try argv.appendSlice(all_args[i..]); |
| 4061 | 4051 | } |
| 4062 | var env_map = try std.process.getEnvMap(arena); | |
| 4052 | var env_map = try process.getEnvMap(arena); | |
| 4063 | 4053 | try env_map.put("ZIG_EXE", self_exe_path); |
| 4064 | 4054 | |
| 4065 | 4055 | // We do not execve for tests because if the test fails we want to print |
| 4066 | 4056 | // the error message and invocation below. |
| 4067 | if (std.process.can_execv and arg_mode == .run) { | |
| 4057 | if (process.can_execv and arg_mode == .run) { | |
| 4068 | 4058 | // execv releases the locks; no need to destroy the Compilation here. |
| 4069 | const err = std.process.execve(gpa, argv.items, &env_map); | |
| 4059 | const err = process.execve(gpa, argv.items, &env_map); | |
| 4070 | 4060 | try warnAboutForeignBinaries(arena, arg_mode, target_info, link_libc); |
| 4071 | 4061 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4072 | 4062 | fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd }); |
| 4073 | } else if (std.process.can_spawn) { | |
| 4063 | } else if (process.can_spawn) { | |
| 4074 | 4064 | var child = std.ChildProcess.init(argv.items, gpa); |
| 4075 | 4065 | child.env_map = &env_map; |
| 4076 | 4066 | child.stdin_behavior = .Inherit; |
| ... | ... | @@ -4489,7 +4479,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 4489 | 4479 | try stdout_writer.print("{s}\n\n", .{argv.items[argv.items.len - 1]}); |
| 4490 | 4480 | } |
| 4491 | 4481 | |
| 4492 | if (std.process.can_spawn) { | |
| 4482 | if (process.can_spawn) { | |
| 4493 | 4483 | var result = std.ChildProcess.exec(.{ |
| 4494 | 4484 | .allocator = gpa, |
| 4495 | 4485 | .argv = argv.items, |
| ... | ... | @@ -4922,7 +4912,7 @@ pub const usage_build = |
| 4922 | 4912 | |
| 4923 | 4913 | pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 4924 | 4914 | const work_around_btrfs_bug = builtin.os.tag == .linux and |
| 4925 | std.process.hasEnvVarConstant("ZIG_BTRFS_WORKAROUND"); | |
| 4915 | EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); | |
| 4926 | 4916 | var color: Color = .auto; |
| 4927 | 4917 | |
| 4928 | 4918 | // We want to release all the locks before executing the child process, so we make a nice |
| ... | ... | @@ -4931,10 +4921,10 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 4931 | 4921 | const self_exe_path = try introspect.findZigExePath(arena); |
| 4932 | 4922 | |
| 4933 | 4923 | var build_file: ?[]const u8 = null; |
| 4934 | var override_lib_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIB_DIR"); | |
| 4935 | var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR"); | |
| 4936 | var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR"); | |
| 4937 | var override_build_runner: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_BUILD_RUNNER"); | |
| 4924 | var override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena); | |
| 4925 | var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena); | |
| 4926 | var override_local_cache_dir: ?[]const u8 = try EnvVar.ZIG_LOCAL_CACHE_DIR.get(arena); | |
| 4927 | var override_build_runner: ?[]const u8 = try EnvVar.ZIG_BUILD_RUNNER.get(arena); | |
| 4938 | 4928 | var child_argv = std.ArrayList([]const u8).init(arena); |
| 4939 | 4929 | var reference_trace: ?u32 = null; |
| 4940 | 4930 | var debug_compile_errors = false; |
| ... | ... | @@ -5292,7 +5282,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 5292 | 5282 | break :argv child_argv.items; |
| 5293 | 5283 | }; |
| 5294 | 5284 | |
| 5295 | if (std.process.can_spawn) { | |
| 5285 | if (process.can_spawn) { | |
| 5296 | 5286 | var child = std.ChildProcess.init(child_argv, gpa); |
| 5297 | 5287 | child.stdin_behavior = .Inherit; |
| 5298 | 5288 | child.stdout_behavior = .Inherit; |
| ... | ... | @@ -7003,9 +6993,9 @@ fn cmdFetch( |
| 7003 | 6993 | ) !void { |
| 7004 | 6994 | const color: Color = .auto; |
| 7005 | 6995 | const work_around_btrfs_bug = builtin.os.tag == .linux and |
| 7006 | std.process.hasEnvVarConstant("ZIG_BTRFS_WORKAROUND"); | |
| 6996 | EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); | |
| 7007 | 6997 | var opt_path_or_url: ?[]const u8 = null; |
| 7008 | var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR"); | |
| 6998 | var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena); | |
| 7009 | 6999 | var debug_hash: bool = false; |
| 7010 | 7000 | |
| 7011 | 7001 | { |
src/print_env.zig+29-39| ... | ... | @@ -1,62 +1,52 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const mem = std.mem; | |
| 3 | 2 | const build_options = @import("build_options"); |
| 4 | 3 | const introspect = @import("introspect.zig"); |
| 5 | 4 | const Allocator = std.mem.Allocator; |
| 6 | 5 | const fatal = @import("main.zig").fatal; |
| 7 | 6 | |
| 8 | const Env = struct { | |
| 9 | name: []const u8, | |
| 10 | value: []const u8, | |
| 11 | }; | |
| 7 | pub fn cmdEnv(arena: Allocator, args: []const []const u8, stdout: std.fs.File.Writer) !void { | |
| 8 | _ = args; | |
| 9 | const self_exe_path = try introspect.findZigExePath(arena); | |
| 12 | 10 | |
| 13 | pub fn cmdEnv(gpa: Allocator, args: []const []const u8, stdout: std.fs.File.Writer) !void { | |
| 14 | const self_exe_path = try introspect.findZigExePath(gpa); | |
| 15 | defer gpa.free(self_exe_path); | |
| 16 | ||
| 17 | var zig_lib_directory = introspect.findZigLibDirFromSelfExe(gpa, self_exe_path) catch |err| { | |
| 11 | var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| { | |
| 18 | 12 | fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)}); |
| 19 | 13 | }; |
| 20 | defer gpa.free(zig_lib_directory.path.?); | |
| 21 | 14 | defer zig_lib_directory.handle.close(); |
| 22 | 15 | |
| 23 | const zig_std_dir = try std.fs.path.join(gpa, &[_][]const u8{ zig_lib_directory.path.?, "std" }); | |
| 24 | defer gpa.free(zig_std_dir); | |
| 16 | const zig_std_dir = try std.fs.path.join(arena, &[_][]const u8{ zig_lib_directory.path.?, "std" }); | |
| 25 | 17 | |
| 26 | const global_cache_dir = try introspect.resolveGlobalCacheDir(gpa); | |
| 27 | defer gpa.free(global_cache_dir); | |
| 18 | const global_cache_dir = try introspect.resolveGlobalCacheDir(arena); | |
| 28 | 19 | |
| 29 | 20 | const info = try std.zig.system.NativeTargetInfo.detect(.{}); |
| 30 | const triple = try info.target.zigTriple(gpa); | |
| 31 | defer gpa.free(triple); | |
| 32 | ||
| 33 | const envars: []Env = &[_]Env{ | |
| 34 | .{ .name = "zig_exe", .value = self_exe_path }, | |
| 35 | .{ .name = "lib_dir", .value = zig_lib_directory.path.? }, | |
| 36 | .{ .name = "std_dir", .value = zig_std_dir }, | |
| 37 | .{ .name = "global_cache_dir", .value = global_cache_dir }, | |
| 38 | .{ .name = "version", .value = build_options.version }, | |
| 39 | .{ .name = "target", .value = triple }, | |
| 40 | }; | |
| 21 | const triple = try info.target.zigTriple(arena); | |
| 41 | 22 | |
| 42 | 23 | var bw = std.io.bufferedWriter(stdout); |
| 43 | 24 | const w = bw.writer(); |
| 44 | 25 | |
| 45 | if (args.len > 0) { | |
| 46 | for (args) |name| { | |
| 47 | for (envars) |env| { | |
| 48 | if (mem.eql(u8, name, env.name)) { | |
| 49 | try w.print("{s}\n", .{env.value}); | |
| 50 | } | |
| 51 | } | |
| 26 | try w.print( | |
| 27 | \\zig_exe={s} | |
| 28 | \\lib_dir={s} | |
| 29 | \\std_dir={s} | |
| 30 | \\global_cache_dir={s} | |
| 31 | \\version={s} | |
| 32 | \\target={s} | |
| 33 | \\ | |
| 34 | , .{ | |
| 35 | self_exe_path, | |
| 36 | zig_lib_directory.path.?, | |
| 37 | zig_std_dir, | |
| 38 | global_cache_dir, | |
| 39 | build_options.version, | |
| 40 | triple, | |
| 41 | }); | |
| 42 | ||
| 43 | inline for (@typeInfo(introspect.EnvVar).Enum.fields) |field| { | |
| 44 | if (try @field(introspect.EnvVar, field.name).get(arena)) |value| { | |
| 45 | try w.print("{s}={s}\n", .{ field.name, value }); | |
| 46 | } else { | |
| 47 | try w.print("{s}\n", .{field.name}); | |
| 52 | 48 | } |
| 53 | try bw.flush(); | |
| 54 | ||
| 55 | return; | |
| 56 | 49 | } |
| 57 | 50 | |
| 58 | for (envars) |env| { | |
| 59 | try w.print("{[name]s}=\"{[value]s}\"\n", env); | |
| 60 | } | |
| 61 | 51 | try bw.flush(); |
| 62 | 52 | } |
src/resinator/compile.zig+3-2| ... | ... | @@ -28,6 +28,7 @@ const windows1252 = @import("windows1252.zig"); |
| 28 | 28 | const lang = @import("lang.zig"); |
| 29 | 29 | const code_pages = @import("code_pages.zig"); |
| 30 | 30 | const errors = @import("errors.zig"); |
| 31 | const introspect = @import("../introspect.zig"); | |
| 31 | 32 | |
| 32 | 33 | pub const CompileOptions = struct { |
| 33 | 34 | cwd: std.fs.Dir, |
| ... | ... | @@ -91,7 +92,7 @@ pub fn compile(allocator: Allocator, source: []const u8, writer: anytype, option |
| 91 | 92 | // `catch unreachable` since `options.cwd` is expected to be a valid dir handle, so opening |
| 92 | 93 | // a new handle to it should be fine as well. |
| 93 | 94 | // TODO: Maybe catch and return an error instead |
| 94 | const cwd_dir = options.cwd.openDir(".", .{}) catch unreachable; | |
| 95 | const cwd_dir = options.cwd.openDir(".", .{}) catch @panic("unable to open dir"); | |
| 95 | 96 | try search_dirs.append(.{ .dir = cwd_dir, .path = null }); |
| 96 | 97 | for (options.extra_include_paths) |extra_include_path| { |
| 97 | 98 | var dir = openSearchPathDir(options.cwd, extra_include_path) catch { |
| ... | ... | @@ -110,7 +111,7 @@ pub fn compile(allocator: Allocator, source: []const u8, writer: anytype, option |
| 110 | 111 | try search_dirs.append(.{ .dir = dir, .path = try allocator.dupe(u8, system_include_path) }); |
| 111 | 112 | } |
| 112 | 113 | if (!options.ignore_include_env_var) { |
| 113 | const INCLUDE = std.process.getEnvVarOwned(allocator, "INCLUDE") catch ""; | |
| 114 | const INCLUDE = (introspect.EnvVar.INCLUDE.get(allocator) catch @panic("OOM")) orelse ""; | |
| 114 | 115 | defer allocator.free(INCLUDE); |
| 115 | 116 | |
| 116 | 117 | // TODO: Should this be platform-specific? How does windres/llvm-rc handle this (if at all)? |
src/resinator/preprocess.zig+2-1| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const Allocator = std.mem.Allocator; |
| 3 | 3 | const cli = @import("cli.zig"); |
| 4 | const introspect = @import("../introspect.zig"); | |
| 4 | 5 | |
| 5 | 6 | pub const IncludeArgs = struct { |
| 6 | 7 | clang_target: ?[]const u8 = null, |
| ... | ... | @@ -67,7 +68,7 @@ pub fn appendClangArgs(arena: Allocator, argv: *std.ArrayList([]const u8), optio |
| 67 | 68 | } |
| 68 | 69 | |
| 69 | 70 | if (!options.ignore_include_env_var) { |
| 70 | const INCLUDE = std.process.getEnvVarOwned(arena, "INCLUDE") catch ""; | |
| 71 | const INCLUDE = (introspect.EnvVar.INCLUDE.get(arena) catch @panic("OOM")) orelse ""; | |
| 71 | 72 | |
| 72 | 73 | // TODO: Should this be platform-specific? How does windres/llvm-rc handle this (if at all)? |
| 73 | 74 | var it = std.mem.tokenize(u8, INCLUDE, ";"); |