aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt10
-rwxr-xr-xci/drone/linux_script3
-rw-r--r--src/Compilation.zig12
-rw-r--r--src/ThreadPool.zig6
-rw-r--r--src/stage1/zig0.cpp4
5 files changed, 29 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2580c06066..e3c4e67c5a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -75,6 +75,7 @@ set(ZIG_TARGET_TRIPLE "native" CACHE STRING "arch-os-abi to output binaries for"
set(ZIG_TARGET_MCPU "baseline" CACHE STRING "-mcpu parameter to output binaries for")
set(ZIG_EXECUTABLE "" CACHE STRING "(when cross compiling) path to already-built zig binary")
set(ZIG_PREFER_LLVM_CONFIG off CACHE BOOL "(when cross compiling) use llvm-config to find target llvm dependencies if needed")
+set(ZIG_SINGLE_THREADED off CACHE BOOL "limit the zig compiler to use only 1 thread")
find_package(llvm)
find_package(clang)
@@ -510,10 +511,13 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/Cache.zig"
"${CMAKE_SOURCE_DIR}/src/Compilation.zig"
"${CMAKE_SOURCE_DIR}/src/DepTokenizer.zig"
+ "${CMAKE_SOURCE_DIR}/src/Event.zig"
"${CMAKE_SOURCE_DIR}/src/Module.zig"
"${CMAKE_SOURCE_DIR}/src/Package.zig"
"${CMAKE_SOURCE_DIR}/src/RangeSet.zig"
+ "${CMAKE_SOURCE_DIR}/src/ThreadPool.zig"
"${CMAKE_SOURCE_DIR}/src/TypedValue.zig"
+ "${CMAKE_SOURCE_DIR}/src/WaitGroup.zig"
"${CMAKE_SOURCE_DIR}/src/astgen.zig"
"${CMAKE_SOURCE_DIR}/src/clang.zig"
"${CMAKE_SOURCE_DIR}/src/clang_options.zig"
@@ -713,6 +717,11 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
else()
set(ZIG1_RELEASE_ARG -OReleaseFast --strip)
endif()
+if(ZIG_SINGLE_THREADED)
+ set(ZIG1_SINGLE_THREADED_ARG "--single-threaded")
+else()
+ set(ZIG1_SINGLE_THREADED_ARG "")
+endif()
set(BUILD_ZIG1_ARGS
"src/stage1.zig"
@@ -722,6 +731,7 @@ set(BUILD_ZIG1_ARGS
--override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
"-femit-bin=${ZIG1_OBJECT}"
"${ZIG1_RELEASE_ARG}"
+ "${ZIG1_SINGLE_THREADED_ARG}"
-lc
--pkg-begin build_options "${ZIG_CONFIG_ZIG_OUT}"
--pkg-end
diff --git a/ci/drone/linux_script b/ci/drone/linux_script
index fdc1704fb7..8c5dc1be2a 100755
--- a/ci/drone/linux_script
+++ b/ci/drone/linux_script
@@ -17,7 +17,8 @@ git config core.abbrev 9
mkdir build
cd build
-cmake .. -DCMAKE_BUILD_TYPE=Release "-DCMAKE_INSTALL_PREFIX=$DISTDIR" -DZIG_STATIC=ON -DCMAKE_PREFIX_PATH=/deps/local -GNinja
+# TODO figure out why Drone CI is deadlocking and stop passing -DZIG_SINGLE_THREADED=ON
+cmake .. -DCMAKE_BUILD_TYPE=Release "-DCMAKE_INSTALL_PREFIX=$DISTDIR" -DZIG_STATIC=ON -DCMAKE_PREFIX_PATH=/deps/local -GNinja -DZIG_SINGLE_THREADED=ON
samu install
./zig build test -Dskip-release -Dskip-non-native
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 1c27a589ee..23f67f5b37 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -1728,7 +1728,7 @@ fn workerUpdateCObject(
error.AnalysisFail => return,
else => {
{
- var lock = comp.mutex.acquire();
+ const lock = comp.mutex.acquire();
defer lock.release();
comp.failed_c_objects.ensureCapacity(comp.gpa, comp.failed_c_objects.items().len + 1) catch {
fatal("TODO handle this by setting c_object.status = oom failure", .{});
@@ -1759,7 +1759,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *
if (c_object.clearStatus(comp.gpa)) {
// There was previous failure.
- var lock = comp.mutex.acquire();
+ const lock = comp.mutex.acquire();
defer lock.release();
comp.failed_c_objects.removeAssertDiscard(c_object);
}
@@ -1789,10 +1789,12 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *
{
const is_collision = blk: {
- var lock = comp.mutex.acquire();
+ const bin_digest = man.hash.peekBin();
+
+ const lock = comp.mutex.acquire();
defer lock.release();
- const gop = try comp.c_object_cache_digest_set.getOrPut(comp.gpa, man.hash.peekBin());
+ const gop = try comp.c_object_cache_digest_set.getOrPut(comp.gpa, bin_digest);
break :blk gop.found_existing;
};
if (is_collision) {
@@ -2211,7 +2213,7 @@ fn failCObj(comp: *Compilation, c_object: *CObject, comptime format: []const u8,
fn failCObjWithOwnedErrorMsg(comp: *Compilation, c_object: *CObject, err_msg: *ErrorMsg) InnerError {
{
- var lock = comp.mutex.acquire();
+ const lock = comp.mutex.acquire();
defer lock.release();
{
errdefer err_msg.destroy(comp.gpa);
diff --git a/src/ThreadPool.zig b/src/ThreadPool.zig
index 7d6af3d24c..00cb26772a 100644
--- a/src/ThreadPool.zig
+++ b/src/ThreadPool.zig
@@ -25,6 +25,8 @@ pub fn init(self: *ThreadPool, allocator: *std.mem.Allocator) !void {
.allocator = allocator,
.threads = &[_]*std.Thread{},
};
+ if (std.builtin.single_threaded)
+ return;
errdefer self.deinit();
@@ -67,6 +69,10 @@ pub fn shutdown(self: *ThreadPool) void {
}
pub fn spawn(self: *ThreadPool, comptime func: anytype, args: anytype) !void {
+ if (std.builtin.single_threaded) {
+ @call(.{}, func, args);
+ return;
+ }
const Args = @TypeOf(args);
const Closure = struct {
arguments: Args,
diff --git a/src/stage1/zig0.cpp b/src/stage1/zig0.cpp
index 73f5b4f685..bcc9dbc00a 100644
--- a/src/stage1/zig0.cpp
+++ b/src/stage1/zig0.cpp
@@ -266,6 +266,7 @@ int main(int argc, char **argv) {
TargetSubsystem subsystem = TargetSubsystemAuto;
const char *override_lib_dir = nullptr;
const char *mcpu = nullptr;
+ bool single_threaded = false;
for (int i = 1; i < argc; i += 1) {
char *arg = argv[i];
@@ -281,6 +282,8 @@ int main(int argc, char **argv) {
optimize_mode = BuildModeSafeRelease;
} else if (strcmp(arg, "-OReleaseSmall") == 0) {
optimize_mode = BuildModeSmallRelease;
+ } else if (strcmp(arg, "--single-threaded") == 0) {
+ single_threaded = true;
} else if (strcmp(arg, "--help") == 0) {
return print_full_usage(arg0, stdout, EXIT_SUCCESS);
} else if (strcmp(arg, "--strip") == 0) {
@@ -469,6 +472,7 @@ int main(int argc, char **argv) {
stage1->link_libcpp = link_libcpp;
stage1->subsystem = subsystem;
stage1->pic = true;
+ stage1->is_single_threaded = single_threaded;
zig_stage1_build_object(stage1);