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) {...@@ -35,55 +35,54 @@ pub fn build(b: &Builder) {
3535
36 const test_step = b.step("test", "Run all the tests");36 const test_step = b.step("test", "Run all the tests");
3737
38 if (findLLVM(b)) |llvm| {38 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library
39 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library39 const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"});
40 const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"});40 var index: usize = 0;
41 var index: usize = 0;41 const cmake_binary_dir = nextValue(&index, build_info);
42 const cmake_binary_dir = nextValue(&index, build_info);42 const cxx_compiler = nextValue(&index, build_info);
43 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);44 const lld_include_dir = nextValue(&index, build_info);
45 const lld_libraries = nextValue(&index, build_info);45 const lld_libraries = nextValue(&index, build_info);
46 const std_files = nextValue(&index, build_info);46 const std_files = nextValue(&index, build_info);
47 const c_header_files = nextValue(&index, build_info);47 const c_header_files = nextValue(&index, build_info);
4848
49 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");49 const llvm = findLLVM(b, llvm_config_exe);
50 exe.setBuildMode(mode);50
51 exe.addIncludeDir("src");51 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
52 exe.addIncludeDir(cmake_binary_dir);52 exe.setBuildMode(mode);
53 addCppLib(b, exe, cmake_binary_dir, "zig_cpp");53 exe.addIncludeDir("src");
54 if (lld_include_dir.len != 0) {54 exe.addIncludeDir(cmake_binary_dir);
55 exe.addIncludeDir(lld_include_dir);55 addCppLib(b, exe, cmake_binary_dir, "zig_cpp");
56 var it = mem.split(lld_libraries, ";");56 if (lld_include_dir.len != 0) {
57 while (it.next()) |lib| {57 exe.addIncludeDir(lld_include_dir);
58 exe.addObjectFile(lib);58 var it = mem.split(lld_libraries, ";");
59 }59 while (it.next()) |lib| {
60 } else {60 exe.addObjectFile(lib);
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");
73 }61 }
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);74 exe.linkSystemLibrary("pthread");
78 b.default_step.dependOn(docs_step);75 }
79 test_step.dependOn(&exe.step);
8076
81 b.installArtifact(exe);77 exe.linkSystemLibrary("c");
82 installStdLib(b, std_files);
83 installCHeaders(b, c_header_files);
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
88 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");87 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
89 const with_lldb = b.option(bool, "with-lldb", "Run tests in LLDB to get a backtrace if one fails") ?? false;88 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 {...@@ -142,20 +141,7 @@ const LibraryDep = struct {
142 includes: ArrayList([]const u8),141 includes: ArrayList([]const u8),
143};142};
144143
145fn findLLVM(b: &Builder) -> ?LibraryDep {144fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> 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 };
159 const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});145 const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});
160 const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"});146 const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"});
161 const libdir_output = b.exec([][]const u8{llvm_config_exe, "--libdir"});147 const libdir_output = b.exec([][]const u8{llvm_config_exe, "--libdir"});
src/config.h.in+1
...@@ -29,6 +29,7 @@...@@ -29,6 +29,7 @@
29#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"29#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
30#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"30#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
31#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"31#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"
32#define ZIG_LLVM_CONFIG_EXE "@LLVM_CONFIG_EXE@"
32#define ZIG_STD_FILES "@ZIG_STD_FILES@"33#define ZIG_STD_FILES "@ZIG_STD_FILES@"
33#define ZIG_C_HEADER_FILES "@ZIG_C_HEADER_FILES@"34#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) {...@@ -267,9 +267,10 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {
267267
268int main(int argc, char **argv) {268int main(int argc, char **argv) {
269 if (argc == 2 && strcmp(argv[1], "BUILD_INFO") == 0) {269 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",
271 ZIG_CMAKE_BINARY_DIR,271 ZIG_CMAKE_BINARY_DIR,
272 ZIG_CXX_COMPILER,272 ZIG_CXX_COMPILER,
273 ZIG_LLVM_CONFIG_EXE,
273 ZIG_LLD_INCLUDE_PATH,274 ZIG_LLD_INCLUDE_PATH,
274 ZIG_LLD_LIBRARIES,275 ZIG_LLD_LIBRARIES,
275 ZIG_STD_FILES,276 ZIG_STD_FILES,