diff --git a/build.zig b/build.zig index 148e4c1366..fa76a2138c 100644 --- a/build.zig +++ b/build.zig @@ -68,6 +68,7 @@ const BunBuildOptions = struct { cached_options_module: ?*Module = null, windows_shim: ?WindowsShim = null, + llvm_codegen_threads: ?u32 = null, pub fn isBaseline(this: *const BunBuildOptions) bool { return this.arch.isX86() and @@ -269,6 +270,7 @@ pub fn build(b: *Build) !void { .enable_logs = b.option(bool, "enable_logs", "Enable logs in release") orelse false, .enable_asan = b.option(bool, "enable_asan", "Enable asan") orelse false, .enable_valgrind = b.option(bool, "enable_valgrind", "Enable valgrind") orelse false, + .llvm_codegen_threads = b.option(u32, "llvm_codegen_threads", "Number of threads to use for LLVM codegen") orelse 1, }; // zig build obj @@ -603,7 +605,15 @@ fn configureObj(b: *Build, opts: *BunBuildOptions, obj: *Compile) void { // Object options obj.use_llvm = !opts.no_llvm; - obj.use_lld = if (opts.os == .mac) false else !opts.no_llvm; + obj.use_lld = if (opts.os == .mac or opts.os == .linux) false else !opts.no_llvm; + + if (opts.optimize == .Debug) { + if (@hasField(std.meta.Child(@TypeOf(obj)), "llvm_codegen_threads")) + obj.llvm_codegen_threads = opts.llvm_codegen_threads orelse 0; + } + + obj.no_link_obj = true; + if (opts.enable_asan and !enableFastBuild(b)) { if (@hasField(Build.Module, "sanitize_address")) { obj.root_module.sanitize_address = true; diff --git a/cmake/targets/BuildBun.cmake b/cmake/targets/BuildBun.cmake index 888c360739..31b007050c 100644 --- a/cmake/targets/BuildBun.cmake +++ b/cmake/targets/BuildBun.cmake @@ -44,6 +44,14 @@ else() set(CONFIGURE_DEPENDS "") endif() +set(LLVM_ZIG_CODEGEN_THREADS 0) +# This makes the build slower, so we turn it off for now. +# if (DEBUG) +# include(ProcessorCount) +# ProcessorCount(CPU_COUNT) +# set(LLVM_ZIG_CODEGEN_THREADS ${CPU_COUNT}) +# endif() + # --- Dependencies --- set(BUN_DEPENDENCIES @@ -578,7 +586,13 @@ if (TEST) set(BUN_ZIG_OUTPUT ${BUILD_PATH}/bun-test.o) set(ZIG_STEPS test) else() - set(BUN_ZIG_OUTPUT ${BUILD_PATH}/bun-zig.o) + if (LLVM_ZIG_CODEGEN_THREADS GREATER 1) + foreach(i RANGE ${LLVM_ZIG_CODEGEN_THREADS}) + list(APPEND BUN_ZIG_OUTPUT ${BUILD_PATH}/bun-zig.${i}.o) + endforeach() + else() + set(BUN_ZIG_OUTPUT ${BUILD_PATH}/bun-zig.o) + endif() set(ZIG_STEPS obj) endif() @@ -622,6 +636,7 @@ register_command( -Denable_logs=$,true,false> -Denable_asan=$,true,false> -Denable_valgrind=$,true,false> + -Dllvm_codegen_threads=${LLVM_ZIG_CODEGEN_THREADS} -Dversion=${VERSION} -Dreported_nodejs_version=${NODEJS_VERSION} -Dcanary=${CANARY_REVISION} diff --git a/cmake/tools/SetupZig.cmake b/cmake/tools/SetupZig.cmake index 5143353ca0..925fdee0cb 100644 --- a/cmake/tools/SetupZig.cmake +++ b/cmake/tools/SetupZig.cmake @@ -20,7 +20,7 @@ else() unsupported(CMAKE_SYSTEM_NAME) endif() -set(ZIG_COMMIT "e0b7c318f318196c5f81fdf3423816a7b5bb3112") +set(ZIG_COMMIT "55fdbfa0c86be86b68d43a4ba761e6909eb0d7b2") optionx(ZIG_TARGET STRING "The zig target to use" DEFAULT ${DEFAULT_ZIG_TARGET}) if(CMAKE_BUILD_TYPE STREQUAL "Release")