Skip to content

Commit 0a7a1be

Browse files
committed
consolidate libpython wasi
1 parent e415ef5 commit 0a7a1be

File tree

4 files changed

+64
-9
lines changed

4 files changed

+64
-9
lines changed

scripts/cpython-build-emsdk.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ END
203203
GIL="--disable-gil"
204204
sed -i 's|{ABIFLAGS}t|{ABIFLAGS}|g' configure
205205
sed -i 's|{ABIFLAGS}t|{ABIFLAGS}|g' configure.ac
206+
sed -i 's|--wasi preview2||g' configure
207+
sed -i 's|--wasi preview2||g' configure.ac
206208
else
207209
GIL=""
208210
fi

scripts/cpython-build-wasisdk.sh

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ END
6464

6565
LDSHARED="${SDKROOT}/wasisdk/upstream/bin/wasm-ld --no-entry" CONFIG_SITE=$PYSRC/Tools/wasm/config.site-wasm32-wasisdk \
6666
$PYSRC/configure -C \
67-
--with-c-locale-coercion --without-pymalloc --disable-ipv6 --with-ensurepip=no \
67+
--with-c-locale-coercion --without-pymalloc --disable-ipv6 --disable-gil --with-ensurepip=no \
6868
--prefix=${PREFIX} \
6969
--host=wasm32-unknown-wasi --with-suffix=.wasm \
7070
--build=$($PYSRC/config.guess) \
@@ -88,16 +88,32 @@ END
8888

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

95+
pushd ${SDKROOT}/wasisdk
96+
if [ -f libpython${PYBUILD}.a ]
97+
then
98+
echo already moved initial libpython${PYBUILD}.a
99+
else
100+
mv /opt/python-wasm-sdk/devices/wasisdk/usr/lib/libpython${PYBUILD}.a /opt/python-wasm-sdk/wasisdk/
101+
fi
102+
103+
LINKALL="/opt/python-wasm-sdk/wasisdk/libpython3.13.a \
104+
/opt/python-wasm-sdk/build/cpython-wasi/Modules/_decimal/libmpdec/libmpdec.a \
105+
/opt/python-wasm-sdk/build/cpython-wasi/Modules/_hacl/libHacl_Hash_SHA2.a \
106+
/opt/python-wasm-sdk/build/cpython-wasi/Modules/expat/libexpat.a \
107+
/opt/python-wasm-sdk/wasisdk/upstream/share/wasi-sysroot/lib/wasm32-wasi/libbz2.a \
108+
/opt/python-wasm-sdk/wasisdk/upstream/share/wasi-sysroot/lib/wasm32-wasi/libz.a \
109+
/opt/python-wasm-sdk/wasisdk/upstream/share/wasi-sysroot/lib/wasm32-wasi/libsqlite3.a \
110+
/opt/python-wasm-sdk/wasisdk/upstream/share/wasi-sysroot/lib/wasm32-wasi/libuuid.a"
111+
112+
wasi-c -nostdlib -fpic -r -Wl,--whole-archive -o libpython${PYBUILD}.o $LINKALL
113+
llvm-ar rcs ${PREFIX}/lib/libpython${PYBUILD}.a libpython${PYBUILD}.o
114+
popd
115+
116+
101117
else
102118
echo cannot find PYTHON_FOR_BUILD=$PYTHON_FOR_BUILD
103119
fi

wasisdk/hotfix/cxa.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#if defined(__wasi__)
2+
extern "C" {
3+
void *
4+
__cxa_allocate_exception(size_t thrown_size) { return NULL; }
5+
void
6+
__cxa_throw(void *thrown_exception, std::type_info *tinfo, void *dest) {}
7+
}
8+
#endif
9+

wasisdk/hotfix/pwd.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef _WASIX_PWD_H
2+
#define _WASIX_PWD_H
3+
4+
#include <unistd.h>
5+
#include <features.h>
6+
#include <bits/alltypes.h>
7+
8+
#define __need_size_t
9+
#include <stddef.h>
10+
11+
/* A record in the user database. */
12+
struct passwd
13+
{
14+
char *pw_name; /* Username. */
15+
char *pw_passwd; /* Hashed passphrase, if shadow database
16+
not in use (see shadow.h). */
17+
uid_t pw_uid; /* User ID. */
18+
gid_t pw_gid; /* Group ID. */
19+
char *pw_gecos; /* Real name. */
20+
char *pw_dir; /* Home directory. */
21+
char *pw_shell; /* Shell program. */
22+
};
23+
24+
struct passwd *getpwnam(const char *name);
25+
26+
struct passwd *getpwuid(uid_t uid);
27+
28+
#endif

0 commit comments

Comments
 (0)