Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -604,6 +606,14 @@ 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;

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;
Expand Down Expand Up @@ -664,7 +674,7 @@ pub fn addInstallObjectFile(
return &b.addInstallFile(switch (out_mode) {
.obj => bin,
.bc => compile.getEmittedLlvmBc(),
}, b.fmt("{s}.o", .{name})).step;
}, b.fmt("{s}", .{name})).step;
}

var checked_file_exists: std.AutoHashMap(u64, void) = undefined;
Expand Down
17 changes: 16 additions & 1 deletion cmake/targets/BuildBun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -622,6 +636,7 @@ register_command(
-Denable_logs=$<IF:$<BOOL:${ENABLE_LOGS}>,true,false>
-Denable_asan=$<IF:$<BOOL:${ENABLE_ZIG_ASAN}>,true,false>
-Denable_valgrind=$<IF:$<BOOL:${ENABLE_VALGRIND}>,true,false>
-Dllvm_codegen_threads=${LLVM_ZIG_CODEGEN_THREADS}
-Dversion=${VERSION}
-Dreported_nodejs_version=${NODEJS_VERSION}
-Dcanary=${CANARY_REVISION}
Expand Down
2 changes: 1 addition & 1 deletion cmake/tools/SetupZig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ else()
unsupported(CMAKE_SYSTEM_NAME)
endif()

set(ZIG_COMMIT "e0b7c318f318196c5f81fdf3423816a7b5bb3112")
set(ZIG_COMMIT "147300b883a771ffdfe187c7e1027671482adf4f")
optionx(ZIG_TARGET STRING "The zig target to use" DEFAULT ${DEFAULT_ZIG_TARGET})

if(CMAKE_BUILD_TYPE STREQUAL "Release")
Expand Down
Loading