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) {...@@ -80,9 +80,12 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) {
80 for (dep.libdirs.toSliceConst()) |lib_dir| {80 for (dep.libdirs.toSliceConst()) |lib_dir| {
81 lib_exe_obj.addLibPath(lib_dir);81 lib_exe_obj.addLibPath(lib_dir);
82 }82 }
83 for (dep.libs.toSliceConst()) |lib| {83 for (dep.system_libs.toSliceConst()) |lib| {
84 lib_exe_obj.linkSystemLibrary(lib);84 lib_exe_obj.linkSystemLibrary(lib);
85 }85 }
86 for (dep.libs.toSliceConst()) |lib| {
87 lib_exe_obj.addObjectFile(lib);
88 }
86 for (dep.includes.toSliceConst()) |include_path| {89 for (dep.includes.toSliceConst()) |include_path| {
87 lib_exe_obj.addIncludeDir(include_path);90 lib_exe_obj.addIncludeDir(include_path);
88 }91 }
...@@ -91,6 +94,7 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) {...@@ -91,6 +94,7 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) {
91const LibraryDep = struct {94const LibraryDep = struct {
92 libdirs: ArrayList([]const u8),95 libdirs: ArrayList([]const u8),
93 libs: ArrayList([]const u8),96 libs: ArrayList([]const u8),
97 system_libs: ArrayList([]const u8),
94 includes: ArrayList([]const u8),98 includes: ArrayList([]const u8),
95};99};
96100
...@@ -98,11 +102,11 @@ fn findLLVM(b: &Builder) -> ?LibraryDep {...@@ -98,11 +102,11 @@ fn findLLVM(b: &Builder) -> ?LibraryDep {
98 const llvm_config_exe = b.findProgram(102 const llvm_config_exe = b.findProgram(
99 [][]const u8{"llvm-config-5.0", "llvm-config"},103 [][]const u8{"llvm-config-5.0", "llvm-config"},
100 [][]const u8{104 [][]const u8{
101 "/usr/local/opt/llvm@5/bin",105 "C:/Libraries/llvm-5.0.0/bin",
102 "/mingw64/bin",
103 "/c/msys64/mingw64/bin",106 "/c/msys64/mingw64/bin",
104 "c:/msys64/mingw64/bin",107 "c:/msys64/mingw64/bin",
105 "C:/Libraries/llvm-5.0.0/bin",108 "/usr/local/opt/llvm@5/bin",
109 "/mingw64/bin",
106 }) %% |err|110 }) %% |err|
107 {111 {
108 warn("unable to find llvm-config: {}\n", err);112 warn("unable to find llvm-config: {}\n", err);
...@@ -114,6 +118,7 @@ fn findLLVM(b: &Builder) -> ?LibraryDep {...@@ -114,6 +118,7 @@ fn findLLVM(b: &Builder) -> ?LibraryDep {
114118
115 var result = LibraryDep {119 var result = LibraryDep {
116 .libs = ArrayList([]const u8).init(b.allocator),120 .libs = ArrayList([]const u8).init(b.allocator),
121 .system_libs = ArrayList([]const u8).init(b.allocator),
117 .includes = ArrayList([]const u8).init(b.allocator),122 .includes = ArrayList([]const u8).init(b.allocator),
118 .libdirs = ArrayList([]const u8).init(b.allocator),123 .libdirs = ArrayList([]const u8).init(b.allocator),
119 };124 };
...@@ -121,7 +126,9 @@ fn findLLVM(b: &Builder) -> ?LibraryDep {...@@ -121,7 +126,9 @@ fn findLLVM(b: &Builder) -> ?LibraryDep {
121 var it = mem.split(libs_output, " \n");126 var it = mem.split(libs_output, " \n");
122 while (it.next()) |lib_arg| {127 while (it.next()) |lib_arg| {
123 if (mem.startsWith(u8, lib_arg, "-l")) {128 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);
125 }132 }
126 }133 }
127 }134 }
std/build.zig+21
...@@ -47,6 +47,7 @@ pub const Builder = struct {...@@ -47,6 +47,7 @@ pub const Builder = struct {
47 env_map: BufMap,47 env_map: BufMap,
48 top_level_steps: ArrayList(&TopLevelStep),48 top_level_steps: ArrayList(&TopLevelStep),
49 prefix: []const u8,49 prefix: []const u8,
50 search_prefixes: ArrayList([]const u8),
50 lib_dir: []const u8,51 lib_dir: []const u8,
51 exe_dir: []const u8,52 exe_dir: []const u8,
52 installed_files: ArrayList([]const u8),53 installed_files: ArrayList([]const u8),
...@@ -114,6 +115,7 @@ pub const Builder = struct {...@@ -114,6 +115,7 @@ pub const Builder = struct {
114 .default_step = undefined,115 .default_step = undefined,
115 .env_map = %%os.getEnvMap(allocator),116 .env_map = %%os.getEnvMap(allocator),
116 .prefix = undefined,117 .prefix = undefined,
118 .search_prefixes = ArrayList([]const u8).init(allocator),
117 .lib_dir = undefined,119 .lib_dir = undefined,
118 .exe_dir = undefined,120 .exe_dir = undefined,
119 .installed_files = ArrayList([]const u8).init(allocator),121 .installed_files = ArrayList([]const u8).init(allocator),
...@@ -671,7 +673,22 @@ pub const Builder = struct {...@@ -671,7 +673,22 @@ pub const Builder = struct {
671 }673 }
672674
673 pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) -> %[]const u8 {675 pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) -> %[]const u8 {
676 // TODO report error for ambiguous situations
674 const exe_extension = (Target { .Native = {}}).exeFileExt();677 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 }
675 if (self.env_map.get("PATH")) |PATH| {692 if (self.env_map.get("PATH")) |PATH| {
676 for (names) |name| {693 for (names) |name| {
677 if (os.path.isAbsolute(name)) {694 if (os.path.isAbsolute(name)) {
...@@ -727,6 +744,10 @@ pub const Builder = struct {...@@ -727,6 +744,10 @@ pub const Builder = struct {
727 },744 },
728 }745 }
729 }746 }
747
748 pub fn addSearchPrefix(self: &Builder, search_prefix: []const u8) {
749 %%self.search_prefixes.append(search_prefix);
750 }
730};751};
731752
732const Version = struct {753const Version = struct {
std/special/build_runner.zig+7
...@@ -84,6 +84,12 @@ pub fn main() -> %void {...@@ -84,6 +84,12 @@ pub fn main() -> %void {
84 warn("Expected argument after --prefix\n\n");84 warn("Expected argument after --prefix\n\n");
85 return usageAndErr(&builder, false, %return stderr_stream);85 return usageAndErr(&builder, false, %return stderr_stream);
86 });86 });
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);
87 } else if (mem.eql(u8, arg, "--verbose-tokenize")) {93 } else if (mem.eql(u8, arg, "--verbose-tokenize")) {
88 builder.verbose_tokenize = true;94 builder.verbose_tokenize = true;
89 } else if (mem.eql(u8, arg, "--verbose-ast")) {95 } else if (mem.eql(u8, arg, "--verbose-ast")) {
...@@ -145,6 +151,7 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream)...@@ -145,6 +151,7 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream)
145 \\ --help Print this help and exit151 \\ --help Print this help and exit
146 \\ --verbose Print commands before executing them152 \\ --verbose Print commands before executing them
147 \\ --prefix [path] Override default install prefix153 \\ --prefix [path] Override default install prefix
154 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
148 \\155 \\
149 \\Project-Specific Options:156 \\Project-Specific Options:
150 \\157 \\