@@ -2,21 +2,14 @@ CURDIR=$(abspath .)
22
33# These three are passed in from nox.
44BUILDROOT ?= $(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
1110PLATFORM =wasm32_emscripten
1211SYSCONFIGDATA_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.
2114version_tuple := $(subst ., ,$(PYMAJORMINORMICRO:v%=% ) )
2215PYMAJOR =$(word 1,$(version_tuple ) )
@@ -27,61 +20,66 @@ PYMAJORMINOR=$(PYMAJOR).$(PYMINOR)
2720
2821
2922PYTHONURL =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
3328PYTHONLIBDIR =$(BUILDROOT ) /install/Python-$(PYVERSION ) /lib
3429
30+ CROSS_PYTHON =$(PYTHONBUILD ) /cross-build/wasm32-emscripten/build/python/python.sh
31+
3532all : $(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-
8684clean :
8785 rm -rf $(BUILDROOT )
0 commit comments