Skip to content

Commit e215d59

Browse files
committed
Zig 0.14 compatibility
1 parent 2148c4b commit e215d59

File tree

5 files changed

+21
-25
lines changed

5 files changed

+21
-25
lines changed

.github/workflows/build-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ permissions:
1111
contents: write
1212

1313
env:
14-
ZIG_VERSION: 0.13.0
14+
ZIG_VERSION: 0.14.0
1515

1616
jobs:
1717
build-x86_64-linux:

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Static libs are built and released with [Github Actions](https://github.com/fuba
2424
\* Time is measured on standard Github instances.
2525

2626
## System Requirements
27-
- Zig compiler (0.13.0). You can get that [here](https://ziglang.org/download/).
27+
- Zig compiler (0.14.0). Clone and build https://github.com/ziglang/zig.
2828
- Python 3 (2.7 seems to work as well)
2929
- For native macOS builds:
3030
- XCode (You won't need this when using zig's c++ toolchain!)<br/>
@@ -50,17 +50,17 @@ zig build get-v8
5050

5151
# Build, resulting static library should be at:
5252
# v8-build/{target}/{debug/release}/ninja/obj/zig/libc_v8.a
53-
# On windows, use msvc: zig build -Drelease-safe -Dtarget=x86_64-windows-msvc
54-
zig build -Drelease-safe
53+
# On windows, use msvc: zig build zig build -Doptimize=ReleaseSafe -Dtarget=x86_64-windows-msvc
54+
zig build -Doptimize=ReleaseSafe
5555
```
5656
## Demo
5757
```sh
5858
# shell.zig is a simple JS repl.
5959
# Assumes you've already built v8.
60-
zig build run -Dpath="src/shell.zig" -Drelease-safe
60+
zig build run -Dpath="src/shell.zig" -Doptimize=ReleaseSafe
6161

6262
# If you built v8 using the zig toolchain, you'll need to add the flag here as well.
63-
zig build run -Dpath="src/shell.zig" -Drelease-safe -Dzig-toolchain
63+
zig build run -Dpath="src/shell.zig" -Doptimize=ReleaseSafe -Dzig-toolchain
6464
```
6565

6666
## Cross Compiling
@@ -70,13 +70,13 @@ With Zig's toolchain, we can build V8 from libstdc++ that's bundled with zig and
7070
# Assumes you've fetched tools and v8 sources. See above build steps.
7171
# Resulting static lib will be at:
7272
# v8-build/aarch64-macos/release/ninja/obj/zig/libc_v8.a
73-
zig build -Drelease-safe -Dtarget=aarch64-macos-gnu -Dzig-toolchain
73+
zig build -Doptimize=ReleaseSafe -Dtarget=aarch64-macos-gnu -Dzig-toolchain
7474
```
7575

7676
### Cross compile to Windows with gnu (mingw64)
7777
Zig comes with mingw64 source and headers so you'll be able to target Windows without MSVC.
7878
```sh
79-
zig build -Drelease-safe -Dtarget=x86_64-windows-gnu -Dzig-toolchain
79+
zig build -Doptimize=ReleaseSafe -Dtarget=x86_64-windows-gnu -Dzig-toolchain
8080
```
8181

8282
## Usage

build.zig

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn createV8_Build(b: *std.Build, target: std.Build.ResolvedTarget, mode: std.bui
127127

128128
if (use_zig_tc) {
129129
// Set target and cpu for building the lib.
130-
// TODO: If mcpu is equavalent to -Dcpu then use that instead
130+
// TODO: If mcpu is equivalent to -Dcpu then use that instead
131131
try zig_cc.append(b.fmt("zig cc --target={s} -mcpu=baseline", .{try target.result.zigTriple(b.allocator)}));
132132
try zig_cxx.append(b.fmt("zig c++ --target={s} -mcpu=baseline", .{try target.result.zigTriple(b.allocator)}));
133133

@@ -228,7 +228,7 @@ fn createV8_Build(b: *std.Build, target: std.Build.ResolvedTarget, mode: std.bui
228228
}
229229
if (target.result.os.tag == .linux and target.result.cpu.arch == .aarch64) {
230230
// On linux aarch64, we can not use the clang version provided in v8 sources
231-
// as it's built for x86_64 (TODO: using Rosetta2 for Linux VM on Apple Sillicon?)
231+
// as it's built for x86_64 (TODO: using Rosetta2 for Linux VM on Apple Silicon?)
232232
// Instead we can use a clang system version
233233
// as long as we use the same version number (currently clang-16)
234234
// Currently v8 uses clang-16 but Debian/Ubuntu are using older versions
@@ -332,8 +332,7 @@ const CheckV8DepsStep = struct {
332332
return step;
333333
}
334334

335-
fn make(step: *Step, prog_node: *std.Progress.Node) anyerror!void {
336-
_ = prog_node;
335+
fn make(step: *Step, _: Step.MakeOptions) anyerror!void {
337336
const output = try step.evalChildProcess(&.{ "clang", "--version" });
338337
print("clang: {s}", .{output});
339338

@@ -439,8 +438,7 @@ const MakePathStep = struct {
439438
return new;
440439
}
441440

442-
fn make(step: *Step, prog_node: std.Progress.Node) anyerror!void {
443-
_ = prog_node;
441+
fn make(step: *Step, _: Step.MakeOptions) anyerror!void {
444442
const self: *Self = @fieldParentPtr("step", step);
445443
try std.fs.cwd().makePath(self.b.pathFromRoot(self.path));
446444
}
@@ -470,8 +468,7 @@ const CopyFileStep = struct {
470468
return new;
471469
}
472470

473-
fn make(step: *Step, prog_node: std.Progress.Node) anyerror!void {
474-
_ = prog_node;
471+
fn make(step: *Step, _: Step.MakeOptions) anyerror!void {
475472
const self: *Self = @fieldParentPtr("step", step);
476473
try std.fs.copyFileAbsolute(self.src_path, self.dst_path, .{});
477474
}
@@ -641,8 +638,7 @@ pub const GetV8SourceStep = struct {
641638
}
642639
}
643640

644-
fn make(step: *Step, prog_node: std.Progress.Node) anyerror!void {
645-
_ = prog_node;
641+
fn make(step: *Step, _: Step.MakeOptions) anyerror!void {
646642
const self: *Self = @fieldParentPtr("step", step);
647643

648644
// Pull the minimum source we need by looking at DEPS.
@@ -804,5 +800,5 @@ fn statPathFromRoot(b: *std.Build, path_rel: []const u8) !PathStat {
804800
}
805801

806802
fn isMinZigVersion() bool {
807-
return builtin.zig_version.major == 0 and builtin.zig_version.minor == 12;
803+
return builtin.zig_version.major == 0 and builtin.zig_version.minor == 14;
808804
}

src/shell.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ pub fn executeString(alloc: std.mem.Allocator, isolate: v8.Isolate, src: []const
120120
try_catch.init(isolate);
121121
defer try_catch.deinit();
122122

123-
var origin = v8.ScriptOrigin.initDefault(isolate, src_origin.toValue());
123+
const origin = v8.ScriptOrigin.initDefault(isolate, src_origin.toValue());
124124

125-
var context = isolate.getCurrentContext();
125+
const context = isolate.getCurrentContext();
126126

127127
const js_src = v8.String.initUtf8(isolate, src);
128128

src/v8.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ pub const Function = struct {
780780
} else return null;
781781
}
782782

783-
// Equavalent to js "new".
783+
// Equivalent to js "new".
784784
pub fn initInstance(self: Self, ctx: Context, args: []const Value) ?Object {
785785
const c_args = @as(?[*]const ?*c.Value, @ptrCast(args.ptr));
786786
if (c.v8__Function__NewInstance(self.handle, ctx.handle, @as(c_int, @intCast(args.len)), c_args)) |ret| {
@@ -816,7 +816,7 @@ pub const Function = struct {
816816
pub fn Persistent(comptime T: type) type {
817817
comptime var handleT: type = undefined;
818818
comptime {
819-
for (@typeInfo(T).Struct.fields) |field| {
819+
for (@typeInfo(T).@"struct".fields) |field| {
820820
if (!std.mem.eql(u8, field.name, "handle")) {
821821
continue;
822822
}
@@ -1770,7 +1770,7 @@ pub const Module = struct {
17701770
} else return error.JsException;
17711771
}
17721772

1773-
/// Evaulates the module, assumes module has been instantiated.
1773+
/// Evaluates the module, assumes module has been instantiated.
17741774
/// [v8]
17751775
/// Evaluates the module and its dependencies.
17761776
///
@@ -2312,7 +2312,7 @@ pub const Inspector = struct {
23122312
// Set when a context is created.
23132313
ctx_handle: ?*const C_Context = null,
23142314

2315-
const RndGen = std.rand.DefaultPrng;
2315+
const RndGen = std.Random.DefaultPrng;
23162316

23172317
const contextGroupId = 1;
23182318
const clientTrustLevel = 1;

0 commit comments

Comments
 (0)