Get ctypes working in Emscripten build

The emscripten build skips building a number of submodules (I hope I have the terminology correct), one of which is _ctypes.

I found this: hoodmane/libffi-emscripten: Emscripten port of libffi (github.com) which I believe if I could get the build to pull it in as the libffi package, ctypes would work.

The difficulty I’m having is the configure step for emscripten won’t pick up a custom PKG_CONFIG_PATH environment variable. I’m a total noob with respect to building CPython so maybe I’m just not doing something correctly.

Is there a doc somewhere explaining how configure reads environment variables or perhaps somebody else has gotten ctypes to work in the emscripten build?

Figured it out. I had to pass the environment variable on the command line to configure.

I’m using Ethan’s scripts to build. I modified the build-python-emscripten-node.sh to be like so:

CONFIG_SITE=../../Tools/wasm/config.site-wasm32-emscripten \
  emconfigure ../../configure -C \
    --host=wasm32-unknown-emscripten \
    --with-pydebug \
    PKG_CONFIG_PATH=/home/rich/source/libffi-emscripten \ <-- This line 
    --enable-wasm-pthreads=yes \
    --build=$(../../config.guess) \
    --with-emscripten-target=node \
    --enable-wasm-dynamic-linking=no \
    --with-build-python=$(pwd)/../build/python \
    "$@"

With of course building the libffi-emscripten repo first.

emconfigure resets PKG_CONFIG_PATH and sets PKG_CONFIG_LIBDIR for cross compiling. Your workaround does the trick. You can also create $EMSCRIPTEN/cache/sysroot/local/lib/pkgconfig and copy the pc files into that directory.

2 Likes

Christian also found this: Building Projects — Emscripten 3.1.21-git (dev) documentation