diff --git a/config b/config index e25dd0b..ebc6e4c 100644 --- a/config +++ b/config @@ -21,6 +21,7 @@ mkdir -p ${SDKROOT}/build/pycache ${SDKROOT}/build/cache export XDG_CACHE_HOME=$(realpath ${SDKROOT}/build/cache) export PYTHONPYCACHEPREFIX=${PYTHONPYCACHEPREFIX:-$(realpath ${SDKROOT}/build/pycache)} +export WHEELS=/data/git/archives/repo export HOME=${SDKROOT} @@ -118,6 +119,11 @@ do fi done +# ================ aosp =================== + +AOSP_NDK=25.2.9519653 + + # this is python used for emsdk : ${SYS_PYTHON} -> ${EMSDK_PYTHON} for py in 10 9 8 7 diff --git a/python-nim-sdk.sh b/python-nim-sdk.sh index 672047b..0c9e3b8 100755 --- a/python-nim-sdk.sh +++ b/python-nim-sdk.sh @@ -108,11 +108,16 @@ when defined(wasi): switch("passL", "-lwasi-emulated-getpid -lwasi-emulated-mman -lwasi-emulated-signal -lwasi-emulated-process-clocks") switch("passL","-lstdc++") - - # don't use _start/main but _initialize instead - switch("passL", "-Wl,--no-entry,--export-all -mexec-model=reactor") - # component model aka reactor - --noMain + when defined(app): + echo " @@@@@ APP MODE @@@@@" +# switch("passL", "-Wl,--no-entry") +# switch("passL", "-Wl,--no-entry,--export-all -mexec-model=reactor") + --noMain + else: + # don't use _start/main but _initialize instead + switch("passL", "-Wl,--no-entry,--export-all -mexec-model=reactor") + # component model aka reactor + --noMain # FIXME switch("passC", fmt"-m32 -Djmp_buf=int") diff --git a/python-wasi-sdk.sh b/python-wasi-sdk.sh index 47317ed..68ea7e2 100755 --- a/python-wasi-sdk.sh +++ b/python-wasi-sdk.sh @@ -18,20 +18,31 @@ if echo $0|grep -q python-wasm-sdk then echo " * adding emsdk to wasm-sdk" emsdk=true - wasisdk=false - nimsdk=false + wasisdk=${wasisdk:-false} + nimsdk=${nimsdk:-false} else emsdk=false - BUILDS=3.12 - echo " * adding wasi-sdk to wasm-sdk" + BUILDS=3.13 wasisdk=true nimsdk=true fi +if $wasisdk +then + echo " * adding wasi-sdk to wasm-sdk" +fi + +if $nimsdk +then + echo " * adding nim-sdk to wasm-sdk" +fi + + + if [ -d ${SDKROOT} ] then - echo "assming destination $SDKROOT is ready" + echo "Assuming destination $SDKROOT is ready" else sudo mkdir -p ${SDKROOT} sudo chmod 777 ${SDKROOT} @@ -43,18 +54,12 @@ ORIGIN=$(pwd) # 3.12 3.11 3.10 -BUILDS=${BUILDS:-3.11 3.13 3.12} +BUILDS=${BUILDS:-3.12 3.13} for PYBUILD in $BUILDS do cd "$ORIGIN" -# if echo $PYBUILD|grep -q 12$ -# then -# wasisdk=true -# else -# wasisdk=false -# fi if [ -f ${SDKROOT}/dev ] then @@ -74,6 +79,9 @@ do # make install cpython will force bytecode generation export PYTHONPYCACHEPREFIX="$(realpath build/pycache)" + # reset config + unset CONFIG_ENV + . ${CONFIG:-config} cd ${SDKROOT} @@ -106,9 +114,9 @@ export PYTHONPYCACHEPREFIX=$PYTHONPYCACHEPREFIX export HOME=${SDKROOT} export PATH=${SDKROOT}/devices/$(arch)/usr/bin:\$PATH export LD_LIBRARY_PATH=${SDKROOT}/devices/$(arch)/usr/lib:${SDKROOT}/devices/$(arch)/usr/lib64:$LD_LIBRARY_PATH -${SDKROOT}/devices/$(arch)/usr/bin/python\${PYBUILD:-$PYBUILD} $@ +${SDKROOT}/devices/$(arch)/usr/bin/python\${PYBUILD:-$PYBUILD} \$@ END - chmod + /opt/python-wasm-sdk/devices/$(arch)/usr/bin/py + chmod +x /opt/python-wasm-sdk/devices/$(arch)/usr/bin/py if $emsdk diff --git a/scripts/cpython-build-host-deps.sh b/scripts/cpython-build-host-deps.sh index fd0ca88..dcda75f 100755 --- a/scripts/cpython-build-host-deps.sh +++ b/scripts/cpython-build-host-deps.sh @@ -14,3 +14,8 @@ $HPIP install --upgrade pip # 3.12 and git deprecated setuptools bundling. $HPIP install --upgrade setuptools + +# probably lot of pip install made in cpython-build-emsdk-prebuilt.sh +# should only go here in host python + +# TODO diff --git a/scripts/cpython-build-host.sh b/scripts/cpython-build-host.sh index 1eb7e5b..19fb798 100755 --- a/scripts/cpython-build-host.sh +++ b/scripts/cpython-build-host.sh @@ -69,8 +69,7 @@ END PYOPTS="--disable-ipv6 \ --with-c-locale-coercion --without-pymalloc --without-pydebug \ --with-ensurepip $TESTSUITE \ - --with-decimal-contextvar --disable-shared \ - --with-computed-gotos" + --with-decimal-contextvar --disable-shared" cat >> pyconfig.h <&2 else - echo "failed to build $PYTHON_FOR_BUILD" - exit 123 + echo "failed to build $PYTHON_FOR_BUILD" 1>&2 + exit 118 fi + +# if make -j$(nproc) install +# then +# rm -rf $(find $ROOT/devices/ -type d|grep __pycache__$) +# rm $HOST_PREFIX/bin/python3-config \ +# $HOST_PREFIX/bin/idle3 \ +# $HOST_PREFIX/bin/pydoc3 \ +# $HOST_PREFIX/bin/python3 + +# # make ubuntu binaries able to run elsewhere +# patchelf --remove-needed libintl.so.8 $HOST_PREFIX/bin/python${PYBUILD} +# # and able to compile elsewhere +# sed -i 's|-lintl ||g' ${SDKROOT}/devices/x86_64/usr/bin/python${PYBUILD}-config +# cp -Rfv $ROOT/support/__EMSCRIPTEN__.patches/${PYBUILD}/. $HOST_PREFIX/lib/python${PYBUILD}/ +# else +# echo "failed to build $PYTHON_FOR_BUILD" +# exit 123 +# fi else echo " ========================================================================== diff --git a/scripts/cpython-build-wasisdk.sh b/scripts/cpython-build-wasisdk.sh index 7360a7f..2d2ece6 100755 --- a/scripts/cpython-build-wasisdk.sh +++ b/scripts/cpython-build-wasisdk.sh @@ -59,12 +59,12 @@ cross_compiling=yes END pushd ${SDKROOT}/build/cpython-wasi - 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 +# sed -i 's| -Wl,--stack-first -Wl,--initial-memory=10485760| --stack-first --initial-memory=10485760|g' $PYSRC/configure.ac +# sed -i 's| -Wl,--stack-first -Wl,--initial-memory=10485760| --stack-first --initial-memory=10485760|g' $PYSRC/configure 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 \ + --with-c-locale-coercion --without-pymalloc --disable-ipv6 --disable-gil --with-ensurepip=no \ --prefix=${PREFIX} \ --host=wasm32-unknown-wasi --with-suffix=.wasm \ --build=$($PYSRC/config.guess) \ @@ -88,16 +88,32 @@ END if make && make install then - echo done -# cat > ${SDKROOT}/bin/python3 < /proc/sys/fs/binfmt_misc/register + exit 0 +fi +wasmtime --env PYTHONDONTWRITEBYTECODE=1 --dir /::/ -- $WASM $@ + diff --git a/wasisdk/hotfix/cxa.c b/wasisdk/hotfix/cxa.c new file mode 100644 index 0000000..ecfe0f2 --- /dev/null +++ b/wasisdk/hotfix/cxa.c @@ -0,0 +1,9 @@ +#if defined(__wasi__) +extern "C" { +void * +__cxa_allocate_exception(size_t thrown_size) { return NULL; } +void +__cxa_throw(void *thrown_exception, std::type_info *tinfo, void *dest) {} +} +#endif + diff --git a/wasisdk/hotfix/patch.h b/wasisdk/hotfix/patch.h index 3bbec53..389d5b3 100644 --- a/wasisdk/hotfix/patch.h +++ b/wasisdk/hotfix/patch.h @@ -59,6 +59,13 @@ mktemp(char *tmpl) return tmpl; } +static int +mkstemp(char *tmpl) { + FILE *ftemp = fopen(mktemp(tmpl),"w"); + return fileno(ftemp); +} + + #if 0 static char * @@ -95,14 +102,15 @@ static char * tempnam (const char *dir, const char *pfx) { char buf[FILENAME_MAX]; - + int all; + char *ptr; int dirlen = strlen(dir); if (dirlen>=FILENAME_MAX) return NULL; memcpy(buf,dir,FILENAME_MAX); buf[dirlen] = '/'; - int all; + if (pfx) { all = dirlen + 1 + strlen(pfx); @@ -116,7 +124,7 @@ tempnam (const char *dir, const char *pfx) memcpy(buf+all, "XXXXXX", 6 ); all += 6 ; buf[all]= 0; - char *ptr = (char *)malloc(all); + ptr = (char *)malloc(all); memcpy(ptr, buf, all); return mktemp(ptr); } @@ -128,3 +136,38 @@ lockf(int fd, int cmd, off_t len) { return 0; } +static int +pclose(FILE *stream){ + (void)stream; + return 0; +} + + +static pid_t +getpid(void) { + char *val = getenv("WASIX_PID"); + char *end = val + strlen(val); + if (val && val[0] != '\0') { + return (pid_t)strtol(val, &end, 10); + } +#ifdef _WASIX_PID + return (pid_t)(_WASIX_PID); +#else + return 66600; +#endif +} + + +static pid_t +getppid(void) { + char *val = getenv("WASIX_PPID"); + char *end = val + strlen(val); + if (val && val[0] != '\0') { + return (pid_t)strtol(val, &end, 10); + } +#ifdef _WASIX_PPID + return (pid_t)(_WASIX_PPID); +#else + return 1; +#endif +} diff --git a/wasisdk/hotfix/pwd.h b/wasisdk/hotfix/pwd.h new file mode 100644 index 0000000..a79aca4 --- /dev/null +++ b/wasisdk/hotfix/pwd.h @@ -0,0 +1,28 @@ +#ifndef _WASIX_PWD_H +#define _WASIX_PWD_H + +#include +#include +#include + +#define __need_size_t +#include + +/* A record in the user database. */ +struct passwd +{ + char *pw_name; /* Username. */ + char *pw_passwd; /* Hashed passphrase, if shadow database + not in use (see shadow.h). */ + uid_t pw_uid; /* User ID. */ + gid_t pw_gid; /* Group ID. */ + char *pw_gecos; /* Real name. */ + char *pw_dir; /* Home directory. */ + char *pw_shell; /* Shell program. */ +}; + +struct passwd *getpwnam(const char *name); + +struct passwd *getpwuid(uid_t uid); + +#endif diff --git a/wasisdk/hotfix/wasi-setjmp.h b/wasisdk/hotfix/wasi-setjmp.h new file mode 100644 index 0000000..3477357 --- /dev/null +++ b/wasisdk/hotfix/wasi-setjmp.h @@ -0,0 +1,16 @@ +#ifndef _WASIX_SETJMP_H +#define _WASIX_SETJMP_H + +typedef void *jmp_buf; + +static int +setjmp(jmp_buf env) { + return 0; +} +static +void longjmp(jmp_buf env, int value) { + (void)env; + (void)value; +} + +#endif diff --git a/wasisdk/hotfix/wasi-wait.h b/wasisdk/hotfix/wasi-wait.h new file mode 100644 index 0000000..331c2b3 --- /dev/null +++ b/wasisdk/hotfix/wasi-wait.h @@ -0,0 +1,22 @@ + +#ifndef _WASIX_SYS_WAIT_H +#define _WASIX_SYS_WAIT_H + +#include + +#define WNOHANG 1 +#define WUNTRACED 2 + +#define WEXITSTATUS(s) (((s) & 0xff00) >> 8) +#define WTERMSIG(s) ((s) & 0x7f) +#define WSTOPSIG(s) WEXITSTATUS(s) +#define WIFEXITED(s) (!WTERMSIG(s)) +#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00) +#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu) + +typedef int pid_t; + +pid_t wait(int *wstatus); +pid_t waitpid(pid_t pid, int *status, int options); + +#endif diff --git a/wasisdk/wasisdk_env.sh b/wasisdk/wasisdk_env.sh index f723b65..16b8d33 100755 --- a/wasisdk/wasisdk_env.sh +++ b/wasisdk/wasisdk_env.sh @@ -47,6 +47,7 @@ then export RANLIB="${WASI_SDK_PREFIX}/bin/ranlib" export CC="${WASISDK}/bin/wasi-c" + export WASI_CC="${WASISDK}/bin/wasi-c" export CPP="${WASISDK}/bin/wasi-cpp" export CXX="${WASISDK}/bin/wasi-c++"