Skip to content

Commit

Permalink
Fixed single-threaded mode for Windows.
Browse files Browse the repository at this point in the history
Added an option "single-threaded" to test the behaviour, and used
those commands for the testing:

 cd test/standalone/c_compiler
 zig build test
 zig build test -Dtarget=arm-linux-musleabi -Denable-qemu
 zig build test -Dtarget=wasm32-wasi -Denable-wasmtime
 zig build test -Dtarget=x86_64-windows-gnu -Denable-wine
 zig build test -Dtarget=x86_64-windows-gnu -Denable-wine -Dsingle-threaded
 zig build test -Dtarget=x86_64-macos-gnu -Denable-darling
 zig build test -Dtarget=x86_64-macos-gnu -Denable-darling -Dsingle-threaded
  • Loading branch information
nuald committed Nov 17, 2021
1 parent ad26030 commit 58ed467
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/libcxx.zig
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,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");
Expand All @@ -147,11 +153,6 @@ pub fn buildLibCXX(comp: *Compilation) !void {
try cflags.append("-fno-exceptions");
}

// WASM targets are single threaded.
if (comp.bin_file.options.single_threaded) {
try cflags.append("-D_LIBCPP_HAS_NO_THREADS");
}

if (target.os.tag == .zos) {
try cflags.append("-fno-aligned-allocation");
} else {
Expand Down
3 changes: 2 additions & 1 deletion test/standalone/c_compiler/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn build(b: *Builder) void {
const is_qemu_enabled = b.option(bool, "enable-qemu", "Use QEMU to run cross compiled foreign architecture tests") orelse false;
const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false;
const is_darling_enabled = b.option(bool, "enable-darling", "[Experimental] Use Darling to run cross compiled macOS tests") orelse false;
const single_threaded = b.option(bool, "single-threaded", "Test single threaded mode") orelse false;

const test_step = b.step("test", "Test the program");

Expand All @@ -38,7 +39,7 @@ pub fn build(b: *Builder) void {
exe_cpp.setBuildMode(mode);
exe_cpp.setTarget(target);
exe_cpp.linkLibCpp();
exe_cpp.single_threaded = isSingleThreadedTarget(target);
exe_cpp.single_threaded = isSingleThreadedTarget(target) or single_threaded;
const os_tag = target.getOsTag();
// macos C++ exceptions could be compiled, but not being catched,
// additional support is required, possibly unwind + DWARF CFI
Expand Down

0 comments on commit 58ed467

Please sign in to comment.