-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Error "cannot import from modules (env
)" in complex code.
#2160
Comments
The fact that that bounds check is coming up is a bug in compiler-builtins. I don't think that this is a bug in wasm-bindgen? |
@alexcrichton I think that the particular function |
Rustc 1.43.1 does not show the bug, so I assume it is a bug in the wasm backend for 1.44.0-beta. I'm so used to the beta not failing that I forget there is a stable... Should this bug be closed here and reopened elsewhere? |
It's still useful to try to narrow down and figure out where the issue is I think, but yeah it may be best to close this one and figure out best where to open it. |
I don't know, I have skimmed the source code of Rustc, Coreutils, and the LLVM backend for wasm, and I didn't find anything relevant. If you think this bug is better suited anywhere else, I'll close it and reopen a copy there, but where? |
I'd recommend first trying to reduce this to a bite-sized test case. That needs to be done first before reporting an issue. |
Ok, I managed to reduce it a lot. The funny thing was that wasm-pack does some heavy dead-code pruning even in debug mode, so as soon as I removed key lines, the problem disappeared. This minimum program reproduces the issue:
|
Ok bisection shows that this is a regression from rust-lang/rust#70846, and I'll work on fixing this at rust-lang/compiler-builtins#360. This isn't wasm-bindgen-specific, though. Mind opening an issue on the rust-lang/rust repository for this? |
Of course! here it is. I'm closing this now, I hope it is the proper procedure... |
I'm having a very similar issue on Rust 1.49, edit: I'm also getting the same problem on 1.48, so it's not necessarily related to the compiler version |
I now have a new import * as __wbg_star0 from 'env'; in the generated module javascript file from This problem started occurring when I applied the following
|
After at least an hour of bisecting, I narrowed it down to the following package update:
and to be more precise the problem is also exhibited in v0.8.1
Which has the following changelog:
It seems like a good chance this is related to Amanieu/parking_lot#265 |
I am having the same issue as @kellpossible, but My issue is when targeting Build command: I have all optimizations and such turned off. I've tried enabling them in different combinations based on advice in this and other threads but nothing has worked so far.
$ rustup show
...
active toolchain
----------------
nightly-x86_64-apple-darwin (default)
rustc 1.60.0-nightly (89b9f7b28 2022-01-10) |
@MatthewHerbst My understanding is that this is basically the wasm-bindgen version of “undefined symbol when linking”. I ran into it when playing with a C dependency that tried calling a function that it expected the environment to provide. If you’re not doing anything fancy in your own code, most likely one of your dependency crates isn’t “wasm32-unknown-unknown compatible”, and you’ll first have to narrow down which one that is. Unfortunately, I’m not aware of any particularly clever way to do that. |
Summary: ~~~Added new parking-lot version named parking_lot_0_12~~~ allow-large-files previous versions of parking-lot are incompatible with wasm compilation targets rustwasm/wasm-bindgen#2160 Amanieu/parking_lot#302 Reviewed By: dtolnay Differential Revision: D33985872 fbshipit-source-id: ce571ef50289fe97ff89dbf72d2c7f39fbd47758
Summary: ~~~Added new parking-lot version named parking_lot_0_12~~~ allow-large-files previous versions of parking-lot are incompatible with wasm compilation targets rustwasm/wasm-bindgen#2160 Amanieu/parking_lot#302 Reviewed By: dtolnay Differential Revision: D33985872 fbshipit-source-id: ce571ef50289fe97ff89dbf72d2c7f39fbd47758
Summary: ~~~Added new parking-lot version named parking_lot_0_12~~~ allow-large-files previous versions of parking-lot are incompatible with wasm compilation targets rustwasm/wasm-bindgen#2160 Amanieu/parking_lot#302 Reviewed By: dtolnay Differential Revision: D33985872 fbshipit-source-id: ce571ef50289fe97ff89dbf72d2c7f39fbd47758
Summary: ~~~Added new parking-lot version named parking_lot_0_12~~~ allow-large-files previous versions of parking-lot are incompatible with wasm compilation targets rustwasm/wasm-bindgen#2160 Amanieu/parking_lot#302 Reviewed By: dtolnay Differential Revision: D33985872 fbshipit-source-id: ce571ef50289fe97ff89dbf72d2c7f39fbd47758
The symptom of the missing symbols is the same as discussed here: rustwasm/wasm-bindgen#2160 however, to simply identify which symbols are missing, it suffices to use wasm2wat to inspect the generated wasm, for example: wasm2wat webroot/web.wasm | grep env | less
@trevyn I cannot thank you enough for that hint. stumbled over this too just recently. |
Oh, I should probably mention that I made a tool a few months ago for debugging which crate is causing the issue: #3500 (comment) |
Describe the Bug and Steps to Reproduce
First of all, an apology because I've been unable to make a shorter program that shows this issue: it only happens when I compile the full program.
When building my wasm program RAZE with this command and the latest wasm-bindgen:
It gives the following error:
Changing to
--target web
it does build, but it emits this line into the generated JS:that breaks the runtime. If I remove any reference to the
env
module (and rework all my JS to work with modules) it works nice, which proves that theenv
module, whatever it is, is not actually needed.NOTE: I've patched the
wasm-opt
bundled withwasm-pack
withwasm-opt version 93
, because the bundled one (version 90 I think) crashes.Expected Behavior
The
env
module should not be needed.What causes the
env
reference.Disassembling the .wasm file in directory
target
, I find this line:which is weird because this function is actually defined inside the wasm itself, not externally.
Even weirder, if I comment out the call to
f32::sin()
in this line, the problem disappears. although the functionpanic_bounds_check
still exists in the wasm (noenv
though).I've tried extracting this whole module to a simpler project, but then the problem simply does not happen.
Versions used:
The text was updated successfully, but these errors were encountered: