rust-cpython icon indicating copy to clipboard operation
rust-cpython copied to clipboard

Is it possible to build on wasm?

Open zeroexcuses opened this issue 6 years ago • 3 comments

Is there any chance we can build python3-sys or rust-cpython with target = wasm32-unknown-unknown ?

I have a webapp built in Rust/wasm32, and I would like to be able to use Python3.7 as the scripting language for the Rust webapp.

I am getting error:

error: failed to run custom build command for `python3-sys v0.2.1`

--- stderr
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "failed to run python interpreter `\"python\" \"-c\" \"import sys; import sysconfig; print(sys.executable); print(sys.version_info[0:2]); print(sysconfig.get_config_var(\\\'LIBDIR\\\')); print(sysconfig.get_config_var(\\\'Py_ENABLE_SHARED\\\')); print(sysconfig.get_config_var(\\\'LDVERSION\\\') or \\\'%s%s\\\' % (sysconfig.get_config_var(\\\'py_version_short\\\'), sysconfig.get_config_var(\\\'DEBUG_EXT\\\') or \\\'\\\')); print(sys.exec_prefix);\"`: No such file or directory (os error 2)"', src/libcore/result.rs:1051:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

zeroexcuses avatar Jul 14 '19 09:07 zeroexcuses

I'm not maintainer of this project. But I have interest on the idea you have and I have tried a few things. But cpython relies on pthread.h which is not supported by wasm32. It might be supported in the wasm32-wasi target some time in the future.

rafaelcaricio avatar Jan 03 '20 14:01 rafaelcaricio

@rafaelcaricio https://developers.google.com/web/updates/2018/10/wasm-threads it looks like pthread is kind of supported, at least in Chrome

rrader avatar Feb 19 '21 13:02 rrader

The python3-sys build script asks your currently installed python interpreter for its compilation flags, so that python3-sys can be compiled with a compatible ABI. That approach won't really work when cross-compiling. You'll need to adjust the build script and figure out some other way of detecting the relevant flags (maybe just hardcode them?).

dgrunwald avatar Feb 19 '21 13:02 dgrunwald