| ... | ... | @@ -18,6 +18,7 @@ pub fn build(b: *Builder) !void { |
| 18 | 18 | const mode = b.standardReleaseOptions(); |
| 19 | 19 | const target = b.standardTargetOptions(.{}); |
| 20 | 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; |
| 21 | 22 | |
| 22 | 23 | var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig"); |
| 23 | 24 | docgen_exe.single_threaded = single_threaded; |
| ... | ... | @@ -160,8 +161,8 @@ pub fn build(b: *Builder) !void { |
| 160 | 161 | b.addSearchPrefix(cfg.cmake_prefix_path); |
| 161 | 162 | } |
| 162 | 163 | |
| 163 | | try addCmakeCfgOptionsToExe(b, cfg, exe); |
| 164 | | try addCmakeCfgOptionsToExe(b, cfg, test_stage2); |
| 164 | try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx); |
| 165 | try addCmakeCfgOptionsToExe(b, cfg, test_stage2, use_zig_libcxx); |
| 165 | 166 | } else { |
| 166 | 167 | // Here we are -Denable-llvm but no cmake integration. |
| 167 | 168 | try addStaticLlvmOptionsToExe(exe); |
| ... | ... | @@ -408,6 +409,7 @@ fn addCmakeCfgOptionsToExe( |
| 408 | 409 | b: *Builder, |
| 409 | 410 | cfg: CMakeConfig, |
| 410 | 411 | exe: *std.build.LibExeObjStep, |
| 412 | use_zig_libcxx: bool, |
| 411 | 413 | ) !void { |
| 412 | 414 | exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{ |
| 413 | 415 | cfg.cmake_binary_dir, |
| ... | ... | @@ -420,28 +422,32 @@ fn addCmakeCfgOptionsToExe( |
| 420 | 422 | addCMakeLibraryList(exe, cfg.lld_libraries); |
| 421 | 423 | addCMakeLibraryList(exe, cfg.llvm_libraries); |
| 422 | 424 | |
| 423 | | const need_cpp_includes = true; |
| 424 | | |
| 425 | | // System -lc++ must be used because in this code path we are attempting to link |
| 426 | | // against system-provided LLVM, Clang, LLD. |
| 427 | | if (exe.target.getOsTag() == .linux) { |
| 428 | | // First we try to static link against gcc libstdc++. If that doesn't work, |
| 429 | | // we fall back to -lc++ and cross our fingers. |
| 430 | | addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) { |
| 431 | | error.RequiredLibraryNotFound => { |
| 432 | | exe.linkSystemLibrary("c++"); |
| 433 | | }, |
| 434 | | else => |e| return e, |
| 435 | | }; |
| 436 | | exe.linkSystemLibrary("unwind"); |
| 437 | | } else if (exe.target.isFreeBSD()) { |
| 438 | | try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes); |
| 439 | | exe.linkSystemLibrary("pthread"); |
| 440 | | } else if (exe.target.getOsTag() == .openbsd) { |
| 441 | | try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes); |
| 442 | | try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes); |
| 443 | | } else if (exe.target.isDarwin()) { |
| 444 | | exe.linkSystemLibrary("c++"); |
| 425 | if (use_zig_libcxx) { |
| 426 | exe.linkLibCpp(); |
| 427 | } else { |
| 428 | const need_cpp_includes = true; |
| 429 | |
| 430 | // System -lc++ must be used because in this code path we are attempting to link |
| 431 | // against system-provided LLVM, Clang, LLD. |
| 432 | if (exe.target.getOsTag() == .linux) { |
| 433 | // First we try to static link against gcc libstdc++. If that doesn't work, |
| 434 | // we fall back to -lc++ and cross our fingers. |
| 435 | addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) { |
| 436 | error.RequiredLibraryNotFound => { |
| 437 | exe.linkSystemLibrary("c++"); |
| 438 | }, |
| 439 | else => |e| return e, |
| 440 | }; |
| 441 | exe.linkSystemLibrary("unwind"); |
| 442 | } else if (exe.target.isFreeBSD()) { |
| 443 | try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes); |
| 444 | exe.linkSystemLibrary("pthread"); |
| 445 | } else if (exe.target.getOsTag() == .openbsd) { |
| 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 | } |
| 446 | 452 | |
| 447 | 453 | if (cfg.dia_guids_lib.len != 0) { |