mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Clean up options
This commit is contained in:
221
build.zig
221
build.zig
@@ -169,6 +169,23 @@ fn addInternalPackages(step: *std.build.LibExeObjStep, _: std.mem.Allocator, tar
|
||||
step.addPackage(lol_html);
|
||||
step.addPackage(uws);
|
||||
}
|
||||
|
||||
const BunBuildOptions = struct {
|
||||
canary: bool = false,
|
||||
sha: [:0]const u8 = "",
|
||||
baseline: bool = false,
|
||||
bindgen: bool = false,
|
||||
|
||||
pub fn step(this: BunBuildOptions, b: anytype) *std.build.OptionsStep {
|
||||
var opts = b.addOptions();
|
||||
opts.addOption(@TypeOf(this.canary), "is_canary", this.canary);
|
||||
opts.addOption(@TypeOf(this.sha), "sha", this.sha);
|
||||
opts.addOption(@TypeOf(this.baseline), "baseline", this.baseline);
|
||||
opts.addOption(@TypeOf(this.bindgen), "bindgen", this.bindgen);
|
||||
return opts;
|
||||
}
|
||||
};
|
||||
|
||||
var output_dir: []const u8 = "";
|
||||
fn panicIfNotFound(comptime filepath: []const u8) []const u8 {
|
||||
var file = std.fs.cwd().openFile(filepath, .{ .mode = .read_only }) catch |err| {
|
||||
@@ -305,53 +322,47 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
var obj_step = b.step("obj", "Build bun as a .o file");
|
||||
var obj = b.addObject(bun_executable_name, exe.root_src.?.path);
|
||||
|
||||
const is_baseline = arch.isX86() and (target.cpu_model == .baseline or
|
||||
!std.Target.x86.featureSetHas(target.getCpuFeatures(), .avx2));
|
||||
var default_build_options: BunBuildOptions = brk: {
|
||||
const is_baseline = arch.isX86() and (target.cpu_model == .baseline or
|
||||
!std.Target.x86.featureSetHas(target.getCpuFeatures(), .avx2));
|
||||
|
||||
var git_sha: [:0]const u8 = "";
|
||||
if (std.os.getenvZ("GITHUB_SHA") orelse std.os.getenvZ("GIT_SHA")) |sha| {
|
||||
git_sha = std.heap.page_allocator.dupeZ(u8, sha) catch unreachable;
|
||||
} else {
|
||||
sha: {
|
||||
const result = std.ChildProcess.exec(.{
|
||||
.allocator = std.heap.page_allocator,
|
||||
.argv = &.{
|
||||
"git",
|
||||
"rev-parse",
|
||||
"--short",
|
||||
"HEAD",
|
||||
},
|
||||
.cwd = b.pathFromRoot("."),
|
||||
.expand_arg0 = .expand,
|
||||
}) catch {
|
||||
std.debug.print("Warning: failed to get git HEAD", .{});
|
||||
break :sha;
|
||||
};
|
||||
var git_sha: [:0]const u8 = "";
|
||||
if (std.os.getenvZ("GITHUB_SHA") orelse std.os.getenvZ("GIT_SHA")) |sha| {
|
||||
git_sha = std.heap.page_allocator.dupeZ(u8, sha) catch unreachable;
|
||||
} else {
|
||||
sha: {
|
||||
const result = std.ChildProcess.exec(.{
|
||||
.allocator = std.heap.page_allocator,
|
||||
.argv = &.{
|
||||
"git",
|
||||
"rev-parse",
|
||||
"--short",
|
||||
"HEAD",
|
||||
},
|
||||
.cwd = b.pathFromRoot("."),
|
||||
.expand_arg0 = .expand,
|
||||
}) catch {
|
||||
std.debug.print("Warning: failed to get git HEAD", .{});
|
||||
break :sha;
|
||||
};
|
||||
|
||||
git_sha = std.heap.page_allocator.dupeZ(u8, std.mem.trim(u8, result.stdout, "\n \t")) catch unreachable;
|
||||
git_sha = std.heap.page_allocator.dupeZ(u8, std.mem.trim(u8, result.stdout, "\n \t")) catch unreachable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const is_canary = (std.os.getenvZ("BUN_CANARY") orelse "0")[0] == '1';
|
||||
const is_canary = (std.os.getenvZ("BUN_CANARY") orelse "0")[0] == '1';
|
||||
break :brk .{
|
||||
.canary = is_canary,
|
||||
.sha = git_sha,
|
||||
.baseline = is_baseline,
|
||||
.bindgen = false,
|
||||
};
|
||||
};
|
||||
|
||||
{
|
||||
obj.setTarget(target);
|
||||
addPicoHTTP(obj, false);
|
||||
obj.setMainPkgPath(b.pathFromRoot("."));
|
||||
var opts = b.addOptions();
|
||||
opts.addOption(
|
||||
bool,
|
||||
"bindgen",
|
||||
false,
|
||||
);
|
||||
|
||||
opts.addOption(
|
||||
bool,
|
||||
"baseline",
|
||||
is_baseline,
|
||||
);
|
||||
opts.addOption([:0]const u8, "sha", git_sha);
|
||||
opts.addOption(bool, "is_canary", is_canary);
|
||||
|
||||
try addInternalPackages(
|
||||
obj,
|
||||
@@ -359,7 +370,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
target,
|
||||
);
|
||||
|
||||
if (is_baseline) {
|
||||
if (default_build_options.baseline) {
|
||||
obj.target.cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 };
|
||||
} else if (arch.isX86()) {
|
||||
obj.target.cpu_model = .{ .explicit = &std.Target.x86.cpu.haswell };
|
||||
@@ -386,7 +397,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
obj.setOutputDir(output_dir);
|
||||
obj.setBuildMode(mode);
|
||||
|
||||
obj.addOptions("build_options", opts);
|
||||
obj.addOptions("build_options", default_build_options.step(b));
|
||||
|
||||
obj.linkLibC();
|
||||
|
||||
@@ -412,21 +423,9 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
var headers_obj: *std.build.LibExeObjStep = b.addObject("headers", "src/bindgen.zig");
|
||||
defer headers_step.dependOn(&headers_obj.step);
|
||||
try configureObjectStep(b, headers_obj, target, obj.main_pkg_path.?);
|
||||
var headers_opts = b.addOptions();
|
||||
headers_opts.addOption(
|
||||
bool,
|
||||
"bindgen",
|
||||
true,
|
||||
);
|
||||
headers_opts.addOption(
|
||||
bool,
|
||||
"baseline",
|
||||
is_baseline,
|
||||
);
|
||||
headers_opts.addOption([:0]const u8, "sha", git_sha);
|
||||
headers_opts.addOption(bool, "is_canary", is_canary);
|
||||
headers_obj.addOptions("build_options", headers_opts);
|
||||
|
||||
var headers_build_options = default_build_options;
|
||||
headers_build_options.bindgen = true;
|
||||
headers_obj.addOptions("build_options", default_build_options.step(b));
|
||||
headers_obj.linkLibCpp();
|
||||
}
|
||||
|
||||
@@ -446,21 +445,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
var headers_obj: *std.build.LibExeObjStep = b.addObject("httpbench", "misctools/http_bench.zig");
|
||||
defer headers_step.dependOn(&headers_obj.step);
|
||||
try configureObjectStep(b, headers_obj, target, obj.main_pkg_path.?);
|
||||
var opts = b.addOptions();
|
||||
opts.addOption(
|
||||
bool,
|
||||
"bindgen",
|
||||
false,
|
||||
);
|
||||
|
||||
opts.addOption(
|
||||
bool,
|
||||
"baseline",
|
||||
is_baseline,
|
||||
);
|
||||
opts.addOption([:0]const u8, "sha", git_sha);
|
||||
opts.addOption(bool, "is_canary", is_canary);
|
||||
headers_obj.addOptions("build_options", opts);
|
||||
headers_obj.addOptions("build_options", default_build_options.step(b));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -468,21 +453,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
var headers_obj: *std.build.LibExeObjStep = b.addObject("machbench", "misctools/machbench.zig");
|
||||
defer headers_step.dependOn(&headers_obj.step);
|
||||
try configureObjectStep(b, headers_obj, target, obj.main_pkg_path.?);
|
||||
var opts = b.addOptions();
|
||||
opts.addOption(
|
||||
bool,
|
||||
"bindgen",
|
||||
false,
|
||||
);
|
||||
|
||||
opts.addOption(
|
||||
bool,
|
||||
"baseline",
|
||||
is_baseline,
|
||||
);
|
||||
opts.addOption([:0]const u8, "sha", git_sha);
|
||||
opts.addOption(bool, "is_canary", is_canary);
|
||||
headers_obj.addOptions("build_options", opts);
|
||||
headers_obj.addOptions("build_options", default_build_options.step(b));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -490,21 +461,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
var headers_obj: *std.build.LibExeObjStep = b.addObject("fetch", "misctools/fetch.zig");
|
||||
defer headers_step.dependOn(&headers_obj.step);
|
||||
try configureObjectStep(b, headers_obj, target, obj.main_pkg_path.?);
|
||||
var opts = b.addOptions();
|
||||
opts.addOption(
|
||||
bool,
|
||||
"bindgen",
|
||||
false,
|
||||
);
|
||||
|
||||
opts.addOption(
|
||||
bool,
|
||||
"baseline",
|
||||
is_baseline,
|
||||
);
|
||||
opts.addOption([:0]const u8, "sha", git_sha);
|
||||
opts.addOption(bool, "is_canary", is_canary);
|
||||
headers_obj.addOptions("build_options", opts);
|
||||
headers_obj.addOptions("build_options", default_build_options.step(b));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -512,21 +469,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
var headers_obj: *std.build.LibExeObjStep = b.addExecutable("string-bench", "src/bench/string-handling.zig");
|
||||
defer headers_step.dependOn(&headers_obj.step);
|
||||
try configureObjectStep(b, headers_obj, target, obj.main_pkg_path.?);
|
||||
var opts = b.addOptions();
|
||||
opts.addOption(
|
||||
bool,
|
||||
"bindgen",
|
||||
false,
|
||||
);
|
||||
|
||||
opts.addOption(
|
||||
bool,
|
||||
"baseline",
|
||||
is_baseline,
|
||||
);
|
||||
opts.addOption([:0]const u8, "sha", git_sha);
|
||||
opts.addOption(bool, "is_canary", is_canary);
|
||||
headers_obj.addOptions("build_options", opts);
|
||||
headers_obj.addOptions("build_options", default_build_options.step(b));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -534,21 +477,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
var headers_obj: *std.build.LibExeObjStep = b.addObject("sha", "src/sha.zig");
|
||||
defer headers_step.dependOn(&headers_obj.step);
|
||||
try configureObjectStep(b, headers_obj, target, obj.main_pkg_path.?);
|
||||
var opts = b.addOptions();
|
||||
opts.addOption(
|
||||
bool,
|
||||
"bindgen",
|
||||
false,
|
||||
);
|
||||
|
||||
opts.addOption(
|
||||
bool,
|
||||
"baseline",
|
||||
is_baseline,
|
||||
);
|
||||
opts.addOption([:0]const u8, "sha", git_sha);
|
||||
opts.addOption(bool, "is_canary", is_canary);
|
||||
headers_obj.addOptions("build_options", opts);
|
||||
headers_obj.addOptions("build_options", default_build_options.step(b));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -556,21 +485,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
var headers_obj: *std.build.LibExeObjStep = b.addExecutable("vlq-bench", "src/sourcemap/vlq_bench.zig");
|
||||
defer headers_step.dependOn(&headers_obj.step);
|
||||
try configureObjectStep(b, headers_obj, target, obj.main_pkg_path.?);
|
||||
var opts = b.addOptions();
|
||||
opts.addOption(
|
||||
bool,
|
||||
"bindgen",
|
||||
false,
|
||||
);
|
||||
|
||||
opts.addOption(
|
||||
bool,
|
||||
"baseline",
|
||||
is_baseline,
|
||||
);
|
||||
opts.addOption([:0]const u8, "sha", git_sha);
|
||||
opts.addOption(bool, "is_canary", is_canary);
|
||||
headers_obj.addOptions("build_options", opts);
|
||||
headers_obj.addOptions("build_options", default_build_options.step(b));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -578,21 +493,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
var headers_obj: *std.build.LibExeObjStep = b.addObject("tgz", "misctools/tgz.zig");
|
||||
defer headers_step.dependOn(&headers_obj.step);
|
||||
try configureObjectStep(b, headers_obj, target, obj.main_pkg_path.?);
|
||||
var opts = b.addOptions();
|
||||
opts.addOption(
|
||||
bool,
|
||||
"bindgen",
|
||||
false,
|
||||
);
|
||||
|
||||
opts.addOption(
|
||||
bool,
|
||||
"baseline",
|
||||
is_baseline,
|
||||
);
|
||||
opts.addOption([:0]const u8, "sha", git_sha);
|
||||
opts.addOption(bool, "is_canary", is_canary);
|
||||
headers_obj.addOptions("build_options", opts);
|
||||
headers_obj.addOptions("build_options", default_build_options.step(b));
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user