Comments (10)
Without seeing the exact code that's being compiled, it's difficult to say for sure. The error you're seeing is caused by trying to read or skip string data from a WebAssembly module that exceeds the maximum allowed size for a string (100,000 bytes).
If you run wasm-tools validate $PATH_TO_COMPONENT
do you see the error again?
from cargo-component.
Hi Ryan, thanks for the idea. I ran the command that you mentioned, but nothing was output to the console at all. I assume that means that the checks were successful?
For some additional context, I'm writing a parser using a parser combinator library called chumsky. I believe that the problem starts happening when the parser types reach a certain depth of recursion, though I haven't been able to verify that yet.
from cargo-component.
For additional context, I only run into errors when using cargo-component. If I compile to windows-msvc or directly to wasm32-wasi, I don't see any errors.
For more context, I found that when I run wasm-tools compose
to compose my wasm components using the files that were output by the step that raised the error that I mentioned above, I get this error message:
error: failed to parse component `C:\Users\bnhei\source\silex\target/wasm32-wasi/debug/silex-parser.wasm`
Caused by:
0: the file is not a WebAssembly component
It does seem that something was happening after the file was compiled that failed.
from cargo-component.
I dug into the .wasm
file and found that the type information generated for the Chumsky parser is massive -- 19.3 megabytes on its own (see attached file), well over the limit that you mentioned above. Judging from what you mentioned, I would guess that the type information is stored as a string, and thus goes over the maximum possible size for a string?
from cargo-component.
The error about the binary not being a component makes sense. It seems that cargo-component
was successfully able to produce a WebAssembly module, but then when it tried to convert that module into a component, that step failed leaving you with just a plain module.
The type info does seem like a very likely culprit. The short term work around is to strip that info from the binary (perhaps using wasm-tools strip
) and then making the module a component using wasm-tools component new
. What the actual fix for cargo-component
is, I'm less sure of. Seems like this error case might need to be handled more elegantly.
from cargo-component.
Thanks for the suggestions. I tried using wasm-tools strip
and it did significantly reduce the file size, but when I ran wasm-tools component new
I received the same error message as before: error: string size out of bounds (at offset 0x3c4ff4)
. When I opened the binary to check its content, I did find that the massive Chumsky parser type was still included. I tried again with the --all
option and got the following error:
error: failed to encode a component from module
Caused by:
0: failed to decode world from module
1: module was not valid
2: module requires an import interface named `wasi_snapshot_preview1`
I guess in this case, it stripped too much. Next I'll --delete
option and see if I can't target just that specific section.
from cargo-component.
By the way, this issue a limitation of cargo-component
, right? Is this something that I might expect to see a fix for in the near future, or is it niche enough that I should plan or relying on a workaround, or just to avoid using libraries that generate such large type definitions?
from cargo-component.
To add one more update, it does seem that the offending part of the .wasm
file was debug info -- when I tried building the project in release mode, I didn't encounter any error. This suggests that an easy fix would be to make cargo-component
detect and skip debug info.
from cargo-component.
Hi @toadslop.
By the way, this issue a limitation of cargo-component, right?
No, this is an intentional limitation in wasmparser
, the underlying library that various component model tools use to parse WebAssembly modules and components; it's a hard limitation that cargo-component
cannot work around.
This suggests that an easy fix would be to make cargo-component detect and skip debug info.
wasmparser
does not process debug information sections and cargo-component
does not either, so I suspect the offending wasm string is actually contained the name
custom section, which is processed by both wit-component
(the library used to componentize the output from rustc
) and cargo-component
as part of appending producer metadata to the output.
Given that cargo-component
provides error context when adding a producers
section and that context is not present in the observed error message, my first guess would be it's failing from wit-component
's attempt to add its producers
section.
I think the proper fix here is to add a strip
option in Cargo.toml
for cargo-component
to strip the custom sections of the core module prior to componentization; similarly, but a separate issue, an optimize
option should be added for cargo-component
for it to pass the module through wasm-opt
.
from cargo-component.
I haven't tried, but the suppression of the name
section might correlate to one of the profile options in Cargo.toml
.
A possible work around might be adding the following to your Cargo.toml
:
[profile.dev]
debug = false
or
[profile.dev]
strip = "symbols"
Obviously that will impact your ability to see useful stack traces for traps originating from the component (or otherwise being able to debug it).
from cargo-component.
Related Issues (20)
- `cargo component check --workspace` should not generate bindings for workspace members without `[package.metadata.component]` set HOT 2
- `cargo-component` is not acquring a file lock for componentization
- Document the schema of the cargo-component Cargo.toml configuration HOT 1
- Hello world example fails when project name contains underscore HOT 1
- Add a `cargo component serve` subcommand that uses a default runner of `wasmtime serve`
- wit pubilsh --init fails to register the WIT package to wa.dev, while it successfully create a pacakge on the registry HOT 4
- Build fails with 'failed to create a target world for package ...' HOT 2
- Use something like nightly.link or a non-re-published release to avoid excess notifications
- Additional `import`s in generated component HOT 2
- Resource Static Methods Cause Build Failure When Imported HOT 5
- Wit package name/version validated against registry publishes
- Some wasi imports added per default into wit HOT 2
- cargo install cargo-component error HOT 5
- Compile error when installing cargo component HOT 7
- Minimum Supported Rust Version (MSRV)
- Bindings are sometimes incorrectly generated type + `Borrow` suffix vs `&` type HOT 2
- `cargo component add` not producing runnable/usable binaries
- Cargo Component install give error in RPI 4 (ARM CORTEX-A72) HOT 3
- Update to `-S cli` instead of `-S common` for wasmtime commands
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cargo-component.