diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-12-26 19:44:08 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-12-26 19:44:08 -0500 |
| commit | 6fece14cfbb852c108c2094ae0879da76f2f445e (patch) | |
| tree | c2cde629583a94556d65dbc376e0809124550828 /build.zig | |
| parent | 2a25398c869fcdefe8b6508974a5c463ca833520 (diff) | |
| download | zig-6fece14cfbb852c108c2094ae0879da76f2f445e.tar.gz zig-6fece14cfbb852c108c2094ae0879da76f2f445e.zip | |
self-hosted: build against zig_llvm and embedded LLD
Now the self-hosted compiler re-uses the same C++ code for interfacing
with LLVM as the C++ code.
It also links against the same LLD library files.
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -1,3 +1,4 @@ +const builtin = @import("builtin"); const std = @import("std"); const Builder = std.build.Builder; const tests = @import("test/tests.zig"); @@ -33,11 +34,32 @@ pub fn build(b: &Builder) { docs_step.dependOn(&docgen_home_cmd.step); if (findLLVM(b)) |llvm| { + // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library + const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"}); + var build_info_it = mem.split(build_info, "\n"); + const cmake_binary_dir = ??build_info_it.next(); + const cxx_compiler = ??build_info_it.next(); + var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); exe.setBuildMode(mode); - exe.linkSystemLibrary("c"); + exe.addIncludeDir("src"); + exe.addIncludeDir(cmake_binary_dir); + addCppLib(b, exe, cmake_binary_dir, "libzig_cpp"); + addCppLib(b, exe, cmake_binary_dir, "libembedded_lld_elf"); + addCppLib(b, exe, cmake_binary_dir, "libembedded_lld_coff"); + addCppLib(b, exe, cmake_binary_dir, "libembedded_lld_lib"); dependOnLib(exe, llvm); + if (!exe.target.isWindows()) { + const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"}); + const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\n").next(); + exe.addObjectFile(libstdcxx_path); + + exe.linkSystemLibrary("pthread"); + } + + exe.linkSystemLibrary("c"); + b.default_step.dependOn(&exe.step); b.default_step.dependOn(docs_step); @@ -91,6 +113,11 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) { } } +fn addCppLib(b: &Builder, lib_exe_obj: &std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) { + lib_exe_obj.addObjectFile(%%os.path.join(b.allocator, cmake_binary_dir, "zig_cpp", + b.fmt("{}{}", lib_name, lib_exe_obj.target.libFileExt()))); +} + const LibraryDep = struct { libdirs: ArrayList([]const u8), libs: ArrayList([]const u8), |
