diff --git a/.gitignore b/.gitignore index 9a7968b9..59d6886c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ lightpanda.id /v8/ /build/ -src/html5ever/target/ +/src/html5ever/target/ diff --git a/Makefile b/Makefile index 957705e2..7208b9ee 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/build.zig b/build.zig index 704203d2..3632f98d 100644 --- a/build.zig +++ b/build.zig @@ -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", + "src/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(.{