Skip to content

Commit c0de3eb

Browse files
authored
ci: bump emscripten build to 3.14 (#5455)
* ci: bump emscripten build to 3.13 * try 3.14 * fix build of Python 3.14 * restore env.sh usage * copy correct .a files * also copy mpdec, ffi * use 3.14 head with emscripten download * fixup using head CPython * fix finding emsdk_env in noxfile * cleanup * cleanup python passing from noxfile to make
1 parent 1d26e82 commit c0de3eb

7 files changed

Lines changed: 58 additions & 83 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,7 @@ jobs:
457457
- uses: actions/checkout@v6.0.2
458458
- uses: actions/setup-python@v6
459459
with:
460-
# TODO bump emscripten builds to test on 3.13
461-
python-version: 3.11
460+
python-version: 3.14
462461
id: setup-python
463462
- name: Install Rust toolchain
464463
uses: dtolnay/rust-toolchain@stable
@@ -467,7 +466,7 @@ jobs:
467466
components: rust-src
468467
- uses: actions/setup-node@v6
469468
with:
470-
node-version: 18
469+
node-version: 24
471470
- run: python -m pip install --upgrade pip && pip install nox[uv]
472471
- uses: actions/cache/restore@v5
473472
id: cache

emscripten/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pybuilddir.txt
2+
builddir

emscripten/Makefile

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@ CURDIR=$(abspath .)
22

33
# These three are passed in from nox.
44
BUILDROOT ?= $(CURDIR)/builddir
5-
PYMAJORMINORMICRO ?= 3.11.0
5+
PYTHON ?= python3
6+
PYMAJORMINORMICRO ?= $(shell $(PYTHON) --version 2>&1 | awk '{print $$2}')
67

7-
EMSCRIPTEN_VERSION=3.1.68
8-
9-
export EMSDKDIR = $(BUILDROOT)/emsdk
8+
export EMSDKDIR = $(PYTHONBUILD)/emsdk-cache
109

1110
PLATFORM=wasm32_emscripten
1211
SYSCONFIGDATA_NAME=_sysconfigdata__$(PLATFORM)
1312

14-
# BASH_ENV tells bash to source emsdk_env.sh on startup.
15-
export BASH_ENV := $(CURDIR)/env.sh
16-
# Use bash to run each command so that env.sh will be used.
17-
SHELL := /bin/bash
18-
19-
2013
# Set version variables.
2114
version_tuple := $(subst ., ,$(PYMAJORMINORMICRO:v%=%))
2215
PYMAJOR=$(word 1,$(version_tuple))
@@ -27,61 +20,66 @@ PYMAJORMINOR=$(PYMAJOR).$(PYMINOR)
2720

2821

2922
PYTHONURL=https://www.python.org/ftp/python/$(PYMAJORMINORMICRO)/Python-$(PYVERSION).tgz
30-
PYTHONTARBALL=$(BUILDROOT)/downloads/Python-$(PYVERSION).tgz
31-
PYTHONBUILD=$(BUILDROOT)/build/Python-$(PYVERSION)
23+
# TODO: resume download once 3.14.4 ships with emscripten cache
24+
# PYTHONTARBALL=$(BUILDROOT)/downloads/Python-$(PYVERSION).tgz
25+
# PYTHONBUILD=$(BUILDROOT)/build/Python-$(PYVERSION)
26+
PYTHONBUILD=$(BUILDROOT)/build/cpython
3227

3328
PYTHONLIBDIR=$(BUILDROOT)/install/Python-$(PYVERSION)/lib
3429

30+
CROSS_PYTHON=$(PYTHONBUILD)/cross-build/wasm32-emscripten/build/python/python.sh
31+
3532
all: $(PYTHONLIBDIR)/libpython$(PYMAJORMINOR).a
3633

37-
$(BUILDROOT)/.exists:
34+
$(BUILDROOT)/.exists:
3835
mkdir -p $(BUILDROOT)
3936
touch $@
4037

38+
# TODO: use tarball once 3.14.4 ships with emscripten cache
4139

42-
# Install emscripten
43-
$(EMSDKDIR): $(CURDIR)/emscripten_patches/* $(BUILDROOT)/.exists
44-
git clone https://github.com/emscripten-core/emsdk.git --depth 1 --branch $(EMSCRIPTEN_VERSION) $(EMSDKDIR)
45-
$(EMSDKDIR)/emsdk install $(EMSCRIPTEN_VERSION)
46-
cd $(EMSDKDIR)/upstream/emscripten && cat $(CURDIR)/emscripten_patches/* | patch -p1
47-
$(EMSDKDIR)/emsdk activate $(EMSCRIPTEN_VERSION)
40+
# $(PYTHONTARBALL):
41+
# [ -d $(BUILDROOT)/downloads ] || mkdir -p $(BUILDROOT)/downloads
42+
# wget -q -O $@ $(PYTHONURL)
4843

44+
# $(PYTHONBUILD)/.patched: $(PYTHONTARBALL)
45+
# [ -d $(PYTHONBUILD) ] || ( \
46+
# mkdir -p $(dir $(PYTHONBUILD));\
47+
# tar -C $(dir $(PYTHONBUILD)) -xf $(PYTHONTARBALL) \
48+
# )
49+
# touch $@
4950

50-
$(PYTHONTARBALL):
51-
[ -d $(BUILDROOT)/downloads ] || mkdir -p $(BUILDROOT)/downloads
52-
wget -q -O $@ $(PYTHONURL)
51+
ifneq ($(PYMAJORMINOR),3.14)
52+
$(error PYMAJORMINOR must be 3.14, got '$(PYMAJORMINOR)')
53+
endif
5354

54-
$(PYTHONBUILD)/.patched: $(PYTHONTARBALL)
55+
$(PYTHONBUILD)/.patched: $(BUILDROOT)/.exists
5556
[ -d $(PYTHONBUILD) ] || ( \
5657
mkdir -p $(dir $(PYTHONBUILD));\
57-
tar -C $(dir $(PYTHONBUILD)) -xf $(PYTHONTARBALL) \
58+
git clone --depth 1 --branch 3.14 https://github.com/python/cpython $(PYTHONBUILD) \
5859
)
5960
touch $@
6061

61-
$(PYTHONBUILD)/Makefile: $(PYTHONBUILD)/.patched $(BUILDROOT)/emsdk
62-
cd $(PYTHONBUILD) && \
63-
CONFIG_SITE=Tools/wasm/config.site-wasm32-emscripten \
64-
emconfigure ./configure -C \
65-
--host=wasm32-unknown-emscripten \
66-
--build=$(shell $(PYTHONBUILD)/config.guess) \
67-
--with-emscripten-target=browser \
68-
--enable-wasm-dynamic-linking \
69-
--with-build-python=python3.11
70-
71-
$(PYTHONLIBDIR)/libpython$(PYMAJORMINOR).a : $(PYTHONBUILD)/Makefile
62+
$(CROSS_PYTHON): $(PYTHONBUILD)/.patched
7263
cd $(PYTHONBUILD) && \
73-
emmake make -j3 libpython$(PYMAJORMINOR).a
64+
$(PYTHON) Tools/wasm/emscripten install-emscripten --quiet --emsdk-cache=$(EMSDKDIR) && \
65+
$(PYTHON) Tools/wasm/emscripten build --quiet --emsdk-cache=$(EMSDKDIR)
7466

67+
$(PYTHONLIBDIR)/libpython$(PYMAJORMINOR).a: $(CROSS_PYTHON)
7568
# Generate sysconfigdata
76-
_PYTHON_SYSCONFIGDATA_NAME=$(SYSCONFIGDATA_NAME) _PYTHON_PROJECT_BASE=$(PYTHONBUILD) python3.11 -m sysconfig --generate-posix-vars
69+
_PYTHON_SYSCONFIGDATA_NAME=$(SYSCONFIGDATA_NAME) _PYTHON_PROJECT_BASE=$(PYTHONBUILD)/cross-build/wasm32-emscripten/build/python $(CROSS_PYTHON) -m sysconfig --generate-posix-vars
7770
cp `cat pybuilddir.txt`/$(SYSCONFIGDATA_NAME).py $(PYTHONBUILD)/Lib
7871

7972
mkdir -p $(PYTHONLIBDIR)
80-
# Copy libexpat.a, libmpdec.a, and libpython3.11.a
81-
# In noxfile, we explicitly link libexpat and libmpdec via RUSTFLAGS
82-
find $(PYTHONBUILD) -name '*.a' -exec cp {} $(PYTHONLIBDIR) \;
73+
# Make a static library for _hacl, for some reason these are missing from the build?
74+
# source emsdk_env.sh to get emar in PATH, works best when done from the emsdk directory
75+
EMSDK_ENV=$$(find $(PYTHONBUILD)/emsdk-cache -name 'emsdk_env.sh' | head -n 1) && \
76+
cd $$(dirname $$EMSDK_ENV) && \
77+
. $$EMSDK_ENV && \
78+
cd $(PYTHONBUILD)/cross-build/wasm32-emscripten/build/python && \
79+
emar rcs Modules/_hacl/libhacl.a Modules/_hacl/*.o
80+
# Copy all .a libraries
81+
find $(PYTHONBUILD)/cross-build/wasm32-emscripten/ -name '*.a' -exec cp {} $(PYTHONLIBDIR) \;
8382
# Install Python stdlib
8483
cp -r $(PYTHONBUILD)/Lib $(PYTHONLIBDIR)/python$(PYMAJORMINOR)
85-
8684
clean:
8785
rm -rf $(BUILDROOT)

emscripten/emscripten_patches/0001-Add-_gxx_personality_v0-stub-to-library.js.patch

Lines changed: 0 additions & 28 deletions
This file was deleted.

emscripten/env.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

emscripten/runner.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55

66
p = pathlib.Path(sys.argv[1])
77

8-
sys.exit(subprocess.call(["node", p.name], cwd=p.parent))
8+
command = ["node", p.name, *sys.argv[2:]]
9+
print("Running:", " ".join(command))
10+
11+
sys.exit(subprocess.call(command, cwd=p.parent))

noxfile.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from functools import lru_cache
1313
from glob import glob
1414
from pathlib import Path
15+
from shlex import quote
1516
from typing import (
1617
Any,
1718
Callable,
@@ -438,22 +439,29 @@ def test_emscripten(session: nox.Session):
438439
f"-C link-arg={pythonlibdir}@/lib/python{info.pymajorminor}",
439440
f"-C link-arg=-lpython{info.pymajorminor}",
440441
"-C link-arg=-lexpat",
442+
"-C link-arg=-lffi",
441443
"-C link-arg=-lmpdec",
442-
"-C link-arg=-lsqlite3",
443-
"-C link-arg=-lz",
444-
"-C link-arg=-lbz2",
444+
"-C link-arg=-lhacl",
445+
"-C link-arg=-sUSE_SQLITE3",
446+
"-C link-arg=-sUSE_ZLIB",
447+
"-C link-arg=-sUSE_BZIP2",
448+
"-C link-arg=-sEXPORTED_FUNCTIONS=_main,__PyRuntime",
445449
"-C link-arg=-sALLOW_MEMORY_GROWTH=1",
450+
"-C link-arg=-sSTACK_SIZE=262144",
446451
]
447452
)
448453
session.env["RUSTDOCFLAGS"] = session.env["RUSTFLAGS"]
449454
session.env["CARGO_BUILD_TARGET"] = target
450455
session.env["PYO3_CROSS_LIB_DIR"] = pythonlibdir
451456
_run(session, "rustup", "target", "add", target, "--toolchain", "stable")
457+
458+
emsdk_env = next(info.builddir.glob("**/emsdk-cache/**/emsdk_env.sh"))
459+
452460
_run(
453461
session,
454462
"bash",
455463
"-c",
456-
f"source {info.builddir / 'emsdk/emsdk_env.sh'} && cargo test",
464+
f"source {emsdk_env} && cargo test {' '.join(quote(arg) for arg in session.posargs)}",
457465
)
458466

459467

0 commit comments

Comments
 (0)