|
| 1 | +#!/bin/bash |
| 2 | +set -e # Exit immediately if a command fails |
| 3 | + |
| 4 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | +APPS_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 6 | +HOME_FOLDER="$(cd "$APPS_ROOT/.." && pwd)" |
| 7 | + |
| 8 | +if [[ -z "${LIND_WASM_ROOT:-}" ]]; then |
| 9 | + LIND_WASM_ROOT="$(cd "$APPS_ROOT/.." && pwd)" |
| 10 | +fi |
| 11 | + |
| 12 | +LINDFS_ROOT="${LINDFS_ROOT:-$LIND_WASM_ROOT/lindfs}" |
| 13 | +BUILD_WASM="$SCRIPT_DIR/build-wasm" |
| 14 | +SYSROOT="$LIND_WASM_ROOT/src/glibc/sysroot" |
| 15 | +LIND_BOOT="${LIND_WASM_ROOT}/src/lind-boot/target/debug/lind-boot" |
| 16 | +PYTHON_VERSION="3.14.3" |
| 17 | +PYTHON_SRC_DIR="$HOME_FOLDER/Python-$PYTHON_VERSION" |
| 18 | + |
| 19 | +# 1. Build Python WASM if Makefile doesn't exist |
| 20 | +if [[ ! -f "$BUILD_WASM/Makefile" ]]; then |
| 21 | + cd "$SCRIPT_DIR" |
| 22 | + ./build_python_wasm.sh |
| 23 | + ./build_shared_python_wasm.sh |
| 24 | +fi |
| 25 | + |
| 26 | +# This fix is because the python native build we have currently in lind-wasm-apps is having some errors with math library and hence we use a different Python version. We need to fix it either by porting cpython version to 3.14.3 |
| 27 | +if [[ ! -d "$PYTHON_SRC_DIR" ]]; then |
| 28 | + cd "$HOME_FOLDER" |
| 29 | + wget "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tar.xz" |
| 30 | + tar -xf "Python-$PYTHON_VERSION.tar.xz" |
| 31 | + cd "Python-$PYTHON_VERSION" |
| 32 | + ./configure |
| 33 | + make |
| 34 | +fi |
| 35 | + |
| 36 | + |
| 37 | +# The following changes to Makefile is done to run python via lind-boot with dynamic loading rather than natively |
| 38 | +cd $SCRIPT_DIR/build-wasm |
| 39 | + |
| 40 | +TARGET_MAKEFILE="Makefile" |
| 41 | + |
| 42 | +if [[ -f "$TARGET_MAKEFILE" ]]; then |
| 43 | + sed -i \ |
| 44 | + -e "s|../build-native/python|$PYTHON_SRC_DIR/python|g" \ |
| 45 | + -e "s|^HOSTRUNNER=.*|HOSTRUNNER= sudo $LIND_BOOT --preload env=lib/libc.cwasm --preload env=lib/libm.so --preload env=lib/libpython3.14.cwasm|" \ |
| 46 | + -e "s|^PYTHON_FOR_BUILD=_PYTHON_HOSTRUNNER='.*'|PYTHON_FOR_BUILD=_PYTHON_HOSTRUNNER='sudo $LIND_BOOT --preload env=lib/libc.cwasm --preload env=lib/libm.so --preload env=lib/libpython3.14.cwasm'|" \ |
| 47 | + "$TARGET_MAKEFILE" |
| 48 | +else |
| 49 | + echo "Error: $TARGET_MAKEFILE not found in $BUILD_WASM" |
| 50 | + exit 1 |
| 51 | +fi |
| 52 | + |
| 53 | + |
| 54 | +# We do this because the test script expects python.wasm within lindfs root folder. We could change it through some flags later |
| 55 | +cp "$LINDFS_ROOT/bin/python.cwasm" "$LINDFS_ROOT/python.wasm" |
| 56 | + |
| 57 | +#Run tests |
| 58 | +make test |
0 commit comments