diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3ef3a04f..d461fd82 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,8 +5,12 @@ env: AWS_SECRET_ACCESS_KEY: ${{ secrets.NIGHTLY_BUILD_AWS_SECRET_ACCESS_KEY }} AWS_BUCKET: ${{ vars.NIGHTLY_BUILD_AWS_BUCKET }} AWS_REGION: ${{ vars.NIGHTLY_BUILD_AWS_REGION }} + RELEASE: ${{ github.ref_type == 'tag' && github.ref_name || 'nightly' }} on: + push: + tags: + - '*' schedule: - cron: "2 2 * * *" @@ -38,8 +42,11 @@ jobs: arch: ${{env.ARCH}} mode: 'release' + - name: v8 snapshot + run: zig build -Dprebuilt_v8_path=v8/libc_v8.a -Doptimize=ReleaseFast snapshot_creator -- src/snapshot.bin + - name: zig build - run: zig build -Dprebuilt_v8_path=v8/libc_v8.a -Doptimize=ReleaseSafe -Dcpu=x86_64 -Dgit_commit=$(git rev-parse --short ${{ github.sha }}) + run: zig build -Dsnapshot_path=../../snapshot.bin -Dprebuilt_v8_path=v8/libc_v8.a -Doptimize=ReleaseFast -Dcpu=x86_64 -Dgit_commit=$(git rev-parse --short ${{ github.sha }}) - name: Rename binary run: mv zig-out/bin/lightpanda lightpanda-${{ env.ARCH }}-${{ env.OS }} @@ -54,7 +61,7 @@ jobs: with: allowUpdates: true artifacts: lightpanda-${{ env.ARCH }}-${{ env.OS }} - tag: nightly + tag: ${{ env.RELEASE }} build-linux-aarch64: env: @@ -77,8 +84,11 @@ jobs: arch: ${{env.ARCH}} mode: 'release' + - name: v8 snapshot + run: zig build -Dprebuilt_v8_path=v8/libc_v8.a -Doptimize=ReleaseFast snapshot_creator -- src/snapshot.bin + - name: zig build - run: zig build -Dprebuilt_v8_path=v8/libc_v8.a -Doptimize=ReleaseSafe -Dcpu=generic -Dgit_commit=$(git rev-parse --short ${{ github.sha }}) + run: zig build -Dsnapshot_path=../../snapshot.bin -Dprebuilt_v8_path=v8/libc_v8.a -Doptimize=ReleaseFast -Dcpu=generic -Dgit_commit=$(git rev-parse --short ${{ github.sha }}) - name: Rename binary run: mv zig-out/bin/lightpanda lightpanda-${{ env.ARCH }}-${{ env.OS }} @@ -93,7 +103,7 @@ jobs: with: allowUpdates: true artifacts: lightpanda-${{ env.ARCH }}-${{ env.OS }} - tag: nightly + tag: ${{ env.RELEASE }} build-macos-aarch64: env: @@ -118,8 +128,11 @@ jobs: arch: ${{env.ARCH}} mode: 'release' + - name: v8 snapshot + run: zig build -Dprebuilt_v8_path=v8/libc_v8.a -Doptimize=ReleaseFast snapshot_creator -- src/snapshot.bin + - name: zig build - run: zig build -Dprebuilt_v8_path=v8/libc_v8.a -Doptimize=ReleaseSafe -Dgit_commit=$(git rev-parse --short ${{ github.sha }}) + run: zig build -Dsnapshot_path=../../snapshot.bin -Dprebuilt_v8_path=v8/libc_v8.a -Doptimize=ReleaseFast -Dgit_commit=$(git rev-parse --short ${{ github.sha }}) - name: Rename binary run: mv zig-out/bin/lightpanda lightpanda-${{ env.ARCH }}-${{ env.OS }} @@ -134,7 +147,7 @@ jobs: with: allowUpdates: true artifacts: lightpanda-${{ env.ARCH }}-${{ env.OS }} - tag: nightly + tag: ${{ env.RELEASE }} build-macos-x86_64: env: @@ -157,8 +170,11 @@ jobs: arch: ${{env.ARCH}} mode: 'release' + - name: v8 snapshot + run: zig build -Dprebuilt_v8_path=v8/libc_v8.a -Doptimize=ReleaseFast snapshot_creator -- src/snapshot.bin + - name: zig build - run: zig build -Dprebuilt_v8_path=v8/libc_v8.a -Doptimize=ReleaseSafe -Dgit_commit=$(git rev-parse --short ${{ github.sha }}) + run: zig build -Dsnapshot_path=../../snapshot.bin -Dprebuilt_v8_path=v8/libc_v8.a -Doptimize=ReleaseFast -Dgit_commit=$(git rev-parse --short ${{ github.sha }}) - name: Rename binary run: mv zig-out/bin/lightpanda lightpanda-${{ env.ARCH }}-${{ env.OS }} @@ -173,4 +189,4 @@ jobs: with: allowUpdates: true artifacts: lightpanda-${{ env.ARCH }}-${{ env.OS }} - tag: nightly + tag: ${{ env.RELEASE }} diff --git a/Dockerfile b/Dockerfile index 516c3856..e064621e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,8 +48,16 @@ RUN case $TARGETPLATFORM in \ mkdir -p v8/ && \ mv libc_v8.a v8/libc_v8.a +# build v8 snapshot +RUN zig build -Doptimize=ReleaseFast \ + -Dprebuilt_v8_path=v8/libc_v8.a \ + snapshot_creator -- src/snapshot.bin + # build release -RUN zig build -Doptimize=ReleaseFast -Dprebuilt_v8_path=v8/libc_v8.a -Dgit_commit=$(git rev-parse --short HEAD) +RUN zig build -Doptimize=ReleaseFast \ + -Dsnapshot_path=../../snapshot.bin \ + -Dprebuilt_v8_path=v8/libc_v8.a \ + -Dgit_commit=$(git rev-parse --short HEAD) FROM debian:stable-slim diff --git a/Makefile b/Makefile index 7404367f..8adfa092 100644 --- a/Makefile +++ b/Makefile @@ -47,12 +47,18 @@ help: # $(ZIG) commands # ------------ -.PHONY: build build-dev run run-release shell test bench wpt data end2end +.PHONY: build build-v8-snapshot build-dev run run-release shell test bench wpt data end2end -## Build in release-safe mode -build: +## Build v8 snapshot +build-v8-snapshot: + @printf "\033[36mBuilding v8 snapshot (release safe)...\033[0m\n" + @$(ZIG) build -Doptimize=ReleaseFast snapshot_creator -- src/snapshot.bin || (printf "\033[33mBuild ERROR\033[0m\n"; exit 1;) + @printf "\033[33mBuild OK\033[0m\n" + +## Build in release-fast mode +build: build-v8-snapshot @printf "\033[36mBuilding (release safe)...\033[0m\n" - @$(ZIG) build -Doptimize=ReleaseSafe -Dgit_commit=$$(git rev-parse --short HEAD) || (printf "\033[33mBuild ERROR\033[0m\n"; exit 1;) + @$(ZIG) build -Doptimize=ReleaseFast -Dsnapshot_path=../../snapshot.bin -Dgit_commit=$$(git rev-parse --short HEAD) || (printf "\033[33mBuild ERROR\033[0m\n"; exit 1;) @printf "\033[33mBuild OK\033[0m\n" ## Build in debug mode diff --git a/README.md b/README.md index a854ad00..478a28ed 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,23 @@ env. But you can directly use the zig command: `zig build run`. +#### Embed v8 snapshot + +Lighpanda uses v8 snapshot. By default, it is created on startup but you can +embed it by using the following commands: + +Generate the snapshot. +``` +zig build snapshot_creator -- src/snapshot.bin +``` + +Build using the snapshot binary. +``` +zig build -Dsnapshot_path=../../snapshot.bin +``` + +See [#1279](https://github.com/lightpanda-io/browser/pull/1279) for more details. + ## Test ### Unit Tests