mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
feat: Windows + CMake Build System (#4410)
* Prepare for windows event loop * More progress * Update libuv.zig * wip * Make compiling each dependency a shell script * Bump mimalloc * Add the build scripts * Update settings.json * Fix a bunch of compiler warnings * Remove more warnings * more warnings * cmake works * Update JSSQLStatement.h * put it in the zig file * Fix usockets warnings * Fixup * Fix one of the compiler errors * chunk * draw the rest of the owl * theres more * Rename Process -> BunProcess Works around a Windows issue * Add musl polyfill for memmem on Windows * More * 12 mb * Fix getenvZ * fix variosu issues * Add fast-ish path for bun install on Windows * Update windows.zig * Update windows.zig * Fix build issue * it works * hmmm * Rename file * Fixups * Update wtf-bindings.cpp * Update src/bun.js/bindings/headers-handwritten.h Co-authored-by: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> * further! * more * Update .gitignore * hm * quite a lot of fixes * Update CMakeLists.txt * zig fmt * Many more things are starting to work. * reb * regenaret * Update JSSink.h * fixup * fetch works * Bun.serve() and much of the event loop works now * Make require() work * bun install progress * more things work * use less std.os * Fixes * small fixes * Bump * Bummp * Undo that change * We have to bump the version of Debian because libarchive has a higher minimum requirement * ok * some clenaup * windows * Update bun.zig * fixup * avoid duplicate symbols * avoid undefined symbols * bump * Remove issue template for install It's not used, and use the bug issue instead. * Add types for cp and cpSync * Add types for watchFile and unwatchFile * Add bun-types to 'bun fmt' script * Update nodejs compat docs cp/cpSync/watchFile/unwatchFile (#4525) * feat(fetch) rejectUnauthorized and checkServerIdentity (#4514) * enable root certs on fetch * rebase * fix lookup * some fixes and improvements * fmt * more fixes * more fixes * check detached onHandshake * fix promise case * fix cert non-Native * add fetch tls tests * more one test * churn * Update feature_flags.zig * Update response.zig * Revert "avoid undefined symbols" This reverts commitca835b726f. * Revert "avoid duplicate symbols" This reverts commit4ac6ca8700. * Update feature_flags.zig * Set permissions * more * Update mimalloc * Fix sqlite test failures * Fix some test failures * Make sure we remove libusockets is removed * hm * [dave]: fix webcrypto crash * bump * Update index.ts * windows zig compiles * cmake on mac works * progress * yay * bun run build * fix * ok * oops * asdfasfdafdsafda * fghjkl * git ignore * wow * Process -> BunProcess * hmm * blah * finalize merge * now it only has linker errors on mac * sdfadsf * g * getting farther * sxdcvbnmk, * adfhjskfjdhkas * a * fgh * update build dot zig * asdfg * theoretical -DCANARY flag we can use * asdf * cool * okay * colorterm * New build workflow * Fix script * Use sudo * More sudo * Tweak dependencies * Another sudo attempt * Tweak script * 16.0 -> 16 * Tweak script * Tweak script * Tweak script * Tweak script * Tweak script * bun install * ssh into github actions * add more to ssh * Fix postinstal * Skip llvm * New dockerfile * Build * More changes to Dockerfile * chaos chaos chaos * okay * a * more cmake nonsense * add unified sources code (does not work) * stuff * prepare for CI builds * ok * yay * yeah * make this more stable simply by trying again if it fails, 5 times, then lose. it fixes the stability issue i was running into L O L * messing with ci * x * a * clean dependencies before build * oops * this is not going to work but its closer * not gonna work either * a * a * did i do it * a * a * work around weird fs+Bun.build issues * properly pass debug flag correctly * idk im sorry * lose * maybe * run the tests please * a * fix zlib script * a * hi * prevent stupid ci issue * i totally didnt leave in a syntax error on cmakelists * a * lol * relax * 😭 * a * SO SILLY * 😡 one line mistake * one character diff * fix linking symbols missing * work on dependency scripts * does this work now? * fix mac build * a * bump! * woops * add macos baseline build * . * fix sqlite and also enable $assert/$debug support in builtin functions * okay * oops * zig upgrade lol * Merge * Fix spawn test issue * Set a timeout * yeah * etc * mi --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com> Co-authored-by: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Co-authored-by: Ashcon Partovi <ashcon@partovi.net> Co-authored-by: Birk Skyum <74932975+birkskyum@users.noreply.github.com> Co-authored-by: dave caruso <me@paperdave.net>
This commit is contained in:
134
build.zig
134
build.zig
@@ -1,6 +1,7 @@
|
||||
const required_zig_version = "0.12.0-dev.899+027aabf49";
|
||||
|
||||
const recommended_zig_version = "0.12.0-dev.1297+a9e66ed73";
|
||||
const zig_version = @import("builtin").zig_version;
|
||||
const std = @import("std");
|
||||
|
||||
const pathRel = std.fs.path.relative;
|
||||
const Wyhash = @import("./src/wyhash.zig").Wyhash;
|
||||
var is_debug_build = false;
|
||||
@@ -13,6 +14,11 @@ fn moduleSource(comptime out: []const u8) FileSource {
|
||||
}
|
||||
}
|
||||
|
||||
fn exists(path: []const u8) bool {
|
||||
_ = std.fs.openFileAbsolute(path, .{ .mode = .read_only }) catch return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
const color_map = std.ComptimeStringMap([]const u8, .{
|
||||
&.{ "black", "30m" },
|
||||
&.{ "blue", "34m" },
|
||||
@@ -48,11 +54,37 @@ fn addInternalPackages(b: *Build, step: *CompileStep, _: std.mem.Allocator, _: [
|
||||
};
|
||||
|
||||
step.addModule("async_io", io);
|
||||
|
||||
step.addModule("zlib-internal", brk: {
|
||||
if (target.isWindows()) {
|
||||
break :brk b.createModule(.{ .source_file = FileSource.relative("src/deps/zlib.win32.zig") });
|
||||
}
|
||||
|
||||
break :brk b.createModule(.{ .source_file = FileSource.relative("src/deps/zlib.posix.zig") });
|
||||
});
|
||||
|
||||
var async_: *Module = brk: {
|
||||
if (target.isDarwin() or target.isLinux() or target.isFreeBSD()) {
|
||||
break :brk b.createModule(.{
|
||||
.source_file = FileSource.relative("src/async/posix_event_loop.zig"),
|
||||
});
|
||||
} else if (target.isWindows()) {
|
||||
break :brk b.createModule(.{
|
||||
.source_file = FileSource.relative("src/async/windows_event_loop.zig"),
|
||||
});
|
||||
}
|
||||
|
||||
break :brk b.createModule(.{
|
||||
.source_file = FileSource.relative("src/async/stub_event_loop.zig"),
|
||||
});
|
||||
};
|
||||
step.addModule("async", async_);
|
||||
}
|
||||
|
||||
const BunBuildOptions = struct {
|
||||
canary: bool = false,
|
||||
sha: [:0]const u8 = "",
|
||||
version: []const u8 = "",
|
||||
baseline: bool = false,
|
||||
bindgen: bool = false,
|
||||
sizegen: bool = false,
|
||||
@@ -61,6 +93,8 @@ const BunBuildOptions = struct {
|
||||
runtime_js_version: u64 = 0,
|
||||
fallback_html_version: u64 = 0,
|
||||
|
||||
tinycc: bool = true,
|
||||
|
||||
pub fn updateRuntime(this: *BunBuildOptions) anyerror!void {
|
||||
if (std.fs.cwd().openFile("src/runtime.out.js", .{ .mode = .read_only })) |file| {
|
||||
defer file.close();
|
||||
@@ -92,6 +126,11 @@ const BunBuildOptions = struct {
|
||||
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(
|
||||
std.SemanticVersion,
|
||||
"version",
|
||||
std.SemanticVersion.parse(this.version) catch @panic(b.fmt("Invalid version: {s}", .{this.version})),
|
||||
);
|
||||
opts.addOption(@TypeOf(this.sha), "sha", this.sha);
|
||||
opts.addOption(@TypeOf(this.baseline), "baseline", this.baseline);
|
||||
opts.addOption(@TypeOf(this.bindgen), "bindgen", this.bindgen);
|
||||
@@ -99,6 +138,7 @@ const BunBuildOptions = struct {
|
||||
opts.addOption(@TypeOf(this.base_path), "base_path", this.base_path);
|
||||
opts.addOption(@TypeOf(this.runtime_js_version), "runtime_js_version", this.runtime_js_version);
|
||||
opts.addOption(@TypeOf(this.fallback_html_version), "fallback_html_version", this.fallback_html_version);
|
||||
opts.addOption(@TypeOf(this.tinycc), "tinycc", this.tinycc);
|
||||
return opts;
|
||||
}
|
||||
};
|
||||
@@ -148,18 +188,24 @@ pub fn build(b: *Build) !void {
|
||||
}
|
||||
|
||||
pub fn build_(b: *Build) !void {
|
||||
if (!std.mem.eql(u8, @import("builtin").zig_version_string, required_zig_version)) {
|
||||
const colors = std.io.getStdErr().supportsAnsiEscapeCodes();
|
||||
std.debug.print(
|
||||
"{s}WARNING:\nBun requires zig version '{s}', but found '{s}', build may fail...\nMake sure you installed the right version as per https://bun.sh/docs/project/development#install-zig\n{s}You can update to the right version using 'zigup {s}'\n\n",
|
||||
.{
|
||||
if (colors) "\x1b[1;33m" else "",
|
||||
required_zig_version,
|
||||
@import("builtin").zig_version_string,
|
||||
if (colors) "\x1b[0m" else "",
|
||||
required_zig_version,
|
||||
},
|
||||
);
|
||||
switch (comptime zig_version.order(std.SemanticVersion.parse(recommended_zig_version) catch unreachable)) {
|
||||
.eq => {},
|
||||
.lt => {
|
||||
@compileError("The minimum version of Zig required to compile Bun is " ++ recommended_zig_version ++ ", found " ++ @import("builtin").zig_version_string);
|
||||
},
|
||||
.gt => {
|
||||
const colors = std.io.getStdErr().supportsAnsiEscapeCodes();
|
||||
std.debug.print(
|
||||
"{s}WARNING:\nBun recommends Zig version '{s}', but found '{s}', build may fail...\nMake sure you installed the right version as per https://bun.sh/docs/project/contributing#install-zig\n{s}You can update to the right version using 'zigup {s}'\n\n",
|
||||
.{
|
||||
if (colors) "\x1b[1;33m" else "",
|
||||
recommended_zig_version,
|
||||
@import("builtin").zig_version_string,
|
||||
if (colors) "\x1b[0m" else "",
|
||||
recommended_zig_version,
|
||||
},
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
// Standard target options allows the person running `zig build` to choose
|
||||
@@ -171,6 +217,8 @@ pub fn build_(b: *Build) !void {
|
||||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
||||
optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const generated_code_directory = b.option([]const u8, "generated-code", "Set the generated code directory") orelse "./build";
|
||||
|
||||
var output_dir_buf = std.mem.zeroes([4096]u8);
|
||||
var bin_label = if (optimize == std.builtin.OptimizeMode.Debug) "packages/debug-bun-" else "packages/bun-";
|
||||
|
||||
@@ -203,15 +251,17 @@ pub fn build_(b: *Build) !void {
|
||||
|
||||
var triplet = triplet_buf[0 .. osname.len + cpuArchName.len + 1];
|
||||
|
||||
if (b.option([]const u8, "output-dir", "target to install to") orelse std.os.getenv("OUTPUT_DIR")) |output_dir_| {
|
||||
output_dir = try pathRel(b.allocator, b.install_prefix, output_dir_);
|
||||
const outfile_maybe = b.option([]const u8, "output-file", "target to install to");
|
||||
|
||||
if (outfile_maybe) |outfile| {
|
||||
output_dir = try pathRel(b.allocator, b.install_prefix, std.fs.path.dirname(outfile) orelse "");
|
||||
} else {
|
||||
const output_dir_base = try std.fmt.bufPrint(&output_dir_buf, "{s}{s}", .{ bin_label, triplet });
|
||||
output_dir = try pathRel(b.allocator, b.install_prefix, output_dir_base);
|
||||
}
|
||||
|
||||
is_debug_build = optimize == OptimizeMode.Debug;
|
||||
const bun_executable_name = if (optimize == std.builtin.OptimizeMode.Debug) "bun-debug" else "bun";
|
||||
const bun_executable_name = if (outfile_maybe) |outfile| std.fs.path.basename(outfile[0 .. outfile.len - std.fs.path.extension(outfile).len]) else if (is_debug_build) "bun-debug" else "bun";
|
||||
const root_src = if (target.getOsTag() == std.Target.Os.Tag.freestanding)
|
||||
"root_wasm.zig"
|
||||
else
|
||||
@@ -236,7 +286,28 @@ pub fn build_(b: *Build) !void {
|
||||
.main_mod_path = .{ .cwd_relative = b.pathFromRoot(".") },
|
||||
});
|
||||
|
||||
b.reference_trace = 16;
|
||||
if (!exists(b.pathFromRoot(try std.fs.path.join(b.allocator, &.{
|
||||
"src",
|
||||
"js_lexer",
|
||||
"id_continue_bitset.blob",
|
||||
})))) {
|
||||
const identifier_data = b.pathFromRoot(try std.fs.path.join(b.allocator, &.{ "src", "js_lexer", "identifier_data.zig" }));
|
||||
var run_step = b.addSystemCommand(&.{
|
||||
b.zig_exe,
|
||||
"run",
|
||||
identifier_data,
|
||||
});
|
||||
run_step.has_side_effects = true;
|
||||
obj.step.dependOn(&run_step.step);
|
||||
}
|
||||
|
||||
b.reference_trace = if (b.option(u32, "reference-trace", "Set the reference trace")) |trace|
|
||||
if (trace == 0)
|
||||
null
|
||||
else
|
||||
trace
|
||||
else
|
||||
16;
|
||||
|
||||
var default_build_options: BunBuildOptions = brk: {
|
||||
const is_baseline = arch.isX86() and (target.cpu_model == .baseline or
|
||||
@@ -247,7 +318,7 @@ pub fn build_(b: *Build) !void {
|
||||
git_sha = b.allocator.dupeZ(u8, sha) catch unreachable;
|
||||
} else {
|
||||
sha: {
|
||||
const result = std.ChildProcess.exec(.{
|
||||
const result = std.ChildProcess.run(.{
|
||||
.allocator = b.allocator,
|
||||
.argv = &.{
|
||||
"git",
|
||||
@@ -262,9 +333,12 @@ pub fn build_(b: *Build) !void {
|
||||
}
|
||||
}
|
||||
|
||||
const is_canary = (std.os.getenvZ("BUN_CANARY") orelse "0")[0] == '1';
|
||||
const is_canary =
|
||||
b.option(bool, "canary", "Treat this as a canary build") orelse
|
||||
((b.env_map.get("BUN_CANARY") orelse "0")[0] == '1');
|
||||
break :brk .{
|
||||
.canary = is_canary,
|
||||
.version = b.option([]const u8, "version", "Value of `Bun.version`") orelse "0.0.0",
|
||||
.sha = git_sha,
|
||||
.baseline = is_baseline,
|
||||
.bindgen = false,
|
||||
@@ -299,8 +373,9 @@ pub fn build_(b: *Build) !void {
|
||||
min_version,
|
||||
max_version,
|
||||
obj.target.getCpuModel().name,
|
||||
}) catch unreachable;
|
||||
std.io.getStdErr().writer().print("Output: {s}/{s}\n\n", .{ output_dir, bun_executable_name }) catch unreachable;
|
||||
}) catch {};
|
||||
std.io.getStdErr().writer().print("Zig {s}\n", .{@import("builtin").zig_version_string}) catch {};
|
||||
// std.io.getStdErr().writer().print("Output: {s}/{s}\n\n", .{ output_dir, bun_executable_name }) catch unreachable;
|
||||
|
||||
defer obj_step.dependOn(&obj.step);
|
||||
|
||||
@@ -319,13 +394,22 @@ pub fn build_(b: *Build) !void {
|
||||
|
||||
obj.addOptions("build_options", actual_build_options.step(b));
|
||||
|
||||
obj.linkLibC();
|
||||
// Generated Code
|
||||
// TODO: exit with a better error early if these files do not exist. it is an indication someone ran `zig build` directly without the code generators.
|
||||
obj.addModule("generated/ZigGeneratedClasses.zig", b.createModule(.{
|
||||
.source_file = .{ .path = b.fmt("{s}/ZigGeneratedClasses.zig", .{generated_code_directory}) },
|
||||
}));
|
||||
obj.addModule("generated/ResolvedSourceTag.zig", b.createModule(.{
|
||||
.source_file = .{ .path = b.fmt("{s}/ResolvedSourceTag.zig", .{generated_code_directory}) },
|
||||
}));
|
||||
|
||||
obj.linkLibC();
|
||||
obj.dll_export_fns = true;
|
||||
obj.strip = false;
|
||||
obj.bundle_compiler_rt = false;
|
||||
obj.omit_frame_pointer = optimize != .Debug;
|
||||
obj.subsystem = .Console;
|
||||
// Disable stack probing on x86 so we don't need to include compiler_rt
|
||||
if (target.getCpuArch().isX86()) obj.disable_stack_probing = true;
|
||||
if (target.getCpuArch().isX86() or target.isWindows()) obj.disable_stack_probing = true;
|
||||
|
||||
if (b.option(bool, "for-editor", "Do not emit bin, just check for errors") orelse false) {
|
||||
// obj.emit_bin = .no_emit;
|
||||
|
||||
Reference in New Issue
Block a user