Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scipy draft #1851

Open
wants to merge 104 commits into
base: emscripten-3.1.73
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
74305c1
WIP
IsabelParedes Jan 31, 2025
73c5c91
Update build
IsabelParedes Jan 31, 2025
a6b2763
Restore tests
IsabelParedes Jan 31, 2025
a6ac4a3
wrapped
DerThorsten Feb 3, 2025
116185e
wrapped
DerThorsten Feb 3, 2025
651e676
typo
DerThorsten Feb 3, 2025
24c2a86
typo
DerThorsten Feb 3, 2025
7566076
typo
DerThorsten Feb 3, 2025
3f42292
typo
DerThorsten Feb 3, 2025
9945448
wasm-bigint
DerThorsten Feb 3, 2025
af7260b
wasm-bigint
DerThorsten Feb 3, 2025
5b7dd32
undefined symbols
DerThorsten Feb 3, 2025
504b883
shared
DerThorsten Feb 3, 2025
a0cbb9f
shared
DerThorsten Feb 3, 2025
ca0fe23
try with -nostdlib
DerThorsten Feb 3, 2025
f8371e5
meson cross
DerThorsten Feb 3, 2025
4671aab
meson cross
DerThorsten Feb 3, 2025
f0629a4
meson cross
DerThorsten Feb 3, 2025
3cbb8ea
meson cross
DerThorsten Feb 3, 2025
925312b
args
DerThorsten Feb 3, 2025
4825e7b
02
DerThorsten Feb 3, 2025
50b8f6d
no flags
DerThorsten Feb 3, 2025
1c9fa9b
no cross python atm
DerThorsten Feb 3, 2025
3d8e9ed
no cross python atm
DerThorsten Feb 3, 2025
26424bd
disable shared
DerThorsten Feb 3, 2025
aebbdcf
no cross python atm
DerThorsten Feb 3, 2025
66aac25
keep disabled shared
DerThorsten Feb 3, 2025
042cd42
keep disabled shared
DerThorsten Feb 3, 2025
e99e71c
do disabled shared
DerThorsten Feb 3, 2025
045e280
do disabled shared
DerThorsten Feb 3, 2025
757fa33
using cross python again
DerThorsten Feb 3, 2025
6a8a5d9
using cross python again
DerThorsten Feb 3, 2025
ae528d6
using side modules again
DerThorsten Feb 3, 2025
5519865
dont use .js suffix
DerThorsten Feb 3, 2025
79d8c00
try via pip
DerThorsten Feb 3, 2025
45d0fcb
removed wrong ones
DerThorsten Feb 3, 2025
74177aa
try with removing shared libraires
DerThorsten Feb 4, 2025
111026a
bisect
DerThorsten Feb 4, 2025
57f8773
pkg info
DerThorsten Feb 4, 2025
899bf4b
pkg info
DerThorsten Feb 4, 2025
566c0ec
https
DerThorsten Feb 4, 2025
4d83907
all sub dirs but _build_utils
DerThorsten Feb 4, 2025
ae9fbf0
add misc
DerThorsten Feb 4, 2025
02a2d9b
add misc v2
DerThorsten Feb 4, 2025
aa93362
add _lib
DerThorsten Feb 4, 2025
22c371c
special + linalg
DerThorsten Feb 4, 2025
6656fa5
explicit -fc1
DerThorsten Feb 4, 2025
1d62ff5
try flang directely
DerThorsten Feb 4, 2025
59fb01e
try flang directely
DerThorsten Feb 4, 2025
be14a82
no wrapper
DerThorsten Feb 4, 2025
2a1a5b8
hack meson
DerThorsten Feb 5, 2025
4662dc3
all sub dirs
DerThorsten Feb 5, 2025
d42a07f
remove openmp flag
DerThorsten Feb 5, 2025
7ea8411
flags
DerThorsten Feb 5, 2025
99efce6
debug arg-wrapping
DerThorsten Feb 5, 2025
6773350
disabled OPENMP in propack
DerThorsten Feb 5, 2025
437da33
NO WRAP
DerThorsten Feb 5, 2025
220403b
NO WRAP
DerThorsten Feb 5, 2025
b47794e
NO FLAGS
DerThorsten Feb 5, 2025
70a8de3
wrap
DerThorsten Feb 5, 2025
e5adf75
module?
DerThorsten Feb 5, 2025
135cb9b
try pure bash
DerThorsten Feb 5, 2025
e4faefa
use the bak
DerThorsten Feb 5, 2025
527c86a
fix
DerThorsten Feb 5, 2025
aebd568
simple shell
DerThorsten Feb 5, 2025
3d7ebd7
remove bad substitution
DerThorsten Feb 5, 2025
6fe2ee5
...
DerThorsten Feb 5, 2025
93d8a18
....
DerThorsten Feb 5, 2025
5216423
....
DerThorsten Feb 5, 2025
d496ae2
update
DerThorsten Feb 5, 2025
51da68d
update
DerThorsten Feb 5, 2025
5195595
update flang
DerThorsten Feb 5, 2025
3bb54e4
update flang
DerThorsten Feb 5, 2025
b642a40
use emscripten
DerThorsten Feb 5, 2025
5a68077
install libllvm19
DerThorsten Feb 5, 2025
35fd7b8
install libllvm19
DerThorsten Feb 5, 2025
9d81223
dfortran
DerThorsten Feb 5, 2025
1e3928a
dfortran
DerThorsten Feb 5, 2025
7cf95ea
experiment
DerThorsten Feb 6, 2025
820a91c
experiment
DerThorsten Feb 6, 2025
576a40e
experiment ||
DerThorsten Feb 6, 2025
bf9418b
all args
DerThorsten Feb 6, 2025
647793c
all args
DerThorsten Feb 6, 2025
3d0a438
remove unwanted changes
DerThorsten Feb 6, 2025
708d5df
drop first arg
DerThorsten Feb 6, 2025
28da5ef
unwrap
DerThorsten Feb 6, 2025
9dab78f
what could go wrong
DerThorsten Feb 6, 2025
819645b
what could go wrong
DerThorsten Feb 6, 2025
eb6d945
what could go wrong
DerThorsten Feb 6, 2025
461ca79
trigger rebuild
DerThorsten Feb 6, 2025
0bdeb46
cp
DerThorsten Feb 7, 2025
95fc5c9
cp
DerThorsten Feb 7, 2025
b449d27
add micromamba
DerThorsten Feb 7, 2025
20cef43
dir
DerThorsten Feb 7, 2025
da947b8
mkdir
DerThorsten Feb 7, 2025
e97461a
mkdir
DerThorsten Feb 7, 2025
3dfa7a5
use thorstens fork of propack
DerThorsten Feb 7, 2025
eaf15d6
use thorstens fork of propack
DerThorsten Feb 7, 2025
987e2a0
use thorstens fork of propack
DerThorsten Feb 7, 2025
b0a96bd
use thorstens fork of propack
DerThorsten Feb 7, 2025
b61553a
use thorstens propack fork III
DerThorsten Feb 10, 2025
4332759
use target_directory
DerThorsten Feb 10, 2025
9e7a642
verbose
DerThorsten Feb 10, 2025
4f87f14
verbose
DerThorsten Feb 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 0 additions & 110 deletions .github/workflows/bootstrap_python.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/build_recipes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ jobs:
libhyphen0 \
libmanette-0.2-0 \
libgles2 \
gstreamer1.0-libav
gstreamer1.0-libav \
libgtk-4-1
################################################################
# CONFIG
################################################################
Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/run_with_pixi.yaml

This file was deleted.

135 changes: 127 additions & 8 deletions recipes/recipes_emscripten/scipy/build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,129 @@
#!/bin/bash

PYODIDE_PACKED=$RECIPE_DIR/scipy-1.11.1-cp311-cp311-emscripten_3_1_45_wasm32.whl
# unzip
unzip $PYODIDE_PACKED

# copy complete folder scipy to side-packages
mkdir -p $PREFIX/lib/python3.11/site-packages
cp -r scipy $PREFIX/lib/python3.11/site-packages
cp -r scipy-1.11.1.dist-info $PREFIX/lib/python3.11/site-packages
set -e # Exit the script if any command fails

#############################################################
# copy patched / custom code for subprojects/submodules
#############################################################
echo "CONTENT OF custom_submodules/PROPACK"
ls $SRC_DIR/custom_submodules/PROPACK

echo "remove the original propack"
rm -rf $SRC_DIR/scipy/sparse/linalg/_propack/PROPACK

echo "copy the custom propack"
cp -r $SRC_DIR/custom_submodules/PROPACK $SRC_DIR/scipy/sparse/linalg/_propack/

echo "CONTENT OF scipy/sparse/linalg/_propack"
ls $SRC_DIR/scipy/sparse/linalg/_propack


#############################################################
# write out the cross file
#############################################################
export NUMPY_INCLUDE_DIR="$BUILD_PREFIX/lib/python${PY_VER}/site-packages/numpy/_core/include"
sed "s|@(NUMPY_INCLUDE_DIR)|${NUMPY_INCLUDE_DIR}|g" $RECIPE_DIR/emscripten.meson.cross > $SRC_DIR/emscripten.meson.cross.temp
sed "s|@(PYTHON)|${PYTHON}|g" $SRC_DIR/emscripten.meson.cross.temp > $SRC_DIR/emscripten.meson.cross
rm $SRC_DIR/emscripten.meson.cross.temp
echo "THE CROSS FILE"
cat $SRC_DIR/emscripten.meson.cross
echo "END CROSS FILE"


#############################################################
# use pkg-config to find numpy
#############################################################
export PKG_CONFIG_PATH="$BUILD_PREFIX/lib/python${PY_VER}/site-packages/numpy/_core/lib/pkgconfig"


#############################################################
# Using flang as a WASM cross-compiler
# https://github.com/serge-sans-paille/llvm-project/blob/feature/flang-wasm/README.wasm.md
# https://github.com/conda-forge/flang-feedstock/pull/69
#############################################################
micromamba install -p $BUILD_PREFIX conda-forge/label/emscripten::flang libllvm19 --no-channel-priority -y

rm $BUILD_PREFIX/bin/clang # links to clang19
ln -s $BUILD_PREFIX/bin/clang-20 $BUILD_PREFIX/bin/clang # links to emsdk clang


#############################################################
# copy numpy headers from host to the build environment
#############################################################
# note this should actually be done by the cross-python script
# but it is not working (in particular when doing debug builds)


if [ -d "$PREFIX/lib/python${PY_VER}/site-packages/numpy/_core/include/numpy" ]; then
echo "Copying numpy headers from host to the build environment"
mkdir -p $BUILD_PREFIX/lib/python${PY_VER}/site-packages/numpy/_core/include/numpy
cp -r $PREFIX/lib/python${PY_VER}/site-packages/numpy/_core/include/numpy $BUILD_PREFIX/lib/python${PY_VER}/site-packages/numpy/_core/include/

else
echo "numpy headers not found in $PREFIX/lib/python${PY_VER}/site-packages/numpy/_core/include/numpy"
fi

if [ -d "$PREFIX/include/python${PY_VER}" ]; then
mkdir -p $BUILD_PREFIX/include/
echo "Copying python headers from host to the build environment"
cp -r $PREFIX/include/python${PY_VER} $BUILD_PREFIX/include/
else
echo "python headers not found in $PREFIX/include/python${PY_VER}"
fi



############################
# try to compile a simple file
############################
echo "INVOKE FLANG"
$BUILD_PREFIX/bin/flang-new $RECIPE_DIR/test.f90 -o output.obj -D_FILE_OFFSET_BITS=64 -c -g --target=wasm32-unknown-emscripten -O0
echo "INVOKE FLANG DONE"
ls

#############################################################
# patch meson since it otherwise complains with an error that
# emscripten does not support shared libraries ... which is far
# from the truth
#############################################################
find $BUILD_PREFIX -name linkers.py -exec sed -i "s/raise MesonException(f'{self.id} does not support shared libraries.')/return []/g" {} +


# ############################################################
# # wrap flang-new with a python script
# ############################################################
# mv $BUILD_PREFIX/bin/flang-new $BUILD_PREFIX/bin/flang-new-bak
# cp $RECIPE_DIR/flang_wrapper/flang-new $BUILD_PREFIX/bin/
# cp $RECIPE_DIR/flang_wrapper/flang-new.py $BUILD_PREFIX/bin/


#############################################################
# setting up flags
#############################################################
export FC=flang-new
export FFLAGS="-g --target=wasm32-unknown-emscripten"
# enable WASM_BIGINT to support 64-bit integers and fexceptions to support exceptions
export LDFLAGS="$LDFLAGS -sWASM_BIGINT -fexceptions"
export LDFLAGS=""
export CFLAGS=""
export CXXFLAGS=""
export FCFLAGS=""

#############################################################
# delete all shared libraries from prefix to encourage static linking
#############################################################
# print all libraries
ls $PREFIX/lib/
rm -rf $PREFIX/lib/*.so


#############################################################
# trigger the build
#############################################################
${PYTHON} -m pip install . -vvv --no-deps --no-build-isolation \
-Csetup-args="--cross-file=$SRC_DIR/emscripten.meson.cross" \
-Csetup-args="-Dblas=blas" \
-Csetup-args="-Dlapack=lapack" \
-Csetup-args="-Dfortran_std=none" \
-Csetup-args="-Duse-pythran=false" \
-Csetup-args="-Duse-g77-abi=true"
17 changes: 17 additions & 0 deletions recipes/recipes_emscripten/scipy/emscripten.meson.cross
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[properties]
needs_exe_wrapper = true
skip_sanity_check = true
longdouble_format = 'IEEE_QUAD_LE' # for numpy
#numpy-include-dir = '@(NUMPY_INCLUDE_DIR)'


[host_machine]
system = 'emscripten'
cpu_family = 'wasm32'
cpu = 'wasm'
endian = 'little'

[binaries]
exe_wrapper = 'node'
pkg-config = 'pkg-config'
python = '@(PYTHON)'
5 changes: 5 additions & 0 deletions recipes/recipes_emscripten/scipy/flang_wrapper/flang-new
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash


# call flan-new.py with all passed arguments (but the first one)
$PYTHON $BUILD_PREFIX/bin/flang-new.py "$@"
59 changes: 59 additions & 0 deletions recipes/recipes_emscripten/scipy/flang_wrapper/flang-new.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

import os
from pathlib import Path
import subprocess

BUILD_PREFIX = os.environ["BUILD_PREFIX"]
ACTUAL_FLANG_BINARY_PATH = Path(BUILD_PREFIX) / "bin" / "flang-new-bak"


def sanetize_arguments(args):

# replace -03 with -O2
for i, arg in enumerate(args):
if arg == "-O3":
args[i] = "-O2"

# if arg == "-module-dir":
# args[i] = ""
# args[i+1] = ""

# remove all empty strings
args = list(filter(lambda x: x != "", args))

# -nostdlib
args.append("-nostdlib")

return args

if __name__ == "__main__":

# get all arguments
import sys
args = sys.argv[1:]
fixed_args = sanetize_arguments(args)
print(f"""THIS IS A FLANG-WRAPPER
ACTUAL FLANG BINARY: {ACTUAL_FLANG_BINARY_PATH}
Passed arguments: {args}
Sanetized arguments: {fixed_args}
""")

# print all current LDFLAGS / CFLAGS / CXXFLAGS

# print("LDFLAGS: ", os.environ.get("LDFLAGS", ""))
# print("CFLAGS: ", os.environ.get("CFLAGS", ""))
# print("CXXFLAGS: ", os.environ.get("CXXFLAGS", ""))



# Run the actual flang binary
process = subprocess.Popen(
[str(ACTUAL_FLANG_BINARY_PATH)] + fixed_args,
stdout=sys.stdout,
stderr=sys.stderr,
# env=dict(os.environ, LDFLAGS="", CFLAGS="", CXXFLAGS="")
)

# Wait for the process to finish and get the return code
process.wait()
sys.exit(process.returncode)
Loading
Loading