wasm3 / wasm3-rs

Rust wrapper for Wasm3, the fastest WebAssembly interpreter
MIT License
155 stars 43 forks source link

swap to bindgen cli for no_std #2

Closed jacobrosenthal closed 4 years ago

jacobrosenthal commented 4 years ago

Thanks so much for your recent no_std support. There is one problem still, in that using deps with shared features from build.rs pollutes the no_std features with std features. Its sadly a well known problem with the only solution being to swap bindgen api for cli. https://github.com/rust-lang/cargo/issues/5730

I think this is pretty close to complete, but not quite right yet as the pathing on the headers is broken but thought Id open the pr to start discussion

jacobrosenthal@Jacobs-MacBook-Air pygamer (embedded-graphics-addons) $ cargo run --example ferris_img --release
   Compiling wasm3-sys v0.1.0 (/Users/jacobrosenthal/Downloads/wasm3-rs/wasm3-sys)
   Compiling atsamd-hal v0.8.2 (/Users/jacobrosenthal/Downloads/atsamd/hal)
error: failed to run custom build command for `wasm3-sys v0.1.0 (/Users/jacobrosenthal/Downloads/wasm3-rs/wasm3-sys)`

Caused by:
  process didn't exit successfully: `/Users/jacobrosenthal/Downloads/atsamd/boards/pygamer/target/release/build/wasm3-sys-cdaaa8881bf2f36a/build-script-build` (exit code: 101)
--- stdout
cargo:warning=couldn't execute `llvm-config --prefix` (error: No such file or directory (os error 2))
cargo:warning=set the LLVM_CONFIG_PATH environment variable to a valid `llvm-config` executable

--- stderr
/Users/jacobrosenthal/Downloads/atsamd/boards/pygamer/target/thumbv7em-none-eabihf/release/build/wasm3-sys-a2cd32265d2c23a2/out/wrapper.h:1:10: fatal error: 'wasm3/source/m3_api_wasi.h' file not found
/Users/jacobrosenthal/Downloads/atsamd/boards/pygamer/target/thumbv7em-none-eabihf/release/build/wasm3-sys-a2cd32265d2c23a2/out/wrapper.h:1:10: fatal error: 'wasm3/source/m3_api_wasi.h' file not found, err: true
thread 'main' panicked at 'Unable to generate bindings: ()', src/libcore/result.rs:1165:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
thread 'main' panicked at 'Failed to run bindgen: ExitStatus(ExitStatus(256))', /Users/jacobrosenthal/Downloads/wasm3-rs/wasm3-sys/build.rs:61:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed
jacobrosenthal@Jacobs-MacBook-Air pygamer (embedded-graphics-addons) $ 
Veykril commented 4 years ago

Seems reasonable to me. The problem with the headers being not found is that the new header you are creating is in the OUT_DIR path, while you are trying to reference the other headers relatively to this header. This doesn't work since those headers arent in the OUT_DIR.

A quick solution would be to just create the wrapper header manually and put it into the wasm3-sys directory. Then the includes would look something like

#include "wasm3/source/m3_compile.h
...
jacobrosenthal commented 4 years ago

Thanks, that was it. The only change I know that I made was removing default_enum_style as it is the command line default anyway I think.

As for no_std cross compile still doesnt successfully build for me as it doesnt have target arch stuff. Does this run for you as expected?

Veykril commented 4 years ago

Ah, you can even use CARGO_MANIFEST_DIR great, I didn't even think of that one and the default_enum_style was chosen by me at random so far so it doesn't really matter for now. Regarding cross compile I can't say much as I haven't worked with myself so far unfortunately.

Edit: Turns out the enum default is consts while I was using constmodules, I should really set up CI for this 😅