-
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
wasm broken: panicked at 'called Result::unwrap()
on an Err
value: Custom { kind: Other, error: StringError("operation not supported on wasm yet") }
#115
Comments
Result::unwrap()
on an Err
value: Custom { kind: Other, error: StringError("operation not supported on wasm yet") }Result::unwrap()
on an Err
value: Custom { kind: Other, error: StringError("operation not supported on wasm yet") }
It is instructive to see what other games are doing. Zemeroth posted this on their blog with many technical details: https://ozkriff.github.io/2019-05-13--devlog-zemeroth-v0-5/. For the rendering backend investigation (#34). They had a custom engine Häte2d but migrated to ggez and wrote some helpers on top for scene management and widgets. ggez "Good Game Easily" seems to be quite a well supported project with a lot of steam behind it. They used to use SDL2 (like Steven) but moved to winit with ggez 0.5-rc1. Unfortunately, ggez is 2D-only. Not in the running for a graphics backend replacement for this project. For the math library, they were using cgmath but migrated to nalgebra, as that's what ggez uses. Steven uses cgmath. There is this post: Cgmath looking for new maintainers with some concern about the future of cgmath but it works well so I'm deciding against switching for now. More interesting, WebAssembly support. Stuck on dependences myself. What did Zemeroth do? They use a separate crate called good-web-game which implements a subset of compatible API for wasm32-unknown-unknown, using WebGL1 and WebGL2 canvases. That's pretty cool. The blog post is worth reading to see how they substituted one crate for another depending on the target (wasm or not), having a different main() but much of the same code. This may be what has to be done in Stevenarella to replace crates with native dependencies with web-based equivalents. |
Updating the glutin dependency to a 0.21.0-based branch, based on the migration guide at: https://gentz.rocks/posts/glutin-v0-21-0-migration-guide/ * Remove glutin::ContextTrait * Create window with ContextBuilder instead of WindowedContext::new * Add .window() accessor on WindowContext, since it now dereferences to Context In order to not break wasm32-unknown-unknown compilation, a minor fork is used of glutin v0.21.0 and a corresponding version of winit: iceiix/glutin#1 iceiix/winit#2 - with stubs to compile (but not run, see issue #115)
https://www.reddit.com/r/rust/comments/8y3fei/how_do_modules_like_stdfs_and_stdnet_work_with/ confirms they don't. But an idea of how to adopt without rewriting, implement the same methods to replace what is needed in use cfg_if::cfg_if;
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
struct File {}
impl File {
fn open(_: &str) {
}
}
} else {
use std::fs::File;
}
}
fn main() {
let f = File::open("/tmp/a");
println!("f = {:?}", f);
} for both The question then becomes how to implement it, essentially a web filesystem (etc). It has been done: https://github.com/emscripten-core/emscripten/blob/incoming/src/library_fs.js - perhaps port this code or at least the interesting bits. Alternatively, implement it from scratch. But surely this is not too much of an unusual requirement for someone else not to already have done the work. stdweb's File? https://docs.rs/stdweb/0.4.17/stdweb/web/struct.File.html - nope, this doesn't work: use cfg_if::cfg_if;
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
use stdweb::web::File;
} else {
use std::fs::File;
}
}
fn main() {
let f = File::open("/tmp/a");
println!("f = {:?}", f);
} not the same API:
|
This comment has been minimized.
This comment has been minimized.
File operations are invoked very early when loading/saving the console settings: let con = Arc::new(Mutex::new(console::Console::new()));
let (vars, vsync) = {
let mut vars = console::Vars::new();
vars.register(CL_BRAND);
auth::register_vars(&mut vars);
settings::register_vars(&mut vars);
vars.load_config(); // ****** here
vars.save_config(); // ******
let vsync = *vars.get(settings::R_VSYNC);
(Rc::new(vars), vsync)
}; |
There's a brand new target which may solve many of these problems: Unfortunately the www/ setup, which I based on the rustwasm tutorials https://rustwasm.github.io/wasm-pack/book/, is all using wasm32-unknown-unknown, but they mention wasi in their weekly update: https://rustwasm.github.io/2019/03/28/this-week-in-rust-and-wasm-015.html to be standardized: https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webassembly-system-interface/ Can wasm-pack target wasi? Testing building with |
probably due to iceiix/glutin@5ff18de, which keys off target_os = unknown instead of target_arch = wasm32? |
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
Includes iceiix/glutin@1e48d32 Progress towards #115, fixes the missing glutin symbols when compiling with cargo +nightly build --target wasm32-wasi
Fixed glutin missing on wasm32-wasi in c6b753b but it requires a different entrypoint than wasm32-unknown-unknown:
actually, need to remove |
From investigation for #115, now three targets: - wasm32-unknown-unknown: build with `wasm-pack build`, uses the #[wasm_bindgen] directive on main() - wasm32-wasi: build with `cargo +nightly build --target wasm32-wasi`, requires normal main() - native targets: same as wasm32-wasi
Fixed the compilation error so now can compile to both Trying to execute with https://github.com/CraneStation/wasmtime: wasmtime $ target/release/wasmtime ../steven/target/wasm32-wasi/debug/stevenarella.wasm wasm_bindgen is a post-compilation step used by wasm-pack, a step missing here. Can wasm-pack (https://github.com/rustwasm/wasm-pack "📦✨ your favorite rust -> wasm workflow tool! ") target wasm32-wasi instead of wasm32-unknown-unknown? Asked in rustwasm/wasm-pack#654 |
Note after the std::fs error (if src/console/mod.rs load_config/save_config are removed, or hypothetically if they are fixed to support a web virtual filesystem), next error is of course in glutin, the OpenGL wrapper which doesn't support WebGL yet (and winit the web): stevenarella.js:44 panicked at 'not yet implemented: Glutin-Blank: Platform unsupported', /Users/admin/.cargo/git/checkouts/glutin-390166537a874d6b/1e48d32/glutin/src/platform/blank/mod.rs:32:9 makepaddev solved the GL compatibility issues in their app, very nice https://makepad.github.io/makepad/ works well - some details from comment in winit/870 how they did it:
Looks promising, will be watching this app but they already solved these problems, could use their solutions but hopefully they'll be generalized into crates I can import instead of copying code, or better yet if winit/glutin grows native WebGL/HTML5 support...basically stuck here. |
* Add new web-based std::fs replacement, localstoragefs: https://github.com/iceiix/localstoragefs * Add std_or_web to switch between std::fs (native) or localstoragefs (web) * Update www readme for new missing glutin/winit links, opens issue #171
* Add new web-based std::fs replacement, localstoragefs: https://github.com/iceiix/localstoragefs * Add std_or_web to switch between std::fs (native) or localstoragefs (web) * Update www readme for new missing glutin/winit links, opens issue #171
* Add new web-based std::fs replacement, localstoragefs: https://github.com/iceiix/localstoragefs * Add std_or_web to switch between std::fs (native) or localstoragefs (web) * Update www readme for new missing glutin/winit links, opens issue #171
* Add new web-based std::fs replacement, localstoragefs: https://github.com/iceiix/localstoragefs * Add std_or_web to switch between std::fs (native) or localstoragefs (web) * Update www readme for new missing glutin/winit links, opens issue #171
#92 added support for compiling for the wasm32-unknown-unknown target for WebAssembly, but it fails to run, panicking with "operation not supported on wasm yet" - need to adapt all code to support wasm (or compile it out with
#[cfg(not(target_arch = "wasm32"))]
):This particular error appears to come from the Rust standard library: https://github.com/rust-lang/rust/blob/190feb65290d39d7ab6d44e994bd99188d339f16/src/libstd/sys/wasm/mod.rs#L70-L73
from
fs::File::create("conf.cfg")
in src/console.mod.rs, relevant: https://stackoverflow.com/questions/53304832/loading-a-file-from-wasm. But once this particular issue is resolved, more incompatibilities will be uncovered, including in winit iceiix/winit#2 and glutin iceiix/glutin#1, which should wrap WebGL.(Another option besides wasm32-unknown-unknown is wasm32-unknown-emscripten, which would fix File APIs because Emscripten has implementations for the web platform already, but Rust with Emscripten isn't as well supported: rust-windowing/winit#767 and https://rustwasm.github.io is all about wasm32-unknown-unknown, where the implementations are in pure Rust instead (albeit less complete at the moment).)
The text was updated successfully, but these errors were encountered: