| ... | @@ -35,55 +35,54 @@ pub fn build(b: &Builder) { | ... | @@ -35,55 +35,54 @@ pub fn build(b: &Builder) { |
| 35 | | 35 | |
| 36 | const test_step = b.step("test", "Run all the tests"); | 36 | const test_step = b.step("test", "Run all the tests"); |
| 37 | | 37 | |
| 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 library | 39 | 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); |
| 48 | | 48 | |
| 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); |
| 74 | | 68 | |
| 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); |
| 76 | | 73 | |
| 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); | | |
| 80 | | 76 | |
| 81 | b.installArtifact(exe); | 77 | exe.linkSystemLibrary("c"); |
| 82 | installStdLib(b, std_files); | | |
| 83 | installCHeaders(b, c_header_files); | | |
| 84 | | 78 | |
| 85 | } | 79 | b.default_step.dependOn(&exe.step); |
| | 80 | b.default_step.dependOn(docs_step); |
| | 81 | test_step.dependOn(&exe.step); |
| 86 | | 82 | |
| | 83 | b.installArtifact(exe); |
| | 84 | installStdLib(b, std_files); |
| | 85 | installCHeaders(b, c_header_files); |
| 87 | | 86 | |
| 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 | }; |
| 144 | | 143 | |
| 145 | fn findLLVM(b: &Builder) -> ?LibraryDep { | 144 | fn 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"}); |