Add ZIGFLAGS= make download-v8 to fetch prebuilt V8 and skip the source build

This commit is contained in:
Navid EMAD
2026-05-21 14:39:25 +02:00
parent 972be65db7
commit daa8fff5f3
2 changed files with 34 additions and 1 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
/.zig-cache/
/.lp-cache/
/v8/
/zig-pkg/
zig-out
lightpanda.id

View File

@@ -33,6 +33,27 @@ else
endif
# Prebuilt V8
# -----------
# Building V8 from source takes 10+ minutes. `make download-v8` fetches the
# matching prebuilt archive from the zig-v8-fork releases instead. The versions
# are read from the install action so they can't drift from CI.
V8_ACTION := .github/actions/install/action.yml
V8_VERSION := $(shell awk -F\' '/^ v8:/{f=1} f&&/default:/{print $$2; exit}' $(V8_ACTION))
ZIG_V8_TAG := $(shell awk -F\' '/^ zig-v8:/{f=1} f&&/default:/{print $$2; exit}' $(V8_ACTION))
V8_ARCHIVE := libc_v8_$(V8_VERSION)_$(OS)_$(ARCH).a
V8_CACHE := .lp-cache/prebuilt-v8/$(V8_ARCHIVE)
V8_LINK := v8/libc_v8.a
# If the prebuilt archive is in place and the caller hasn't set ZIGFLAGS, link
# against it (the same flag CI passes) rather than building V8 from source.
ifeq ($(strip $(ZIGFLAGS)),)
ifneq ($(wildcard $(V8_LINK)),)
ZIGFLAGS := -Dprebuilt_v8_path=$(V8_LINK)
endif
endif
# Infos
# -----
.PHONY: help
@@ -52,7 +73,18 @@ help:
# $(ZIG) commands
# ------------
.PHONY: build build-v8-snapshot build-dev run run-release test bench data end2end clean
.PHONY: build build-v8-snapshot build-dev download-v8 run run-release test bench data end2end clean
## Download the prebuilt V8 archive (skips the 10+ min source build)
download-v8:
@mkdir -p $(dir $(V8_CACHE)) $(dir $(V8_LINK))
@test -f $(V8_CACHE) || ( \
printf "\033[36mDownloading prebuilt V8 $(V8_VERSION) ($(ZIG_V8_TAG))...\033[0m\n"; \
curl -fL --progress-bar -o $(V8_CACHE) \
https://github.com/lightpanda-io/zig-v8-fork/releases/download/$(ZIG_V8_TAG)/$(V8_ARCHIVE) \
|| (rm -f $(V8_CACHE); printf "\033[33mDownload ERROR\033[0m\n"; exit 1) )
@ln -sf $(abspath $(V8_CACHE)) $(V8_LINK)
@printf "\033[33mV8 ready: %s -> %s\033[0m\n" "$(V8_LINK)" "$(V8_CACHE)"
## Build v8 snapshot
build-v8-snapshot: