forked from PyO3/pyo3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
85 lines (67 loc) · 2.99 KB
/
Copy pathMakefile
File metadata and controls
85 lines (67 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
CURDIR=$(abspath .)
# These three are passed in from nox.
BUILDROOT ?= $(CURDIR)/builddir
PYTHON ?= python3
PYMAJORMINORMICRO ?= $(shell $(PYTHON) --version 2>&1 | awk '{print $$2}')
export EMSDKDIR = $(PYTHONBUILD)/emsdk-cache
PLATFORM=wasm32_emscripten
SYSCONFIGDATA_NAME=_sysconfigdata__$(PLATFORM)
# 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)
PYTHONURL=https://www.python.org/ftp/python/$(PYMAJORMINORMICRO)/Python-$(PYVERSION).tgz
# TODO: resume download once 3.14.4 ships with emscripten cache
# PYTHONTARBALL=$(BUILDROOT)/downloads/Python-$(PYVERSION).tgz
# PYTHONBUILD=$(BUILDROOT)/build/Python-$(PYVERSION)
PYTHONBUILD=$(BUILDROOT)/build/cpython
PYTHONLIBDIR=$(BUILDROOT)/install/Python-$(PYVERSION)/lib
CROSS_PYTHON=$(PYTHONBUILD)/cross-build/wasm32-emscripten/build/python/python.sh
all: $(PYTHONLIBDIR)/libpython$(PYMAJORMINOR).a
$(BUILDROOT)/.exists:
mkdir -p $(BUILDROOT)
touch $@
# TODO: use tarball once 3.14.4 ships with emscripten cache
# $(PYTHONTARBALL):
# [ -d $(BUILDROOT)/downloads ] || mkdir -p $(BUILDROOT)/downloads
# wget -q -O $@ $(PYTHONURL)
# $(PYTHONBUILD)/.patched: $(PYTHONTARBALL)
# [ -d $(PYTHONBUILD) ] || ( \
# mkdir -p $(dir $(PYTHONBUILD));\
# tar -C $(dir $(PYTHONBUILD)) -xf $(PYTHONTARBALL) \
# )
# touch $@
ifneq ($(PYMAJORMINOR),3.14)
$(error PYMAJORMINOR must be 3.14, got '$(PYMAJORMINOR)')
endif
$(PYTHONBUILD)/.patched: $(BUILDROOT)/.exists
[ -d $(PYTHONBUILD) ] || ( \
mkdir -p $(dir $(PYTHONBUILD));\
git clone --depth 1 --branch 3.14 https://github.com/python/cpython $(PYTHONBUILD) \
)
touch $@
$(CROSS_PYTHON): $(PYTHONBUILD)/.patched
cd $(PYTHONBUILD) && \
$(PYTHON) Tools/wasm/emscripten install-emscripten --quiet --emsdk-cache=$(EMSDKDIR) && \
$(PYTHON) Tools/wasm/emscripten build --quiet --emsdk-cache=$(EMSDKDIR)
$(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)
clean:
rm -rf $(BUILDROOT)