pyo3: error when compiling to wasm32-unknown-unknown or wasm32-unknown-emscripten

I’m building a rust lib :

[lib]
crate-type = ["cdylib"]

with pyo3 in my dependencies : pyo3 = { version = "0.19.0", features = ["auto-initialize", "abi3-py39"] }

Trying to build with cross or cargo for wasm32-unknown-unknown gets me this error :

  error: your Rust target architecture (32-bit) does not match your python interpreter (64-bit)

Trying again with cross: cross b --target wasm32-unknown-emscripten with in my cargo.toml : pyo3 = { version = "0.19.0", features = ["auto-initialize", "abi3-py39"] } I get

error: failed to run custom build command for `pyo3-build-config v0.19.0`

Caused by:
  process didn't exit successfully: `/target/debug/build/pyo3-build-config-6833074d719a3ea0/build-script-build` (exit status: 1)
  --- stderr
  /target/debug/build/pyo3-build-config-6833074d719a3ea0/build-script-build: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /target/debug/build/pyo3-build-config-6833074d719a3ea0/build-script-build)
  /target/debug/build/pyo3-build-config-6833074d719a3ea0/build-script-build: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /target/debug/build/pyo3-build-config-6833074d719a3ea0/build-script-build)
  /target/debug/build/pyo3-build-config-6833074d719a3ea0/build-script-build: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /target/debug/build/pyo3-build-config-6833074d719a3ea0/build-script-build)

I would prefer to build for wasm32-unknown-unknown but if someone helps me get this work with wasm32-unknown-emscripten I might settle for that ! I’m stuck and I tried more than I reported here, any tips?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 26 (11 by maintainers)

Most upvoted comments

PYO3_CROSS_LIB_DIR=/usr/lib/x86_64-linux-gnu/

Why did you point it to a Python library for x86-64 if you are building for WASM?

The project you are using says

It will download all needed pre-built static libraries for wasm32-wasi and configure the linker to use them.

but you are not targetting WASI, you are targetting Emscripten.

with features = [“generate-import-lib”]

As per https://pyo3.rs/v0.19.0/building_and_distribution#cross-compiling, this feature is relevant only when compiling for Windows targets so you should not use it.

As a more fundamental question, if you do not have a Python interpreter for your WASM target, how do you intend to run the resulting binary which will need to load said interpreter?

If you do want to build in isolation without access to an interpreter, you need to set the environment variable PYO3_NO_PYTHON and enable one of the abi3-py* features as per the above linked documentation.

maturin only support python3.10+ for emscripten target, because that’s the version pyodide supports.

@astrale-sharp I’d recommend reading https://pyo3.rs/v0.19.0/building_and_distribution#cross-compiling to learn more about how to cross compile pyo3 projects.