Skip to content

Commit 13f64a7

Browse files
committed
Update build.zig so that it will work with 0.15
Bunch of things were deprecated in 0.14 that we were still using, and they're removed in 0.15.
1 parent 78da3d3 commit 13f64a7

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

build.zig

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const std = @import("std");
33
const LazyPath = std.Build.LazyPath;
44

55
pub fn build(b: *std.Build) !void {
6-
const mode = b.standardOptimizeOption(.{});
76
const target = b.standardTargetOptions(.{});
7+
const optimize = b.standardOptimizeOption(.{});
88

99
var build_opts = b.addOptions();
1010
build_opts.addOption(
@@ -13,29 +13,35 @@ pub fn build(b: *std.Build) !void {
1313
b.option(bool, "inspector_subtype", "Export default valueSubtype and descriptionForValueSubtype") orelse true,
1414
);
1515

16-
{
17-
// the module we export as a library
18-
const v8_module = b.addModule("v8", .{
19-
.root_source_file = b.path("src/v8.zig"),
20-
});
21-
v8_module.addIncludePath(b.path("src"));
22-
v8_module.addImport("default_exports", build_opts.createModule());
23-
}
16+
// the module we export as a library
17+
const v8_module = b.addModule("v8", .{
18+
.root_source_file = b.path("src/v8.zig"),
19+
.target = target,
20+
.optimize = optimize,
21+
.link_libc = true,
22+
.link_libcpp = true,
23+
});
24+
v8_module.addIncludePath(b.path("src"));
25+
v8_module.addImport("default_exports", build_opts.createModule());
2426

2527
const root_path = LazyPath{ .cwd_relative = "." };
2628
const build_path = LazyPath{ .cwd_relative = "./v8/" };
2729

30+
const build_module = b.addModule("v8_build", .{
31+
.root_source_file = b.path("src/main_build.zig"),
32+
.target = target,
33+
.optimize = optimize,
34+
});
35+
2836
{
2937
// Get V8
3038
const get_v8 = b.addExecutable(.{
3139
.name = "get-v8",
32-
.optimize = mode,
33-
.target = target,
34-
.root_source_file = b.path("src/main_build.zig"),
40+
.root_module = build_module,
3541
});
3642

3743
const mkdir_v8_dir = blk: {
38-
var mkdir_v8_dir = b.addSystemCommand(&.{ "mkdir", "-p"});
44+
var mkdir_v8_dir = b.addSystemCommand(&.{ "mkdir", "-p" });
3945
mkdir_v8_dir.addDirectoryArg(build_path);
4046
mkdir_v8_dir.setCwd(root_path);
4147
break :blk mkdir_v8_dir;
@@ -53,14 +59,14 @@ pub fn build(b: *std.Build) !void {
5359
};
5460

5561
const run_get_tools = blk: {
56-
var run_get_tools = b.addSystemCommand(&.{"/bin/bash", "get_tools.sh"});
62+
var run_get_tools = b.addSystemCommand(&.{ "/bin/bash", "get_tools.sh" });
5763
run_get_tools.setCwd(build_path);
5864
run_get_tools.step.dependOn(&cp_build_files.step);
5965
break :blk run_get_tools;
6066
};
6167

6268
const run_v8_source = blk: {
63-
var run_v8_source = b.addSystemCommand(&.{"/bin/bash", "get_v8.sh"});
69+
var run_v8_source = b.addSystemCommand(&.{ "/bin/bash", "get_v8.sh" });
6470
run_v8_source.setCwd(build_path);
6571
run_v8_source.step.dependOn(&run_get_tools.step);
6672
break :blk run_v8_source;
@@ -83,15 +89,13 @@ pub fn build(b: *std.Build) !void {
8389
// build V8
8490
const build_v8 = b.addExecutable(.{
8591
.name = "build-v8",
86-
.optimize = mode,
87-
.target = target,
88-
.root_source_file = b.path("src/main_build.zig"),
92+
.root_module = build_module,
8993
});
9094

9195
const run_build = blk: {
92-
var run_build = b.addSystemCommand(&.{"/bin/bash", "build_v8.sh"});
96+
var run_build = b.addSystemCommand(&.{ "/bin/bash", "build_v8.sh" });
9397
run_build.addDirectoryArg(b.path("src"));
94-
run_build.addArg(if (mode == .Debug) "debug" else "release");
98+
run_build.addArg(if (optimize == .Debug) "debug" else "release");
9599
run_build.setCwd(build_path);
96100
break :blk run_build;
97101
};
@@ -110,36 +114,41 @@ pub fn build(b: *std.Build) !void {
110114
}
111115

112116
{
113-
// test
114-
const step = b.addTest(.{
115-
.root_source_file = b.path("./src/test.zig"),
117+
const test_module = b.addModule("test_v8", .{
118+
.root_source_file = b.path("src/v8.zig"),
116119
.target = target,
117-
.optimize = mode,
120+
.optimize = optimize,
118121
.link_libc = true,
122+
.link_libcpp = true,
123+
});
124+
125+
// test
126+
const tests = b.addTest(.{
127+
.root_module = test_module,
119128
});
120-
step.linkLibCpp();
121-
step.root_module.addImport("default_exports", build_opts.createModule());
129+
tests.root_module.addImport("default_exports", build_opts.createModule());
122130

123-
const release_dir = if (mode == .Debug) "debug" else "release";
131+
const release_dir = if (optimize == .Debug) "debug" else "release";
124132
const os = switch (target.result.os.tag) {
125133
.linux => "linux",
126134
.macos => "macos",
127135
else => return error.UnsupportedPlatform,
128136
};
129137

130-
step.addObjectFile(b.path(b.fmt("v8/out/{s}/{s}/obj/zig/libc_v8.a", .{ os, release_dir })));
131-
step.addIncludePath(b.path("src"));
138+
tests.addObjectFile(b.path(b.fmt("v8/out/{s}/{s}/obj/zig/libc_v8.a", .{ os, release_dir })));
139+
tests.addIncludePath(b.path("src"));
132140

133141
switch (target.result.os.tag) {
134142
.macos => {
135143
// v8 has a dependency, abseil-cpp, which, on Mac, uses CoreFoundation
136-
step.addSystemFrameworkPath(.{ .cwd_relative = "/System/Library/Frameworks" });
137-
step.linkFramework("CoreFoundation");
144+
tests.addSystemFrameworkPath(.{ .cwd_relative = "/System/Library/Frameworks" });
145+
tests.linkFramework("CoreFoundation");
138146
},
139147
else => {},
140148
}
141149

142-
const run_test = b.addRunArtifact(step);
143-
b.step("test", "Run tests.").dependOn(&run_test.step);
150+
const run_tests = b.addRunArtifact(tests);
151+
const tests_step = b.step("test", "Run unit tests");
152+
tests_step.dependOn(&run_tests.step);
144153
}
145154
}

0 commit comments

Comments
 (0)