diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-12-08 14:39:17 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-12-08 14:39:17 -0700 |
| commit | 2759313263d58dba324788dbe346ed1506b239dc (patch) | |
| tree | d7cd349ebe71e091992de578ec548ca3a8990d1e /src/main.zig | |
| parent | c796c4528ec8085178fd3ae402ae80be6358dd38 (diff) | |
| download | zig-2759313263d58dba324788dbe346ed1506b239dc.tar.gz zig-2759313263d58dba324788dbe346ed1506b239dc.zip | |
add support for environment variables to control cache directories
This commit adds:
ZIG_LOCAL_CACHE_DIR corresponding to --cache-dir
ZIG_GLOBAL_CACHE_DIR corresponding to --global-cache-dir
ZIG_LIB_DIR corresponding to --override-lib-dir
The main use case is for `zig cc` where we are bound by clang's CLI
options and need alternate channels to pass these configuration options.
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/main.zig b/src/main.zig index 34f8db0eed..48232e6816 100644 --- a/src/main.zig +++ b/src/main.zig @@ -420,6 +420,15 @@ const Emit = union(enum) { } }; +fn optionalStringEnvVar(arena: *Allocator, name: []const u8) !?[]const u8 { + if (std.process.getEnvVarOwned(arena, name)) |value| { + return value; + } else |err| switch (err) { + error.EnvironmentVariableNotFound => return null, + else => |e| return e, + } +} + fn buildOutputType( gpa: *Allocator, arena: *Allocator, @@ -499,17 +508,14 @@ fn buildOutputType( var link_eh_frame_hdr = false; var link_emit_relocs = false; var each_lib_rpath: ?bool = null; - var libc_paths_file: ?[]const u8 = std.process.getEnvVarOwned(arena, "ZIG_LIBC") catch |err| switch (err) { - error.EnvironmentVariableNotFound => null, - else => |e| return e, - }; + var libc_paths_file: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIBC"); var machine_code_model: std.builtin.CodeModel = .default; var runtime_args_start: ?usize = null; var test_filter: ?[]const u8 = null; var test_name_prefix: ?[]const u8 = null; - var override_local_cache_dir: ?[]const u8 = null; - var override_global_cache_dir: ?[]const u8 = null; - var override_lib_dir: ?[]const u8 = null; + var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR"); + var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR"); + var override_lib_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIB_DIR"); var main_pkg_path: ?[]const u8 = null; var clang_preprocessor_mode: Compilation.ClangPreprocessorMode = .no; var subsystem: ?std.Target.SubSystem = null; |
