diff --git a/Tools/wasm/wasix-configure-wrapper b/Tools/wasm/wasix-configure-wrapper index 5e935eacfba7cc..7407782fb7b0b2 100755 --- a/Tools/wasm/wasix-configure-wrapper +++ b/Tools/wasm/wasix-configure-wrapper @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e # function @@ -29,53 +29,56 @@ if test -z "$1"; then exit 1 fi -export LIBLZMA_CFLAGS=$WASIX_LIBLZMA_CFLAGS -export LIBLZMA_LIBS=$WASIX_LIBLZMA_LIBS - -export ZLIB_CFLAGS=$WASIX_ZLIB_CFLAGS -export ZLIB_LIBS=$WASIX_ZLIB_LIBS - -export LIBUUID_CFLAGS=$WASIX_LIBUUID_CFLAGS -export LIBUUID_LIBS=$WASIX_LIBUUID_LIBS - -export LIBREADLINE_CFLAGS=$WASIX_LIBREADLINE_CFLAGS -export LIBREADLINE_LIBS=$WASIX_LIBREADLINE_LIBS - -export CURSES_CFLAGS=$WASIX_CURSES_CFLAGS -export CURSES_LIBS=$WASIX_CURSES_LIBS - -export PANEL_CFLAGS=$WASIX_PANEL_CFLAGS -export PANEL_LIBS=$WASIX_PANEL_LIBS - -export LIBB2_CFLAGS=$WASIX_LIBB2_CFLAGS -export LIBB2_LIBS=$WASIX_LIBB2_LIBS - -export BZIP2_CFLAGS=$WASIX_BZIP2_CFLAGS -export BZIP2_LIBS=$WASIX_BZIP2_LIBS - -export LIBFFI_CFLAGS=$WASIX_LIBFFI_CFLAGS -export LIBFFI_LIBS=$WASIX_LIBFFI_LIBS - -export LIBSQLITE3_CFLAGS=$WASIX_LIBSQLITE3_CFLAGS -export LIBSQLITE3_LIBS=$WASIX_LIBSQLITE3_LIBS - -export "WASIXCC_FLAGS=-sPIC=yes -sWASM_EXCEPTIONS=yes -sINCLUDE_CPP_SYMBOLS=yes -sWASM_OPT_FLAGS=-O4:--strip-debug" +function export_if_set_for_wasix() { + wasix_varname="WASIX_$1" + if [[ -v wasix_varname ]]; then + export "$1"="${!wasix_varname}" + fi +} +export_if_set_for_wasix LIBLZMA_CFLAGS +export_if_set_for_wasix LIBLZMA_LIBS +export_if_set_for_wasix ZLIB_CFLAGS +export_if_set_for_wasix ZLIB_LIBS +export_if_set_for_wasix LIBUUID_CFLAGS +export_if_set_for_wasix LIBUUID_LIBS +export_if_set_for_wasix LIBREADLINE_CFLAGS +export_if_set_for_wasix LIBREADLINE_LIBS +export_if_set_for_wasix CURSES_CFLAGS +export_if_set_for_wasix CURSES_LIBS +export_if_set_for_wasix PANEL_CFLAGS +export_if_set_for_wasix PANEL_LIBS +export_if_set_for_wasix LIBB2_CFLAGS +export_if_set_for_wasix LIBB2_LIBS +export_if_set_for_wasix LIBFFI_CFLAGS +export_if_set_for_wasix LIBFFI_LIBS +export_if_set_for_wasix LIBSQLITE3_CFLAGS +export_if_set_for_wasix LIBSQLITE3_LIBS + +export_if_set_for_wasix PKG_CONFIG_SYSROOT_DIR +export_if_set_for_wasix PKG_CONFIG_LIBDIR + +export CC="wasixcc" +export CXX="wasix++" +export LD="wasixld" export RANLIB="wasixranlib" export AR="wasixar" export NM="wasixnm" -export CC="wasixcc $WASIXCC_FLAGS" -export CXX="wasix++ $WASIXCC_FLAGS" -export LD="wasixld" export CFLAGS="\ -DOPENSSL_THREADS \ -flto" -WASIXCC_RUN_WASM_OPT=no \ - "$@" \ - --with-openssl=$WASIX_OPENSSL_DIR \ - --with-pkg-config=no \ - --with-readline=yes \ - --with-ensurepip=install \ - --prefix=$WASIX_INSTALL/cpython \ No newline at end of file +WASIX_PREFIX_FLAGS= +if [[ -v WASIX_INSTALL ]] ; then + WASIX_PREFIX_FLAGS="--prefix=$WASIX_INSTALL/cpython" +elif [[ -v WASIX_PREFIX ]] ; then + WASIX_PREFIX_FLAGS="--prefix=$WASIX_PREFIX" +fi + +WASIX_OPENSSL_DIR_FLAGS= +if [[ -v WASIX_OPENSSL_DIR ]] ; then + WASIX_OPENSSL_DIR_FLAGS="--with-openssl=$WASIX_OPENSSL_DIR" +fi + +"$@" --with-readline=yes --with-ensurepip=install $WASIX_OPENSSL_DIR_FLAGS $WASIX_PREFIX_FLAGS \ No newline at end of file diff --git a/Tools/wasm/wasm_build.py b/Tools/wasm/wasm_build.py index d07beee3754479..e981677f7ba468 100755 --- a/Tools/wasm/wasm_build.py +++ b/Tools/wasm/wasm_build.py @@ -120,10 +120,9 @@ """ INSTALL_WASIXCC = """ -WASIX builds require wasixcc on PATH. Please install wasixcc from -https://github.com/wasix-org/wasixcc and run -`wasixcc --install-executables` to install the required binaries, -and make sure the directory where the binaries are installed is in your PATH. +WASIX builds requires wasixcc in PATH. Please install wasixcc by running +curl -fsSL https://wasix.cc | sh +or follow instructions at https://github.com/wasix-org/wasixcc. """ INSTALL_WASMER = """ @@ -563,7 +562,7 @@ def configure_cmd(self) -> List[str]: @property def make_cmd(self) -> List[str]: """Generate make command""" - cmd = ["make", "-j8"] + cmd = ["make", "-j1"] platform = self.host.platform if platform.make_wrapper: cmd.insert(0, os.fspath(platform.make_wrapper)) diff --git a/wasix-full.sh b/wasix-full.sh index 73f50f05733b06..d6d05c25628a5e 100644 --- a/wasix-full.sh +++ b/wasix-full.sh @@ -1,125 +1,25 @@ +#!/usr/bin/env bash set -ex - -WORKDIR=$(pwd) -ARTIFACT_ROOT="${WORKDIR}/artifacts" - -if test -z "$WASIX_SYSROOT" ; then - echo "WASIX_SYSROOT is not set. Please set it to the sysroot path (Something like /home/lennart/Documents/wasix-libc/sysroot)." +if test -z "$WASIXCC_SYSROOT" ; then + echo "WASIXCC_SYSROOT is not set. Please set it to the sysroot path (Something like /home/lennart/Documents/wasix-libc/sysroot)." exit 1 fi -export WASI_SDK_VERSION=25 - -export WASI_SDK_PATH="${ARTIFACT_ROOT}/wasix-libs/wasi-sdk" -if ! test -e "$WASI_SDK_PATH/.ready" ; then - rm -rf $WASI_SDK_PATH || true - mkdir -p $WASI_SDK_PATH - chmod -R a+rwx $(dirname $WASI_SDK_PATH) - curl -s -S --location https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK_VERSION/wasi-sdk-$WASI_SDK_VERSION.0-x86_64-linux.tar.gz | \ - tar --strip-components 1 --directory $WASI_SDK_PATH --extract --gunzip - touch $WASI_SDK_PATH/.ready -fi - -WASMER_DIR="${ARTIFACT_ROOT}/wasmer" -WASIX_LIBC_TAG="v2024-07-08.1" - -export OPENSSL_DIR="${ARTIFACT_ROOT}/wasix-libs/openssl" -if ! test -e "$OPENSSL_DIR/.ready" ; then - rm -rf $OPENSSL_DIR || true - mkdir -p $(dirname $OPENSSL_DIR) - chmod -R a+rwx $(dirname $OPENSSL_DIR) - git clone https://github.com/wasix-org/openssl $OPENSSL_DIR - cd $OPENSSL_DIR - ./wasix.sh - mkdir -p lib - cp libcrypto.a lib/libcrypto.a - cp libssl.a lib/libssl.a - touch "$OPENSSL_DIR/.ready" -fi - -export CROSS_BUILD_PYTHON=cross-build/build -export CROSS_BUILD_WASIX=cross-build/wasix - -export WASIX_INSTALL=${ARTIFACT_ROOT}/wasix-install -mkdir -p $WASIX_INSTALL - -# zlib -export ZLIB_DIR="${ARTIFACT_ROOT}/wasix-libs/zlib" -if ! test -e "$ZLIB_DIR/.ready" ; then - rm -rf $ZLIB_DIR || true - mkdir -p $(dirname $ZLIB_DIR) - chmod -R a+rwx $(dirname $ZLIB_DIR) - git clone https://github.com/wasix-org/zlib $ZLIB_DIR - cd $ZLIB_DIR - ./wasix.sh - touch "$ZLIB_DIR/.ready" -fi - -# liblzma -export LIBLZMA_DIR="${ARTIFACT_ROOT}/wasix-libs/liblzma" -if ! test -e "$LIBLZMA_DIR/.ready" ; then - rm -rf $LIBLZMA_DIR || true - mkdir -p $(dirname $LIBLZMA_DIR) - chmod -R a+rwx $(dirname $LIBLZMA_DIR) - git clone https://github.com/wasix-org/liblzma $LIBLZMA_DIR - cd $LIBLZMA_DIR - ./wasix.sh - cp src/liblzma/.libs/liblzma.a liblzma.a - touch "$LIBLZMA_DIR/.ready" -fi - - -export UTIL_LINUX_DIR="${ARTIFACT_ROOT}/wasix-libs/util-linux" -if ! test -e "$UTIL_LINUX_DIR/.ready" ; then - rm -rf $UTIL_LINUX_DIR || true - mkdir -p $(dirname $UTIL_LINUX_DIR) - chmod -R a+rwx $(dirname $UTIL_LINUX_DIR) - git clone https://github.com/wasix-org/util-linux $UTIL_LINUX_DIR - cd $UTIL_LINUX_DIR - ./wasix.sh - cp -v .libs/libuuid.a . - touch "$UTIL_LINUX_DIR/.ready" -fi - -export NCURSES_DIR="${ARTIFACT_ROOT}/wasix-libs/ncurses" -if ! test -e "$NCURSES_DIR/.ready" ; then - rm -rf $NCURSES_DIR || true - mkdir -p $(dirname $NCURSES_DIR) - chmod -R a+rwx $(dirname $NCURSES_DIR) - git clone https://github.com/wasix-org/ncurses -b wasix-support $NCURSES_DIR - cd $NCURSES_DIR - ./wasix.sh - touch "$NCURSES_DIR/.ready" -fi - -export READLINE_DIR="${ARTIFACT_ROOT}/wasix-libs/readline/readline" -if ! test -e "$READLINE_DIR/.ready" ; then - rm -rf $READLINE_DIR || true - mkdir -p $(dirname $READLINE_DIR) - chmod -R a+rwx $(dirname $READLINE_DIR) - git clone https://github.com/wasix-org/readline $READLINE_DIR - cd $READLINE_DIR - WASIX_NCURSES=$NCURSES_DIR ./wasix.sh - touch "$READLINE_DIR/.ready" -fi - -cd $WORKDIR - -rm Lib/multiprocessing/__pycache__/* || true +export WASI_SDK_PATH="${WASIX_LLVM:-$(dirname $(dirname $(which clang)))}" +export WASIX_PKG_CONFIG_SYSROOT_DIR="$WASIXCC_SYSROOT" +export WASIX_PKG_CONFIG_LIBDIR="$WASIXCC_SYSROOT/usr/local/lib/wasm32-wasi/pkgconfig" +export WASM_RUNTIME=wasmer +export WASIXCC_RUN_WASM_OPT="no" +export WASIXCC_WASM_EXCEPTIONS="yes" +export WASIXCC_PIC="yes" +export WASIXCC_INCLUDE_CPP_SYMBOLS="yes" +# Add the other locations to the search path +export WASIXCC_COMPILER_FLAGS="-Wl,-L${WASIXCC_SYSROOT}/usr/local/lib/wasm32-wasi:-I${WASIXCC_SYSROOT}/usr/local/include:-Wl,-mllvm,--wasm-enable-eh:-Wl,-mllvm,--wasm-enable-sjlj:-Wl,-mllvm,--wasm-use-legacy-eh=false:-Wl,-mllvm,--exception-model=wasm:-iwithsysroot:/usr/local/include/c++/v1" +# Make clang emit the non-legacy exception handling directly +export WASIXCC_LINKER_FLAGS="-mllvm:--wasm-enable-eh:-mllvm:--wasm-enable-sjlj:-mllvm:--wasm-use-legacy-eh=false:-mllvm:--exception-model=wasm" -WASM_RUNTIME=wasmer \ -WASIX_ZLIB_CFLAGS="-I$ZLIB_DIR" \ -WASIX_ZLIB_LIBS="-L$ZLIB_DIR -lz " \ -WASIX_LIBLZMA_CFLAGS="-I$LIBLZMA_DIR/src/liblzma/api" \ -WASIX_LIBLZMA_LIBS="-L$LIBLZMA_DIR -llzma" \ -WASIX_LIBUUID_CFLAGS="-I $UTIL_LINUX_DIR/libuuid/src" \ -WASIX_LIBUUID_LIBS="-L $UTIL_LINUX_DIR -l uuid" \ -WASIX_LIBREADLINE_CFLAGS="-I $READLINE_DIR/.." \ -WASIX_LIBREADLINE_LIBS="-L $READLINE_DIR -L $NCURSES_DIR/lib -lreadline -lncurses" \ python3 Tools/wasm/wasm_build.py wasix build -c -cd builddir/wasix -rm -r "$WASIX_INSTALL/cpython" || true -make install -chmod -R a+rw "$WASIX_INSTALL/cpython" \ No newline at end of file +rm -rf "artifacts/wasix-install" && mkdir -p "artifacts/wasix-install" +make -C builddir/wasix install DESTDIR="$(pwd)/artifacts/wasix-install" \ No newline at end of file