authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-03 21:32:50-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-03 21:32:50-05:00
log477e3f64fc632cc87956a9a6354c9069b93d5919
treebbdaaea0f7ecb87b4f4a9ca9894ed488c7382123
parent5c8600d790d28e0765c806ce42346ba17c974630

self-hosted build: use llvm-config from stage1


3 files changed, 46 insertions(+), 58 deletions(-)

build.zig+43-57
......@@ -35,55 +35,54 @@ pub fn build(b: &Builder) {
3535
3636 const test_step = b.step("test", "Run all the tests");
3737
38 if (findLLVM(b)) |llvm| {
39 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library
40 const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"});
41 var index: usize = 0;
42 const cmake_binary_dir = nextValue(&index, build_info);
43 const cxx_compiler = nextValue(&index, build_info);
44 const lld_include_dir = nextValue(&index, build_info);
45 const lld_libraries = nextValue(&index, build_info);
46 const std_files = nextValue(&index, build_info);
47 const c_header_files = nextValue(&index, build_info);
48
49 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
50 exe.setBuildMode(mode);
51 exe.addIncludeDir("src");
52 exe.addIncludeDir(cmake_binary_dir);
53 addCppLib(b, exe, cmake_binary_dir, "zig_cpp");
54 if (lld_include_dir.len != 0) {
55 exe.addIncludeDir(lld_include_dir);
56 var it = mem.split(lld_libraries, ";");
57 while (it.next()) |lib| {
58 exe.addObjectFile(lib);
59 }
60 } else {
61 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_elf");
62 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_coff");
63 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_lib");
64 }
65 dependOnLib(exe, llvm);
66
67 if (!exe.target.isWindows()) {
68 const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"});
69 const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next();
70 exe.addObjectFile(libstdcxx_path);
71
72 exe.linkSystemLibrary("pthread");
38 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library
39 const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"});
40 var index: usize = 0;
41 const cmake_binary_dir = nextValue(&index, build_info);
42 const cxx_compiler = nextValue(&index, build_info);
43 const llvm_config_exe = nextValue(&index, build_info);
44 const lld_include_dir = nextValue(&index, build_info);
45 const lld_libraries = nextValue(&index, build_info);
46 const std_files = nextValue(&index, build_info);
47 const c_header_files = nextValue(&index, build_info);
48
49 const llvm = findLLVM(b, llvm_config_exe);
50
51 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
52 exe.setBuildMode(mode);
53 exe.addIncludeDir("src");
54 exe.addIncludeDir(cmake_binary_dir);
55 addCppLib(b, exe, cmake_binary_dir, "zig_cpp");
56 if (lld_include_dir.len != 0) {
57 exe.addIncludeDir(lld_include_dir);
58 var it = mem.split(lld_libraries, ";");
59 while (it.next()) |lib| {
60 exe.addObjectFile(lib);
7361 }
62 } else {
63 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_elf");
64 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_coff");
65 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_lib");
66 }
67 dependOnLib(exe, llvm);
7468
75 exe.linkSystemLibrary("c");
69 if (!exe.target.isWindows()) {
70 const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"});
71 const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next();
72 exe.addObjectFile(libstdcxx_path);
7673
77 b.default_step.dependOn(&exe.step);
78 b.default_step.dependOn(docs_step);
79 test_step.dependOn(&exe.step);
74 exe.linkSystemLibrary("pthread");
75 }
8076
81 b.installArtifact(exe);
82 installStdLib(b, std_files);
83 installCHeaders(b, c_header_files);
77 exe.linkSystemLibrary("c");
8478
85 }
79 b.default_step.dependOn(&exe.step);
80 b.default_step.dependOn(docs_step);
81 test_step.dependOn(&exe.step);
8682
83 b.installArtifact(exe);
84 installStdLib(b, std_files);
85 installCHeaders(b, c_header_files);
8786
8887 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
8988 const with_lldb = b.option(bool, "with-lldb", "Run tests in LLDB to get a backtrace if one fails") ?? false;
......@@ -142,20 +141,7 @@ const LibraryDep = struct {
142141 includes: ArrayList([]const u8),
143142};
144143
145fn findLLVM(b: &Builder) -> ?LibraryDep {
146 const llvm_config_exe = b.findProgram(
147 [][]const u8{"llvm-config-5.0", "llvm-config"},
148 [][]const u8{
149 "C:/Libraries/llvm-5.0.0/bin",
150 "/c/msys64/mingw64/bin",
151 "c:/msys64/mingw64/bin",
152 "/usr/local/opt/llvm@5/bin",
153 "/mingw64/bin",
154 }) %% |err|
155 {
156 warn("unable to find llvm-config: {}\n", err);
157 return null;
158 };
144fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
159145 const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});
160146 const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"});
161147 const libdir_output = b.exec([][]const u8{llvm_config_exe, "--libdir"});
src/config.h.in+1
......@@ -29,6 +29,7 @@
2929#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
3030#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
3131#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"
32#define ZIG_LLVM_CONFIG_EXE "@LLVM_CONFIG_EXE@"
3233#define ZIG_STD_FILES "@ZIG_STD_FILES@"
3334#define ZIG_C_HEADER_FILES "@ZIG_C_HEADER_FILES@"
3435
src/main.cpp+2-1
......@@ -267,9 +267,10 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {
267267
268268int main(int argc, char **argv) {
269269 if (argc == 2 && strcmp(argv[1], "BUILD_INFO") == 0) {
270 printf("%s\n%s\n%s\n%s\n%s\n%s\n",
270 printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
271271 ZIG_CMAKE_BINARY_DIR,
272272 ZIG_CXX_COMPILER,
273 ZIG_LLVM_CONFIG_EXE,
273274 ZIG_LLD_INCLUDE_PATH,
274275 ZIG_LLD_LIBRARIES,
275276 ZIG_STD_FILES,