Skip to content

Commit b871da3

Browse files
committed
Experiment building scipy using openblas-flang
1 parent f313ec8 commit b871da3

12 files changed

+2640
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
set -ex
2+
3+
LLVM_PKG_URL="https://github.com/IsabelParedes/llvm-project/releases/download/v20.1.7_emscripten-wasm32/llvm_emscripten-wasm32-20.1.7-h2e33cc4_5.tar.bz2"
4+
LLVM_PKG="llvm.tar.bz2"
5+
export LLVM_DIR=$HOME/llvm
6+
7+
if [ ! -d "$LLVM_DIR" ]; then
8+
wget -O "$LLVM_PKG" "$LLVM_PKG_URL"
9+
mkdir -p $LLVM_DIR
10+
tar -xjvf $LLVM_PKG -C $LLVM_DIR --exclude='info/*' --exclude='share/*' --exclude='libexec/*'
11+
fi
12+
13+
export EM_LLVM_ROOT=$LLVM_DIR
14+
15+
echo "LLVM installation complete."
16+
17+
# https://github.com/mesonbuild/meson/blob/e542901af6e30865715d3c3c18f703910a096ec0/mesonbuild/backend/ninjabackend.py#L94
18+
# Prevent from using response file. The response file that meson generates is not compatible to pyodide-build
19+
export MESON_RSP_THRESHOLD=131072
20+
21+
export CFLAGS="-I$PREFIX/include/python3.13 $CFLAGS"
22+
export CXXFLAGS="-I$PREFIX/include/python3.13 $CXXFLAGS"
23+
24+
# Patch mesonbuild/linkers/linkers.py - not sure what version we are patching?
25+
# meson 1.9.1 conda-forge, meson-python 0.18.0 conda-forge
26+
cp $RECIPE_DIR/meson_linkers.py $BUILD_PREFIX/lib/python3.13/site-packages/mesonbuild/linkers/linkers.py
27+
28+
# Remove whitespace after '-s' in LDFLAGS
29+
export LDFLAGS="$(echo "${LDFLAGS}" | sed -E 's/-s +/-s/g')"
30+
31+
# Use local flang-new-wrapper that does some arg mangling.
32+
cp $RECIPE_DIR/flang-new-wrapper $LLVM_DIR/bin/flang-new-wrapper
33+
34+
export FC=$LLVM_DIR/bin/flang-new-wrapper
35+
export FFLAGS="-g --target=wasm32-unknown-emscripten -fPIC"
36+
export FCLIBS="-lFortranRuntime"
37+
38+
export CFLAGS="$CFLAGS -fwasm-exceptions -sSUPPORT_LONGJMP=wasm"
39+
export CXXFLAGS="$CXXFLAGS -fwasm-exceptions -sSUPPORT_LONGJMP=wasm"
40+
41+
# Note bracket after function name is important or 'sgesv' will also match 'sgesvd'
42+
cat void_to_int_return.txt | xargs -i sed -i -r 's/^void ({})\(/int \1(/g' scipy/linalg/cython_lapack_signatures.txt
43+
# Underscore after name is important
44+
cat void_to_int_return.txt | xargs -i sed -i -r 's/^void ({})_/int \1_/g' scipy/linalg/_matfuncs_expm.h
45+
46+
# Add -Wl,--fatal-warnings to flags - this does not work
47+
export LDFLAGS="$LDFLAGS -Wl,--no-fatal-warnings"
48+
49+
${PYTHON} -m pip install . ${PIP_ARGS} --no-build-isolation \
50+
-Csetup-args="--cross-file=$RECIPE_DIR/emscripten.meson.cross" \
51+
-Csetup-args="-Dfortran_std=none" \
52+
-Csetup-args="-Duse-pythran=false" \
53+
-Cbuild-dir="_build" \
54+
-Ccompile-args="--verbose"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[properties]
2+
needs_exe_wrapper = true
3+
skip_sanity_check = true
4+
longdouble_format = 'IEEE_QUAD_LE' # for numpy
5+
6+
[host_machine]
7+
system = 'emscripten'
8+
cpu_family = 'wasm32'
9+
cpu = 'wasm'
10+
endian = 'little'
11+
12+
[binaries]
13+
exe_wrapper = 'node'
14+
pkgconfig = 'pkg-config'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
args=()
4+
for arg in "$@"; do
5+
if [[ "${arg}" != -s* ]]; then
6+
args+=("${arg}")
7+
fi
8+
done
9+
10+
exec "$LLVM_DIR/bin/flang-new" "-v" "${args[@]}"

0 commit comments

Comments
 (0)