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