authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-16 13:09:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-16 13:09:32-07:00
log6d37ae95edc06f15e4e77f64e8e637dd5d269183
tree3ed41fafc72bc523022bf2e1e0972d9be3a187e2
parent8f8294a809f9d975735377e7bfcc2c47ccfc4cb7

build.zig: support -Duse-zig-libcxx

This supports the case when it is known that LLVM, Clang, LLD were built with Clang (or `zig c++`). This commit updates the Linux CI script to pass this since we build using a zig tarball.

2 files changed, 31 insertions(+), 25 deletions(-)

build.zig+30-24
...@@ -18,6 +18,7 @@ pub fn build(b: *Builder) !void {...@@ -18,6 +18,7 @@ pub fn build(b: *Builder) !void {
18 const mode = b.standardReleaseOptions();18 const mode = b.standardReleaseOptions();
19 const target = b.standardTargetOptions(.{});19 const target = b.standardTargetOptions(.{});
20 const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode") orelse false;20 const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode") orelse false;
21 const use_zig_libcxx = b.option(bool, "use-zig-libcxx", "If libc++ is needed, use zig's bundled version, don't try to integrate with the system") orelse false;
2122
22 var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");23 var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");
23 docgen_exe.single_threaded = single_threaded;24 docgen_exe.single_threaded = single_threaded;
...@@ -160,8 +161,8 @@ pub fn build(b: *Builder) !void {...@@ -160,8 +161,8 @@ pub fn build(b: *Builder) !void {
160 b.addSearchPrefix(cfg.cmake_prefix_path);161 b.addSearchPrefix(cfg.cmake_prefix_path);
161 }162 }
162163
163 try addCmakeCfgOptionsToExe(b, cfg, exe);164 try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx);
164 try addCmakeCfgOptionsToExe(b, cfg, test_stage2);165 try addCmakeCfgOptionsToExe(b, cfg, test_stage2, use_zig_libcxx);
165 } else {166 } else {
166 // Here we are -Denable-llvm but no cmake integration.167 // Here we are -Denable-llvm but no cmake integration.
167 try addStaticLlvmOptionsToExe(exe);168 try addStaticLlvmOptionsToExe(exe);
...@@ -408,6 +409,7 @@ fn addCmakeCfgOptionsToExe(...@@ -408,6 +409,7 @@ fn addCmakeCfgOptionsToExe(
408 b: *Builder,409 b: *Builder,
409 cfg: CMakeConfig,410 cfg: CMakeConfig,
410 exe: *std.build.LibExeObjStep,411 exe: *std.build.LibExeObjStep,
412 use_zig_libcxx: bool,
411) !void {413) !void {
412 exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{414 exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
413 cfg.cmake_binary_dir,415 cfg.cmake_binary_dir,
...@@ -420,28 +422,32 @@ fn addCmakeCfgOptionsToExe(...@@ -420,28 +422,32 @@ fn addCmakeCfgOptionsToExe(
420 addCMakeLibraryList(exe, cfg.lld_libraries);422 addCMakeLibraryList(exe, cfg.lld_libraries);
421 addCMakeLibraryList(exe, cfg.llvm_libraries);423 addCMakeLibraryList(exe, cfg.llvm_libraries);
422424
423 const need_cpp_includes = true;425 if (use_zig_libcxx) {
424426 exe.linkLibCpp();
425 // System -lc++ must be used because in this code path we are attempting to link427 } else {
426 // against system-provided LLVM, Clang, LLD.428 const need_cpp_includes = true;
427 if (exe.target.getOsTag() == .linux) {429
428 // First we try to static link against gcc libstdc++. If that doesn't work,430 // System -lc++ must be used because in this code path we are attempting to link
429 // we fall back to -lc++ and cross our fingers.431 // against system-provided LLVM, Clang, LLD.
430 addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {432 if (exe.target.getOsTag() == .linux) {
431 error.RequiredLibraryNotFound => {433 // First we try to static link against gcc libstdc++. If that doesn't work,
432 exe.linkSystemLibrary("c++");434 // we fall back to -lc++ and cross our fingers.
433 },435 addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {
434 else => |e| return e,436 error.RequiredLibraryNotFound => {
435 };437 exe.linkSystemLibrary("c++");
436 exe.linkSystemLibrary("unwind");438 },
437 } else if (exe.target.isFreeBSD()) {439 else => |e| return e,
438 try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);440 };
439 exe.linkSystemLibrary("pthread");441 exe.linkSystemLibrary("unwind");
440 } else if (exe.target.getOsTag() == .openbsd) {442 } else if (exe.target.isFreeBSD()) {
441 try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);443 try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
442 try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes);444 exe.linkSystemLibrary("pthread");
443 } else if (exe.target.isDarwin()) {445 } else if (exe.target.getOsTag() == .openbsd) {
444 exe.linkSystemLibrary("c++");446 try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
447 try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes);
448 } else if (exe.target.isDarwin()) {
449 exe.linkSystemLibrary("c++");
450 }
445 }451 }
446452
447 if (cfg.dia_guids_lib.len != 0) {453 if (cfg.dia_guids_lib.len != 0) {
ci/azure/linux_script+1-1
...@@ -71,7 +71,7 @@ make $JOBS install...@@ -71,7 +71,7 @@ make $JOBS install
7171
72release/bin/zig test ../test/behavior.zig -fno-stage1 -fLLVM -I ../test72release/bin/zig test ../test/behavior.zig -fno-stage1 -fLLVM -I ../test
7373
74release/bin/zig build test -Denable-qemu -Denable-wasmtime -Denable-llvm74release/bin/zig build test -Denable-qemu -Denable-wasmtime -Denable-llvm -Duse-zig-libcxx
7575
76# Look for HTML errors.76# Look for HTML errors.
77tidy -qe ../zig-cache/langref.html77tidy -qe ../zig-cache/langref.html