Skip to content

Commit

Permalink
make _ctypes C module static to avoid emsdk 3.1.46 linking problem
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Sep 14, 2023
1 parent 8ae2363 commit ca29ca4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
4 changes: 4 additions & 0 deletions scripts/cpython-build-emsdk-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
. ${CONFIG:-config}


# cmake for assimp build
$HPIP install --upgrade cmake


for pkg in $ROOT/sources.wasm/*.sh
do
cd $ROOT
Expand Down
4 changes: 2 additions & 2 deletions scripts/cpython-build-emsdk-prebuilt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ $HPIP install --upgrade setuptools
# aioconsole only for the simulator
$HPIP install --upgrade aioconsole

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


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


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

$PIP install --upgrade $PACKAGING

Expand Down
44 changes: 41 additions & 3 deletions scripts/cpython-build-emsdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ else
echo -n
else
pushd src 2>&1 >/dev/null
git clone https://github.com/pmp-p/libffi-emscripten.git libffi
#git clone https://github.com/pmp-p/libffi-emscripten.git libffi
git clone --no-tags --depth 1 --single-branch --branch master https://github.com/libffi/libffi
pushd libffi
./autogen.sh
popd
popd
fi

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

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

Expand Down Expand Up @@ -160,6 +164,18 @@ END



#_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


#*shared*
#_ctypes_test _ctypes/_ctypes_test.c
#_testcapi _testcapimodule.c
#_testimportmultiple _testimportmultiple.c
#_testmultiphase _testmultiphase.c




# OPT="$CPOPTS -DNDEBUG -fwrapv" \
# --with-c-locale-coercion --without-pydebug --without-pymalloc --disable-ipv6 \

Expand Down Expand Up @@ -188,6 +204,8 @@ END

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

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

if emmake make -j$NPROC WASM_ASSETS_DIR=$(realpath ${PYTHONPYCACHEPREFIX}/empty)@/
then
Expand Down Expand Up @@ -217,6 +235,20 @@ END
fi


if pushd ${SDKROOT}/build/cpython-wasm
then
mkdir -p ${SDKROOT}/prebuilt/emsdk
OBJS="build/temp.emscripten-wasm32-${PYBUILD}/opt/python-wasm-sdk/src/Python-3.11.5/Modules/_ctypes/_ctypes.o \
build/temp.emscripten-wasm32-${PYBUILD}/opt/python-wasm-sdk/src/Python-3.11.5/Modules/_ctypes/callbacks.o \
build/temp.emscripten-wasm32-${PYBUILD}/opt/python-wasm-sdk/src/Python-3.11.5/Modules/_ctypes/callproc.o \
build/temp.emscripten-wasm32-${PYBUILD}/opt/python-wasm-sdk/src/Python-3.11.5/Modules/_ctypes/cfield.o \
build/temp.emscripten-wasm32-${PYBUILD}/opt/python-wasm-sdk/src/Python-3.11.5/Modules/_ctypes/stgdict.o"

$SDKROOT/emsdk/upstream/emscripten/emar rcs ${SDKROOT}/prebuilt/emsdk/lib_ctypes${PYBUILD}.a $OBJS
popd
fi


rm -rf $(find $ROOT/devices/ -type d|grep /__pycache__$)

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

echo " =============== FIXME: _ctype dynamic build ==============="
rm ${SDKROOT}/prebuilt/emsdk/${PYBUILD}/lib-dynload/_ctypes.*
rm ${SDKROOT}/prebuilt/emsdk/${PYBUILD}/lib-dynload/xxlimited*

# specific platform support
cp -Rfv $ROOT/support/__EMSCRIPTEN__.patches/${PYBUILD}/. $PREFIX/lib/python${PYBUILD}/

cp -vf build/cpython-wasm/libpython${PYBUILD}.a prebuilt/emsdk/
for lib in $(find build/cpython-wasm/|grep lib.*.a$)
for lib in $(find build/cpython-wasm/|grep -v /libpython3|grep lib.*.a$)
do
name=$(basename $lib .a)
cp $lib prebuilt/emsdk/${name}${PYBUILD}.a
Expand Down Expand Up @@ -373,6 +409,8 @@ do
" 1>&2
cp -rf $HPFX/${moveit} $TPFX/
cp -rf $HPFX/${moveit}-* $TPFX/
cp -rf $HPFX/site-package/${moveit} $TPFX/site-package/
cp -rf $HPFX/site-package/${moveit}-* $TPFX/site-package/
done


Expand Down
16 changes: 10 additions & 6 deletions sources.wasm/assimp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@


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


cd ${ROOT}/src


# 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):
# Unable to determine default CMAKE_INSTALL_LIBDIR directory because no
# target architecture is known. Please enable at least one language before
# including GNUInstallDirs.


export ASSIMP="assimpjs-wasm"

if [ -f assimp.patched ]
Expand All @@ -17,11 +23,9 @@ then
else
git clone --recursive https://github.com/pmp-p/$ASSIMP
pushd $ASSIMP

# patch -p1 <<END END

touch ../assimp.patched
popd
touch assimp.patched
fi


Expand All @@ -31,11 +35,11 @@ then
already built in $PREFIX/lib/libassimp.a
"
else
. $ROOT/scripts/emsdk-fetch.sh
. ${SDKROOT}/scripts/emsdk-fetch.sh

mkdir -p $ROOT/build/assimp
pushd $ROOT/build/assimp
emmake cmake $ROOT/src/$ASSIMP -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_SHARED_LIBS=OFF
emmake ${ROOT}/devices/$(arch)/usr/bin/cmake $ROOT/src/$ASSIMP -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_SHARED_LIBS=OFF
emmake make install
popd
fi
Expand Down

0 comments on commit ca29ca4

Please sign in to comment.