authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-23 20:21:57-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-23 20:21:57-05:00
log3cbc244e982da2189acfe1de9d60b478d2e60de4
tree0ce8946be60ec85b4ec53070d4026a1d50624676
parent74a12d818d2b90823313d7f5b77de1f497d9fc99

build: add --search-prefix option


3 files changed, 40 insertions(+), 5 deletions(-)

build.zig+12-5
......@@ -80,9 +80,12 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) {
8080 for (dep.libdirs.toSliceConst()) |lib_dir| {
8181 lib_exe_obj.addLibPath(lib_dir);
8282 }
83 for (dep.libs.toSliceConst()) |lib| {
83 for (dep.system_libs.toSliceConst()) |lib| {
8484 lib_exe_obj.linkSystemLibrary(lib);
8585 }
86 for (dep.libs.toSliceConst()) |lib| {
87 lib_exe_obj.addObjectFile(lib);
88 }
8689 for (dep.includes.toSliceConst()) |include_path| {
8790 lib_exe_obj.addIncludeDir(include_path);
8891 }
......@@ -91,6 +94,7 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) {
9194const LibraryDep = struct {
9295 libdirs: ArrayList([]const u8),
9396 libs: ArrayList([]const u8),
97 system_libs: ArrayList([]const u8),
9498 includes: ArrayList([]const u8),
9599};
96100
......@@ -98,11 +102,11 @@ fn findLLVM(b: &Builder) -> ?LibraryDep {
98102 const llvm_config_exe = b.findProgram(
99103 [][]const u8{"llvm-config-5.0", "llvm-config"},
100104 [][]const u8{
101 "/usr/local/opt/llvm@5/bin",
102 "/mingw64/bin",
105 "C:/Libraries/llvm-5.0.0/bin",
103106 "/c/msys64/mingw64/bin",
104107 "c:/msys64/mingw64/bin",
105 "C:/Libraries/llvm-5.0.0/bin",
108 "/usr/local/opt/llvm@5/bin",
109 "/mingw64/bin",
106110 }) %% |err|
107111 {
108112 warn("unable to find llvm-config: {}\n", err);
......@@ -114,6 +118,7 @@ fn findLLVM(b: &Builder) -> ?LibraryDep {
114118
115119 var result = LibraryDep {
116120 .libs = ArrayList([]const u8).init(b.allocator),
121 .system_libs = ArrayList([]const u8).init(b.allocator),
117122 .includes = ArrayList([]const u8).init(b.allocator),
118123 .libdirs = ArrayList([]const u8).init(b.allocator),
119124 };
......@@ -121,7 +126,9 @@ fn findLLVM(b: &Builder) -> ?LibraryDep {
121126 var it = mem.split(libs_output, " \n");
122127 while (it.next()) |lib_arg| {
123128 if (mem.startsWith(u8, lib_arg, "-l")) {
124 %%result.libs.append(lib_arg[2..]);
129 %%result.system_libs.append(lib_arg[2..]);
130 } else {
131 %%result.libs.append(lib_arg);
125132 }
126133 }
127134 }
std/build.zig+21
......@@ -47,6 +47,7 @@ pub const Builder = struct {
4747 env_map: BufMap,
4848 top_level_steps: ArrayList(&TopLevelStep),
4949 prefix: []const u8,
50 search_prefixes: ArrayList([]const u8),
5051 lib_dir: []const u8,
5152 exe_dir: []const u8,
5253 installed_files: ArrayList([]const u8),
......@@ -114,6 +115,7 @@ pub const Builder = struct {
114115 .default_step = undefined,
115116 .env_map = %%os.getEnvMap(allocator),
116117 .prefix = undefined,
118 .search_prefixes = ArrayList([]const u8).init(allocator),
117119 .lib_dir = undefined,
118120 .exe_dir = undefined,
119121 .installed_files = ArrayList([]const u8).init(allocator),
......@@ -671,7 +673,22 @@ pub const Builder = struct {
671673 }
672674
673675 pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) -> %[]const u8 {
676 // TODO report error for ambiguous situations
674677 const exe_extension = (Target { .Native = {}}).exeFileExt();
678 for (self.search_prefixes.toSliceConst()) |search_prefix| {
679 for (names) |name| {
680 if (os.path.isAbsolute(name)) {
681 return name;
682 }
683 const full_path = %return os.path.join(self.allocator, search_prefix, "bin",
684 self.fmt("{}{}", name, exe_extension));
685 if (os.path.real(self.allocator, full_path)) |real_path| {
686 return real_path;
687 } else |_| {
688 continue;
689 }
690 }
691 }
675692 if (self.env_map.get("PATH")) |PATH| {
676693 for (names) |name| {
677694 if (os.path.isAbsolute(name)) {
......@@ -727,6 +744,10 @@ pub const Builder = struct {
727744 },
728745 }
729746 }
747
748 pub fn addSearchPrefix(self: &Builder, search_prefix: []const u8) {
749 %%self.search_prefixes.append(search_prefix);
750 }
730751};
731752
732753const Version = struct {
std/special/build_runner.zig+7
......@@ -84,6 +84,12 @@ pub fn main() -> %void {
8484 warn("Expected argument after --prefix\n\n");
8585 return usageAndErr(&builder, false, %return stderr_stream);
8686 });
87 } else if (mem.eql(u8, arg, "--search-prefix")) {
88 const search_prefix = %return unwrapArg(arg_it.next(allocator) ?? {
89 warn("Expected argument after --search-prefix\n\n");
90 return usageAndErr(&builder, false, %return stderr_stream);
91 });
92 builder.addSearchPrefix(search_prefix);
8793 } else if (mem.eql(u8, arg, "--verbose-tokenize")) {
8894 builder.verbose_tokenize = true;
8995 } else if (mem.eql(u8, arg, "--verbose-ast")) {
......@@ -145,6 +151,7 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream)
145151 \\ --help Print this help and exit
146152 \\ --verbose Print commands before executing them
147153 \\ --prefix [path] Override default install prefix
154 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
148155 \\
149156 \\Project-Specific Options:
150157 \\