From bb7da6aafbbfdd870537fc11cf9608f860821ef5 Mon Sep 17 00:00:00 2001 From: Nikolay Govorov Date: Tue, 9 Dec 2025 07:18:38 +0000 Subject: [PATCH] Get rid of copies of the Zig version --- .github/actions/install/action.yml | 7 +--- .github/workflows/build.yml | 3 +- .github/workflows/e2e-test.yml | 3 +- .github/workflows/wpt.yml | 3 +- .github/workflows/zig-fmt.yml | 13 +++--- .github/workflows/zig-test.yml | 3 +- Dockerfile | 29 +++++++------- Makefile | 13 +----- build.zig | 64 +++++++++++++++++------------- build.zig.zon | 5 ++- 10 files changed, 64 insertions(+), 79 deletions(-) diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml index 0029d22e..01327202 100644 --- a/.github/actions/install/action.yml +++ b/.github/actions/install/action.yml @@ -2,10 +2,6 @@ name: "Browsercore install" description: "Install deps for the project browsercore" inputs: - zig: - description: 'Zig version to install' - required: false - default: '0.15.2' arch: description: 'CPU arch used to select the v8 lib' required: false @@ -38,9 +34,8 @@ runs: sudo apt-get update sudo apt-get install -y wget xz-utils python3 ca-certificates git pkg-config libglib2.0-dev gperf libexpat1-dev cmake clang + # Zig version used from the `minimum_zig_version` field in build.zig.zon - uses: mlugg/setup-zig@v2 - with: - version: ${{ inputs.zig }} - name: Cache v8 id: cache-v8 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 98abeffd..7873010b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,10 +26,9 @@ jobs: timeout-minutes: 15 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 with: fetch-depth: 0 - # fetch submodules recusively, to get zig-js-runtime submodules also. submodules: recursive - uses: ./.github/actions/install diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index b436ad35..a39edb61 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -49,10 +49,9 @@ jobs: if: github.event.pull_request.draft == false steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 with: fetch-depth: 0 - # fetch submodules recusively, to get zig-js-runtime submodules also. submodules: recursive - uses: ./.github/actions/install diff --git a/.github/workflows/wpt.yml b/.github/workflows/wpt.yml index 205c63ae..3426cea4 100644 --- a/.github/workflows/wpt.yml +++ b/.github/workflows/wpt.yml @@ -22,10 +22,9 @@ jobs: timeout-minutes: 90 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 with: fetch-depth: 0 - # fetch submodules recusively, to get zig-js-runtime submodules also. submodules: recursive - uses: ./.github/actions/install diff --git a/.github/workflows/zig-fmt.yml b/.github/workflows/zig-fmt.yml index 106e557a..a6df7e1f 100644 --- a/.github/workflows/zig-fmt.yml +++ b/.github/workflows/zig-fmt.yml @@ -1,8 +1,5 @@ name: zig-fmt -env: - ZIG_VERSION: 0.15.2 - on: pull_request: @@ -32,14 +29,13 @@ jobs: timeout-minutes: 15 steps: - - uses: mlugg/setup-zig@v2 - with: - version: ${{ env.ZIG_VERSION }} - - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 with: fetch-depth: 0 + # Zig version used from the `minimum_zig_version` field in build.zig.zon + - uses: mlugg/setup-zig@v2 + - name: Run zig fmt id: fmt run: | @@ -58,6 +54,7 @@ jobs: fi echo "${delimiter}" >> "${GITHUB_OUTPUT}" + - name: Fail the job if: steps.fmt.outputs.zig_fmt_errs != '' run: exit 1 diff --git a/.github/workflows/zig-test.yml b/.github/workflows/zig-test.yml index db54a893..f30a68e3 100644 --- a/.github/workflows/zig-test.yml +++ b/.github/workflows/zig-test.yml @@ -47,10 +47,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 with: fetch-depth: 0 - # fetch submodules recusively, to get zig-js-runtime submodules also. submodules: recursive - uses: ./.github/actions/install diff --git a/Dockerfile b/Dockerfile index ef26df94..2ce342b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ FROM debian:stable-slim ARG MINISIG=0.12 -ARG ZIG=0.15.2 ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U ARG V8=14.0.365.4 ARG ZIG_V8=v0.1.34 @@ -17,25 +16,25 @@ RUN apt-get update -yq && \ # install minisig RUN curl --fail -L -O https://github.com/jedisct1/minisign/releases/download/${MINISIG}/minisign-${MINISIG}-linux.tar.gz && \ - tar xvzf minisign-${MINISIG}-linux.tar.gz - -# install zig -RUN case $TARGETPLATFORM in \ - "linux/arm64") ARCH="aarch64" ;; \ - *) ARCH="x86_64" ;; \ - esac && \ - curl --fail -L -O https://ziglang.org/download/${ZIG}/zig-${ARCH}-linux-${ZIG}.tar.xz && \ - curl --fail -L -O https://ziglang.org/download/${ZIG}/zig-${ARCH}-linux-${ZIG}.tar.xz.minisig && \ - minisign-linux/${ARCH}/minisign -Vm zig-${ARCH}-linux-${ZIG}.tar.xz -P ${ZIG_MINISIG} && \ - tar xvf zig-${ARCH}-linux-${ZIG}.tar.xz && \ - mv zig-${ARCH}-linux-${ZIG} /usr/local/lib && \ - ln -s /usr/local/lib/zig-${ARCH}-linux-${ZIG}/zig /usr/local/bin/zig + tar xvzf minisign-${MINISIG}-linux.tar.gz -C / # clone lightpanda RUN git clone https://github.com/lightpanda-io/browser.git - WORKDIR /browser +# install zig +RUN ZIG=$(grep '\.minimum_zig_version = "' "build.zig.zon" | cut -d'"' -f2) && \ + case $TARGETPLATFORM in \ + "linux/arm64") ARCH="aarch64" ;; \ + *) ARCH="x86_64" ;; \ + esac && \ + curl --fail -L -O https://ziglang.org/download/${ZIG}/zig-${ARCH}-linux-${ZIG}.tar.xz && \ + curl --fail -L -O https://ziglang.org/download/${ZIG}/zig-${ARCH}-linux-${ZIG}.tar.xz.minisig && \ + /minisign-linux/${ARCH}/minisign -Vm zig-${ARCH}-linux-${ZIG}.tar.xz -P ${ZIG_MINISIG} && \ + tar xvf zig-${ARCH}-linux-${ZIG}.tar.xz && \ + mv zig-${ARCH}-linux-${ZIG} /usr/local/lib && \ + ln -s /usr/local/lib/zig-${ARCH}-linux-${ZIG}/zig /usr/local/bin/zig + # install deps RUN git submodule init && \ git submodule update --recursive diff --git a/Makefile b/Makefile index b32cdbe3..75c6d60b 100644 --- a/Makefile +++ b/Makefile @@ -47,18 +47,7 @@ help: # $(ZIG) commands # ------------ -.PHONY: build build-dev run run-release shell test bench download-zig wpt data -.PHONY: end2end - -zig_version = $(shell grep 'recommended_zig_version = "' "vendor/zig-js-runtime/build.zig" | cut -d'"' -f2) - -## Download the zig recommended version -download-zig: - $(eval url = "https://ziglang.org/download/$(zig_version)/zig-$(OS)-$(ARCH)-$(zig_version).tar.xz") - $(eval dest = "/tmp/zig-$(OS)-$(ARCH)-$(zig_version).tar.xz") - @printf "\e[36mDownload zig version $(zig_version)...\e[0m\n" - @curl -o "$(dest)" -L "$(url)" || (printf "\e[33mBuild ERROR\e[0m\n"; exit 1;) - @printf "\e[33mDownloaded $(dest)\e[0m\n" +.PHONY: build build-dev run run-release shell test bench wpt data end2end ## Build in release-safe mode build: diff --git a/build.zig b/build.zig index abed283c..342326eb 100644 --- a/build.zig +++ b/build.zig @@ -21,38 +21,21 @@ const builtin = @import("builtin"); const Build = std.Build; -/// Do not rename this constant. It is scanned by some scripts to determine -/// which zig version to install. -const recommended_zig_version = "0.15.2"; - pub fn build(b: *Build) !void { - switch (comptime builtin.zig_version.order(std.SemanticVersion.parse(recommended_zig_version) catch unreachable)) { - .eq => {}, - .lt => { - @compileError("The minimum version of Zig required to compile is '" ++ recommended_zig_version ++ "', found '" ++ builtin.zig_version_string ++ "'."); - }, - .gt => { - std.debug.print( - "WARNING: Recommended Zig version '{s}', but found '{s}', build may fail...\n\n", - .{ recommended_zig_version, builtin.zig_version_string }, - ); - }, - } - - var opts = b.addOptions(); - opts.addOption( - []const u8, - "git_commit", - b.option([]const u8, "git_commit", "Current git commit") orelse "dev", - ); - - const prebuilt_v8_path = b.option([]const u8, "prebuilt_v8_path", "Path to prebuilt libc_v8.a"); - const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - // We're still using llvm because the new x86 backend seems to crash - // with v8. This can be reproduced in zig-v8-fork. + const manifest = Manifest.init(b); + + const git_commit = b.option([]const u8, "git_commit", "Current git commit"); + const prebuilt_v8_path = b.option([]const u8, "prebuilt_v8_path", "Path to prebuilt libc_v8.a"); + + var opts = b.addOptions(); + opts.addOption([]const u8, "version", manifest.version); + opts.addOption([]const u8, "git_commit", git_commit orelse "dev"); + + // We're still using llvm because the new x86 backend seems to crash with v8. + // This can be reproduced in zig-v8-fork. const lightpanda_module = b.addModule("lightpanda", .{ .root_source_file = b.path("src/main.zig"), @@ -851,3 +834,28 @@ pub fn buildAda(b: *Build, m: *Build.Module) !void { // Expose ada module to main module. m.addImport("ada", ada_mod); } + +const Manifest = struct { + version: []const u8, + minimum_zig_version: []const u8, + + fn init(b: *std.Build) Manifest { + const input = @embedFile("build.zig.zon"); + + var diagnostics: std.zon.parse.Diagnostics = .{}; + defer diagnostics.deinit(b.allocator); + + return std.zon.parse.fromSlice(Manifest, b.allocator, input, &diagnostics, .{ + .free_on_error = true, + .ignore_unknown_fields = true, + }) catch |err| { + switch (err) { + error.OutOfMemory => @panic("OOM"), + error.ParseZon => { + std.debug.print("Parse diagnostics:\n{f}\n", .{diagnostics}); + std.process.exit(1); + }, + } + }; + } +}; diff --git a/build.zig.zon b/build.zig.zon index e63e36dd..a7bf4d4f 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,8 +1,8 @@ .{ .name = .browser, - .paths = .{""}, .version = "0.0.0", - .fingerprint = 0xda130f3af836cea0, + .fingerprint = 0xda130f3af836cea0, // Changing this has security and trust implications. + .minimum_zig_version = "0.15.2", .dependencies = .{ .v8 = .{ .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/e047d2a4d5af5783763f0f6a652fab8982a08603.tar.gz", @@ -18,4 +18,5 @@ .hash = "boringssl-0.1.0-VtJeWehMAAA4RNnwRnzEvKcS9rjsR1QVRw1uJrwXxmVK", }, }, + .paths = .{""}, }