Vendor deps.
This commit is contained in:
1 parent
294527085e
commit
91e18fde3a
1714 files changed
+556667
-7
No files matched your search
Vendored
+44
@@ -0,0 +1,44 @@
|
||||
# Shared logic to download Python source tarball for the wasm builds.
|
||||
|
||||
CURDIR=$(abspath .)
|
||||
|
||||
# These three are passed in from nox.
|
||||
BUILDROOT ?= $(CURDIR)/builddir
|
||||
PYTHON ?= python3
|
||||
PYMAJORMINORMICRO ?= $(shell $(PYTHON) --version 2>&1 | awk '{print $$2}')
|
||||
|
||||
# Set version variables.
|
||||
version_tuple := $(subst ., ,$(PYMAJORMINORMICRO:v%=%))
|
||||
PYMAJOR=$(word 1,$(version_tuple))
|
||||
PYMINOR=$(word 2,$(version_tuple))
|
||||
PYMICRO=$(word 3,$(version_tuple))
|
||||
PYVERSION=$(PYMAJORMINORMICRO)
|
||||
PYMAJORMINOR=$(PYMAJOR).$(PYMINOR)
|
||||
|
||||
ifneq ($(PYMAJORMINOR),3.14)
|
||||
$(error PYMAJORMINOR must be 3.14, got '$(PYMAJORMINOR)')
|
||||
endif
|
||||
|
||||
PYTHONURL=https://www.python.org/ftp/python/$(PYMAJORMINORMICRO)/Python-$(PYVERSION).tgz
|
||||
PYTHONTARBALL=$(BUILDROOT)/downloads/Python-$(PYVERSION).tgz
|
||||
PYTHONBUILD=$(BUILDROOT)/build/Python-$(PYVERSION)
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
$(BUILDROOT)/.exists:
|
||||
mkdir -p $(BUILDROOT)
|
||||
touch $@
|
||||
|
||||
$(PYTHONTARBALL): $(BUILDROOT)/.exists
|
||||
mkdir -p $(BUILDROOT)/downloads
|
||||
curl -sL $(PYTHONURL) -o $@
|
||||
|
||||
$(PYTHONBUILD)/.exists: $(PYTHONTARBALL)
|
||||
[ -d $(PYTHONBUILD) ] || ( \
|
||||
mkdir -p $(dir $(PYTHONBUILD));\
|
||||
tar -C $(dir $(PYTHONBUILD)) -xf $(PYTHONTARBALL) \
|
||||
)
|
||||
touch $@
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILDROOT)
|
||||
@@ -0,0 +1,2 @@
|
||||
pybuilddir.txt
|
||||
builddir
|
||||
Vendored
+58
@@ -0,0 +1,58 @@
|
||||
include ../common.mk
|
||||
|
||||
NODE_VERSION=24.18.0
|
||||
|
||||
PLATFORM=wasm32_emscripten
|
||||
SYSCONFIGDATA_NAME=_sysconfigdata__$(PLATFORM)
|
||||
|
||||
export EMSDKDIR = $(PYTHONBUILD)/emsdk-cache
|
||||
|
||||
PYTHONLIBDIR=$(BUILDROOT)/install/Python-$(PYVERSION)/lib
|
||||
CROSS_PYTHON=$(PYTHONBUILD)/cross-build/wasm32-emscripten/build/python/python.sh
|
||||
|
||||
# Download Node.js when building locally; in CI it is provided by actions/setup-node.
|
||||
ifdef GITHUB_ACTIONS
|
||||
NODE_DEP=
|
||||
NODE_BIN=$(shell which node)
|
||||
else
|
||||
NODE_DIR=$(BUILDROOT)/node
|
||||
NODE_DEP=$(NODE_DIR)/.exists
|
||||
NODE_BIN=$(NODE_DIR)/bin/node
|
||||
NODE_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
|
||||
NODE_ARCH := $(shell uname -m | sed -e 's/x86_64/x64/' -e 's/aarch64/arm64/')
|
||||
NODE_URL=https://nodejs.org/dist/v$(NODE_VERSION)/node-v$(NODE_VERSION)-$(NODE_OS)-$(NODE_ARCH).tar.xz
|
||||
endif
|
||||
|
||||
# Prepend the downloaded Node.js to PATH (no-op in CI, where setup-node provides it).
|
||||
export PATH := $(NODE_BIN)$(PATH)
|
||||
|
||||
all: $(PYTHONLIBDIR)/libpython$(PYMAJORMINOR).a
|
||||
|
||||
$(NODE_DIR)/.exists: $(BUILDROOT)/.exists
|
||||
[ -d $(NODE_DIR) ] || mkdir -p $(NODE_DIR)
|
||||
curl -s -S --location $(NODE_URL) | \
|
||||
tar --strip-components 1 --directory $(NODE_DIR) --extract --xz
|
||||
touch $@
|
||||
|
||||
$(CROSS_PYTHON): $(PYTHONBUILD)/.exists $(NODE_DEP)
|
||||
cd $(PYTHONBUILD) && \
|
||||
$(PYTHON) Platforms/emscripten install-emscripten --emsdk-cache=$(EMSDKDIR) && \
|
||||
$(PYTHON) Platforms/emscripten build --emsdk-cache=$(EMSDKDIR) --host-runner=$(NODE_BIN)
|
||||
|
||||
$(PYTHONLIBDIR)/libpython$(PYMAJORMINOR).a: $(CROSS_PYTHON)
|
||||
# Generate sysconfigdata
|
||||
_PYTHON_SYSCONFIGDATA_NAME=$(SYSCONFIGDATA_NAME) _PYTHON_PROJECT_BASE=$(PYTHONBUILD)/cross-build/wasm32-emscripten/build/python $(CROSS_PYTHON) -m sysconfig --generate-posix-vars
|
||||
cp `cat pybuilddir.txt`/$(SYSCONFIGDATA_NAME).py $(PYTHONBUILD)/Lib
|
||||
|
||||
mkdir -p $(PYTHONLIBDIR)
|
||||
# Make a static library for _hacl, for some reason these are missing from the build?
|
||||
# source emsdk_env.sh to get emar in PATH, works best when done from the emsdk directory
|
||||
EMSDK_ENV=$$(find $(PYTHONBUILD)/emsdk-cache -name 'emsdk_env.sh' | head -n 1) && \
|
||||
cd $$(dirname $$EMSDK_ENV) && \
|
||||
. $$EMSDK_ENV && \
|
||||
cd $(PYTHONBUILD)/cross-build/wasm32-emscripten/build/python && \
|
||||
emar rcs Modules/_hacl/libhacl.a Modules/_hacl/*.o
|
||||
# Copy all .a libraries
|
||||
find $(PYTHONBUILD)/cross-build/wasm32-emscripten/ -name '*.a' -exec cp {} $(PYTHONLIBDIR) \;
|
||||
# Install Python stdlib
|
||||
cp -r $(PYTHONBUILD)/Lib $(PYTHONLIBDIR)/python$(PYMAJORMINOR)
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
#!/usr/local/bin/python
|
||||
import pathlib
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
p = pathlib.Path(sys.argv[1])
|
||||
|
||||
command = ["node", p.name, *sys.argv[2:]]
|
||||
print("Running:", " ".join(command))
|
||||
|
||||
sys.exit(subprocess.call(command, cwd=p.parent))
|
||||
@@ -0,0 +1 @@
|
||||
builddir
|
||||
Vendored
+67
@@ -0,0 +1,67 @@
|
||||
include ../common.mk
|
||||
|
||||
WASI_SDK_VERSION=24
|
||||
WASMTIME_VERSION=46.0.1
|
||||
|
||||
CONFIG_SITE=$(PYTHONBUILD)/Tools/wasm/wasi/config.site-wasm32-wasi
|
||||
CROSSBUILD=$(PYTHONBUILD)/cross-build/wasm32-wasip1
|
||||
LIBDIR=$(CROSSBUILD)/build/lib.wasi-wasm32-$(PYMAJORMINOR)
|
||||
|
||||
# In CI the WASI SDK is installed by bytecodealliance/setup-wasi-sdk-action, which sets
|
||||
# WASI_SDK_PATH; otherwise download the release asset matching this host into the build dir.
|
||||
ifdef GITHUB_ACTIONS
|
||||
WASI_SDK_DIR=$(WASI_SDK_PATH)
|
||||
WASI_SDK_DEP=
|
||||
else
|
||||
WASI_SDK_DIR=$(BUILDROOT)/wasi-sdk
|
||||
WASI_SDK_DEP=$(WASI_SDK_DIR)/.exists
|
||||
WASI_SDK_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | sed 's/darwin/macos/')
|
||||
WASI_SDK_ARCH := $(shell uname -m | sed 's/aarch64/arm64/')
|
||||
WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(WASI_SDK_VERSION)/wasi-sdk-$(WASI_SDK_VERSION).0-$(WASI_SDK_ARCH)-$(WASI_SDK_OS).tar.gz
|
||||
endif
|
||||
|
||||
# Similar for wasmtime, which is otherwise expected on PATH.
|
||||
ifdef GITHUB_ACTIONS
|
||||
WASMTIME_DEP=
|
||||
WASMTIME_PATH=
|
||||
else
|
||||
WASMTIME_DIR=$(BUILDROOT)/wasmtime
|
||||
WASMTIME_DEP=$(WASMTIME_DIR)/.exists
|
||||
WASMTIME_PATH=$(WASMTIME_DIR):
|
||||
WASMTIME_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | sed 's/darwin/macos/')
|
||||
# NB wasmtime names artifacts with aarch64 architecture, unlike wasi which uses arm64
|
||||
WASMTIME_ARCH := $(shell uname -m | sed 's/arm64/aarch64/')
|
||||
WASMTIME_URL=https://github.com/bytecodealliance/wasmtime/releases/download/v$(WASMTIME_VERSION)/wasmtime-v$(WASMTIME_VERSION)-$(WASMTIME_ARCH)-$(WASMTIME_OS).tar.xz
|
||||
endif
|
||||
|
||||
all: $(LIBDIR)/libpython$(PYMAJORMINOR).a
|
||||
|
||||
$(WASI_SDK_DIR)/.exists: $(BUILDROOT)/.exists
|
||||
[ -d $(WASI_SDK_DIR) ] || mkdir -p $(WASI_SDK_DIR)
|
||||
curl -s -S --location $(WASI_SDK_URL) | \
|
||||
tar --strip-components 1 --directory $(WASI_SDK_DIR) --extract --gunzip
|
||||
touch $@
|
||||
|
||||
$(WASMTIME_DIR)/.exists: $(BUILDROOT)/.exists
|
||||
[ -d $(WASMTIME_DIR) ] || mkdir -p $(WASMTIME_DIR)
|
||||
curl -s -S --location $(WASMTIME_URL) | \
|
||||
tar --strip-components 1 --directory $(WASMTIME_DIR) --extract --xz
|
||||
touch $@
|
||||
|
||||
$(PYTHONBUILD)/.patched: $(PYTHONBUILD)/.exists
|
||||
# Force-disable POSIX dynamic loading for WASI
|
||||
grep -q '^ac_cv_func_dlopen=no' $(CONFIG_SITE) || \
|
||||
printf '\nac_cv_func_dlopen=no\nac_cv_lib_dl_dlopen=no\n' >> $(CONFIG_SITE)
|
||||
touch $@
|
||||
|
||||
$(LIBDIR)/libpython$(PYMAJORMINOR).a: $(PYTHONBUILD)/.patched $(WASI_SDK_DEP) $(WASMTIME_DEP)
|
||||
cd $(PYTHONBUILD) && \
|
||||
WASI_SDK_PATH=$(WASI_SDK_DIR) \
|
||||
PATH=$(WASMTIME_PATH)$(PATH) \
|
||||
$(PYTHON) Tools/wasm/wasi build -- --config-cache
|
||||
# Collect the static libraries the test build links against
|
||||
cp $(CROSSBUILD)/libpython$(PYMAJORMINOR).a \
|
||||
$(CROSSBUILD)/Modules/_hacl/libHacl_HMAC.a \
|
||||
$(CROSSBUILD)/Modules/_decimal/libmpdec/libmpdec.a \
|
||||
$(CROSSBUILD)/Modules/expat/libexpat.a \
|
||||
$(LIBDIR)
|
||||
Reference in new issue
Block a user