-
Notifications
You must be signed in to change notification settings - Fork 410
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-opt: Exported global cannot be mutable #886
Comments
saw this same issue the other day in some e2e tests |
For me this issue showed up in CI. The last build that was correct before the failed one today was on July 21st. The nightly compiler from that version already exhibited the bug so it seems the cause is some dependency somewhere triggering this behavior which is not supported by |
Thanks for the input @EverlastingBugstopper, @vtavernier. I've created a bit more atomic example: // src/lib.rs
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct Boat {
length: u32,
}
#[wasm_bindgen]
impl Boat {
// works
pub fn new(length: u32) -> Self {
Self { length }
}
// doesn't work
pub fn float(&self) -> String {
String::from("floating... ⛵")
}
// works
pub fn volume(&self) -> u32 {
self.length * 2
}
}
// doesn't work
#[wasm_bindgen]
pub fn string() -> String {
String::from("wasm-opt")
} So it seems returning a It is also failing, when returning some structs, but for others not. I will investigate what the failing ones have in common. |
For me the bug was introduced by wasm-bindgen 0.2.66 (0.2.65 is fine). |
The problem seems to be with the non-MVP webassembly feature mutable-global. Adding My workaround is now:
[package.metadata.wasm-pack.profile.release]
wasm-opt = false
$ wasm-pack build
$ /path/to/wasm-opt pkg/repo_bg.wasm -o pkg/repo_bg.wasm -O --enable-mutable-globals (My Edit: Originally I recommended to use |
Add '--dev'. This is needed, because of rustwasm/wasm-pack#886.
Add `--dev` to `wasm-pack build`. This is needed, because of rustwasm/wasm-pack#886.
Ran into the same issue while doing the wasm game of life tutorial: https://rustwasm.github.io/docs/book/game-of-life/implementing.html |
@Urhengulas It's possible to specify wasm-opt arguments, so you should be able to do this: [package.metadata.wasm-pack.profile.release]
wasm-opt = ["-Oz", "--enable-mutable-globals"] Change |
Thanks @0xd4d. This surely is the better workaround. |
Add `--dev` to `wasm-pack build`. This is needed, because of rustwasm/wasm-pack#886.
The arc-script online REPL currently fails to compile with the error: Exported global cannot be mutable It is a known error: rustwasm/wasm-pack#886 This commit is a fix for the error + a small cleanup of unused code.
The arc-script online REPL currently fails to compile with the error: Exported global cannot be mutable It is a known error: rustwasm/wasm-pack#886 This commit is a fix for the error + a small cleanup of unused code.
Mutable globals are now phase 4 in the WebAssembly CG, it should be enabled by default in wasm-opt |
@xtuc I don't think we have a clear answer on that. Discussions have been going on about what the defaults should be for various tools including wasm-opt and LLVM and we should discuss those more on https://github.com/WebAssembly/tool-conventions cc @sbc100 The main risk I see is that we turn a feature on by default, but not all VMs support it yet, and if the developer doesn't test everywhere then they can end up shipping code that only works in some places. |
In this particular case I think we While I agree that using/adding new features during |
My understanding of the target-features section is that it's used by the toolchain but doesn't necessarily reflect what the target browser supports. In JS we used to transpile down the unsupported features given some user preference. |
If you want to transpile those features away in order to support older runtimes that seems fine too. In this case it seems clear that this is the problem: llvm is producing code that depends a feature but that information not being correctly transmitted to |
I don't have much context here on what exactly the problem is but I will say that whatever changed broke pretty much every standard Hello World project in the Rust-Wasm ecosystem and that doesn't feel great. Wherever this change was introduced needs to have some sort of integration test with some common tutorials so that releases don't break documentation across the entire ecosystem. If a breaking change must happen (which I'd argue it probably doesn't) then there should be advance notice, some warning messages in terminal output before a breaking change (similar to how Rust itself deprecates things), and work put in to update documentation across the ecosystem that does not break with default settings. edit: i think we might want to revisit whether |
For me this ends up slightly more problematic - due to React Native support, I'm also compiling from the generated wasm to asm.js (same binaryen toolset, different binary), and cannot find a working option to make that work at all. (So There is def. a mismatch with this tooling and the binaryen tooling that has "some" impacts. TL;DR Can (based on suggestions here) get the wasm part compiled, bundled and optimized, however have no luck generating output to an asm.js bundle from the compiled WASM now being generated. For now fixed to the last know working .25 and all is well. |
I agree. Maybe mirroring the |
Do this by allowing mutable globals, which is the current recommendation per rustwasm/wasm-pack#886.
@Niedzwiedzw currently my solution is to use a fork of wasm-pack, as it's not maintained now. Or you could directly use |
wasm-bindgen is currently locked to 0.2.65 due to rustwasm/wasm-pack#886
wasm-bindgen is currently locked to 0.2.65 due to rustwasm/wasm-pack#886
Add `--dev` to `wasm-pack build`. This is needed, because of rustwasm/wasm-pack#886.
This issue may be fixed by rustwasm/wasm-bindgen#2391 , which prevents wasm-bindgen from exporting mutable globals for compatibility reasons. |
rustwasm/wasm-bindgen#2391 has been merged & released in |
- Building adapter crate - Requires wasm-bindgen ^0.2.70 due to bug in toolchain [1] - Requires local installation of sarcaustech/unifac [2] with no parallelization (Rayon). Used with commit 4711916 [1] rustwasm/wasm-pack#886 [2] https://github.com/sarcaustech/unifac
…r nightly version as a workaround for rustwasm/wasm-pack#886
Removed wasm-pack config now that issue is fixed: rustwasm/wasm-pack#886
Is this fixed? I just ran into it trying to compile the threads example: https://rustwasm.github.io/docs/wasm-bindgen/examples/raytrace.html |
rustwasm/wasm-pack#886 was resolved a while ago, so we can remove this as long as we have a sufficiently-moderm wasm-bindgen.
rustwasm/wasm-pack#886 was resolved a while ago, so we can remove this as long as we have a sufficiently-moderm wasm-bindgen.
rustwasm/wasm-pack#886 was resolved a while ago, so we can remove this as long as we have a sufficiently-moderm wasm-bindgen.
🐛 Bug description
I am using
wasm-pack
andwasm-bingen
to build a javascript package with rust.Since today when I am running
wasm-pack build
I am getting following error:It was still working on master yesterday (see CI), but doesn't anymore today with the same commit (see CI). (The important step is "Build").
🤔 Expected Behavior
Build package and optimize it with
wasm-opt
as it did before.(Running
wasm-pack build --dev
works, but I'd like to have the optimization).👟 Steps to reproduce
Trying a few things I figured out that I can make
wasm-opt
pass when I am removing all exported (non-static) methods on the exported structs (which is abviously not desireable).On urhengulas/rav1e@wasm-opt-fix I removed all the methods and it builds and optimizes fine:
But, as soon I am adding a method (e.g.
fn Frame.debug(&self) -> Self
inrav1e_js/src/frame.rs
) back, I am getting the error from the bug description.🌍 Your environment
Include the relevant details of your environment.
➜ rustc --version rustc 1.45.0 (5c1f21c3b 2020-07-13) ➜ wasm-pack --version wasm-pack 0.9.1 ➜ ~/.cache/.wasm-pack/wasm-opt-4d7a65327e9363b7/wasm-opt --version wasm-opt version_90
Thx
Thanks to everyone taking the time and having a look at this issue!
The text was updated successfully, but these errors were encountered: