Skip to content

Cannot build wasm demo. Build fails at wasm-bindgen #3592

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

Closed
yashgorana opened this issue Apr 8, 2022 · 0 comments · Fixed by #3634
Closed

Cannot build wasm demo. Build fails at wasm-bindgen #3592

yashgorana opened this issue Apr 8, 2022 · 0 comments · Fixed by #3634
Labels

Comments

@yashgorana
Copy link

When building the WASM demo app, I'm getting this error

$ npm run dev
...
i 「wds」: Project is running at http://localhost:8080/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from C:\Projects\RustPython\wasm\demo
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
warning: unused imports: `IntoPyResult`, `PyInt`
    --> vm\src\exceptions.rs:1028:47
     |
1028 |         builtins::{traceback::PyTracebackRef, PyInt, PyTupleRef, PyTypeRef},
     |                                               ^^^^^
1029 |         function::{FuncArgs, IntoPyResult},
     |                              ^^^^^^^^^^^^
     |
     = note: `#[warn(unused_imports)]` on by default

warning: unused import: `std::ops::Deref`
    --> vm\src\exceptions.rs:1034:9
     |
1034 |     use std::ops::Deref;
     |         ^^^^^^^^^^^^^^^

warning: unused import: `_io::io_open as open`
  --> vm\src\stdlib\io.rs:13:16
   |
13 | pub(crate) use _io::io_open as open;
   |                ^^^^^^^^^^^^^^^^^^^^

warning: `rustpython-vm` (lib) generated 3 warnings
    Finished dev [unoptimized + debuginfo] target(s) in 2.68s
[INFO]: License key is set in Cargo.toml but no LICENSE file(s) were found; Please add the LICENSE file(s) to your project directory
[INFO]: Installing wasm-bindgen...
error: failed to parse input file as wasm

Caused by:
    0: failed to parse code section
    1: locals exceed maximum (at offset 18929596)
Error: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit code: 1
  full command: "C:\\Users\\<USER>\\AppData\\Local\\.wasm-pack\\wasm-bindgen-866ccfefff3842a2\\wasm-bindgen.exe" "C:\Projects\RustPython\\target\\wasm32-unknown-unknown\\debug\\rustpython_wasm.wasm" "--out-dir" "C:\Projects\RustPython\\wasm\\lib\\pkg" "--typescript" "--target" "bundler" "--out-name" "index" "--debug"
× 「wdm」: Hash: 4cbecc264801045dd3e3

Unsure about the root cause of this error, but it looks like C:\Projects\RustPython\target\wasm32-unknown-unknown\debug\rustpython_wasm.wasm is too big (170+MB) and hence wasm-bindgen is failing with locals exceed maximum (at offset 18929596). This error results in an empty pkg directory that breaks import('rustpython') in index.js`

Current workaround is to use the WasmPackPlugin in release configuration in wasm/demo/webpack.conf.js

config.plugins.push(
    new WasmPackPlugin({
        crateDirectory: path.resolve(__dirname, '../lib'),
        outDir: path.resolve(__dirname, "../lib/pkg"),
        forceMode: "production"
    })
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants