Skip to content

Commit

Permalink
ninja/glib fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Dec 17, 2024
1 parent 869346f commit 20a28cb
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 44 deletions.
21 changes: 11 additions & 10 deletions proot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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

2 changes: 1 addition & 1 deletion python-wasm-sdk/emsdk-cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
99 changes: 92 additions & 7 deletions python-wasm-sdk/scripts/cpython-build-emsdk-prebuilt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<END
#!${HOST_PREFIX}/bin/python${PYBUILD}
cat > ${HOST_PREFIX}/lib/python${PYBUILD}/site-packages/ninja/__init__.py <<END
from __future__ import annotations
import os
import subprocess
import sys
import sysconfig
from collections.abc import Iterable
from typing import NoReturn
from ._version import version as __version__
from .ninja_syntax import Writer, escape, expand
__all__ = ["BIN_DIR", "DATA", "Writer", "__version__", "escape", "expand", "ninja"]
def __dir__() -> 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 <<END
#!/opt/python-wasm-sdk/devices/x86_64/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
sys.argv.insert(1,'1')
sys.argv.insert(1,'-j')
import os
os.environ['NINJA']="1"
from ninja import ninja
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?\$', '', sys.argv[0])
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(ninja())
END
chmod +x $HOST_PREFIX/bin/ninja
fi



echo "
* cpython-build-emsdk-prebuilt pip==$PIP *
Expand Down
6 changes: 2 additions & 4 deletions python-wasm-sdk/scripts/cpython-build-emsdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export PYTHON_FOR_BUILD=${PYTHON_FOR_BUILD:-${HPY}}

. ./scripts/emsdk-fetch.sh

REBUILD_WASM=${REBUILD_WASMPY:-false}

if $REBUILD || $REBUILD_WASMPY
if ${REBUILD_WASMPY:-false}
then
rm -rf build/cpython-wasm/ build/pycache/config.cache
rm build/cpython-wasm/libpython${PYBUILD}.a 2>/dev/null
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,8 +39,7 @@ then
done

# Common compiler flags
export CFLAGS="-O3"
export CXXFLAGS="$CFLAGS"
export COPTS="-Os -g0"
export LDFLAGS="-L$PREFIX/lib"


Expand Down Expand Up @@ -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
Expand Down
26 changes: 15 additions & 11 deletions python-wasm-sdk/sources.wasm/5000-ncurses-65.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -68,17 +73,16 @@ 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

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
Expand All @@ -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
Expand Down

0 comments on commit 20a28cb

Please sign in to comment.