rylev / wasmtime-component-demo

A demo of how to work with WebAssembly components in wasmtime
11 stars 1 forks source link

Error while building wasm component to target #1

Closed iamshreeram closed 5 months ago

iamshreeram commented 5 months ago

@rylev , Seeing below error while building the wasm component -

error[E0463]: can't find crate for `core`
  |
  = note: the `wasm32-unknown-unknown` target may not be installed
  = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`

error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `core`
   --> /Users/ram/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bitflags-1.3.2/src/lib.rs:282:1
    |
282 | pub extern crate core as _core;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
    |
    = note: the `wasm32-unknown-unknown` target may not be installed
    = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `bitflags` (lib) due to 3 previous errors
warning: build failed, waiting for other jobs to finish...
error[E0412]: cannot find type `Option` in this scope
  --> /Users/ram/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unicode-width-0.1.10/src/lib.rs:78:23
   |
78 |     fn width(self) -> Option<usize>;
   |                       ^^^^^^ not found in this scope

error[E0412]: cannot find type `Option` in this scope
  --> /Users/ram/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unicode-width-0.1.10/src/lib.rs:87:27
   |
87 |     fn width_cjk(self) -> Option<usize>;
   |                           ^^^^^^ not found in this scope

error[E0412]: cannot find type `Option` in this scope
  --> /Users/ram/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unicode-width-0.1.10/src/lib.rs:92:23
   |
92 |     fn width(self) -> Option<usize> { cw::width(self, false) }
   |                       ^^^^^^ not found in this scope

error[E0412]: cannot find type `Option` in this scope
  --> /Users/ram/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unicode-width-0.1.10/src/lib.rs:95:27
   |
95 |     fn width_cjk(self) -> Option<usize> { cw::width(self, true) }
   |                           ^^^^^^ not found in this scope

error: requires `receiver` lang_item
   --> /Users/ram/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unicode-width-0.1.10/src/lib.rs:123:14
    |
123 |     fn width(&self) -> usize {
    |              ^^^^^

error: requires `receiver` lang_item
   --> /Users/ram/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unicode-width-0.1.10/src/lib.rs:128:18
    |
128 |     fn width_cjk(&self) -> usize {
    |                  ^^^^^

error: requires `sized` lang_item

Some errors have detailed explanations: E0412, E0463.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `unicode-width` (lib) due to 9 previous errors
rylev commented 5 months ago

The key to fixing this is buried in the error message:

consider downloading the target with rustup target add wasm32-unknown-unknown

iamshreeram commented 5 months ago

Thanks @rylev ; Build is successful after adding the wasm32 target. After the cargo build, the ./target/release doesnt contain any binary or the ./target/wasm32-unknown-unknown/release/markdown.wasm file; Is this expected?

Seeing below error while creating component

~/r/p/r/wasmtime-component-demo ❯❯❯ wasm-tools component new ./target/wasm32-unknown-unknown/release/markdown.wasm -o markdown-component.wasm
error: decoding custom section component-type:markdown

Caused by:
    0: magic header not detected: bad magic number (at offset 0x0)
rylev commented 5 months ago

And you're running cargo build --target wasm32-unknown-unknown --release -p markdown or just cargo build?

iamshreeram commented 5 months ago

@rylev , Yes, Im running cargo build --target wasm32-unknown-unknown --release -p markdown

image

After restarting my system, markdown.wasm (2 MB) got built into the target release directory. But, still seeing the same error -

image
rylev commented 5 months ago

@iamshreeram I had forgotten how out of date all the dependencies I use in this repo are. I updated the dependencies in https://github.com/rylev/wasmtime-component-demo/commit/12a202dee8c7be0463ad440996d685f78bcae045 and everything should work now. Can you pull the latest changes and try again?

iamshreeram commented 5 months ago

@rylev , Yes, this is working well. thanks for fixing. Does the code only transform one line of markdown into HTML?

Additionally, it would be beneficial to include information about the project's functionality and the process of creating components, which will greatly assist beginners.

rylev commented 5 months ago

Indeed the code only reads one line of input and transforms that to markdown. Thanks for the feedback!