| author | |
| committer | |
| log | 7b2cb7e679b114057f95692a88a666669246131f |
| tree | 480afe1721354097ae1c1bbd0d6c43ccda8949dd |
| parent | c43f77f10974e754c7b4c1093b019394262cb111 |
3 files changed, 21 insertions(+), 63 deletions(-)
src-self-hosted/introspect.zig+12-26| ... | ... | @@ -39,33 +39,19 @@ pub fn findZigLibDir(allocator: &mem.Allocator) ![]u8 { |
| 39 | 39 | }; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | // TODO look in hard coded installation path from configuration | |
| 43 | //if (ZIG_INSTALL_PREFIX != nullptr) { | |
| 44 | // if (test_zig_install_prefix(buf_create_from_str(ZIG_INSTALL_PREFIX), out_path)) { | |
| 45 | // return 0; | |
| 46 | // } | |
| 47 | //} | |
| 48 | ||
| 49 | 42 | return error.FileNotFound; |
| 50 | 43 | } |
| 51 | 44 | |
| 52 | pub fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const u8) ![]u8 { | |
| 53 | if (zig_install_prefix_arg) |zig_install_prefix| { | |
| 54 | return testZigInstallPrefix(allocator, zig_install_prefix) catch |err| { | |
| 55 | warn("No Zig installation found at prefix {}: {}\n", zig_install_prefix_arg, @errorName(err)); | |
| 56 | return error.ZigInstallationNotFound; | |
| 57 | }; | |
| 58 | } else { | |
| 59 | return findZigLibDir(allocator) catch |err| { | |
| 60 | warn( | |
| 61 | \\Unable to find zig lib directory: {}. | |
| 62 | \\Reinstall Zig or use --zig-install-prefix. | |
| 63 | \\ | |
| 64 | , | |
| 65 | @errorName(err) | |
| 66 | ); | |
| 67 | ||
| 68 | return error.ZigLibDirNotFound; | |
| 69 | }; | |
| 70 | } | |
| 45 | pub fn resolveZigLibDir(allocator: &mem.Allocator) ![]u8 { | |
| 46 | return findZigLibDir(allocator) catch |err| { | |
| 47 | warn( | |
| 48 | \\Unable to find zig lib directory: {}. | |
| 49 | \\Reinstall Zig or use --zig-install-prefix. | |
| 50 | \\ | |
| 51 | , | |
| 52 | @errorName(err) | |
| 53 | ); | |
| 54 | ||
| 55 | return error.ZigLibDirNotFound; | |
| 56 | }; | |
| 71 | 57 | } |
src-self-hosted/main.zig+2-12| ... | ... | @@ -106,7 +106,6 @@ const usage_build = |
| 106 | 106 | \\ --cache-dir [path] Override path to cache directory |
| 107 | 107 | \\ --verbose Print commands before executing them |
| 108 | 108 | \\ --prefix [path] Override default install prefix |
| 109 | \\ --zig-install-prefix [path] Override directory where zig thinks it is installed | |
| 110 | 109 | \\ |
| 111 | 110 | \\Project-Specific Options: |
| 112 | 111 | \\ |
| ... | ... | @@ -132,7 +131,6 @@ const args_build_spec = []Flag { |
| 132 | 131 | Flag.Arg1("--cache-dir"), |
| 133 | 132 | Flag.Bool("--verbose"), |
| 134 | 133 | Flag.Arg1("--prefix"), |
| 135 | Flag.Arg1("--zig-install-prefix"), | |
| 136 | 134 | |
| 137 | 135 | Flag.Arg1("--build-file"), |
| 138 | 136 | Flag.Arg1("--cache-dir"), |
| ... | ... | @@ -163,7 +161,7 @@ fn cmdBuild(allocator: &Allocator, args: []const []const u8) !void { |
| 163 | 161 | os.exit(0); |
| 164 | 162 | } |
| 165 | 163 | |
| 166 | const zig_lib_dir = try introspect.resolveZigLibDir(allocator, flags.single("zig-install-prefix") ?? null); | |
| 164 | const zig_lib_dir = try introspect.resolveZigLibDir(allocator); | |
| 167 | 165 | defer allocator.free(zig_lib_dir); |
| 168 | 166 | |
| 169 | 167 | const zig_std_dir = try os.path.join(allocator, zig_lib_dir, "std"); |
| ... | ... | @@ -230,10 +228,6 @@ fn cmdBuild(allocator: &Allocator, args: []const []const u8) !void { |
| 230 | 228 | try build_args.append(build_file_dirname); |
| 231 | 229 | try build_args.append(full_cache_dir); |
| 232 | 230 | |
| 233 | if (flags.single("zig-install-prefix")) |zig_install_prefix| { | |
| 234 | try build_args.append(zig_install_prefix); | |
| 235 | } | |
| 236 | ||
| 237 | 231 | var proc = try os.ChildProcess.init(build_args.toSliceConst(), allocator); |
| 238 | 232 | defer proc.deinit(); |
| 239 | 233 | |
| ... | ... | @@ -296,7 +290,6 @@ const usage_build_generic = |
| 296 | 290 | \\ --verbose-ir Turn on compiler debug output for Zig IR |
| 297 | 291 | \\ --verbose-llvm-ir Turn on compiler debug output for LLVM IR |
| 298 | 292 | \\ --verbose-cimport Turn on compiler debug output for C imports |
| 299 | \\ --zig-install-prefix [path] Override directory where zig thinks it is installed | |
| 300 | 293 | \\ -dirafter [dir] Same as -isystem but do it last |
| 301 | 294 | \\ -isystem [dir] Add additional search path for other .h files |
| 302 | 295 | \\ -mllvm [arg] Additional arguments to forward to LLVM's option processing |
| ... | ... | @@ -357,7 +350,6 @@ const args_build_generic = []Flag { |
| 357 | 350 | Flag.Bool("--verbose-ir"), |
| 358 | 351 | Flag.Bool("--verbose-llvm-ir"), |
| 359 | 352 | Flag.Bool("--verbose-cimport"), |
| 360 | Flag.Arg1("--zig-install-prefix"), | |
| 361 | 353 | Flag.Arg1("-dirafter"), |
| 362 | 354 | Flag.ArgMergeN("-isystem", 1), |
| 363 | 355 | Flag.Arg1("-mllvm"), |
| ... | ... | @@ -500,9 +492,7 @@ fn buildOutputType(allocator: &Allocator, args: []const []const u8, out_type: Mo |
| 500 | 492 | }; |
| 501 | 493 | defer allocator.free(full_cache_dir); |
| 502 | 494 | |
| 503 | const zig_lib_dir = introspect.resolveZigLibDir(allocator, flags.single("zig-install-prefix") ?? null) catch { | |
| 504 | os.exit(1); | |
| 505 | }; | |
| 495 | const zig_lib_dir = introspect.resolveZigLibDir(allocator) catch os.exit(1); | |
| 506 | 496 | defer allocator.free(zig_lib_dir); |
| 507 | 497 | |
| 508 | 498 | var module = |
src/main.cpp+7-25| ... | ... | @@ -54,7 +54,6 @@ static int usage(const char *arg0) { |
| 54 | 54 | " --verbose-ir turn on compiler debug output for Zig IR\n" |
| 55 | 55 | " --verbose-llvm-ir turn on compiler debug output for LLVM IR\n" |
| 56 | 56 | " --verbose-cimport turn on compiler debug output for C imports\n" |
| 57 | " --zig-install-prefix [path] override directory where zig thinks it is installed\n" | |
| 58 | 57 | " -dirafter [dir] same as -isystem but do it last\n" |
| 59 | 58 | " -isystem [dir] add additional search path for other .h files\n" |
| 60 | 59 | " -mllvm [arg] additional arguments to forward to LLVM's option processing\n" |
| ... | ... | @@ -199,23 +198,14 @@ static int find_zig_lib_dir(Buf *out_path) { |
| 199 | 198 | return ErrorFileNotFound; |
| 200 | 199 | } |
| 201 | 200 | |
| 202 | static Buf *resolve_zig_lib_dir(const char *zig_install_prefix_arg) { | |
| 201 | static Buf *resolve_zig_lib_dir(void) { | |
| 203 | 202 | int err; |
| 204 | 203 | Buf *result = buf_alloc(); |
| 205 | if (zig_install_prefix_arg == nullptr) { | |
| 206 | if ((err = find_zig_lib_dir(result))) { | |
| 207 | fprintf(stderr, "Unable to find zig lib directory. Reinstall Zig or use --zig-install-prefix.\n"); | |
| 208 | exit(EXIT_FAILURE); | |
| 209 | } | |
| 210 | return result; | |
| 211 | } | |
| 212 | Buf *zig_lib_dir_buf = buf_create_from_str(zig_install_prefix_arg); | |
| 213 | if (test_zig_install_prefix(zig_lib_dir_buf, result)) { | |
| 214 | return result; | |
| 204 | if ((err = find_zig_lib_dir(result))) { | |
| 205 | fprintf(stderr, "Unable to find zig lib directory\n"); | |
| 206 | exit(EXIT_FAILURE); | |
| 215 | 207 | } |
| 216 | ||
| 217 | fprintf(stderr, "No Zig installation found at prefix: %s\n", zig_install_prefix_arg); | |
| 218 | exit(EXIT_FAILURE); | |
| 208 | return result; | |
| 219 | 209 | } |
| 220 | 210 | |
| 221 | 211 | enum Cmd { |
| ... | ... | @@ -299,7 +289,6 @@ int main(int argc, char **argv) { |
| 299 | 289 | const char *libc_include_dir = nullptr; |
| 300 | 290 | const char *msvc_lib_dir = nullptr; |
| 301 | 291 | const char *kernel32_lib_dir = nullptr; |
| 302 | const char *zig_install_prefix = nullptr; | |
| 303 | 292 | const char *dynamic_linker = nullptr; |
| 304 | 293 | ZigList<const char *> clang_argv = {0}; |
| 305 | 294 | ZigList<const char *> llvm_argv = {0}; |
| ... | ... | @@ -359,17 +348,12 @@ int main(int argc, char **argv) { |
| 359 | 348 | } else if (i + 1 < argc && strcmp(argv[i], "--cache-dir") == 0) { |
| 360 | 349 | cache_dir = argv[i + 1]; |
| 361 | 350 | i += 1; |
| 362 | } else if (i + 1 < argc && strcmp(argv[i], "--zig-install-prefix") == 0) { | |
| 363 | args.append(argv[i]); | |
| 364 | i += 1; | |
| 365 | zig_install_prefix = argv[i]; | |
| 366 | args.append(zig_install_prefix); | |
| 367 | 351 | } else { |
| 368 | 352 | args.append(argv[i]); |
| 369 | 353 | } |
| 370 | 354 | } |
| 371 | 355 | |
| 372 | Buf *zig_lib_dir_buf = resolve_zig_lib_dir(zig_install_prefix); | |
| 356 | Buf *zig_lib_dir_buf = resolve_zig_lib_dir(); | |
| 373 | 357 | |
| 374 | 358 | Buf *zig_std_dir = buf_alloc(); |
| 375 | 359 | os_path_join(zig_lib_dir_buf, buf_create_from_str("std"), zig_std_dir); |
| ... | ... | @@ -590,8 +574,6 @@ int main(int argc, char **argv) { |
| 590 | 574 | msvc_lib_dir = argv[i]; |
| 591 | 575 | } else if (strcmp(arg, "--kernel32-lib-dir") == 0) { |
| 592 | 576 | kernel32_lib_dir = argv[i]; |
| 593 | } else if (strcmp(arg, "--zig-install-prefix") == 0) { | |
| 594 | zig_install_prefix = argv[i]; | |
| 595 | 577 | } else if (strcmp(arg, "--dynamic-linker") == 0) { |
| 596 | 578 | dynamic_linker = argv[i]; |
| 597 | 579 | } else if (strcmp(arg, "-isystem") == 0) { |
| ... | ... | @@ -803,7 +785,7 @@ int main(int argc, char **argv) { |
| 803 | 785 | full_cache_dir); |
| 804 | 786 | } |
| 805 | 787 | |
| 806 | Buf *zig_lib_dir_buf = resolve_zig_lib_dir(zig_install_prefix); | |
| 788 | Buf *zig_lib_dir_buf = resolve_zig_lib_dir(); | |
| 807 | 789 | |
| 808 | 790 | CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, zig_lib_dir_buf); |
| 809 | 791 | codegen_set_out_name(g, buf_out_name); |