diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-05-10 23:38:44 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-10 23:38:44 -0400 |
| commit | f5edf78eea403c14635a05e1729672cfb50aca89 (patch) | |
| tree | 1661a15b3ee4427ce6a4286f4c972be49e9f572c /src | |
| parent | 458943e324e81762a9a2aa839d2fa3c851068e6f (diff) | |
| parent | 45415093c655d30ec226172695248fbf28941667 (diff) | |
| download | zig-f5edf78eea403c14635a05e1729672cfb50aca89.tar.gz zig-f5edf78eea403c14635a05e1729672cfb50aca89.zip | |
Merge pull request #10143 from nuald/single-threaded-cpp1
Normalized C++ compilation options for single-threaded targets
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 13 | ||||
| -rw-r--r-- | src/libcxx.zig | 24 |
2 files changed, 31 insertions, 6 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 9126289804..5e4ab0ec12 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1180,6 +1180,15 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { if (must_single_thread and !single_threaded) { return error.TargetRequiresSingleThreaded; } + if (!single_threaded and options.link_libcpp) { + if (options.target.cpu.arch.isARM()) { + log.warn( + \\libc++ does not work on multi-threaded ARM yet. + \\For more details: https://github.com/ziglang/zig/issues/6573 + , .{}); + return error.TargetRequiresSingleThreaded; + } + } const llvm_cpu_features: ?[*:0]const u8 = if (build_options.have_llvm and use_llvm) blk: { var buf = std.ArrayList(u8).init(arena); @@ -3803,6 +3812,10 @@ pub fn addCCArgs( try argv.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS"); try argv.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS"); try argv.append("-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS"); + + if (comp.bin_file.options.single_threaded) { + try argv.append("-D_LIBCPP_HAS_NO_THREADS"); + } } if (comp.bin_file.options.link_libunwind) { diff --git a/src/libcxx.zig b/src/libcxx.zig index b2974e24c9..a5ab242339 100644 --- a/src/libcxx.zig +++ b/src/libcxx.zig @@ -128,6 +128,12 @@ pub fn buildLibCXX(comp: *Compilation) !void { continue; if (std.mem.startsWith(u8, cxx_src, "src/support/ibm/") and target.os.tag != .zos) continue; + if (comp.bin_file.options.single_threaded) { + if (std.mem.startsWith(u8, cxx_src, "src/support/win32/thread_win32.cpp")) { + continue; + } + try cflags.append("-D_LIBCPP_HAS_NO_THREADS"); + } try cflags.append("-DNDEBUG"); try cflags.append("-D_LIBCPP_BUILDING_LIBRARY"); @@ -145,8 +151,7 @@ pub fn buildLibCXX(comp: *Compilation) !void { } if (target.os.tag == .wasi) { - // WASI doesn't support thread and exception yet. - try cflags.append("-D_LIBCPP_HAS_NO_THREADS"); + // WASI doesn't support exceptions yet. try cflags.append("-fno-exceptions"); } @@ -264,13 +269,20 @@ pub fn buildLibCXXABI(comp: *Compilation) !void { var cflags = std.ArrayList([]const u8).init(arena); if (target.os.tag == .wasi) { - // WASI doesn't support thread and exception yet. - if (std.mem.startsWith(u8, cxxabi_src, "src/cxa_thread_atexit.cpp") or - std.mem.startsWith(u8, cxxabi_src, "src/cxa_exception.cpp") or + // WASI doesn't support exceptions yet. + if (std.mem.startsWith(u8, cxxabi_src, "src/cxa_exception.cpp") or std.mem.startsWith(u8, cxxabi_src, "src/cxa_personality.cpp")) continue; - try cflags.append("-D_LIBCXXABI_HAS_NO_THREADS"); try cflags.append("-fno-exceptions"); + } + + // WASM targets are single threaded. + if (comp.bin_file.options.single_threaded) { + if (std.mem.startsWith(u8, cxxabi_src, "src/cxa_thread_atexit.cpp")) { + continue; + } + try cflags.append("-D_LIBCXXABI_HAS_NO_THREADS"); + try cflags.append("-D_LIBCPP_HAS_NO_THREADS"); } else { try cflags.append("-DHAVE___CXA_THREAD_ATEXIT_IMPL"); } |
