Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update zig to 0.11.0 #4233

Merged
merged 19 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/zig-fmt.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: zig-fmt

env:
ZIG_VERSION: 0.11.0-dev.4006+bf827d0b5
ZIG_VERSION: 0.12.0-dev.161+6a5463951

on:
pull_request:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ src/js/out/tmp
src/js/out/DebugPath.h

make-dev-stats.csv

.uuid
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ARG TRIPLET=${ARCH}-linux-gnu
ARG BUILDARCH=amd64
ARG WEBKIT_TAG=2023-aug3-5
ARG ZIG_TAG=jul1
ARG ZIG_VERSION="0.11.0-dev.4006+bf827d0b5"
ARG ZIG_VERSION="0.12.0-dev.161+6a5463951"
ARG WEBKIT_BASENAME="bun-webkit-linux-$BUILDARCH"

ARG ZIG_FOLDERNAME=zig-linux-${BUILD_MACHINE_ARCH}-${ZIG_VERSION}
Expand Down
98 changes: 62 additions & 36 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("std");
const pathRel = std.fs.path.relative;
const Wyhash = @import("./src/wyhash.zig").Wyhash;
var is_debug_build = false;
fn moduleSource(comptime out: []const u8) FileSource {
Expand Down Expand Up @@ -96,6 +97,7 @@ const BunBuildOptions = struct {
}
};

// relative to the prefix
var output_dir: []const u8 = "";
fn panicIfNotFound(comptime filepath: []const u8) []const u8 {
var file = std.fs.cwd().openFile(filepath, .{ .optimize = .read_only }) catch |err| {
Expand Down Expand Up @@ -172,26 +174,25 @@ 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 = b.pathFromRoot(output_dir_);
output_dir = try pathRel(b.allocator, b.install_prefix, output_dir_);
} else {
const output_dir_base = try std.fmt.bufPrint(&output_dir_buf, "{s}{s}", .{ bin_label, triplet });
output_dir = b.pathFromRoot(output_dir_base);
output_dir = try pathRel(b.allocator, b.install_prefix, output_dir_base);
}

std.fs.cwd().makePath(output_dir) catch {};
is_debug_build = optimize == OptimizeMode.Debug;
const bun_executable_name = if (optimize == std.builtin.OptimizeMode.Debug) "bun-debug" else "bun";
const root_src = if (target.getOsTag() == std.Target.Os.Tag.freestanding)
"root_wasm.zig"
else
"root.zig";

const min_version: std.SemanticVersion = if (target.getOsTag() != .freestanding and !target.isWindows())
const min_version: std.SemanticVersion = if (target.getOsTag() != .freestanding)
target.getOsVersionMin().semver
else
.{ .major = 0, .minor = 0, .patch = 0 };

const max_version: std.SemanticVersion = if (target.getOsTag() != .freestanding and !target.isWindows())
const max_version: std.SemanticVersion = if (target.getOsTag() != .freestanding)
target.getOsVersionMax().semver
else
.{ .major = 0, .minor = 0, .patch = 0 };
Expand All @@ -202,6 +203,7 @@ pub fn build(b: *Build) !void {
.root_source_file = FileSource.relative(root_src),
.target = target,
.optimize = optimize,
.main_pkg_path = .{ .cwd_relative = b.pathFromRoot(".") },
});

var default_build_options: BunBuildOptions = brk: {
Expand Down Expand Up @@ -239,8 +241,6 @@ pub fn build(b: *Build) !void {
};

{
obj.setMainPkgPath(b.pathFromRoot("."));

try addInternalPackages(
b,
obj,
Expand Down Expand Up @@ -271,9 +271,15 @@ pub fn build(b: *Build) !void {
std.io.getStdErr().writer().print("Output: {s}/{s}\n\n", .{ output_dir, bun_executable_name }) catch unreachable;

defer obj_step.dependOn(&obj.step);
obj.emit_bin = .{
.emit_to = b.fmt("{s}/{s}.o", .{ output_dir, bun_executable_name }),
};

var install = b.addInstallFileWithDir(
obj.getEmittedBin(),
.{ .custom = output_dir },
b.fmt("{s}.o", .{bun_executable_name}),
);
install.step.dependOn(&obj.step);
obj_step.dependOn(&install.step);

var actual_build_options = default_build_options;
if (b.option(bool, "generate-sizes", "Generate sizes of things") orelse false) {
actual_build_options.sizegen = true;
Expand All @@ -290,7 +296,8 @@ pub fn build(b: *Build) !void {
if (target.getCpuArch().isX86()) 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;
// obj.emit_bin = .no_emit;
obj.generated_bin = null;
}

if (target.getOsTag() == .linux) {
Expand All @@ -308,31 +315,33 @@ pub fn build(b: *Build) !void {
.root_source_file = FileSource.relative("src/bindgen.zig"),
.target = target,
.optimize = optimize,
.main_pkg_path = obj.main_pkg_path,
});
defer headers_step.dependOn(&headers_obj.step);
try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?);
try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target);
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();
}

{
const wasm = b.step("bun-wasm", "Build WASM");
var wasm_step = b.addStaticLibrary(.{
const wasm_step = b.step("bun-wasm", "Build WASM");
var wasm = b.addStaticLibrary(.{
.name = "bun-wasm",
.root_source_file = FileSource.relative("root_wasm.zig"),
.target = target,
.optimize = optimize,
.main_pkg_path = obj.main_pkg_path,
});
defer wasm.dependOn(&wasm_step.step);
wasm_step.strip = false;
defer wasm_step.dependOn(&wasm.step);
wasm.strip = false;
// wasm_step.link_function_sections = true;
// wasm_step.link_emit_relocs = true;
// wasm_step.single_threaded = true;
try configureObjectStep(b, wasm_step, @TypeOf(target), target, obj.main_pkg_path.?);
try configureObjectStep(b, wasm, wasm_step, @TypeOf(target), target);
var build_opts = default_build_options;
wasm_step.addOptions("build_options", build_opts.step(b));
wasm.addOptions("build_options", build_opts.step(b));
}

{
Expand All @@ -342,9 +351,10 @@ pub fn build(b: *Build) !void {
.root_source_file = FileSource.relative("misctools/http_bench.zig"),
.target = target,
.optimize = optimize,
.main_pkg_path = obj.main_pkg_path,
});
defer headers_step.dependOn(&headers_obj.step);
try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?);
try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target);
headers_obj.addOptions("build_options", default_build_options.step(b));
}

Expand All @@ -355,9 +365,10 @@ pub fn build(b: *Build) !void {
.root_source_file = FileSource.relative("misctools/machbench.zig"),
.target = target,
.optimize = optimize,
.main_pkg_path = obj.main_pkg_path,
});
defer headers_step.dependOn(&headers_obj.step);
try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?);
try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target);
headers_obj.addOptions("build_options", default_build_options.step(b));
}

Expand All @@ -368,9 +379,10 @@ pub fn build(b: *Build) !void {
.root_source_file = FileSource.relative("misctools/fetch.zig"),
.target = target,
.optimize = optimize,
.main_pkg_path = obj.main_pkg_path,
});
defer headers_step.dependOn(&headers_obj.step);
try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?);
try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target);
headers_obj.addOptions("build_options", default_build_options.step(b));
}

Expand All @@ -381,9 +393,10 @@ pub fn build(b: *Build) !void {
.root_source_file = FileSource.relative("src/bench/string-handling.zig"),
.target = target,
.optimize = optimize,
.main_pkg_path = obj.main_pkg_path,
});
defer headers_step.dependOn(&headers_obj.step);
try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?);
try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target);
headers_obj.addOptions("build_options", default_build_options.step(b));
}

Expand All @@ -394,9 +407,10 @@ pub fn build(b: *Build) !void {
.root_source_file = FileSource.relative("src/sha.zig"),
.target = target,
.optimize = optimize,
.main_pkg_path = obj.main_pkg_path,
});
defer headers_step.dependOn(&headers_obj.step);
try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?);
try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target);
headers_obj.addOptions("build_options", default_build_options.step(b));
}

Expand All @@ -407,9 +421,10 @@ pub fn build(b: *Build) !void {
.root_source_file = FileSource.relative("src/sourcemap/vlq_bench.zig"),
.target = target,
.optimize = optimize,
.main_pkg_path = obj.main_pkg_path,
});
defer headers_step.dependOn(&headers_obj.step);
try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?);
try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target);
headers_obj.addOptions("build_options", default_build_options.step(b));
}

Expand All @@ -420,9 +435,10 @@ pub fn build(b: *Build) !void {
.root_source_file = FileSource.relative("misctools/tgz.zig"),
.target = target,
.optimize = optimize,
.main_pkg_path = obj.main_pkg_path,
});
defer headers_step.dependOn(&headers_obj.step);
try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?);
try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target);
headers_obj.addOptions("build_options", default_build_options.step(b));
}

Expand All @@ -436,16 +452,23 @@ pub fn build(b: *Build) !void {
var headers_obj: *CompileStep = b.addTest(.{
.root_source_file = FileSource.relative(test_file orelse "src/main.zig"),
.target = target,
.main_pkg_path = obj.main_pkg_path,
});
headers_obj.filter = test_filter;
if (test_bin_) |test_bin| {
headers_obj.name = std.fs.path.basename(test_bin);
if (std.fs.path.dirname(test_bin)) |dir| headers_obj.emit_bin = .{
.emit_to = b.fmt("{s}/{s}", .{ dir, headers_obj.name }),
};
if (std.fs.path.dirname(test_bin)) |dir| {
var install = b.addInstallFileWithDir(
headers_obj.getEmittedBin(),
.{ .custom = try std.fs.path.relative(b.allocator, output_dir, dir) },
headers_obj.name,
);
install.step.dependOn(&headers_obj.step);
headers_step.dependOn(&install.step);
}
}

try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?);
try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target);

headers_step.dependOn(&headers_obj.step);
headers_obj.addOptions("build_options", default_build_options.step(b));
Expand All @@ -456,21 +479,24 @@ pub fn build(b: *Build) !void {

pub var original_make_fn: ?*const fn (step: *std.build.Step) anyerror!void = null;

pub fn configureObjectStep(b: *std.build.Builder, obj: *CompileStep, comptime Target: type, target: Target, main_pkg_path: []const u8) !void {
obj.setMainPkgPath(main_pkg_path);

pub fn configureObjectStep(b: *std.build.Builder, obj: *CompileStep, obj_step: *std.build.Step, comptime Target: type, target: Target) !void {
// obj.setTarget(target);
try addInternalPackages(b, obj, std.heap.page_allocator, b.zig_exe, target);

obj.strip = false;

// obj.setBuildMode(optimize);
obj.bundle_compiler_rt = false;
if (obj.emit_bin == .default)
obj.emit_bin = .{
.emit_to = b.fmt("{s}/{s}.o", .{ output_dir, obj.name }),
};
if (obj.emit_directory == null) {
var install = b.addInstallFileWithDir(
obj.getEmittedBin(),
.{ .custom = output_dir },
b.fmt("{s}.o", .{obj.name}),
);

install.step.dependOn(&obj.step);
obj_step.dependOn(&install.step);
}
if (target.getOsTag() != .freestanding) obj.linkLibC();
if (target.getOsTag() != .freestanding) obj.bundle_compiler_rt = false;

Expand Down
2 changes: 1 addition & 1 deletion docs/project/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Zig can be installed either with our npm package [`@oven/zig`](https://www.npmjs

```bash
$ bun install -g @oven/zig
$ zigup 0.11.0-dev.4006+bf827d0b5
$ zigup 0.12.0-dev.161+6a5463951
```

{% callout %}
Expand Down
12 changes: 6 additions & 6 deletions src/analytics/analytics_schema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ pub const analytics = struct {

_,

pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void {
return try std.json.stringify(@tagName(self), opts, o);
pub fn jsonStringify(self: *const @This(), writer: anytype) !void {
return try writer.write(@tagName(self));
}
};

Expand All @@ -361,8 +361,8 @@ pub const analytics = struct {

_,

pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void {
return try std.json.stringify(@tagName(self), opts, o);
pub fn jsonStringify(self: *const @This(), writer: anytype) !void {
return try writer.write(@tagName(self));
}
};

Expand Down Expand Up @@ -411,8 +411,8 @@ pub const analytics = struct {

_,

pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void {
return try std.json.stringify(@tagName(self), opts, o);
pub fn jsonStringify(self: *const @This(), writer: anytype) !void {
return try writer.write(@tagName(self));
}
};

Expand Down
Loading