From b21688a0ace80b64afca2b7e6c27c955c7fa6eb7 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Wed, 20 Aug 2025 14:54:27 +0800 Subject: [PATCH 1/3] Makes build.zig Zig 0.15 ready Our build.zig is using a number of deprecated features, which are removed in 0.15. This updates build.zig so that it still works in 0.14 and [hopefully] will work in 0.15. Related: https://github.com/lightpanda-io/zig-v8-fork/pull/87 --- build.zig | 140 ++++++++++++++++++++++++++------------------------ build.zig.zon | 8 +-- 2 files changed, 76 insertions(+), 72 deletions(-) diff --git a/build.zig b/build.zig index dc2e8bc4..23bdae30 100644 --- a/build.zig +++ b/build.zig @@ -49,6 +49,13 @@ pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); + const lightpanda_module = b.addModule("lightpanda", .{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + try addDependencies(b, lightpanda_module, opts); + { // browser // ------- @@ -56,12 +63,8 @@ pub fn build(b: *Build) !void { // compile and install const exe = b.addExecutable(.{ .name = "lightpanda", - .target = target, - .optimize = optimize, - .root_source_file = b.path("src/main.zig"), + .root_module = lightpanda_module, }); - - try common(b, opts, exe); b.installArtifact(exe); // run @@ -75,6 +78,52 @@ pub fn build(b: *Build) !void { run_step.dependOn(&run_cmd.step); } + { + // tests + // ---- + + // compile + const tests = b.addTest(.{ + .root_module = lightpanda_module, + .test_runner = .{ .path = b.path("src/test_runner.zig"), .mode = .simple }, + }); + + const run_tests = b.addRunArtifact(tests); + if (b.args) |args| { + run_tests.addArgs(args); + } + + // step + const tests_step = b.step("test", "Run unit tests"); + tests_step.dependOn(&run_tests.step); + } + + { + // wpt + // ----- + const wpt_module = b.addModule("lightpanda", .{ + .root_source_file = b.path("src/main_wpt.zig"), + .target = target, + .optimize = optimize, + }); + try addDependencies(b, wpt_module, opts); + + // compile and install + const wpt = b.addExecutable(.{ + .name = "lightpanda-wpt", + .root_module = wpt_module, + }); + + // run + const wpt_cmd = b.addRunArtifact(wpt); + if (b.args) |args| { + wpt_cmd.addArgs(args); + } + // step + const wpt_step = b.step("wpt", "WPT tests"); + wpt_step.dependOn(&wpt_cmd.step); + } + { // get v8 // ------- @@ -92,70 +141,24 @@ pub fn build(b: *Build) !void { const build_step = b.step("build-v8", "Build v8"); build_step.dependOn(&build_v8.step); } - - { - // tests - // ---- - - // compile - const tests = b.addTest(.{ - .root_source_file = b.path("src/main.zig"), - .test_runner = .{ .path = b.path("src/test_runner.zig"), .mode = .simple }, - .target = target, - .optimize = optimize, - }); - try common(b, opts, tests); - - const run_tests = b.addRunArtifact(tests); - if (b.args) |args| { - run_tests.addArgs(args); - } - - // step - const tests_step = b.step("test", "Run unit tests"); - tests_step.dependOn(&run_tests.step); - } - - { - // wpt - // ----- - - // compile and install - const wpt = b.addExecutable(.{ - .name = "lightpanda-wpt", - .root_source_file = b.path("src/main_wpt.zig"), - .target = target, - .optimize = optimize, - }); - try common(b, opts, wpt); - - // run - const wpt_cmd = b.addRunArtifact(wpt); - if (b.args) |args| { - wpt_cmd.addArgs(args); - } - // step - const wpt_step = b.step("wpt", "WPT tests"); - wpt_step.dependOn(&wpt_cmd.step); - } } -fn common(b: *Build, opts: *Build.Step.Options, step: *Build.Step.Compile) !void { - const mod = step.root_module; - const target = mod.resolved_target.?; - const optimize = mod.optimize.?; - const dep_opts = .{ .target = target, .optimize = optimize }; - - try moduleNetSurf(b, step, target); +fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !void { + try moduleNetSurf(b, mod); mod.addImport("build_config", opts.createModule()); + + const target = mod.resolved_target.?; + const dep_opts = .{ + .target = target, + .optimize = mod.optimize.?, + }; + mod.addImport("tigerbeetle-io", b.dependency("tigerbeetle_io", .{}).module("tigerbeetle_io")); mod.addIncludePath(b.path("vendor/lightpanda")); { // v8 - mod.link_libcpp = true; - const v8_opts = b.addOptions(); v8_opts.addOption(bool, "inspector_subtype", false); @@ -386,7 +389,8 @@ fn common(b: *Build, opts: *Build.Step.Options, step: *Build.Step.Compile) !void } } -fn moduleNetSurf(b: *Build, step: *Build.Step.Compile, target: std.Build.ResolvedTarget) !void { +fn moduleNetSurf(b: *Build, mod: *Build.Module) !void { + const target = mod.resolved_target.?; const os = target.result.os.tag; const arch = target.result.cpu.arch; @@ -401,8 +405,8 @@ fn moduleNetSurf(b: *Build, step: *Build.Step.Compile, target: std.Build.Resolve "vendor/libiconv/out/{s}-{s}/lib/libiconv.a", .{ @tagName(os), @tagName(arch) }, ); - step.addObjectFile(b.path(libiconv_lib_path)); - step.addIncludePath(b.path(libiconv_include_path)); + mod.addObjectFile(b.path(libiconv_lib_path)); + mod.addIncludePath(b.path(libiconv_include_path)); { // mimalloc @@ -412,8 +416,8 @@ fn moduleNetSurf(b: *Build, step: *Build.Step.Compile, target: std.Build.Resolve mimalloc ++ "/out/{s}-{s}/lib/libmimalloc.a", .{ @tagName(os), @tagName(arch) }, ); - step.addObjectFile(b.path(lib_path)); - step.addIncludePath(b.path(mimalloc ++ "/include")); + mod.addObjectFile(b.path(lib_path)); + mod.addIncludePath(b.path(mimalloc ++ "/include")); } // netsurf libs @@ -423,7 +427,7 @@ fn moduleNetSurf(b: *Build, step: *Build.Step.Compile, target: std.Build.Resolve ns ++ "/out/{s}-{s}/include", .{ @tagName(os), @tagName(arch) }, ); - step.addIncludePath(b.path(ns_include_path)); + mod.addIncludePath(b.path(ns_include_path)); const libs: [4][]const u8 = .{ "libdom", @@ -437,8 +441,8 @@ fn moduleNetSurf(b: *Build, step: *Build.Step.Compile, target: std.Build.Resolve ns ++ "/out/{s}-{s}/lib/" ++ lib ++ ".a", .{ @tagName(os), @tagName(arch) }, ); - step.addObjectFile(b.path(ns_lib_path)); - step.addIncludePath(b.path(ns ++ "/" ++ lib ++ "/src")); + mod.addObjectFile(b.path(ns_lib_path)); + mod.addIncludePath(b.path(ns ++ "/" ++ lib ++ "/src")); } } diff --git a/build.zig.zon b/build.zig.zon index 6a45c2d8..f5811d7e 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -5,12 +5,12 @@ .fingerprint = 0xda130f3af836cea0, .dependencies = .{ .tigerbeetle_io = .{ - .url = "https://github.com/lightpanda-io/tigerbeetle-io/archive/61d9652f1a957b7f4db723ea6aa0ce9635e840ce.tar.gz", - .hash = "tigerbeetle_io-0.0.0-ViLgxpyRBAB5BMfIcj3KMXfbJzwARs9uSl8aRy2OXULd", + .url = "https://github.com/lightpanda-io/tigerbeetle-io/archive/19ae89eb3814d48c202ac9e0495fc5cadb29dfe7.tar.gz", + .hash = "tigerbeetle_io-0.0.0-ViLgxjqSBADhuHO_RZm4yNzuoKDXWP39hDn60Kht40OC", }, .v8 = .{ - .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/b22911e02e4884a76acf52aa9aff2ba169d05b40.tar.gz", - .hash = "v8-0.0.0-xddH69zCAwAzm1u5cQVa-uG5ib2y6PpENXCl8yEYdUYk", + .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/13f64a747c65a6b97ce08b89a2a1c9eb922e5495.tar.gz", + .hash = "v8-0.0.0-xddH6-3DAwAi5Enn3IxrIUvsSa7vBBqxZBAHZzAAyKeq", }, //.v8 = .{ .path = "../zig-v8-fork" }, //.tigerbeetle_io = .{ .path = "../tigerbeetle-io" }, From 4ad19fc4d8033a13a4843224dcf7876a5588e8f6 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Thu, 21 Aug 2025 09:23:11 +0800 Subject: [PATCH 2/3] use merged v8 commit --- build.zig.zon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig.zon b/build.zig.zon index f5811d7e..27eed18a 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -9,7 +9,7 @@ .hash = "tigerbeetle_io-0.0.0-ViLgxjqSBADhuHO_RZm4yNzuoKDXWP39hDn60Kht40OC", }, .v8 = .{ - .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/13f64a747c65a6b97ce08b89a2a1c9eb922e5495.tar.gz", + .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/4caba1c389af70b5083418da055987ecfd771120.tar.gz", .hash = "v8-0.0.0-xddH6-3DAwAi5Enn3IxrIUvsSa7vBBqxZBAHZzAAyKeq", }, //.v8 = .{ .path = "../zig-v8-fork" }, From 65088b864403c12a7a858406386f90fc3bb6bc52 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Thu, 21 Aug 2025 09:59:42 +0800 Subject: [PATCH 3/3] swap unnecessary addModule with createModule --- build.zig | 2 +- build.zig.zon | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index 23bdae30..141c3859 100644 --- a/build.zig +++ b/build.zig @@ -101,7 +101,7 @@ pub fn build(b: *Build) !void { { // wpt // ----- - const wpt_module = b.addModule("lightpanda", .{ + const wpt_module = b.createModule(.{ .root_source_file = b.path("src/main_wpt.zig"), .target = target, .optimize = optimize, diff --git a/build.zig.zon b/build.zig.zon index 27eed18a..9940a9bb 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -9,8 +9,8 @@ .hash = "tigerbeetle_io-0.0.0-ViLgxjqSBADhuHO_RZm4yNzuoKDXWP39hDn60Kht40OC", }, .v8 = .{ - .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/4caba1c389af70b5083418da055987ecfd771120.tar.gz", - .hash = "v8-0.0.0-xddH6-3DAwAi5Enn3IxrIUvsSa7vBBqxZBAHZzAAyKeq", + .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/cf412d5b3d9d608582571d821e0d552337ef690d.tar.gz", + .hash = "v8-0.0.0-xddH69zDAwA4fp1dBo_jEDjS5bhXycPwRlZHp6_X890t", }, //.v8 = .{ .path = "../zig-v8-fork" }, //.tigerbeetle_io = .{ .path = "../tigerbeetle-io" },