Skip to content

Commit bb7da6a

Browse files
committed
Get rid of copies of the Zig version
1 parent f7fd68c commit bb7da6a

File tree

10 files changed

+58
-73
lines changed

10 files changed

+58
-73
lines changed

.github/actions/install/action.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ name: "Browsercore install"
22
description: "Install deps for the project browsercore"
33

44
inputs:
5-
zig:
6-
description: 'Zig version to install'
7-
required: false
8-
default: '0.15.2'
95
arch:
106
description: 'CPU arch used to select the v8 lib'
117
required: false
@@ -38,9 +34,8 @@ runs:
3834
sudo apt-get update
3935
sudo apt-get install -y wget xz-utils python3 ca-certificates git pkg-config libglib2.0-dev gperf libexpat1-dev cmake clang
4036
37+
# Zig version used from the `minimum_zig_version` field in build.zig.zon
4138
- uses: mlugg/setup-zig@v2
42-
with:
43-
version: ${{ inputs.zig }}
4439

4540
- name: Cache v8
4641
id: cache-v8

.github/workflows/build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ jobs:
2626
timeout-minutes: 15
2727

2828
steps:
29-
- uses: actions/checkout@v4
29+
- uses: actions/checkout@v6
3030
with:
3131
fetch-depth: 0
32-
# fetch submodules recusively, to get zig-js-runtime submodules also.
3332
submodules: recursive
3433

3534
- uses: ./.github/actions/install

.github/workflows/e2e-test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ jobs:
4949
if: github.event.pull_request.draft == false
5050

5151
steps:
52-
- uses: actions/checkout@v4
52+
- uses: actions/checkout@v6
5353
with:
5454
fetch-depth: 0
55-
# fetch submodules recusively, to get zig-js-runtime submodules also.
5655
submodules: recursive
5756

5857
- uses: ./.github/actions/install

.github/workflows/wpt.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ jobs:
2222
timeout-minutes: 90
2323

2424
steps:
25-
- uses: actions/checkout@v4
25+
- uses: actions/checkout@v6
2626
with:
2727
fetch-depth: 0
28-
# fetch submodules recusively, to get zig-js-runtime submodules also.
2928
submodules: recursive
3029

3130
- uses: ./.github/actions/install

.github/workflows/zig-fmt.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: zig-fmt
22

3-
env:
4-
ZIG_VERSION: 0.15.2
5-
63
on:
74
pull_request:
85

@@ -32,14 +29,13 @@ jobs:
3229
timeout-minutes: 15
3330

3431
steps:
35-
- uses: mlugg/setup-zig@v2
36-
with:
37-
version: ${{ env.ZIG_VERSION }}
38-
39-
- uses: actions/checkout@v4
32+
- uses: actions/checkout@v6
4033
with:
4134
fetch-depth: 0
4235

36+
# Zig version used from the `minimum_zig_version` field in build.zig.zon
37+
- uses: mlugg/setup-zig@v2
38+
4339
- name: Run zig fmt
4440
id: fmt
4541
run: |
@@ -58,6 +54,7 @@ jobs:
5854
fi
5955
6056
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
57+
6158
- name: Fail the job
6259
if: steps.fmt.outputs.zig_fmt_errs != ''
6360
run: exit 1

.github/workflows/zig-test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ jobs:
4747
runs-on: ubuntu-latest
4848

4949
steps:
50-
- uses: actions/checkout@v4
50+
- uses: actions/checkout@v6
5151
with:
5252
fetch-depth: 0
53-
# fetch submodules recusively, to get zig-js-runtime submodules also.
5453
submodules: recursive
5554

5655
- uses: ./.github/actions/install

Dockerfile

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
FROM debian:stable-slim
22

33
ARG MINISIG=0.12
4-
ARG ZIG=0.15.2
54
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
65
ARG V8=14.0.365.4
76
ARG ZIG_V8=v0.1.34
@@ -17,25 +16,25 @@ RUN apt-get update -yq && \
1716

1817
# install minisig
1918
RUN curl --fail -L -O https://github.com/jedisct1/minisign/releases/download/${MINISIG}/minisign-${MINISIG}-linux.tar.gz && \
20-
tar xvzf minisign-${MINISIG}-linux.tar.gz
19+
tar xvzf minisign-${MINISIG}-linux.tar.gz -C /
20+
21+
# clone lightpanda
22+
RUN git clone https://github.com/lightpanda-io/browser.git
23+
WORKDIR /browser
2124

2225
# install zig
23-
RUN case $TARGETPLATFORM in \
24-
"linux/arm64") ARCH="aarch64" ;; \
25-
*) ARCH="x86_64" ;; \
26+
RUN ZIG=$(grep '\.minimum_zig_version = "' "build.zig.zon" | cut -d'"' -f2) && \
27+
case $TARGETPLATFORM in \
28+
"linux/arm64") ARCH="aarch64" ;; \
29+
*) ARCH="x86_64" ;; \
2630
esac && \
2731
curl --fail -L -O https://ziglang.org/download/${ZIG}/zig-${ARCH}-linux-${ZIG}.tar.xz && \
2832
curl --fail -L -O https://ziglang.org/download/${ZIG}/zig-${ARCH}-linux-${ZIG}.tar.xz.minisig && \
29-
minisign-linux/${ARCH}/minisign -Vm zig-${ARCH}-linux-${ZIG}.tar.xz -P ${ZIG_MINISIG} && \
33+
/minisign-linux/${ARCH}/minisign -Vm zig-${ARCH}-linux-${ZIG}.tar.xz -P ${ZIG_MINISIG} && \
3034
tar xvf zig-${ARCH}-linux-${ZIG}.tar.xz && \
3135
mv zig-${ARCH}-linux-${ZIG} /usr/local/lib && \
3236
ln -s /usr/local/lib/zig-${ARCH}-linux-${ZIG}/zig /usr/local/bin/zig
3337

34-
# clone lightpanda
35-
RUN git clone https://github.com/lightpanda-io/browser.git
36-
37-
WORKDIR /browser
38-
3938
# install deps
4039
RUN git submodule init && \
4140
git submodule update --recursive

Makefile

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,7 @@ help:
4747

4848
# $(ZIG) commands
4949
# ------------
50-
.PHONY: build build-dev run run-release shell test bench download-zig wpt data
51-
.PHONY: end2end
52-
53-
zig_version = $(shell grep 'recommended_zig_version = "' "vendor/zig-js-runtime/build.zig" | cut -d'"' -f2)
54-
55-
## Download the zig recommended version
56-
download-zig:
57-
$(eval url = "https://ziglang.org/download/$(zig_version)/zig-$(OS)-$(ARCH)-$(zig_version).tar.xz")
58-
$(eval dest = "/tmp/zig-$(OS)-$(ARCH)-$(zig_version).tar.xz")
59-
@printf "\e[36mDownload zig version $(zig_version)...\e[0m\n"
60-
@curl -o "$(dest)" -L "$(url)" || (printf "\e[33mBuild ERROR\e[0m\n"; exit 1;)
61-
@printf "\e[33mDownloaded $(dest)\e[0m\n"
50+
.PHONY: build build-dev run run-release shell test bench wpt data end2end
6251

6352
## Build in release-safe mode
6453
build:

build.zig

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,21 @@ const builtin = @import("builtin");
2121

2222
const Build = std.Build;
2323

24-
/// Do not rename this constant. It is scanned by some scripts to determine
25-
/// which zig version to install.
26-
const recommended_zig_version = "0.15.2";
27-
2824
pub fn build(b: *Build) !void {
29-
switch (comptime builtin.zig_version.order(std.SemanticVersion.parse(recommended_zig_version) catch unreachable)) {
30-
.eq => {},
31-
.lt => {
32-
@compileError("The minimum version of Zig required to compile is '" ++ recommended_zig_version ++ "', found '" ++ builtin.zig_version_string ++ "'.");
33-
},
34-
.gt => {
35-
std.debug.print(
36-
"WARNING: Recommended Zig version '{s}', but found '{s}', build may fail...\n\n",
37-
.{ recommended_zig_version, builtin.zig_version_string },
38-
);
39-
},
40-
}
25+
const target = b.standardTargetOptions(.{});
26+
const optimize = b.standardOptimizeOption(.{});
4127

42-
var opts = b.addOptions();
43-
opts.addOption(
44-
[]const u8,
45-
"git_commit",
46-
b.option([]const u8, "git_commit", "Current git commit") orelse "dev",
47-
);
28+
const manifest = Manifest.init(b);
4829

30+
const git_commit = b.option([]const u8, "git_commit", "Current git commit");
4931
const prebuilt_v8_path = b.option([]const u8, "prebuilt_v8_path", "Path to prebuilt libc_v8.a");
5032

51-
const target = b.standardTargetOptions(.{});
52-
const optimize = b.standardOptimizeOption(.{});
33+
var opts = b.addOptions();
34+
opts.addOption([]const u8, "version", manifest.version);
35+
opts.addOption([]const u8, "git_commit", git_commit orelse "dev");
5336

54-
// We're still using llvm because the new x86 backend seems to crash
55-
// with v8. This can be reproduced in zig-v8-fork.
37+
// We're still using llvm because the new x86 backend seems to crash with v8.
38+
// This can be reproduced in zig-v8-fork.
5639

5740
const lightpanda_module = b.addModule("lightpanda", .{
5841
.root_source_file = b.path("src/main.zig"),
@@ -851,3 +834,28 @@ pub fn buildAda(b: *Build, m: *Build.Module) !void {
851834
// Expose ada module to main module.
852835
m.addImport("ada", ada_mod);
853836
}
837+
838+
const Manifest = struct {
839+
version: []const u8,
840+
minimum_zig_version: []const u8,
841+
842+
fn init(b: *std.Build) Manifest {
843+
const input = @embedFile("build.zig.zon");
844+
845+
var diagnostics: std.zon.parse.Diagnostics = .{};
846+
defer diagnostics.deinit(b.allocator);
847+
848+
return std.zon.parse.fromSlice(Manifest, b.allocator, input, &diagnostics, .{
849+
.free_on_error = true,
850+
.ignore_unknown_fields = true,
851+
}) catch |err| {
852+
switch (err) {
853+
error.OutOfMemory => @panic("OOM"),
854+
error.ParseZon => {
855+
std.debug.print("Parse diagnostics:\n{f}\n", .{diagnostics});
856+
std.process.exit(1);
857+
},
858+
}
859+
};
860+
}
861+
};

build.zig.zon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.{
22
.name = .browser,
3-
.paths = .{""},
43
.version = "0.0.0",
5-
.fingerprint = 0xda130f3af836cea0,
4+
.fingerprint = 0xda130f3af836cea0, // Changing this has security and trust implications.
5+
.minimum_zig_version = "0.15.2",
66
.dependencies = .{
77
.v8 = .{
88
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/e047d2a4d5af5783763f0f6a652fab8982a08603.tar.gz",
@@ -18,4 +18,5 @@
1818
.hash = "boringssl-0.1.0-VtJeWehMAAA4RNnwRnzEvKcS9rjsR1QVRw1uJrwXxmVK",
1919
},
2020
},
21+
.paths = .{""},
2122
}

0 commit comments

Comments
 (0)