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)
Why did you point it to a Python library for x86-64 if you are building for WASM?
Maybe https://stackoverflow.com/questions/68265851/cannot-execute-standalone-webassembly-file-with-wasmer? Maybe try Wasmtime as discussed there?
The project you are using says
but you are not targetting WASI, you are targetting Emscripten.
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_PYTHONand enable one of theabi3-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.
See https://github.com/PyO3/pyo3/discussions/2306#discussioncomment-2564793.
We have support for
wasm32-unknown-emscriptentarget in maturin, for example: https://github.com/pydantic/pydantic-core/blob/c8e38786c83ecf09803026f2f7794dfa367d514d/.github/workflows/ci.yml#L229-L277