Skip to content

Commit 557f844

Browse files
authored
Merge pull request #955 from lightpanda-io/replace_deprecated_build
Makes build.zig Zig 0.15 ready
2 parents 7cc9521 + 65088b8 commit 557f844

File tree

2 files changed

+55
-51
lines changed

2 files changed

+55
-51
lines changed

build.zig

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,22 @@ pub fn build(b: *Build) !void {
4949
const target = b.standardTargetOptions(.{});
5050
const optimize = b.standardOptimizeOption(.{});
5151

52+
const lightpanda_module = b.addModule("lightpanda", .{
53+
.root_source_file = b.path("src/main.zig"),
54+
.target = target,
55+
.optimize = optimize,
56+
});
57+
try addDependencies(b, lightpanda_module, opts);
58+
5259
{
5360
// browser
5461
// -------
5562

5663
// compile and install
5764
const exe = b.addExecutable(.{
5865
.name = "lightpanda",
59-
.target = target,
60-
.optimize = optimize,
61-
.root_source_file = b.path("src/main.zig"),
66+
.root_module = lightpanda_module,
6267
});
63-
64-
try common(b, opts, exe);
6568
b.installArtifact(exe);
6669

6770
// run
@@ -75,36 +78,15 @@ pub fn build(b: *Build) !void {
7578
run_step.dependOn(&run_cmd.step);
7679
}
7780

78-
{
79-
// get v8
80-
// -------
81-
const v8 = b.dependency("v8", .{ .target = target, .optimize = optimize });
82-
const get_v8 = b.addRunArtifact(v8.artifact("get-v8"));
83-
const get_step = b.step("get-v8", "Get v8");
84-
get_step.dependOn(&get_v8.step);
85-
}
86-
87-
{
88-
// build v8
89-
// -------
90-
const v8 = b.dependency("v8", .{ .target = target, .optimize = optimize });
91-
const build_v8 = b.addRunArtifact(v8.artifact("build-v8"));
92-
const build_step = b.step("build-v8", "Build v8");
93-
build_step.dependOn(&build_v8.step);
94-
}
95-
9681
{
9782
// tests
9883
// ----
9984

10085
// compile
10186
const tests = b.addTest(.{
102-
.root_source_file = b.path("src/main.zig"),
87+
.root_module = lightpanda_module,
10388
.test_runner = .{ .path = b.path("src/test_runner.zig"), .mode = .simple },
104-
.target = target,
105-
.optimize = optimize,
10689
});
107-
try common(b, opts, tests);
10890

10991
const run_tests = b.addRunArtifact(tests);
11092
if (b.args) |args| {
@@ -119,15 +101,18 @@ pub fn build(b: *Build) !void {
119101
{
120102
// wpt
121103
// -----
104+
const wpt_module = b.createModule(.{
105+
.root_source_file = b.path("src/main_wpt.zig"),
106+
.target = target,
107+
.optimize = optimize,
108+
});
109+
try addDependencies(b, wpt_module, opts);
122110

123111
// compile and install
124112
const wpt = b.addExecutable(.{
125113
.name = "lightpanda-wpt",
126-
.root_source_file = b.path("src/main_wpt.zig"),
127-
.target = target,
128-
.optimize = optimize,
114+
.root_module = wpt_module,
129115
});
130-
try common(b, opts, wpt);
131116

132117
// run
133118
const wpt_cmd = b.addRunArtifact(wpt);
@@ -138,24 +123,42 @@ pub fn build(b: *Build) !void {
138123
const wpt_step = b.step("wpt", "WPT tests");
139124
wpt_step.dependOn(&wpt_cmd.step);
140125
}
126+
127+
{
128+
// get v8
129+
// -------
130+
const v8 = b.dependency("v8", .{ .target = target, .optimize = optimize });
131+
const get_v8 = b.addRunArtifact(v8.artifact("get-v8"));
132+
const get_step = b.step("get-v8", "Get v8");
133+
get_step.dependOn(&get_v8.step);
134+
}
135+
136+
{
137+
// build v8
138+
// -------
139+
const v8 = b.dependency("v8", .{ .target = target, .optimize = optimize });
140+
const build_v8 = b.addRunArtifact(v8.artifact("build-v8"));
141+
const build_step = b.step("build-v8", "Build v8");
142+
build_step.dependOn(&build_v8.step);
143+
}
141144
}
142145

143-
fn common(b: *Build, opts: *Build.Step.Options, step: *Build.Step.Compile) !void {
144-
const mod = step.root_module;
146+
fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !void {
147+
try moduleNetSurf(b, mod);
148+
mod.addImport("build_config", opts.createModule());
149+
145150
const target = mod.resolved_target.?;
146-
const optimize = mod.optimize.?;
147-
const dep_opts = .{ .target = target, .optimize = optimize };
151+
const dep_opts = .{
152+
.target = target,
153+
.optimize = mod.optimize.?,
154+
};
148155

149-
try moduleNetSurf(b, step, target);
150-
mod.addImport("build_config", opts.createModule());
151156
mod.addImport("tigerbeetle-io", b.dependency("tigerbeetle_io", .{}).module("tigerbeetle_io"));
152157

153158
mod.addIncludePath(b.path("vendor/lightpanda"));
154159

155160
{
156161
// v8
157-
mod.link_libcpp = true;
158-
159162
const v8_opts = b.addOptions();
160163
v8_opts.addOption(bool, "inspector_subtype", false);
161164

@@ -386,7 +389,8 @@ fn common(b: *Build, opts: *Build.Step.Options, step: *Build.Step.Compile) !void
386389
}
387390
}
388391

389-
fn moduleNetSurf(b: *Build, step: *Build.Step.Compile, target: std.Build.ResolvedTarget) !void {
392+
fn moduleNetSurf(b: *Build, mod: *Build.Module) !void {
393+
const target = mod.resolved_target.?;
390394
const os = target.result.os.tag;
391395
const arch = target.result.cpu.arch;
392396

@@ -401,8 +405,8 @@ fn moduleNetSurf(b: *Build, step: *Build.Step.Compile, target: std.Build.Resolve
401405
"vendor/libiconv/out/{s}-{s}/lib/libiconv.a",
402406
.{ @tagName(os), @tagName(arch) },
403407
);
404-
step.addObjectFile(b.path(libiconv_lib_path));
405-
step.addIncludePath(b.path(libiconv_include_path));
408+
mod.addObjectFile(b.path(libiconv_lib_path));
409+
mod.addIncludePath(b.path(libiconv_include_path));
406410

407411
{
408412
// mimalloc
@@ -412,8 +416,8 @@ fn moduleNetSurf(b: *Build, step: *Build.Step.Compile, target: std.Build.Resolve
412416
mimalloc ++ "/out/{s}-{s}/lib/libmimalloc.a",
413417
.{ @tagName(os), @tagName(arch) },
414418
);
415-
step.addObjectFile(b.path(lib_path));
416-
step.addIncludePath(b.path(mimalloc ++ "/include"));
419+
mod.addObjectFile(b.path(lib_path));
420+
mod.addIncludePath(b.path(mimalloc ++ "/include"));
417421
}
418422

419423
// netsurf libs
@@ -423,7 +427,7 @@ fn moduleNetSurf(b: *Build, step: *Build.Step.Compile, target: std.Build.Resolve
423427
ns ++ "/out/{s}-{s}/include",
424428
.{ @tagName(os), @tagName(arch) },
425429
);
426-
step.addIncludePath(b.path(ns_include_path));
430+
mod.addIncludePath(b.path(ns_include_path));
427431

428432
const libs: [4][]const u8 = .{
429433
"libdom",
@@ -437,8 +441,8 @@ fn moduleNetSurf(b: *Build, step: *Build.Step.Compile, target: std.Build.Resolve
437441
ns ++ "/out/{s}-{s}/lib/" ++ lib ++ ".a",
438442
.{ @tagName(os), @tagName(arch) },
439443
);
440-
step.addObjectFile(b.path(ns_lib_path));
441-
step.addIncludePath(b.path(ns ++ "/" ++ lib ++ "/src"));
444+
mod.addObjectFile(b.path(ns_lib_path));
445+
mod.addIncludePath(b.path(ns ++ "/" ++ lib ++ "/src"));
442446
}
443447
}
444448

build.zig.zon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
.fingerprint = 0xda130f3af836cea0,
66
.dependencies = .{
77
.tigerbeetle_io = .{
8-
.url = "https://github.com/lightpanda-io/tigerbeetle-io/archive/61d9652f1a957b7f4db723ea6aa0ce9635e840ce.tar.gz",
9-
.hash = "tigerbeetle_io-0.0.0-ViLgxpyRBAB5BMfIcj3KMXfbJzwARs9uSl8aRy2OXULd",
8+
.url = "https://github.com/lightpanda-io/tigerbeetle-io/archive/19ae89eb3814d48c202ac9e0495fc5cadb29dfe7.tar.gz",
9+
.hash = "tigerbeetle_io-0.0.0-ViLgxjqSBADhuHO_RZm4yNzuoKDXWP39hDn60Kht40OC",
1010
},
1111
.v8 = .{
12-
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/b22911e02e4884a76acf52aa9aff2ba169d05b40.tar.gz",
13-
.hash = "v8-0.0.0-xddH69zCAwAzm1u5cQVa-uG5ib2y6PpENXCl8yEYdUYk",
12+
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/cf412d5b3d9d608582571d821e0d552337ef690d.tar.gz",
13+
.hash = "v8-0.0.0-xddH69zDAwA4fp1dBo_jEDjS5bhXycPwRlZHp6_X890t",
1414
},
1515
//.v8 = .{ .path = "../zig-v8-fork" },
1616
//.tigerbeetle_io = .{ .path = "../tigerbeetle-io" },

0 commit comments

Comments
 (0)