-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbuild_wasm.sh
More file actions
executable file
·41 lines (28 loc) · 1.21 KB
/
build_wasm.sh
File metadata and controls
executable file
·41 lines (28 loc) · 1.21 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
#!/bin/bash
set -eou pipefail
# CPYTHON_ROOT must contain a build of cpython for wasm32-wasip2
TARGET="wasm32-wasip2"
CROSS_BUILD="${CPYTHON_ROOT}/cross-build/${TARGET}"
WASI_SDK_PATH=${WASI_SDK_PATH:-/opt/wasi-sdk}
PYTHON_VERSION=$(grep '^VERSION=' "${CROSS_BUILD}/Makefile" | sed 's/VERSION=[[:space:]]*//')
if [ ! -e wasm_venv ]; then
uv venv --python ${PYTHON_VERSION} wasm_venv
fi
. wasm_venv/bin/activate
HOST_PYTHON=$(which python3)
uv pip install build wheel cython setuptools
ARCH_TRIPLET=_wasi_wasm32-wasi
export CC="${WASI_SDK_PATH}/bin/clang"
export CXX="${WASI_SDK_PATH}/bin/clang++"
export PYTHONPATH="${CROSS_BUILD}/build/lib.wasi-wasm32-${PYTHON_VERSION}"
export CFLAGS="--target=${TARGET} -fPIC -I${CROSS_BUILD}/install/include/python${PYTHON_VERSION} -D__EMSCRIPTEN__=1"
export CXXFLAGS="--target=${TARGET} -fPIC -I${CROSS_BUILD}/install/include/python${PYTHON_VERSION}"
export LDSHARED=${CC}
export AR="${WASI_SDK_PATH}/bin/ar"
export RANLIB=true
export LDFLAGS="--target=${TARGET} -shared -Wl,--allow-undefined"
export _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata__wasi_wasm32-wasi
export _PYTHON_HOST_PLATFORM=wasm32-wasi
python3 -m build -n -w
wheel unpack --dest build dist/*.whl
rm -rf ./wasm_venv