add a build step for html5ever in build.zig

This commit is contained in:
Halil Durak
2025-11-25 12:43:52 +03:00
parent 23e3a1d012
commit 6280232e91
3 changed files with 36 additions and 19 deletions

1
.gitignore vendored
View File

@@ -3,4 +3,3 @@
lightpanda.id
/v8/
/build/
src/html5ever/target/

View File

@@ -127,20 +127,13 @@ build-v8:
# Install and build required dependencies commands
# ------------
.PHONY: install-html5ever install-html5ever-dev
.PHONY: install install-dev
## Install and build dependencies for release
install: install-submodule install-html5ever
install: install-submodule
## Install and build dependencies for dev
install-dev: install-submodule install-html5ever-dev
install-html5ever:
cd src/html5ever && cargo build --release --target-dir ../../build/html5ever/
install-html5ever-dev:
cd src/html5ever && cargo build --target-dir ../../build/html5ever/
install-dev: install-submodule
data:
cd src/data && go run public_suffix_list_gen.go > public_suffix_list.zig

View File

@@ -39,6 +39,9 @@ pub fn build(b: *Build) !void {
},
}
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
var opts = b.addOptions();
opts.addOption(
[]const u8,
@@ -46,8 +49,30 @@ pub fn build(b: *Build) !void {
b.option([]const u8, "git_commit", "Current git commit") orelse "dev",
);
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Build step to install html5ever dependency.
const html5ever_argv = blk: {
const argv: []const []const u8 = &.{
"cargo",
"build",
// Seems cargo can figure out required paths out of Cargo.toml.
"--manifest-path",
"vendor/html5ever/Cargo.toml",
// TODO: We can prefer `--artifact-dir` once it become stable.
"--target-dir",
b.getInstallPath(.prefix, "html5ever"),
// This must be the last argument.
"--release",
};
break :blk switch (optimize) {
// Consider these as dev builds.
.Debug, .ReleaseSafe => argv[0 .. argv.len - 1],
.ReleaseFast, .ReleaseSmall => argv,
};
};
const html5ever_exec_cargo = b.addSystemCommand(html5ever_argv);
const html5ever_step = b.step("html5ever", "Install html5ever dependency (requires cargo)");
html5ever_step.dependOn(&html5ever_exec_cargo.step);
const enable_tsan = b.option(bool, "tsan", "Enable Thread Sanitizer");
const enable_csan = b.option(std.zig.SanitizeC, "csan", "Enable C Sanitizers");
@@ -65,16 +90,16 @@ pub fn build(b: *Build) !void {
try addDependencies(b, mod, opts);
if (optimize == .ReleaseFast or optimize == .ReleaseSmall) {
mod.addLibraryPath(b.path("build/html5ever/release"));
} else {
mod.addLibraryPath(b.path("build/html5ever/debug"));
}
mod.linkSystemLibrary("litefetch_html5ever", .{});
break :blk mod;
};
const html5ever_obj = switch (optimize) {
.Debug, .ReleaseSafe => b.getInstallPath(.prefix, "html5ever/debug/liblitefetch_html5ever.a"),
.ReleaseFast, .ReleaseSmall => b.getInstallPath(.prefix, "html5ever/release/liblitefetch_html5ever.a"),
};
lightpanda_module.addObjectFile(.{ .cwd_relative = html5ever_obj });
{
// browser
const exe = b.addExecutable(.{