| ... | @@ -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; |
| 21 | | 22 | |
| 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 | } |
| 162 | | 163 | |
| 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); |
| 422 | | 424 | |
| 423 | const need_cpp_includes = true; | 425 | if (use_zig_libcxx) { |
| 424 | | 426 | exe.linkLibCpp(); |
| 425 | // System -lc++ must be used because in this code path we are attempting to link | 427 | } 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 | } |
| 446 | | 452 | |
| 447 | if (cfg.dia_guids_lib.len != 0) { | 453 | if (cfg.dia_guids_lib.len != 0) { |