diff --git a/proot.sh b/proot.sh index d48a702..1a716ae 100755 --- a/proot.sh +++ b/proot.sh @@ -3,8 +3,8 @@ export ROOT=$(pwd) export SDKROOT=${ROOT}/python-wasm-sdk export PATH=$(pwd):$PATH export WORKDIR=/data/git/python-wasm-sdk -export CONTAINER_PATH=${CONTAINER_PATH:-${ROOT}/fs} -export HOME=$CONTAINER_PATH +export CONTAINER_PATH=${CONTAINER_PATH:-/tmp/fs} +export HOME=/tmp if mkdir -p $CONTAINER_PATH then @@ -37,8 +37,6 @@ fi [ $(uname -s) != "Linux" ] && [ ! "$ALPINEPROOT_FORCE" ] && exec echo "Expected Linux kernel, But got unsupported kernel ($(uname -s))." -[ -x ${ALPINEPROOT_RC_PATH:-~/.alpineprootrc} ] && source ${ALPINEPROOT_RC_PATH:-~/.alpineprootrc} - [ "$ALPINEPROOT_FORCE" ] && echo "Warning: I'm sure you know what are you doing." # Do not run if user run this script as root @@ -52,16 +50,12 @@ fi export CONTAINER_DOWNLOAD_URL="" alpineproot() { - export PROOT=$(command -v proot) || $(command -v proot-rs) if [ -x $CONTAINER_PATH/bin/busybox ]; then __start $@ exit fi - [ -n "$ALPINEPROOT_USE_PROOT_RS" ] && [ -x $(command -v proot-rs) ] && unset PROOT && export PROOT=$(command -v proot-rs) - [ -n "$ALPINEPROOT_PROOT_PATH" ] && unset PROOT && export PROOT=$ALPINEPROOT_PROOT_PATH - # Check whenever proot is installed or no if [ -z "$PROOT" ] || [ ! -x $PROOT ]; then [ "$(uname -o)" = "Android" ] && pkg=$(command -v pkg) && pkg install proot -y && alpineproot $@ && exit 0 @@ -96,7 +90,8 @@ alpineproot() { [ ! -d $CONTAINER_PATH ] && mkdir -p $CONTAINER_PATH # Use proot to prevent hard link extraction error - $PROOT tar -xzf $HOME/.cached_rootfs.tar.gz -C $CONTAINER_PATH + # $PROOT $HOME/.cached_rootfs.tar.gz -C $CONTAINER_PATH + tar -xzf $HOME/.cached_rootfs.tar.gz -C $CONTAINER_PATH # If extraction fail, Delete cached rootfs and try again [ "$?" != "0" ] && rm -f $HOME/.cached_rootfs.tar.gz && alpineproot $@ && exit 0 @@ -292,7 +287,7 @@ __start() { COMMANDS=$PROOT # COMMANDS+=" --link2symlink" -# COMMANDS+=" --kill-on-exit" + COMMANDS+=" --kill-on-exit" COMMANDS+=" --kernel-release=\"${ALPINEPROOT_KERNEL_RELEASE:-5.18}\"" COMMANDS+=" -b /dev -b /proc -b /sys" COMMANDS+=" -b /proc/self/fd:/dev/fd" @@ -331,10 +326,16 @@ __start() { fi } +#export PROOT=$(pwd)/proot-rs +#export ALPINEPROOT_USE_PROOT_RS=true +export PROOT=$(pwd)/proot + if ${CI:-false} then + alpineproot "apk add bash;/bin/bash /initrc" else + export PROOT=$(pwd)/proot alpineproot "apk add bash;/bin/bash --init-file /initrc" fi diff --git a/python-wasm-sdk/emsdk-cc b/python-wasm-sdk/emsdk-cc index 8d1eb17..b54dafb 100644 --- a/python-wasm-sdk/emsdk-cc +++ b/python-wasm-sdk/emsdk-cc @@ -308,7 +308,7 @@ if SKIP: final.extend(sys.argv) else: if AOUT: - if CMAKE or CONFIGURE: + if CMAKE or NINJA or RUSTC or CONFIGURE: EXE = False # should not happen elif AOUT.endswith(".o") and "-c" not in out: diff --git a/python-wasm-sdk/scripts/cpython-build-emsdk-prebuilt.sh b/python-wasm-sdk/scripts/cpython-build-emsdk-prebuilt.sh index c3a5aad..7e714d5 100755 --- a/python-wasm-sdk/scripts/cpython-build-emsdk-prebuilt.sh +++ b/python-wasm-sdk/scripts/cpython-build-emsdk-prebuilt.sh @@ -83,20 +83,105 @@ $HPIP install --force ninja # patch ninja for jobs limit and wrapper detection # https://github.com/ninja-build/ninja/issues/1482 -cat > ${HOST_PREFIX}/bin/ninja < ${HOST_PREFIX}/lib/python${PYBUILD}/site-packages/ninja/__init__.py < list[str]: + return __all__ + + +def _get_ninja_dir() -> str: + ninja_exe = "ninja" + sysconfig.get_config_var("EXE") + + # Default path + path = os.path.join(sysconfig.get_path("scripts"), ninja_exe) + if os.path.isfile(path): + return os.path.dirname(path) + + # User path + if sys.version_info >= (3, 10): + user_scheme = sysconfig.get_preferred_scheme("user") + elif os.name == "nt": + user_scheme = "nt_user" + elif sys.platform.startswith("darwin") and getattr(sys, "_framework", None): + user_scheme = "osx_framework_user" + else: + user_scheme = "posix_user" + + path = sysconfig.get_path("scripts", scheme=user_scheme) + + if os.path.isfile(os.path.join(path, ninja_exe)): + return path + + # Fallback to python location + path = os.path.dirname(sys.executable) + if os.path.isfile(os.path.join(path, ninja_exe)): + return path + + return "" + + +BIN_DIR = _get_ninja_dir() + + +def _program(name: str, args: Iterable[str]) -> int: + cmd = os.path.join('${HOST_PREFIX}/bin', name) + return subprocess.call([cmd, *args], close_fds=False) + +def ninja() -> NoReturn: + import os + os.environ['NINJA'] = "1" + if not sys.argv[-1] != "--version": + sys.argv.insert(1,'1') + sys.argv.insert(1,'-j') +# import time +# while os.path.isfile('/tmp/ninja'): +# time.sleep(.5) +# open('/tmp/ninja','w').close() + + ret = _program('ninja.real', sys.argv[1:]) +# try: +# os.unlink('/tmp/ninja') +# except: +# pass + raise SystemExit(ret) + +END + + + +if [ -f $HOST_PREFIX/bin/ninja.real ] +then + echo ninja already patched +else + mv $HOST_PREFIX/bin/ninja $HOST_PREFIX/bin/ninja.real + cat > $HOST_PREFIX/bin/ninja </dev/null @@ -130,7 +128,7 @@ echo " -if [ -f build/cpython-wasm/libpython${PYBUILD}.a ] +if [ -f ${SDKROOT}/build/cpython-wasm/libpython${PYBUILD}.a ] then echo " * not rebuilding cpython-wasm for [$PYDK_PYTHON_HOST_PLATFORM] diff --git a/python-wasm-sdk/sources.extra/1000-glib.sh b/python-wasm-sdk/sources.extra/1900-glib.sh similarity index 89% rename from python-wasm-sdk/sources.extra/1000-glib.sh rename to python-wasm-sdk/sources.extra/1900-glib.sh index 968d83d..c16d99a 100755 --- a/python-wasm-sdk/sources.extra/1000-glib.sh +++ b/python-wasm-sdk/sources.extra/1900-glib.sh @@ -5,13 +5,6 @@ . ${CONFIG:-config} -if which meson -then - echo meson found $(which meson) -else - $HPY -m pip install meson -fi - . scripts/emsdk-fetch.sh if pushd ${ROOT}/src @@ -46,8 +39,7 @@ then done # Common compiler flags - export CFLAGS="-O3" - export CXXFLAGS="$CFLAGS" + export COPTS="-Os -g0" export LDFLAGS="-L$PREFIX/lib" @@ -138,14 +130,37 @@ cpu_family = 'wasm32' cpu = 'wasm32' endian = 'little' -[ninja] +[backend] backend_max_links = 1 END - meson setup _build --prefix=$PREFIX --cross-file=emscripten-crossfile.meson --default-library=static --buildtype=release \ + echo " + + + ============ MESON SETUP $(which ninja) ========================= + + +" + meson setup _build --reconfigure --prefix=$PREFIX --cross-file=emscripten-crossfile.meson --default-library=static --buildtype=minsize \ --force-fallback-for=pcre2,gvdb -Dselinux=disabled -Dxattr=false -Dlibmount=disabled -Dnls=disabled \ -Dtests=false -Dglib_assert=false -Dglib_checks=false + echo " + + + ============ MESON COMPILE ========================= + + +" + # meson compile _build -j 1 + echo " + + + ============ MESON INSTALL ========================= + + +" + meson install -C _build --tag devel popd # glib popd # src diff --git a/python-wasm-sdk/sources.wasm/5000-ncurses-65.sh b/python-wasm-sdk/sources.wasm/5000-ncurses-65.sh index bc7ce87..6fd61b4 100755 --- a/python-wasm-sdk/sources.wasm/5000-ncurses-65.sh +++ b/python-wasm-sdk/sources.wasm/5000-ncurses-65.sh @@ -39,24 +39,29 @@ function FIX () { if cd ${SDKROOT}/src then - - wget -c $URL_NCURSES && tar xfz $NCURSES.tar.gz + if [ -d ${SDKROOT}/src/$NCURSES ] + then + echo using $NCURSES local sources + else + wget -c $URL_NCURSES && tar xfz $NCURSES.tar.gz + fi if cd ${SDKROOT}/src/$NCURSES then - [ -f $NCURSES.done ] || patch -p1 < $SDKROOT/support/__EMSCRIPTEN__.deps/${NCURSES}_emscripten.patch - touch $NCURSES.done + [ -f $NCURSES.patched ] || patch -p1 < $SDKROOT/support/__EMSCRIPTEN__.deps/${NCURSES}_emscripten.patch + touch $NCURSES.patched fi + mkdir -p ${SDKROOT}/build/ncurses/ + if true then cd $ROOT - mkdir -p ${SDKROOT}/build/ncurses/ - if [ -f ../devices/emsdk/usr/lib/libncurses.a ] + if [ -f ${PREFIX}/lib/libncurses.a ] then echo " - * skiping [ncurses] or already built + * ncurses (non unicode) already built " 1>&2 else echo " building non unicode ${NCURSES}" @@ -68,7 +73,7 @@ then emmake make clean emmake make 2>&1 > /dev/null || FIX - emmake make install 2>&1 > /dev/null || exit 69 + emmake make install 2>&1 > /dev/null || exit 76 fi fi @@ -76,9 +81,8 @@ then if true then cd $ROOT - mkdir -p ${SDKROOT}/build/ncurses/ - if [ -f devices/emsdk/usr/lib/libncursesw.a ] + if [ -f ${PREFIX}/lib/libncursesw.a ] then echo " * ncursesw already built @@ -99,7 +103,7 @@ then emmake make clean emmake make 2>&1 > /dev/null || FIX - emmake make install 2>&1 > /dev/null || exit 100 + emmake make install 2>&1 > /dev/null || exit 106 fi fi fi