Skip to content
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: failed to resolve: could not find Context in platform_impl #171

Closed
iceiix opened this issue May 29, 2019 · 7 comments · Fixed by #444
Closed

wasm broken: failed to resolve: could not find Context in platform_impl #171

iceiix opened this issue May 29, 2019 · 7 comments · Fixed by #444
Labels
bug Something isn't working

Comments

@iceiix
Copy link
Owner

iceiix commented May 29, 2019

After fixing #115 #166 std::fs (continuing #92 wasm), a new problem arises: glutin/winit doesn't support the web yet:

inline417.js:3 Panic error message: not yet implemented: Glutin-Blank: Platform unsupported inline418.js:3 Encountered a panic! __cargo_web_snippet_dc2fd915bd92f9e9c6a3bd15174f1414eee3dbaf @ inline418.js:3 __wbg_cargowebsnippetdc2fd915bd92f9e9c6a3bd15174f1414eee3dbaf_ce624dc8989b7508 @ stevenarella.js:262 __wbg_cargowebsnippetdc2fd915bd92f9e9c6a3bd15174f1414eee3dbaf_ce624dc8989b7508 @ bootstrap.js:122 stdweb::webcore::initialization::initialize::{{closure}}::hfaf8b55158d3d793 @ wasm-002ccbc2-399:21 std::panicking::rust_panic_with_hook::h5d8808384a53a826 @ wasm-002ccbc2-378:115 std::panicking::continue_panic_fmt::h821bed92a14cf5d5 @ wasm-002ccbc2-550:52 std::panicking::begin_panic_fmt::h83a0a8c60964976b @ wasm-002ccbc2-609:42 glutin::platform::platform::Context::new_windowed::h12dee54925d08191 @ wasm-002ccbc2-534:54 stevenarella::main2::hcc90ca13771299f1 @ wasm-002ccbc2-70:761 stevenarella::main::hbc764074c370a7d5 @ wasm-002ccbc2-949:2 main @ wasm-002ccbc2-950:2 main @ stevenarella.js:63 (anonymous) @ index.js:5 ./index.js @ 0.bootstrap.js:178 __webpack_require__ @ bootstrap.js:165 Promise.then (async) (anonymous) @ bootstrap.js:4 ./bootstrap.js @ bootstrap.js:344 __webpack_require__ @ bootstrap.js:165 (anonymous) @ client:2 0 @ bootstrap.js:631 __webpack_require__ @ bootstrap.js:165 (anonymous) @ bootstrap.js:332 (anonymous) @ bootstrap.js:335 inline417.js:3 Panic error message: not yet implemented: Glutin-Blank: Platform unsupported __cargo_web_snippet_97495987af1720d8a9a923fa4683a7b683e3acd6 @ inline417.js:3 __wbg_cargowebsnippet97495987af1720d8a9a923fa4683a7b683e3acd6_4d6a8b798885113c @ stevenarella.js:258 __wbg_cargowebsnippet97495987af1720d8a9a923fa4683a7b683e3acd6_4d6a8b798885113c @ bootstrap.js:125 stdweb::webcore::initialization::initialize::{{closure}}::hfaf8b55158d3d793 @ wasm-002ccbc2-399:72 std::panicking::rust_panic_with_hook::h5d8808384a53a826 @ wasm-002ccbc2-378:115 std::panicking::continue_panic_fmt::h821bed92a14cf5d5 @ wasm-002ccbc2-550:52 std::panicking::begin_panic_fmt::h83a0a8c60964976b @ wasm-002ccbc2-609:42 glutin::platform::platform::Context::new_windowed::h12dee54925d08191 @ wasm-002ccbc2-534:54 stevenarella::main2::hcc90ca13771299f1 @ wasm-002ccbc2-70:761 stevenarella::main::hbc764074c370a7d5 @ wasm-002ccbc2-949:2 main @ wasm-002ccbc2-950:2 main @ stevenarella.js:63 (anonymous) @ index.js:5 ./index.js @ 0.bootstrap.js:178 __webpack_require__ @ bootstrap.js:165 Promise.then (async) (anonymous) @ bootstrap.js:4 ./bootstrap.js @ bootstrap.js:344 __webpack_require__ @ bootstrap.js:165 (anonymous) @ client:2 0 @ bootstrap.js:631 __webpack_require__ @ bootstrap.js:165 (anonymous) @ bootstrap.js:332 (anonymous) @ bootstrap.js:335 inline416.js:3 Panic location: /Users/admin/.cargo/git/checkouts/glutin-390166537a874d6b/1e48d32/glutin/src/platform/blank/mod.rs:32 __cargo_web_snippet_72fc447820458c720c68d0d8e078ede631edd723 @ inline416.js:3 __wbg_cargowebsnippet72fc447820458c720c68d0d8e078ede631edd723_60857d6a328c5ce1 @ stevenarella.js:254 __wbg_cargowebsnippet72fc447820458c720c68d0d8e078ede631edd723_60857d6a328c5ce1 @ bootstrap.js:128 stdweb::webcore::initialization::initialize::{{closure}}::hfaf8b55158d3d793 @ wasm-002ccbc2-399:104 std::panicking::rust_panic_with_hook::h5d8808384a53a826 @ wasm-002ccbc2-378:115 std::panicking::continue_panic_fmt::h821bed92a14cf5d5 @ wasm-002ccbc2-550:52 std::panicking::begin_panic_fmt::h83a0a8c60964976b @ wasm-002ccbc2-609:42 glutin::platform::platform::Context::new_windowed::h12dee54925d08191 @ wasm-002ccbc2-534:54 stevenarella::main2::hcc90ca13771299f1 @ wasm-002ccbc2-70:761 stevenarella::main::hbc764074c370a7d5 @ wasm-002ccbc2-949:2 main @ wasm-002ccbc2-950:2 main @ stevenarella.js:63 (anonymous) @ index.js:5 ./index.js @ 0.bootstrap.js:178 __webpack_require__ @ bootstrap.js:165 Promise.then (async) (anonymous) @ bootstrap.js:4 ./bootstrap.js @ bootstrap.js:344 __webpack_require__ @ bootstrap.js:165 (anonymous) @ client:2 0 @ bootstrap.js:631 __webpack_require__ @ bootstrap.js:165 (anonymous) @ bootstrap.js:332 (anonymous) @ bootstrap.js:335 bootstrap.js:5 Error importing `index.js`: RuntimeError: unreachable at __rust_start_panic (wasm-function[1045]:1) at rust_panic (wasm-function[704]:31) at std::panicking::rust_panic_with_hook::h5d8808384a53a826 (wasm-function[378]:304) at std::panicking::continue_panic_fmt::h821bed92a14cf5d5 (wasm-function[550]:116) at std::panicking::begin_panic_fmt::h83a0a8c60964976b (wasm-function[609]:95) at glutin::platform::platform::Context::new_windowed::h12dee54925d08191 (wasm-function[534]:120) at stevenarella::main2::hcc90ca13771299f1 (wasm-function[70]:1695) at stevenarella::main::hbc764074c370a7d5 (wasm-function[949]:1) at main (wasm-function[950]:1) at Module.main (webpack:///../pkg/stevenarella.js?:63:66)

#34 Investigate rendering backends, such as gfx-rs or wgpu

https://github.com/iceiix/stevenarella/tree/master/www

@iceiix iceiix added the bug Something isn't working label May 29, 2019
iceiix added a commit that referenced this issue May 29, 2019
* 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
@iceiix
Copy link
Owner Author

iceiix commented Dec 30, 2019

A potential way forward: glow, see #34 (comment)

@iceiix iceiix changed the title wasm broken: not yet implemented: Glutin-Blank: Platform unsupported wasm broken: failed to resolve: could not find Context in platform_impl Jan 6, 2020
@iceiix
Copy link
Owner Author

iceiix commented Jan 6, 2020

With #260 (comment) the new error is:

   Compiling glutin v0.22.0-alpha5
error[E0432]: unresolved import `self::platform_impl`
 --> .cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.22.0-alpha5/src/platform_impl/mod.rs:1:15
  |
1 | pub use self::platform_impl::*;
  |               ^^^^^^^^^^^^^ could not find `platform_impl` in `self`
error[E0433]: failed to resolve: could not find `Context` in `platform_impl`
   --> .cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.22.0-alpha5/src/context.rs:182:24
    |
182 |         platform_impl::Context::new_headless(el, &pf_reqs, &gl_attr, size).map(
    |                        ^^^^^^^ could not find `Context` in `platform_impl`
error[E0433]: failed to resolve: could not find `Context` in `platform_impl`
   --> .cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.22.0-alpha5/src/windowed.rs:362:24
    |
362 |         platform_impl::Context::new_windowed(wb, el, &pf_reqs, &gl_attr).map(
    |                        ^^^^^^^ could not find `Context` in `platform_impl`
error[E0412]: cannot find type `Context` in module `platform_impl`
  --> .cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.22.0-alpha5/src/context.rs:35:40
   |
35 |     pub(crate) context: platform_impl::Context,
   |                                        ^^^^^^^ not found in `platform_impl`
   |
help: possible candidates are found in other modules, you can import them into scope
   |
1  | use core::task::Context;
   |
1  | use crate::context::Context;
   |
1  | use std::task::Context;
   |

(same potential solution: https://github.com/grovesNL/glow)

iceiix added a commit that referenced this issue Jan 6, 2020
Update from glutin 0.21.x fork to glutin 0.22.0-alpha5 and corresponding
compatible version of winit. This removes our custom temporary wasm_stub
branches, back to mainline glutin and winit, and is a step towards WebAssembly
compatibility, most importantly merging the game loop and event loops as
required by winit _which now supports wasm_. Not yet functional on the web
because other web dependencies have to be added, see #171 and #34, but native
functionality is preserved.

* Update for 0.22 glutin API changes:

* Move game logic into event loop, run() replacing poll_events()

* Specify fullscreen Borderless mode

* Pass generic parameter of Event through handle_window_event
* hidpi_factor() replaces get_hidpi_factor()
* with_inner_size() replaces with_dimensions()
* No longer need to unwrap() LogicalSize
* set_cursor_grab/visible() replaces grab/hide_cursor()

* Fix modifiers deprecated warnings by destructuring only event fields we use, ignoring the rest with '..'

* Remove unnecessary mutability from events_loop

* Listen for ModifiersChanged event, fixing deprecated modifiers field

* Change to stdweb for web backend, replacing web-sys

* Pin to glutin =0.22.0-alpha5 and winit =0.20.0-alpha6
@iceiix iceiix mentioned this issue Jan 6, 2020
iceiix added a commit that referenced this issue Feb 1, 2020
* 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
iceiix added a commit that referenced this issue Feb 1, 2020
* 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
iceiix added a commit that referenced this issue Feb 1, 2020
* 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
iceiix added a commit that referenced this issue Feb 2, 2020
* 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
@iceiix
Copy link
Owner Author

iceiix commented Feb 2, 2020

With (#277 and #278?), wasm-pack build now fails with a different error:

error[E0433]: failed to resolve: use of undeclared type or module `wasm_bindgen`
  --> registry/src/github.com-1ecc6299db9ec823/instant-0.1.2/src/wasm.rs:92:13
   |
92 |     let v = js! { return performance.now(); };
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `wasm_bindgen`
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `WasmDescribe`
  --> registry/src/github.com-1ecc6299db9ec823/instant-0.1.2/src/wasm.rs:92:13
   |
92 |     let v = js! { return performance.now(); };
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `WasmDescribe`
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0425]: cannot find function `inform` in this scope
  --> registry/src/github.com-1ecc6299db9ec823/instant-0.1.2/src/wasm.rs:92:13
   |
92 |     let v = js! { return performance.now(); };
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0425]: cannot find value `FUNCTION` in this scope
  --> registry/src/github.com-1ecc6299db9ec823/instant-0.1.2/src/wasm.rs:92:13
   |
92 |     let v = js! { return performance.now(); };
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to 4 previous errors

iceiix added a commit that referenced this issue Feb 2, 2020
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)
@iceiix
Copy link
Owner Author

iceiix commented Feb 2, 2020

cargo web start --target wasm32-unknown-unknown however still fails with the platform_impl Context error, which would be solved by glow #262.

iceiix added a commit that referenced this issue Feb 2, 2020
wasm-pack is more broken, see #171 (comment)
cargo web start is still broken (#171) but less so
@TheGreatRambler
Copy link

I've been following this project and would love web support. What remains to make stevenarella build able for web? Anything I can do?

@iceiix
Copy link
Owner Author

iceiix commented Jul 18, 2020

@TheGreatRambler The biggest missing piece is currently WebGL compatibility. I think replacing steven_gl with a cross-platform wrapper would be a good way to solve this. Some more background and notes in #34

I started migrating to glow (GL on Whatever) in #262 but it is very incomplete. If you (or anyone) wants to work on it and can get it working, would be much appreciated. It is a large effort because of the extensive use of raw OpenGL through steven_gl, but switching off directly using OpenGL is (I believe) a necessary prerequisite for web support.

After rendering is working on the web, there will probably be a lot of other small compatibility changes needed to make it usable on the web, but rendering is the biggest blocker.

@iceiix iceiix mentioned this issue Dec 25, 2020
3 tasks
@iceiix
Copy link
Owner Author

iceiix commented Dec 25, 2020

Glow support (#262) is in, knocking down one of the largest blockers. #442 is still a blocker for rendering with WebGL, however. Lots has changed since I last tested this. Testing cargo web start --target wasm32-unknown-unknown on latest master:

   Compiling winit v0.24.0
error[E0433]: failed to resolve: use of undeclared crate or module `fs`
    --> protocol/src/protocol/mod.rs:1145:17
     |
1145 |             fs::File::create("last-packet")?.write_all(buf.get_ref())?;
     |                 ^^^^ not found in `fs`
     |
help: consider importing one of these items
     |
18   | use crate::types::metadata::io::sys::os::path::fs::File;
     |
18   | use crate::types::metadata::io::sys::process::File;
     |
18   | use std::fs::File;
     |
18   | use std_or_web::fs::File;
     |

   Compiling glutin v0.26.0
error[E0432]: unresolved import `self::platform_impl`
 --> registry/src/github.com-1ecc6299db9ec823/glutin-0.26.0/src/platform_impl/mod.rs:1:15
  |
1 | pub use self::platform_impl::*;
  |               ^^^^^^^^^^^^^ could not find `platform_impl` in `self`
error[E0412]: cannot find type `Context` in module `platform_impl`
  --> .cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.26.0/src/context.rs:35:40
   |
35 |     pub(crate) context: platform_impl::Context,
   |                                        ^^^^^^^ not found in `platform_impl`
   |
help: consider importing one of these items
   |
1  | use core::task::Context;
   |
1  | use crate::Context;
   |
1  | use std::task::Context;
   |

error[E0433]: failed to resolve: could not find `Context` in `platform_impl`
   --> .cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.26.0/src/context.rs:154:24
    |
154 |         platform_impl::Context::new_headless(el, &pf_reqs, &gl_attr, size)
    |                        ^^^^^^^ not found in `platform_impl`
    |
help: consider importing one of these items
    |
1   | use core::task::Context;
    |
1   | use crate::Context;
    |
1   | use std::task::Context;
    |

error[E0433]: failed to resolve: could not find `Context` in `platform_impl`
   --> .cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.26.0/src/windowed.rs:341:24
    |
341 |         platform_impl::Context::new_windowed(wb, el, &pf_reqs, &gl_attr).map(|(window, context)| {
    |                        ^^^^^^^ not found in `platform_impl`
    |
help: consider importing one of these items
    |
1   | use core::task::Context;
    |
1   | use crate::Context;
    |
1   | use std::task::Context;
    |

The recent glutin update (#334) is another possible source of incompatibilities.

stdweb is unfortunately unmaintained (2019): koute/stdweb#403. The replacement is to use Web API bindings through web-sys.

glow has removed stdweb support: grovesNL/glow@7af2a26

winit supports stdweb but is deprecated and recommends web-sys: https://github.com/rust-windowing/winit#webassembly

Winit supports compiling to the wasm32-unknown-unknown target with either a stdweb or a web-sys backend for use on web browsers. However, please note that the stdweb backend is being deprecated and may be removed in a future release of Winit. The web-sys backend is also more feature complete.

glutin https://github.com/rust-windowing/glutin#emscripten-with-asmjs says only glow should be used on the web, not with glutin:

To get an OpenGL context on these platforms, please use crates like glow instead.

glutin is used in this project for virtual key codes (src/settings.rs, src/ui/mod.rs) and getting the OpenGL context (src/main.rs) / event loop. Example of web-sys replacement for creating a WebGL2 context: https://github.com/grovesNL/glow/blob/main/examples/hello/src/main.rs#L6

This was referenced Dec 26, 2020
iceiix added a commit that referenced this issue Dec 26, 2020
A small step for #446 🕸️ Web support, use web-sys to interface to the web.
Previously, we would try to use glutin on the web, which is not supported;
now glutin is only used on native: fixes #171 could not find Context in platform_impl.

winit is still used on both, but the GL context is created with web-sys and glow
(on the web), and created with glutin and used with glow (on native). stdweb is
no longer used, being replaced by web-sys.

Substantial refactoring to allow reusing the code between web/native:

* settings: use VirtualKeyCode from winit, not reexported from glutin
* std_or_web: remove broken localstoragefs/stdweb, add File placeholder
* render: disable skin_thread on wasm since we don't have threads

* gl: use glow types in gl wrapper (integers in native, but Web*Key in web)
* gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't
* gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web
* gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper

* glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2

* shaders: add explicit float/int type conversions, required for WebGL
* shaders: specify mediump precision, required for WebGL
* shaders: specify fragment shader output locations for WebGL

* main: refactor handle_window_event to take a winit window, not glutin context
* main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this)
* main: use winit events in handle_window_event not reexported glutin events
* main: refactor game loop handling into tick_all()
* main: create winit window for WebGL, and use winit_window from glutin
* main: restore console_error_panic_hook,  mistakingly removed in (#260)
* main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web

* www: index.js: fix wasm import path
* www: npm update, npm audit fix
* www: update readme to link to status on #446 🕸️ Web support
iceiix added a commit that referenced this issue Dec 26, 2020
A small step for #446 🕸️ Web support, use web-sys to interface to the web.
Previously, we would try to use glutin on the web, which is not supported;
now glutin is only used on native: fixes #171 could not find Context in platform_impl.

winit is still used on both, but the GL context is created with web-sys and glow
(on the web), and created with glutin and used with glow (on native). stdweb is
no longer used, being replaced by web-sys.

Substantial refactoring to allow reusing the code between web/native:

* settings: use VirtualKeyCode from winit, not reexported from glutin
* std_or_web: remove broken localstoragefs/stdweb, add File placeholder
* render: disable skin_thread on wasm since we don't have threads

* gl: use glow types in gl wrapper (integers in native, but Web*Key in web)
* gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't
* gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web
* gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper

* glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2

* shaders: add explicit float/int type conversions, required for WebGL
* shaders: specify mediump precision, required for WebGL
* shaders: specify fragment shader output locations for WebGL

* main: refactor handle_window_event to take a winit window, not glutin context
* main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this)
* main: use winit events in handle_window_event not reexported glutin events
* main: refactor game loop handling into tick_all()
* main: create winit window for WebGL, and use winit_window from glutin
* main: restore console_error_panic_hook,  mistakingly removed in (#260)
* main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web

* www: index.js: fix wasm import path
* www: npm update, npm audit fix
* www: update readme to link to status on #446 🕸️ Web support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants