-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for compiling WebAssembly wasm32-unknown-unknown target #92
Conversation
fails in rustc-serialize:
rustc-serialize is deprecated in favor of serde, who is still using it? Cargo.lock shows num 0.1, which is depended on by collision 0.18.0. num 0.2 fixes this, collision-rs in git has an update to num 0.2 not yet published: rustgd/collision-rs@e6cf494 |
Using git version until in a release: rustgd/collision-rs#106 Fixes wasm incompatibility in deprecated rustc-serialize crate: error[E0046]: not all trait items implemented, missing: `encode` --> github.aaakk.us.kg-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1358:1
Getting past the collision-rs/num/rustc-serialize incompatibility, there are now 243 errors, cannot find symbols, but they are all in: registry/src/github.aaakk.us.kg-1ecc6299db9ec823/net2-0.2.33/src/ext.rs shared_library tries to use the
|
glutin seems to have at least some support for wasm: rust-windowing/glutin#36 [WIP] Support for emscripten. It uses emscripten, which suggests wasm32-unknown-emscripten target, instead of wasm32-unknown-unknown. How about building against that target? It fails but with surprisingly fewer errors:
xcb is X clipboard, used by x11-clipboard, used by rust-clipboard. HTML5 has clipboard APIs: https://www.w3.org/TR/clipboard-apis/ but may want to just |
Next failure, error[E0432]: unresolved imports |
Now it compiles, with a few warnings but no errors: Finished dev [optimized + debuginfo] target(s) in 8m 20s -rw-r--r-- 2 admin staff 6.9M Jan 12 13:56 target/wasm32-unknown-emscripten/debug/stevenarella.wasm but does it run? |
https://rustwasm.github.io/book/game-of-life/hello-world.html shows how to setup the rust wasm binary with wasmpack |
Followed the tutorial at https://rustwasm.github.io/book/game-of-life/hello-world.html but it uses pre-generated templates, creating a new project, will have to work through how to adopt this project to it.
but its an application, not a library; adding that to Cargo.toml fails:
What's the best way to support both a native application and wasm in the same project? There's also some setup steps at https://github.com/rustwasm/wasm-pack#-quickstart-guide |
Following the quick start guide, then wasm-pack build fails again compiling shared_library (a glutin dependency), undeclared module dl, same errors as earlier #92 (comment) when using wasm32-unknown-unknown. The wasm32-unknown-emscripten target gets further, would like to try using it instead, but the rustwasm book is not about emscripten. https://www.reddit.com/r/rust/comments/7jpjoe/trying_to_build_httpsgithubcomkvarkwasmtriangle/ says there is https://github.com/lord/wargo to make running emscripten wasm rust apps easier, but the wasm32-unknown-unknown target is newer. wargo last modified 2017. https://www.reddit.com/r/rust/comments/7dqa8c/cant_figure_out_webassembly/ has some more insight, how Emscripten emulates a lot of features in a traditional runtime. steveklabnik1 says on https://www.reddit.com/r/rust/comments/87r4st/trying_to_set_up_the_webassembly_target/:
https://www.reddit.com/r/rust/comments/86o2al/cargo_not_compiling_web_asm_file/ is a similar situation to mine:
9 months ago:
so what's a wasm-compatible dependency to replace glutin? Not married to glutin, already switched from sdl 2 (#35 iceiix/steven#35), can switch again if required. |
Progress: copying shell.html from https://github.com/kripken/emscripten/blob/incoming/src/shell.html, updating the script src, then serve through but there is a panic in winit: shell.html:1246 thread 'main' panicked at 'assertion failed: validate_hidpi_factor(dpi_factor)', .cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/winit-0.18.0/src/dpi.rs:236:9 https://github.com/tomaka/winit/blob/master/src/dpi.rs#L236 #[inline]
pub fn to_physical(&self, dpi_factor: f64) -> PhysicalSize {
assert!(validate_hidpi_factor(dpi_factor));
let width = self.width * dpi_factor;
let height = self.height * dpi_factor;
PhysicalSize::new(width, height)
} |
How to enable RUST_BACKTRACE with wasm32-unknown-emscripten? https://github.com/kvark/wasm-triangle example is from a year ago, but it has this information:
can it still not be passed? But RUST_BACKTRACE is for rustc, not emcc. https://users.rust-lang.org/t/compiling-to-the-web-with-rust-and-emscripten/7627 has some introductory information https://mozilla.logbot.info/rust/20180114
|
To do:
|
https://travis-ci.org/iceiix/stevenarella/jobs/500994533 passed but it doesn't seem to have actually built for wasm:
"Terminated travis_jigger " search finds travis-ci/travis-ci#4924 Host shut down during build, which was fixed last year. |
uploading wasm/cache-linux-trusty-3879e5e05f8e7b938c85cd9971db8997f2b1857f15cdc4d7dbe31cd1d57906c8--cargo-nightly.tgz /home/travis/.casher/bin/casher:54: warning: constant ::TimeoutError is deprecated running `casher push` took longer than 180 seconds and has been aborted. You can extend the timeout with `cache.timeout`. See https://docs.travis-ci.com/user/caching/#Setting-the-timeout for details https://docs.travis-ci.com/user/caching/#Setting-the-timeout%20for%20details
Logging from the `log` facade goes to the colorized in-game GUI console (opened with the backtick key), as well as standard output using `println!` on the native build. To make this work on the wasm build, web-sys is used to access the `console` object, to call `console.log`, `console.warn`, and so on corresponding to the log levels. Extends #92, fails later (see also #115) but now outputs the starting up message: [main.rs:206][INFO] Starting steven * Add println! logging to console.log on wasm * Initialize logger before config (called 'console variables' for some reason) to avoid having to disable it to reach the first logging statement * Add web-sys crate for browser console access, wasm32-only * Refactor logger to call println_level on both web/native * Add multiple log levels, console.warn etc., matching console_log crate https://github.com/iamcodemaker/console_log#details
) Note this only is the first step in web support, although the project compiles, it doesn't run! Merging now to avoid branch divergence, until dependencies can be updated for wasm support. * Add instructions to build for wasm32-unknown-unknown with wasm-pack in www/ * Update to rust-clipboard fork to compile with emscripten aweinstock314/rust-clipboard#62 * Exclude reqwest dependency in wasm32 * Exclude compiling clipboard pasting on wasm32 * Exclude reqwest-using code from wasm32 * Install wasm target with rustup in Travis CI * Update to collision 0.19.0 Fixes wasm incompatibility in deprecated rustc-serialize crate: rustgd/collision-rs#106 error[E0046]: not all trait items implemented, missing: `encode` --> github.aaakk.us.kg-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1358:1 * Increase travis_wait time even further, try 120 minutes * Set RUST_BACKTRACE=1 in main * Remove unused unneeded bzip2 features in zip crate To fix wasm32-unknown-unknown target compile error: error[E0432]: unresolved imports `libc::c_int`, `libc::c_uint`, `libc::c_void`, `libc::c_char` --> src/github.aaakk.us.kg-1ecc6299db9ec823/bzip2-sys-0.1.7/lib.rs:5:12 | 5 | use libc::{c_int, c_uint, c_void, c_char}; | ^^^^^ ^^^^^^ ^^^^^^ ^^^^^^ no `c_char` in the root | | | | | | | no `c_void` in the root | | no `c_uint` in the root | no `c_int` in the root * flate2 use Rust backend * Add console_error_panic_hook module for wasm backtraces * Build using wasm-pack, wasm-bindgen, run with wasm-app * Update to miniz_oxide 0.2.1, remove patch for Frommi/miniz_oxide#42 * Update to official clipboard crate since aweinstock314/rust-clipboard#62 was merged, but git revision pending release * Update to branch of glutin attempting to build for wasm iceiix/glutin#1 * Update winit dependency of glutin to git master iceiix/winit#2 * Update to glutin branch with working (compiles, doesn't run) wasm_stub * Add app name in title on web page * Add wasm to Travis-CI test matrix * Update glutin to fix Windows EGL compilation on AppVeyor iceiix/glutin@9779735
) Note this only is the first step in web support, although the project compiles, it doesn't run! Merging now to avoid branch divergence, until dependencies can be updated for wasm support. * Add instructions to build for wasm32-unknown-unknown with wasm-pack in www/ * Update to rust-clipboard fork to compile with emscripten aweinstock314/rust-clipboard#62 * Exclude reqwest dependency in wasm32 * Exclude compiling clipboard pasting on wasm32 * Exclude reqwest-using code from wasm32 * Install wasm target with rustup in Travis CI * Update to collision 0.19.0 Fixes wasm incompatibility in deprecated rustc-serialize crate: rustgd/collision-rs#106 error[E0046]: not all trait items implemented, missing: `encode` --> github.aaakk.us.kg-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1358:1 * Increase travis_wait time even further, try 120 minutes * Set RUST_BACKTRACE=1 in main * Remove unused unneeded bzip2 features in zip crate To fix wasm32-unknown-unknown target compile error: error[E0432]: unresolved imports `libc::c_int`, `libc::c_uint`, `libc::c_void`, `libc::c_char` --> src/github.aaakk.us.kg-1ecc6299db9ec823/bzip2-sys-0.1.7/lib.rs:5:12 | 5 | use libc::{c_int, c_uint, c_void, c_char}; | ^^^^^ ^^^^^^ ^^^^^^ ^^^^^^ no `c_char` in the root | | | | | | | no `c_void` in the root | | no `c_uint` in the root | no `c_int` in the root * flate2 use Rust backend * Add console_error_panic_hook module for wasm backtraces * Build using wasm-pack, wasm-bindgen, run with wasm-app * Update to miniz_oxide 0.2.1, remove patch for Frommi/miniz_oxide#42 * Update to official clipboard crate since aweinstock314/rust-clipboard#62 was merged, but git revision pending release * Update to branch of glutin attempting to build for wasm iceiix/glutin#1 * Update winit dependency of glutin to git master iceiix/winit#2 * Update to glutin branch with working (compiles, doesn't run) wasm_stub * Add app name in title on web page * Add wasm to Travis-CI test matrix * Update glutin to fix Windows EGL compilation on AppVeyor iceiix/glutin@9779735
) Note this only is the first step in web support, although the project compiles, it doesn't run! Merging now to avoid branch divergence, until dependencies can be updated for wasm support. * Add instructions to build for wasm32-unknown-unknown with wasm-pack in www/ * Update to rust-clipboard fork to compile with emscripten aweinstock314/rust-clipboard#62 * Exclude reqwest dependency in wasm32 * Exclude compiling clipboard pasting on wasm32 * Exclude reqwest-using code from wasm32 * Install wasm target with rustup in Travis CI * Update to collision 0.19.0 Fixes wasm incompatibility in deprecated rustc-serialize crate: rustgd/collision-rs#106 error[E0046]: not all trait items implemented, missing: `encode` --> github.aaakk.us.kg-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1358:1 * Increase travis_wait time even further, try 120 minutes * Set RUST_BACKTRACE=1 in main * Remove unused unneeded bzip2 features in zip crate To fix wasm32-unknown-unknown target compile error: error[E0432]: unresolved imports `libc::c_int`, `libc::c_uint`, `libc::c_void`, `libc::c_char` --> src/github.aaakk.us.kg-1ecc6299db9ec823/bzip2-sys-0.1.7/lib.rs:5:12 | 5 | use libc::{c_int, c_uint, c_void, c_char}; | ^^^^^ ^^^^^^ ^^^^^^ ^^^^^^ no `c_char` in the root | | | | | | | no `c_void` in the root | | no `c_uint` in the root | no `c_int` in the root * flate2 use Rust backend * Add console_error_panic_hook module for wasm backtraces * Build using wasm-pack, wasm-bindgen, run with wasm-app * Update to miniz_oxide 0.2.1, remove patch for Frommi/miniz_oxide#42 * Update to official clipboard crate since aweinstock314/rust-clipboard#62 was merged, but git revision pending release * Update to branch of glutin attempting to build for wasm iceiix/glutin#1 * Update winit dependency of glutin to git master iceiix/winit#2 * Update to glutin branch with working (compiles, doesn't run) wasm_stub * Add app name in title on web page * Add wasm to Travis-CI test matrix * Update glutin to fix Windows EGL compilation on AppVeyor iceiix/glutin@9779735
) Note this only is the first step in web support, although the project compiles, it doesn't run! Merging now to avoid branch divergence, until dependencies can be updated for wasm support. * Add instructions to build for wasm32-unknown-unknown with wasm-pack in www/ * Update to rust-clipboard fork to compile with emscripten aweinstock314/rust-clipboard#62 * Exclude reqwest dependency in wasm32 * Exclude compiling clipboard pasting on wasm32 * Exclude reqwest-using code from wasm32 * Install wasm target with rustup in Travis CI * Update to collision 0.19.0 Fixes wasm incompatibility in deprecated rustc-serialize crate: rustgd/collision-rs#106 error[E0046]: not all trait items implemented, missing: `encode` --> github.aaakk.us.kg-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1358:1 * Increase travis_wait time even further, try 120 minutes * Set RUST_BACKTRACE=1 in main * Remove unused unneeded bzip2 features in zip crate To fix wasm32-unknown-unknown target compile error: error[E0432]: unresolved imports `libc::c_int`, `libc::c_uint`, `libc::c_void`, `libc::c_char` --> src/github.aaakk.us.kg-1ecc6299db9ec823/bzip2-sys-0.1.7/lib.rs:5:12 | 5 | use libc::{c_int, c_uint, c_void, c_char}; | ^^^^^ ^^^^^^ ^^^^^^ ^^^^^^ no `c_char` in the root | | | | | | | no `c_void` in the root | | no `c_uint` in the root | no `c_int` in the root * flate2 use Rust backend * Add console_error_panic_hook module for wasm backtraces * Build using wasm-pack, wasm-bindgen, run with wasm-app * Update to miniz_oxide 0.2.1, remove patch for Frommi/miniz_oxide#42 * Update to official clipboard crate since aweinstock314/rust-clipboard#62 was merged, but git revision pending release * Update to branch of glutin attempting to build for wasm iceiix/glutin#1 * Update winit dependency of glutin to git master iceiix/winit#2 * Update to glutin branch with working (compiles, doesn't run) wasm_stub * Add app name in title on web page * Add wasm to Travis-CI test matrix * Update glutin to fix Windows EGL compilation on AppVeyor iceiix/glutin@9779735
The git dependency was only for wasm32-unknown-emscripten support: aweinstock314/rust-clipboard#62 but #92 changes to using wasm32-unknown-unknown instead, a better supported path (though still incomplete in this project, see #171)
Another target besides Windows, Linux, Mac: add WebAssembly support, now that it is supported well by Rust. Reference: https://rustwasm.github.io/book/