Skip to content

Commit ca29ca4

Browse files
committed
make _ctypes C module static to avoid emsdk 3.1.46 linking problem
1 parent 8ae2363 commit ca29ca4

File tree

4 files changed

+57
-11
lines changed

4 files changed

+57
-11
lines changed

scripts/cpython-build-emsdk-deps.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
. ${CONFIG:-config}
44

55

6+
# cmake for assimp build
7+
$HPIP install --upgrade cmake
8+
9+
610
for pkg in $ROOT/sources.wasm/*.sh
711
do
812
cd $ROOT

scripts/cpython-build-emsdk-prebuilt.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ $HPIP install --upgrade setuptools
1616
# aioconsole only for the simulator
1717
$HPIP install --upgrade aioconsole
1818

19+
# support package build/install
20+
$HPY -m pip install --upgrade $PACKAGING
1921

2022

2123
PIP="${SDKROOT}/python3-wasm -m pip"
@@ -25,8 +27,6 @@ echo "
2527
" 1>&2
2628

2729

28-
# support package build/install
29-
$HPY -m pip install --upgrade $PACKAGING
3030

3131
$PIP install --upgrade $PACKAGING
3232

scripts/cpython-build-emsdk.sh

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ else
4848
echo -n
4949
else
5050
pushd src 2>&1 >/dev/null
51-
git clone https://github.com/pmp-p/libffi-emscripten.git libffi
51+
#git clone https://github.com/pmp-p/libffi-emscripten.git libffi
52+
git clone --no-tags --depth 1 --single-branch --branch master https://github.com/libffi/libffi
53+
pushd libffi
54+
./autogen.sh
55+
popd
5256
popd
5357
fi
5458

@@ -59,7 +63,7 @@ else
5963
#and no loder lib-dynload in the way.
6064

6165
EMCC_CFLAGS="-O0 -g0 -fPIC" CFLAGS="-O0 -g0 -fPIC" CC=${SDKROOT}/emsdk/upstream/emscripten/emcc \
62-
emconfigure $ROOT/src/libffi/configure --host=wasm32-mvp-emscripten\
66+
emconfigure $ROOT/src/libffi/configure --host=wasm32-bi-emscripten\
6367
--prefix=$PREFIX --enable-static --disable-shared --disable-dependency-tracking\
6468
--disable-builddir --disable-multi-os-directory --disable-raw-api --disable-docs
6569

@@ -160,6 +164,18 @@ END
160164

161165

162166

167+
#_ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/stgdict.c _ctypes/cfield.c -ldl -lffi -DHAVE_FFI_PREP_CIF_VAR -DHAVE_FFI_PREP_CLOSURE_LOC -DHAVE_FFI_CLOSURE_ALLOC
168+
169+
170+
#*shared*
171+
#_ctypes_test _ctypes/_ctypes_test.c
172+
#_testcapi _testcapimodule.c
173+
#_testimportmultiple _testimportmultiple.c
174+
#_testmultiphase _testmultiphase.c
175+
176+
177+
178+
163179
# OPT="$CPOPTS -DNDEBUG -fwrapv" \
164180
# --with-c-locale-coercion --without-pydebug --without-pymalloc --disable-ipv6 \
165181

@@ -188,6 +204,8 @@ END
188204

189205
#echo "#define HAVE_NCURSES_H" >> pyconfig.h
190206

207+
# prevent an error in install when byte compiling is disabled.
208+
mkdir -p ${ROOT}/devices/emsdk/usr/lib/python${PYMAJOR}.${PYMINOR}/lib-dynload/__pycache__
191209

192210
if emmake make -j$NPROC WASM_ASSETS_DIR=$(realpath ${PYTHONPYCACHEPREFIX}/empty)@/
193211
then
@@ -217,6 +235,20 @@ END
217235
fi
218236

219237

238+
if pushd ${SDKROOT}/build/cpython-wasm
239+
then
240+
mkdir -p ${SDKROOT}/prebuilt/emsdk
241+
OBJS="build/temp.emscripten-wasm32-${PYBUILD}/opt/python-wasm-sdk/src/Python-3.11.5/Modules/_ctypes/_ctypes.o \
242+
build/temp.emscripten-wasm32-${PYBUILD}/opt/python-wasm-sdk/src/Python-3.11.5/Modules/_ctypes/callbacks.o \
243+
build/temp.emscripten-wasm32-${PYBUILD}/opt/python-wasm-sdk/src/Python-3.11.5/Modules/_ctypes/callproc.o \
244+
build/temp.emscripten-wasm32-${PYBUILD}/opt/python-wasm-sdk/src/Python-3.11.5/Modules/_ctypes/cfield.o \
245+
build/temp.emscripten-wasm32-${PYBUILD}/opt/python-wasm-sdk/src/Python-3.11.5/Modules/_ctypes/stgdict.o"
246+
247+
$SDKROOT/emsdk/upstream/emscripten/emar rcs ${SDKROOT}/prebuilt/emsdk/lib_ctypes${PYBUILD}.a $OBJS
248+
popd
249+
fi
250+
251+
220252
rm -rf $(find $ROOT/devices/ -type d|grep /__pycache__$)
221253

222254
popd
@@ -229,11 +261,15 @@ END
229261
# move them to MEMFS
230262
mv $PREFIX/lib/python${PYBUILD}/lib-dynload/* ${SDKROOT}/prebuilt/emsdk/${PYBUILD}/lib-dynload/
231263

264+
echo " =============== FIXME: _ctype dynamic build ==============="
265+
rm ${SDKROOT}/prebuilt/emsdk/${PYBUILD}/lib-dynload/_ctypes.*
266+
rm ${SDKROOT}/prebuilt/emsdk/${PYBUILD}/lib-dynload/xxlimited*
267+
232268
# specific platform support
233269
cp -Rfv $ROOT/support/__EMSCRIPTEN__.patches/${PYBUILD}/. $PREFIX/lib/python${PYBUILD}/
234270

235271
cp -vf build/cpython-wasm/libpython${PYBUILD}.a prebuilt/emsdk/
236-
for lib in $(find build/cpython-wasm/|grep lib.*.a$)
272+
for lib in $(find build/cpython-wasm/|grep -v /libpython3|grep lib.*.a$)
237273
do
238274
name=$(basename $lib .a)
239275
cp $lib prebuilt/emsdk/${name}${PYBUILD}.a
@@ -373,6 +409,8 @@ do
373409
" 1>&2
374410
cp -rf $HPFX/${moveit} $TPFX/
375411
cp -rf $HPFX/${moveit}-* $TPFX/
412+
cp -rf $HPFX/site-package/${moveit} $TPFX/site-package/
413+
cp -rf $HPFX/site-package/${moveit}-* $TPFX/site-package/
376414
done
377415

378416

sources.wasm/assimp.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33

44
. ${CONFIG:-config}
5-
. scripts/emsdk-fetch.sh
65

76

87
cd ${ROOT}/src
98

9+
10+
# CMake Warning (dev) at /opt/python-wasm-sdk/devices/x86_64/usr/lib/python3.11/site-packages/cmake/data/share/cmake-3.27/Modules/GNUInstallDirs.cmake:243 (message):
11+
# Unable to determine default CMAKE_INSTALL_LIBDIR directory because no
12+
# target architecture is known. Please enable at least one language before
13+
# including GNUInstallDirs.
14+
15+
1016
export ASSIMP="assimpjs-wasm"
1117

1218
if [ -f assimp.patched ]
@@ -17,11 +23,9 @@ then
1723
else
1824
git clone --recursive https://github.com/pmp-p/$ASSIMP
1925
pushd $ASSIMP
20-
2126
# patch -p1 <<END END
22-
23-
touch ../assimp.patched
2427
popd
28+
touch assimp.patched
2529
fi
2630

2731

@@ -31,11 +35,11 @@ then
3135
already built in $PREFIX/lib/libassimp.a
3236
"
3337
else
34-
. $ROOT/scripts/emsdk-fetch.sh
38+
. ${SDKROOT}/scripts/emsdk-fetch.sh
3539

3640
mkdir -p $ROOT/build/assimp
3741
pushd $ROOT/build/assimp
38-
emmake cmake $ROOT/src/$ASSIMP -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_SHARED_LIBS=OFF
42+
emmake ${ROOT}/devices/$(arch)/usr/bin/cmake $ROOT/src/$ASSIMP -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_SHARED_LIBS=OFF
3943
emmake make install
4044
popd
4145
fi

0 commit comments

Comments
 (0)