authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-12 16:03:20-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-12 16:03:20-05:00
log2b9302107fdd4adbbcfc2735afd7f2e4cd4c6769
tree2066ea0666b9f3c3794e2eb40b84a9b31e96283b
parentcd5fd653d7dd738d4c67b304e9cb17fb211f0163

self-hosted: cleanup build looking for llvm-config


3 files changed, 76 insertions(+), 74 deletions(-)

build.zig+14-74
......@@ -92,81 +92,21 @@ const LibraryDep = struct {
9292};
9393
9494fn findLLVM(b: &Builder) -> LibraryDep {
95 const libs_output = {
96 const args1 = [][]const u8{"llvm-config-5.0", "--libs", "--system-libs"};
97 const args2 = [][]const u8{"llvm-config", "--libs", "--system-libs"};
98 const max_output_size = 10 * 1024;
99 const good_result = os.ChildProcess.exec(b.allocator, args1, null, null, max_output_size) %% |err| {
100 if (err == error.FileNotFound) {
101 os.ChildProcess.exec(b.allocator, args2, null, null, max_output_size) %% |err2| {
102 std.debug.panic("unable to spawn {}: {}\n", args2[0], err2);
103 }
104 } else {
105 std.debug.panic("unable to spawn {}: {}\n", args1[0], err);
106 }
107 };
108 switch (good_result.term) {
109 os.ChildProcess.Term.Exited => |code| {
110 if (code != 0) {
111 std.debug.panic("llvm-config exited with {}:\n{}\n", code, good_result.stderr);
112 }
113 },
114 else => {
115 std.debug.panic("llvm-config failed:\n{}\n", good_result.stderr);
116 },
117 }
118 good_result.stdout
119 };
120 const includes_output = {
121 const args1 = [][]const u8{"llvm-config-5.0", "--includedir"};
122 const args2 = [][]const u8{"llvm-config", "--includedir"};
123 const max_output_size = 10 * 1024;
124 const good_result = os.ChildProcess.exec(b.allocator, args1, null, null, max_output_size) %% |err| {
125 if (err == error.FileNotFound) {
126 os.ChildProcess.exec(b.allocator, args2, null, null, max_output_size) %% |err2| {
127 std.debug.panic("unable to spawn {}: {}\n", args2[0], err2);
128 }
129 } else {
130 std.debug.panic("unable to spawn {}: {}\n", args1[0], err);
131 }
132 };
133 switch (good_result.term) {
134 os.ChildProcess.Term.Exited => |code| {
135 if (code != 0) {
136 std.debug.panic("llvm-config --includedir exited with {}:\n{}\n", code, good_result.stderr);
137 }
138 },
139 else => {
140 std.debug.panic("llvm-config failed:\n{}\n", good_result.stderr);
141 },
142 }
143 good_result.stdout
144 };
145 const libdir_output = {
146 const args1 = [][]const u8{"llvm-config-5.0", "--libdir"};
147 const args2 = [][]const u8{"llvm-config", "--libdir"};
148 const max_output_size = 10 * 1024;
149 const good_result = os.ChildProcess.exec(b.allocator, args1, null, null, max_output_size) %% |err| {
150 if (err == error.FileNotFound) {
151 os.ChildProcess.exec(b.allocator, args2, null, null, max_output_size) %% |err2| {
152 std.debug.panic("unable to spawn {}: {}\n", args2[0], err2);
153 }
154 } else {
155 std.debug.panic("unable to spawn {}: {}\n", args1[0], err);
156 }
157 };
158 switch (good_result.term) {
159 os.ChildProcess.Term.Exited => |code| {
160 if (code != 0) {
161 std.debug.panic("llvm-config --libdir exited with {}:\n{}\n", code, good_result.stderr);
162 }
163 },
164 else => {
165 std.debug.panic("llvm-config failed:\n{}\n", good_result.stderr);
166 },
167 }
168 good_result.stdout
95 const llvm_config_exe = b.findProgram(
96 [][]const u8{"llvm-config-5.0", "llvm-config"},
97 [][]const u8{
98 "/usr/local/opt/llvm@5/",
99 "/mingw64/bin",
100 "/c/msys64/mingw64/bin",
101 "c:/msys64/mingw64/bin",
102 "C:/Libraries/llvm-5.0.0/bin",
103 }) %% |err|
104 {
105 std.debug.panic("unable to find llvm-config: {}\n", err);
169106 };
107 const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});
108 const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"});
109 const libdir_output = b.exec([][]const u8{llvm_config_exe, "--libdir"});
170110
171111 var result = LibraryDep {
172112 .libs = ArrayList([]const u8).init(b.allocator),
std/buf_map.zig+5
......@@ -42,6 +42,11 @@ pub const BufMap = struct {
4242 }
4343 }
4444
45 pub fn get(self: &BufMap, key: []const u8) -> ?[]const u8 {
46 const entry = self.hash_map.get(key) ?? return null;
47 return entry.value;
48 }
49
4550 pub fn delete(self: &BufMap, key: []const u8) {
4651 const entry = self.hash_map.remove(key) ?? return;
4752 self.free(entry.key);
std/build.zig+57
......@@ -671,6 +671,63 @@ pub const Builder = struct {
671671 };
672672 }
673673 }
674
675 pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) -> %[]const u8 {
676 if (self.env_map.get("PATH")) |PATH| {
677 for (names) |name| {
678 if (os.path.isAbsolute(name)) {
679 return name;
680 }
681 var it = mem.split(PATH, []u8{os.path.delimiter});
682 while (it.next()) |path| {
683 const full_path = %return os.path.join(self.allocator, path, name);
684 if (os.path.real(self.allocator, full_path)) |real_path| {
685 return real_path;
686 } else |_| {
687 continue;
688 }
689 }
690 }
691 }
692 for (names) |name| {
693 if (os.path.isAbsolute(name)) {
694 return name;
695 }
696 for (paths) |path| {
697 const full_path = %return os.path.join(self.allocator, path, name);
698 if (os.path.real(self.allocator, full_path)) |real_path| {
699 return real_path;
700 } else |_| {
701 continue;
702 }
703 }
704 }
705 return error.FileNotFound;
706 }
707
708 pub fn exec(self: &Builder, argv: []const []const u8) -> []u8 {
709 const max_output_size = 100 * 1024;
710 const result = os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size) %% |err| {
711 std.debug.panic("Unable to spawn {}: {}", argv[0], @errorName(err));
712 };
713 switch (result.term) {
714 os.ChildProcess.Term.Exited => |code| {
715 if (code != 0) {
716 warn("The following command exited with error code {}:\n", code);
717 printCmd(null, argv);
718 warn("stderr:{}\n", result.stderr);
719 std.debug.panic("command failed");
720 }
721 return result.stdout;
722 },
723 else => {
724 warn("The following command terminated unexpectedly:\n");
725 printCmd(null, argv);
726 warn("stderr:{}\n", result.stderr);
727 std.debug.panic("command failed");
728 },
729 }
730 }
674731};
675732
676733const Version = struct {