Skip to content

Commit c189523

Browse files
committed
Try using shared libraries for the pyodide wheel
1 parent 33f9617 commit c189523

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

bin/cibw_before_all_pyodide.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ mkdir -p "$WASM_LIBRARY_DIR"
1515

1616
# The Pyodide cibuildwheel environment for building python-flint itself sets
1717
# include/library flags that reference libgmp/libmpfr/libflint. Those libraries
18-
# do not exist yet while bootstrapping the static dependencies here, so letting
18+
# do not exist yet while bootstrapping the shared dependencies here, so letting
1919
# them leak into configure would break link tests such as "does the C compiler
2020
# work?" for GMP. Use a minimal environment for the bootstrap step.
21+
unset CFLAGS
2122
unset PKG_CONFIG_PATH
2223
unset LDFLAGS
23-
export CFLAGS="-fPIC"
2424

2525
"$SCRIPT_DIR/pyodide_build_dependencies.sh" --wasm-library-dir "$WASM_LIBRARY_DIR"

bin/pyodide_build_dependencies.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ cd "$WASM_LIBRARY_DIR/src"
5252

5353
source "$SCRIPT_DIR/build_variables.sh"
5454

55+
# Keep these in sync with the pinned Pyodide build environment.
56+
SIDE_MODULE_CFLAGS="-O2 -g0 -fPIC -fwasm-exceptions -sSUPPORT_LONGJMP"
57+
SIDE_MODULE_LDFLAGS="-O2 -g0 -sWASM_BIGINT -fwasm-exceptions -sSUPPORT_LONGJMP -sSIDE_MODULE=2"
58+
5559
# Download mirrored copy of source distributions for GMP and MPFR
5660

5761
git clone https://github.com/oscarbenjamin/gmp_mirror.git
@@ -67,11 +71,14 @@ tar -xf mpfr-$MPFRVER.tar.gz
6771
cd gmp-$GMPVER
6872

6973
emconfigure ./configure \
74+
CFLAGS="$SIDE_MODULE_CFLAGS" \
75+
LDFLAGS="$SIDE_MODULE_LDFLAGS" \
7076
--disable-dependency-tracking \
7177
--host none \
72-
--disable-shared \
73-
--enable-static \
74-
--enable-cxx \
78+
--enable-shared=yes \
79+
--enable-static=no \
80+
--disable-cxx \
81+
--disable-assembly \
7582
--prefix=$WASM_LIBRARY_DIR
7683

7784
emmake make -j $(nproc)
@@ -86,8 +93,11 @@ cd ..
8693
cd mpfr-$MPFRVER
8794

8895
emconfigure ./configure \
96+
CFLAGS="$SIDE_MODULE_CFLAGS" \
97+
LDFLAGS="$SIDE_MODULE_LDFLAGS -L$WASM_LIBRARY_DIR/lib" \
8998
--disable-dependency-tracking \
90-
--disable-shared \
99+
--enable-shared=yes \
100+
--enable-static=no \
91101
--with-gmp=$WASM_LIBRARY_DIR \
92102
--prefix=$WASM_LIBRARY_DIR
93103

@@ -116,8 +126,12 @@ fi
116126
./bootstrap.sh
117127

118128
emconfigure ./configure \
129+
CFLAGS="$SIDE_MODULE_CFLAGS" \
130+
LDFLAGS="$SIDE_MODULE_LDFLAGS -L$WASM_LIBRARY_DIR/lib" \
119131
--disable-dependency-tracking \
120-
--disable-shared \
132+
--enable-shared=yes \
133+
--disable-static \
134+
--disable-debug \
121135
--prefix=$WASM_LIBRARY_DIR \
122136
--with-gmp=$WASM_LIBRARY_DIR \
123137
--with-mpfr=$WASM_LIBRARY_DIR \

pyproject.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,26 +179,26 @@ repair-wheel-command = [
179179

180180
[tool.cibuildwheel.pyodide]
181181
before-all = "bin/cibw_before_all_pyodide.sh"
182-
before-build = "pip install wheel"
182+
before-build = "pip install wheel auditwheel-emscripten"
183183

184184
# This needs to be kept in sync with the Pyodide row in
185185
# .github/workflows/buildwheel.yml. The Pyodide version pins both an
186186
# Emscripten version and a CPython minor version. The command
187187
# `pyodide xbuildenv search --all` shows the compatible combinations.
188188
pyodide-version = "0.28.2"
189189

190-
# GMP, MPFR, and FLINT are built as static libraries for Pyodide.
190+
# GMP, MPFR, and FLINT are built as shared libraries for Pyodide.
191191
repair-wheel-command = [
192192
"""python bin/cibw_repair_wheel_licenses.py "{wheel}" \
193193
--license LGPL-3.0-or-later \
194-
--license-file 'wasm-library-dir/src/gmp-*/COPYING:python-flint.libs/gmp-*/COPYING' \
195-
--license-file 'wasm-library-dir/src/gmp-*/COPYING.LESSERv3:python-flint.libs/gmp-*/COPYING.LESSERv3' \
196-
--license-file 'wasm-library-dir/src/mpfr-*/COPYING:python-flint.libs/mpfr-*/COPYING' \
197-
--license-file 'wasm-library-dir/src/mpfr-*/COPYING.LESSER:python-flint.libs/mpfr-*/COPYING.LESSER' \
198-
--license-file 'wasm-library-dir/src/flint-*/COPYING:python-flint.libs/flint-*/COPYING' \
199-
--license-file 'wasm-library-dir/src/flint-*/COPYING.LESSER:python-flint.libs/flint-*/COPYING.LESSER' \
194+
--license-file 'wasm-library-dir/src/gmp-*/COPYING:python_flint.libs/gmp-*/COPYING' \
195+
--license-file 'wasm-library-dir/src/gmp-*/COPYING.LESSERv3:python_flint.libs/gmp-*/COPYING.LESSERv3' \
196+
--license-file 'wasm-library-dir/src/mpfr-*/COPYING:python_flint.libs/mpfr-*/COPYING' \
197+
--license-file 'wasm-library-dir/src/mpfr-*/COPYING.LESSER:python_flint.libs/mpfr-*/COPYING.LESSER' \
198+
--license-file 'wasm-library-dir/src/flint-*/COPYING:python_flint.libs/flint-*/COPYING' \
199+
--license-file 'wasm-library-dir/src/flint-*/COPYING.LESSER:python_flint.libs/flint-*/COPYING.LESSER' \
200200
""",
201-
"cp \"{wheel}\" \"{dest_dir}\"",
201+
"pyodide auditwheel repair --libdir wasm-library-dir/lib --output-dir {dest_dir} {wheel}",
202202
]
203203

204204
[tool.cibuildwheel.pyodide.environment]

0 commit comments

Comments
 (0)