add an option to compile zig in single-threaded mode
And enable it for Drone CI. I hate to do this, but I need to make progress on other fronts.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user