authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-12 11:00:11-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-12 11:00:11-04:00
log7b2cb7e679b114057f95692a88a666669246131f
tree480afe1721354097ae1c1bbd0d6c43ccda8949dd
parentc43f77f10974e754c7b4c1093b019394262cb111

remove --zig-install-prefix arg now that we find std at runtime


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 {
3939 };
4040 }
4141
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
4942 return error.FileNotFound;
5043}
5144
52pub 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 }
45pub 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 };
7157}
src-self-hosted/main.zig+2-12
......@@ -106,7 +106,6 @@ const usage_build =
106106 \\ --cache-dir [path] Override path to cache directory
107107 \\ --verbose Print commands before executing them
108108 \\ --prefix [path] Override default install prefix
109 \\ --zig-install-prefix [path] Override directory where zig thinks it is installed
110109 \\
111110 \\Project-Specific Options:
112111 \\
......@@ -132,7 +131,6 @@ const args_build_spec = []Flag {
132131 Flag.Arg1("--cache-dir"),
133132 Flag.Bool("--verbose"),
134133 Flag.Arg1("--prefix"),
135 Flag.Arg1("--zig-install-prefix"),
136134
137135 Flag.Arg1("--build-file"),
138136 Flag.Arg1("--cache-dir"),
......@@ -163,7 +161,7 @@ fn cmdBuild(allocator: &Allocator, args: []const []const u8) !void {
163161 os.exit(0);
164162 }
165163
166 const zig_lib_dir = try introspect.resolveZigLibDir(allocator, flags.single("zig-install-prefix") ?? null);
164 const zig_lib_dir = try introspect.resolveZigLibDir(allocator);
167165 defer allocator.free(zig_lib_dir);
168166
169167 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 {
230228 try build_args.append(build_file_dirname);
231229 try build_args.append(full_cache_dir);
232230
233 if (flags.single("zig-install-prefix")) |zig_install_prefix| {
234 try build_args.append(zig_install_prefix);
235 }
236
237231 var proc = try os.ChildProcess.init(build_args.toSliceConst(), allocator);
238232 defer proc.deinit();
239233
......@@ -296,7 +290,6 @@ const usage_build_generic =
296290 \\ --verbose-ir Turn on compiler debug output for Zig IR
297291 \\ --verbose-llvm-ir Turn on compiler debug output for LLVM IR
298292 \\ --verbose-cimport Turn on compiler debug output for C imports
299 \\ --zig-install-prefix [path] Override directory where zig thinks it is installed
300293 \\ -dirafter [dir] Same as -isystem but do it last
301294 \\ -isystem [dir] Add additional search path for other .h files
302295 \\ -mllvm [arg] Additional arguments to forward to LLVM's option processing
......@@ -357,7 +350,6 @@ const args_build_generic = []Flag {
357350 Flag.Bool("--verbose-ir"),
358351 Flag.Bool("--verbose-llvm-ir"),
359352 Flag.Bool("--verbose-cimport"),
360 Flag.Arg1("--zig-install-prefix"),
361353 Flag.Arg1("-dirafter"),
362354 Flag.ArgMergeN("-isystem", 1),
363355 Flag.Arg1("-mllvm"),
......@@ -500,9 +492,7 @@ fn buildOutputType(allocator: &Allocator, args: []const []const u8, out_type: Mo
500492 };
501493 defer allocator.free(full_cache_dir);
502494
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);
506496 defer allocator.free(zig_lib_dir);
507497
508498 var module =
src/main.cpp+7-25
......@@ -54,7 +54,6 @@ static int usage(const char *arg0) {
5454 " --verbose-ir turn on compiler debug output for Zig IR\n"
5555 " --verbose-llvm-ir turn on compiler debug output for LLVM IR\n"
5656 " --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"
5857 " -dirafter [dir] same as -isystem but do it last\n"
5958 " -isystem [dir] add additional search path for other .h files\n"
6059 " -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) {
199198 return ErrorFileNotFound;
200199}
201200
202static Buf *resolve_zig_lib_dir(const char *zig_install_prefix_arg) {
201static Buf *resolve_zig_lib_dir(void) {
203202 int err;
204203 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);
215207 }
216
217 fprintf(stderr, "No Zig installation found at prefix: %s\n", zig_install_prefix_arg);
218 exit(EXIT_FAILURE);
208 return result;
219209}
220210
221211enum Cmd {
......@@ -299,7 +289,6 @@ int main(int argc, char **argv) {
299289 const char *libc_include_dir = nullptr;
300290 const char *msvc_lib_dir = nullptr;
301291 const char *kernel32_lib_dir = nullptr;
302 const char *zig_install_prefix = nullptr;
303292 const char *dynamic_linker = nullptr;
304293 ZigList<const char *> clang_argv = {0};
305294 ZigList<const char *> llvm_argv = {0};
......@@ -359,17 +348,12 @@ int main(int argc, char **argv) {
359348 } else if (i + 1 < argc && strcmp(argv[i], "--cache-dir") == 0) {
360349 cache_dir = argv[i + 1];
361350 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);
367351 } else {
368352 args.append(argv[i]);
369353 }
370354 }
371355
372 Buf *zig_lib_dir_buf = resolve_zig_lib_dir(zig_install_prefix);
356 Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
373357
374358 Buf *zig_std_dir = buf_alloc();
375359 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) {
590574 msvc_lib_dir = argv[i];
591575 } else if (strcmp(arg, "--kernel32-lib-dir") == 0) {
592576 kernel32_lib_dir = argv[i];
593 } else if (strcmp(arg, "--zig-install-prefix") == 0) {
594 zig_install_prefix = argv[i];
595577 } else if (strcmp(arg, "--dynamic-linker") == 0) {
596578 dynamic_linker = argv[i];
597579 } else if (strcmp(arg, "-isystem") == 0) {
......@@ -803,7 +785,7 @@ int main(int argc, char **argv) {
803785 full_cache_dir);
804786 }
805787
806 Buf *zig_lib_dir_buf = resolve_zig_lib_dir(zig_install_prefix);
788 Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
807789
808790 CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, zig_lib_dir_buf);
809791 codegen_set_out_name(g, buf_out_name);