diff --git a/config b/config index 92277a3..a6c70a0 100644 --- a/config +++ b/config @@ -42,6 +42,7 @@ else fi fi +# ============ emscripten ============== # stable # export EMFLAVOUR=3.1.34 @@ -53,8 +54,26 @@ fi #export EMFLAVOUR=${EMFLAVOUR:latest} export EMFLAVOUR=${EMFLAVOUR:-tot} +# ============== wasi sdk =============== + # stable WASI_SDK=${WASI_SDK:-20} +WASI_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK}/wasi-sdk-${WASI_SDK}.0-linux.tar.gz + +WASISDK="${SDKROOT}/wasisdk" + + +# =============== Nimrod ==================== + +# stable +NIM_VERSION=nim-2.0.2 +NIM_URL=https://nim-lang.org/download/${NIM_VERSION}-linux_x64.tar.xz + + +NIM_VERSION=nim-git +NIM_URL=https://github.com/nim-lang/Nim + +NIMSDK=${NIMSDK:-"${SDKROOT}/nimsdk"} # base wasm features pure is "mvp" , "bi" is bigint @@ -85,7 +104,22 @@ then echo -n else OLDPATH=${PATH} - PATH=/usr/local/bin:/usr/bin:/opt/bin:/bin + + PATH=/usr/bin:/bin + for extrabin in /usr/local/bin /opt/bin + do + if echo $PATH|grep -q ":$extrabin" + then + continue + fi + + if [ -d $extrabin ] + then + PATH=$extrabin:$PATH + fi + done + + # this is python used for emsdk : ${SYS_PYTHON} -> ${EMSDK_PYTHON} for py in 10 9 8 7 do @@ -99,6 +133,7 @@ else fi done + export GITGET="git clone --recursive --no-tags --depth 1 --single-branch --branch" export LD_LIBRARY_PATH="${HOST_PREFIX}/lib:$LD_LIBRARY_PATH" - export PATH="${HOST_PREFIX}/bin:$OLDPATH" + export PATH="${HOST_PREFIX}/bin:$PATH:$OLDPATH" fi diff --git a/python-nim-sdk.sh b/python-nim-sdk.sh new file mode 100755 index 0000000..cbba50b --- /dev/null +++ b/python-nim-sdk.sh @@ -0,0 +1,185 @@ +#!/bin/bash + +SDKROOT=${SDKROOT:-/opt/python-wasm-sdk} +CONFIG=$(realpath ${CONFIG:-config}) +. $CONFIG + +if [ -d ${NIMSDK} ] +then + echo " + + + + will not overwrite existing working directory + NIMSDK=${NIMSDK} + + + +" +else + mkdir ${NIMSDK} +fi + + +pushd ${NIMSDK} + if [ -d $NIM_VERSION/bin ] + then + echo " + + will not overwrite existing Nim build found in + ${NIMSDK}/$NIM_VERSION/bin + + + " + else + if echo $NIM_URL|grep -q nim-lang\.org + then + echo ERROR download/install release from $NIM_URL + else + $GITGET devel $NIM_URL $NIM_VERSION + pushd $NIM_VERSION + chmod +x *sh + CC=clang CXX=clang++ ./build_all.sh + popd + fi + fi + +# --usenimcache + + mkdir -p ${NIMSDK}/nim + + cat > ${NIMSDK}/nim/config.nims < need libgc.so.1 +--gc:orc +--define:noSignalHandler + +# +--define:static + +# better debug but optionnal/tweakable +--parallelBuild:1 +--opt:speed +--define:debug + +when defined(wasi): + echo " ===== Panda3D: wasi build ======" + # overwrite + ARCH="wasisdk" + + # needed for compiler + --cc:clang + --os:linux + + --define:emscripten + --define:static + + # component model aka reactor + --noMain + + --cpu:wasm32 + switch("clibdir", fmt"{SDKROOT}/devices/{ARCH}/usr/lib/wasm32-wasi") + + + switch("passC", fmt"-m32 -Djmp_buf=int") + switch("passC", "-Os -g3 -mllvm -inline-threshold=1") + + switch("passL","-lstdc++ ") + + # more compat but in the long term workaround Panda3D instead + # wasi emulations + switch("passC", "-D_GNU_SOURCE") + switch("passC", "-D_WASI_EMULATED_MMAN -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_GETPID") + switch("passL", "-lwasi-emulated-getpid -lwasi-emulated-mman -lwasi-emulated-signal -lwasi-emulated-process-clocks") + + + # don't use _start/main but _initialize instead + switch("passL", "-Wl,--export-all -mexec-model=reactor") + + # better debug but optionnal/tweakable + --parallelBuild:1 + --opt:none + +else: + echo fmt" ===== Panda3D: native {ARCH} build ======" + switch("passL", "-lfreetype -lharfbuzz") + # -lfftw3 -lassimp") + +# static +switch("passL", "-lp3tinydisplay") +# common +switch("passL", "-lc -lz") + +# only for script gen which does not pass cincludes +# --passC:-I/opt/python-wasm-sdk/devices/${ARCH}/usr/include/panda3d +# --passL:-L${SDKROOT}/devices/${ARCH}/usr/lib + + +switch("nimcache", fmt"{SDKROOT}/nimsdk/cache.{ARCH}") +switch("clibdir", fmt"{SDKROOT}/devices/{ARCH}/usr/lib") +switch("cincludes", fmt"{SDKROOT}/devices/{ARCH}/usr/include/panda3d") + +switch("out", fmt"out.{ARCH}") + + + +END + + cat > nimsdk_env.sh < /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' +} + export PS1="[PyDK:nim] \[\e[32m\]\w \[\e[91m\]\$(parse_git_branch)\[\e[00m\]\$ " + +else + echo "nimsdk: config already set !" 1>&2 +fi +END + +popd + diff --git a/python-wasi-sdk.sh b/python-wasi-sdk.sh index eb74af6..538dc01 100755 --- a/python-wasi-sdk.sh +++ b/python-wasi-sdk.sh @@ -18,13 +18,16 @@ if echo $0|grep -q python-wasm-sdk then echo " * adding emsdk to wasm-sdk" emsdk=true + wasisdk=false + nimsdk=false else emsdk=false BUILDS=3.12 + echo " * adding wasi-sdk to wasm-sdk" + wasisdk=true + nimsdk=true fi -echo " * adding wasi-sdk to wasm-sdk" -wasisdk=true if [ -d ${SDKROOT} ] then @@ -40,18 +43,18 @@ ORIGIN=$(pwd) # 3.12 3.11 3.10 -BUILDS=${BUILDS:-3.11 3.12 3.13} +BUILDS=${BUILDS:-3.11 3.13 3.12} for PYBUILD in $BUILDS do cd "$ORIGIN" - if echo $PYBUILD|grep -q 12$ - then - wasisdk=true - else - wasisdk=false - fi +# if echo $PYBUILD|grep -q 12$ +# then +# wasisdk=true +# else +# wasisdk=false +# fi if [ -f ${SDKROOT}/dev ] then @@ -94,6 +97,19 @@ do fi + cat > /opt/python-wasm-sdk/devices/$(arch)/usr/bin/py <&2 - - - if [ -f ${PYTHON_FOR_BUILD} ] then echo found PYTHON_FOR_BUILD=${PYTHON_FOR_BUILD} @@ -32,8 +23,6 @@ else popd fi -. ${SDKROOT}/wasisdk/wasisdk_env.sh - export LD_LIBRARY_PATH=${SDKROOT}/devices/x86_64/usr/lib:$LD_LIBRARY_PATH @@ -42,9 +31,20 @@ then PYSRC=${SDKROOT}/src/cpython${PYBUILD} + . ${SDKROOT}/wasisdk/wasisdk_env.sh + + echo " - * building python wasi from ${PYSRC} -" + + * building cpython-wasi ${PREFIX}/bin/python${PYBUILD}.wasm + from ${PYSRC} + with PYTHON_FOR_BUILD=$PYTHON_FOR_BUILD + CC=$CC + CXX=$CXX + CPP=$CPP + +" 1>&2 + mkdir -p ${SDKROOT}/build/cpython-wasi @@ -62,7 +62,7 @@ END sed -i 's| -Wl,--stack-first -Wl,--initial-memory=10485760||g' $PYSRC/configure.ac sed -i 's| -Wl,--stack-first -Wl,--initial-memory=10485760||g' $PYSRC/configure - CC=clang CXX=clang++ LDSHARED="${SDKROOT}/wasisdk/upstream/bin/wasm-ld --no-entry" CONFIG_SITE=$PYSRC/Tools/wasm/config.site-wasm32-wasisdk \ + LDSHARED="${SDKROOT}/wasisdk/upstream/bin/wasm-ld --no-entry" CONFIG_SITE=$PYSRC/Tools/wasm/config.site-wasm32-wasisdk \ $PYSRC/configure -C \ --with-c-locale-coercion --without-pymalloc --disable-ipv6 --with-ensurepip=no \ --prefix=${PREFIX} \ diff --git a/wasisdk/wasisdk_env.sh b/wasisdk/wasisdk_env.sh index 90054bc..f723b65 100755 --- a/wasisdk/wasisdk_env.sh +++ b/wasisdk/wasisdk_env.sh @@ -2,17 +2,19 @@ SDKROOT=${SDKROOT:-/opt/python-wasm-sdk} -if [[ -z ${WASISDK+z} ]] +if [[ -z ${WASISDK_ENV+z} ]] then - + export WASISDK_ENV=true . ${CONFIG:-${SDKROOT}/config} - export WASISDK="${SDKROOT}/wasisdk" + export ARCH=wasisdk + export WASISDK=${WASISDK:-"${SDKROOT}/${ARCH}"} export WASI_SDK_PREFIX="${WASISDK}/upstream" export WASI_SYSROOT="${WASI_SDK_PREFIX}/share/wasi-sysroot" - export CMAKE_TOOLCHAIN_FILE=${SDKROOT}/wasisdk/share/cmake/Modules/Platform/WASI.cmake - export CMAKE_INSTALL_PREFIX="${SDKROOT}/devices/wasisdk/usr" + export CMAKE_TOOLCHAIN_FILE=${WASISDK}/share/cmake/Modules/Platform/WASI.cmake + export CMAKE_INSTALL_PREFIX="${SDKROOT}/devices/${ARCH}/usr" + export PREFIX=$CMAKE_INSTALL_PREFIX if [ -d ${WASI_SDK_PREFIX}/bin ] then @@ -29,8 +31,6 @@ then export PATH="${WASISDK}/bin:${WASI_SDK_PREFIX}/bin:$PATH" - export PREFIX=$CMAKE_INSTALL_PREFIX - # instruct pkg-config to use wasi target root export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig:${WASI_SYSROOT}/lib/wasm32-wasi/pkgconfig"