# Get ctypes working in Emscripten build

**URL:** <https://discuss.python.org/t/get-ctypes-working-in-emscripten-build/18466>\
**Category:** WebAssembly\
**Created:** [August 24, 2022, 4:12pm UTC](https://discuss.python.org/t/get-ctypes-working-in-emscripten-build/18466 "2022-08-24T16:12:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rchiodo](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rchiodo/32/8617_2.png) [@rchiodo](https://discuss.python.org/u/rchiodo)\
**Post date:** [August 24, 2022, 4:12pm UTC](https://discuss.python.org/t/get-ctypes-working-in-emscripten-build/18466/1 "2022-08-24T16:12:21Z")

</div>

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)](https://github.com/hoodmane/libffi-emscripten) 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?

---

<div class="post-metadata">

**Author:** ![rchiodo](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rchiodo/32/8617_2.png) [@rchiodo](https://discuss.python.org/u/rchiodo)\
**Post date:** [August 24, 2022, 4:44pm UTC](https://discuss.python.org/t/get-ctypes-working-in-emscripten-build/18466/2 "2022-08-24T16:44:55Z")

</div>

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

I’m using [Ethan’s scripts](https://github.com/ethanhs/python-wasm.git) to build. I modified the `build-python-emscripten-node.sh` to be like so:

```auto
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.

---

<div class="post-metadata">

**Author:** ![tiran](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/tiran/32/48_2.png) [@tiran](https://discuss.python.org/u/tiran)\
**Post date:** [August 24, 2022, 7:01pm UTC](https://discuss.python.org/t/get-ctypes-working-in-emscripten-build/18466/3 "2022-08-24T19:01:35Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![rchiodo](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rchiodo/32/8617_2.png) [@rchiodo](https://discuss.python.org/u/rchiodo)\
**Post date:** [September 6, 2022, 8:45pm UTC](https://discuss.python.org/t/get-ctypes-working-in-emscripten-build/18466/4 "2022-09-06T20:45:55Z")

</div>

Christian also found this: [Building Projects — Emscripten 3.1.21-git (dev) documentation](https://emscripten.org/docs/compiling/Building-Projects.html#pkg-config)
