Skip to content

Commit

Permalink
3.13a5 ok
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Mar 27, 2024
1 parent 2762af5 commit 4b68d44
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 56 deletions.
6 changes: 6 additions & 0 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions python-nim-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
36 changes: 22 additions & 14 deletions python-wasi-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions scripts/cpython-build-host-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 22 additions & 16 deletions scripts/cpython-build-host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<END
#ifdef HAVE_LIBINTL_H
Expand Down Expand Up @@ -111,24 +110,31 @@ END
${ROOT}/src/cpython${PYBUILD}/configure \
--prefix=$HOST_PREFIX $PYOPTS
then

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}/
echo "CPython $PYTHON_FOR_BUILD ready" 1>&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 "
==========================================================================
Expand Down
38 changes: 27 additions & 11 deletions scripts/cpython-build-wasisdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand All @@ -88,16 +88,32 @@ END

if make && make install
then
echo done
# cat > ${SDKROOT}/bin/python3 <<END
##!/bin/bash
#wasmtime --dir=/ --dir=. ${SDKROOT}/bin/python3.wasm \$@
#END
# chmod +x ${SDKROOT}/bin/python3
# ln ${SDKROOT}/bin/python3 ${SDKROOT}/bin/python
fi
sed -i 's|cpython/pthread_stubs|pthread|g' ${PREFIX}/include/python${PYBUILD}/cpython/pythread.h
fi
popd

pushd ${SDKROOT}/wasisdk
if [ -f libpython${PYBUILD}.a ]
then
echo already moved initial libpython${PYBUILD}.a
else
mv /opt/python-wasm-sdk/devices/wasisdk/usr/lib/libpython${PYBUILD}.a /opt/python-wasm-sdk/wasisdk/
fi

LINKALL="/opt/python-wasm-sdk/wasisdk/libpython3.13.a \
/opt/python-wasm-sdk/build/cpython-wasi/Modules/_decimal/libmpdec/libmpdec.a \
/opt/python-wasm-sdk/build/cpython-wasi/Modules/_hacl/libHacl_Hash_SHA2.a \
/opt/python-wasm-sdk/build/cpython-wasi/Modules/expat/libexpat.a \
/opt/python-wasm-sdk/wasisdk/upstream/share/wasi-sysroot/lib/wasm32-wasi/libbz2.a \
/opt/python-wasm-sdk/wasisdk/upstream/share/wasi-sysroot/lib/wasm32-wasi/libz.a \
/opt/python-wasm-sdk/wasisdk/upstream/share/wasi-sysroot/lib/wasm32-wasi/libsqlite3.a \
/opt/python-wasm-sdk/wasisdk/upstream/share/wasi-sysroot/lib/wasm32-wasi/libuuid.a"

wasi-c -nostdlib -fpic -r -Wl,--whole-archive -o libpython${PYBUILD}.o $LINKALL
llvm-ar rcs ${PREFIX}/lib/libpython${PYBUILD}.a libpython${PYBUILD}.o
popd


else
echo cannot find PYTHON_FOR_BUILD=$PYTHON_FOR_BUILD
fi
Expand Down
12 changes: 6 additions & 6 deletions scripts/cpython-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ fi

if echo $PYBUILD |grep -q 12$
then
wget -q -c https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tar.xz
tar xf Python-3.12.1.tar.xz
ln -s Python-3.12.1 cpython${PYBUILD}
wget -q -c https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tar.xz
tar xf Python-3.12.2.tar.xz
ln -s Python-3.12.2 cpython${PYBUILD}
export REBUILD=true
fi


if echo $PYBUILD | grep -q 11$
then
wget -q -c https://www.python.org/ftp/python/3.11.7/Python-3.11.7.tar.xz
tar xf Python-3.11.7.tar.xz
ln -s Python-3.11.7 cpython${PYBUILD}
wget -q -c https://www.python.org/ftp/python/3.11.8/Python-3.11.8.tar.xz
tar xf Python-3.11.8.tar.xz
ln -s Python-3.11.8 cpython${PYBUILD}
export REBUILD=true
fi

Expand Down
3 changes: 2 additions & 1 deletion scripts/wasisdk-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pushd ${SDKROOT}
wget -c https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK}/wasi-sdk-${WASI_SDK}.0-linux.tar.gz
tar xfz wasi-sdk-${WASI_SDK}.0-linux.tar.gz
mv wasi-sdk-${WASI_SDK}.0 upstream && rm wasi-sdk-${WASI_SDK}.0-linux.tar.gz


ln ${SDKROOT}/wasisdk/bin/wasi ${SDKROOT}/wasisdk/bin/cc
ln ${SDKROOT}/wasisdk/bin/wasi ${SDKROOT}/wasisdk/bin/wasi-c
ln ${SDKROOT}/wasisdk/bin/wasi ${SDKROOT}/wasisdk/bin/wasi-cpp
ln ${SDKROOT}/wasisdk/bin/wasi ${SDKROOT}/wasisdk/bin/wasi-c++
Expand Down
11 changes: 11 additions & 0 deletions wasisdk/bin/wasi-binfmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
if [ -f /proc/sys/fs/binfmt_misc/wasm32-wasi ]
then
WASM=$1
shift
else
echo ':wasm32-wasi:M::\x00asm:\xff\xff\xff\xff:/opt/python-wasm-sdk/wasisdk/bin/wasi-binfmt:' > /proc/sys/fs/binfmt_misc/register
exit 0
fi
wasmtime --env PYTHONDONTWRITEBYTECODE=1 --dir /::/ -- $WASM $@

9 changes: 9 additions & 0 deletions wasisdk/hotfix/cxa.c
Original file line number Diff line number Diff line change
@@ -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

49 changes: 46 additions & 3 deletions wasisdk/hotfix/patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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
}
Loading

0 comments on commit 4b68d44

Please sign in to comment.