Compare commits

...

5 Commits

Author SHA1 Message Date
Don Isaac
f7bb2700a0 Merge branch 'main' into jarred/lto- 2025-04-02 18:38:32 -07:00
Jarred Sumner
968e8abf8e Merge branch 'main' into jarred/lto- 2025-03-20 22:32:16 -07:00
Jarred Sumner
34ae847933 Update build.zig 2025-02-07 01:08:08 -08:00
Jarred Sumner
0c24596137 Make it a -D option 2025-02-07 01:01:43 -08:00
Jarred Sumner
c353199662 Enable lto in zig 2025-02-07 00:37:22 -08:00
2 changed files with 15 additions and 1 deletions

View File

@@ -41,7 +41,7 @@ const BunBuildOptions = struct {
optimize: OptimizeMode,
os: OperatingSystem,
arch: Arch,
lto: bool = false,
version: Version,
canary_revision: ?u32,
sha: []const u8,
@@ -213,6 +213,7 @@ pub fn build(b: *Build) !void {
const obj_format = b.option(ObjectFormat, "obj_format", "Output file for object files") orelse .obj;
const no_llvm = b.option(bool, "no_llvm", "Experiment with Zig self hosted backends. No stability guaranteed") orelse false;
b.verbose = true;
var build_options = BunBuildOptions{
.target = target,
@@ -236,6 +237,8 @@ pub fn build(b: *Build) !void {
"0.0.0-unset",
),
.lto = b.option(bool, "lto", "Enable LTO") orelse false,
.sha = sha: {
const sha_buildoption = b.option([]const u8, "sha", "Force the git sha");
const sha_github = b.graph.env_map.get("GITHUB_SHA");
@@ -281,8 +284,10 @@ pub fn build(b: *Build) !void {
{
var step = b.step("obj", "Build Bun's Zig code as a .o file");
var bun_obj = addBunObject(b, &build_options);
step.dependOn(&bun_obj.step);
step.dependOn(addInstallObjectFile(b, bun_obj, "bun-zig", obj_format));
build_options.lto = false;
}
// zig build windows-shim
@@ -455,6 +460,7 @@ pub fn addBunObject(b: *Build, opts: *BunBuildOptions) *Compile {
.omit_frame_pointer = false,
.strip = false, // stripped at the end
});
if (opts.enable_asan) {
if (@hasField(Build.Module, "sanitize_address")) {
@@ -466,6 +472,9 @@ pub fn addBunObject(b: *Build, opts: *BunBuildOptions) *Compile {
}
obj.bundle_compiler_rt = false;
obj.bundle_ubsan_rt = false;
if (opts.lto) {
obj.want_lto = true;
}
obj.root_module.omit_frame_pointer = false;
// Link libc

View File

@@ -573,6 +573,11 @@ if(NOT "${REVISION}" STREQUAL "")
set(ZIG_FLAGS_BUN ${ZIG_FLAGS_BUN} -Dsha=${REVISION})
endif()
if(ENABLE_LTO)
set(ZIG_FLAGS_BUN ${ZIG_FLAGS_BUN} -Dlto=true)
endif()
register_command(
TARGET
bun-zig