Skip to content
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

Local dependencies lead to build panic #937

Closed
KoltesDigital opened this issue Feb 19, 2023 · 5 comments · Fixed by #941
Closed

Local dependencies lead to build panic #937

KoltesDigital opened this issue Feb 19, 2023 · 5 comments · Fixed by #941

Comments

@KoltesDigital
Copy link

Hi,

I'm trying to update crates/wasm-compose/example to use current version of cargo component.

When I declare middleware's dependency to service:

[package.metadata.component.dependencies]
	service = { path = "../service/target/wasm32-unknown-unknown/release/service.wasm" }

a wild compilation panic: appears:

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', C:\Users\X\.cargo\registry\src\github.com-1ecc6299db9ec823\wit-component-0.6.0\src\encoding\wit.rs:212:24

Url::parse(pkg.url.as_ref().unwrap()).unwrap()

I barely understand that dependencies are expected to have an URL, which local ones do not have. Or am I wrong?

Note that the middleware WIT does not import service because it's still unclear to me and I can't get it to work neither. If I add:

import service: service.component

then build fails with that error instead:

no package dependency specified for `service`
       --> X\wasm-tools\crates\wasm-compose\example\middleware\./middleware.wit:16:21
        |
     16 |     import service: service.component
        |                     ^------

In brief, can I please have some guidance on compiling a component with local dependencies? I'll gladly PR the changes once they work.

@peterhuene
Copy link
Member

Hi @KoltesDigital. Sorry you ran into this and thank you for the reminder to update this example.

I think this is a bug in cargo-component. Let me take a closer look shortly, although I'm mostly off this week.

peterhuene added a commit to peterhuene/wasm-tools that referenced this issue Feb 22, 2023
This commit updates the `wasm-compose` example to the latest tooling.

It updates the examples for the latest `cargo-component` and updates Wasmtime
and dependencies to latest.

The server also has been updated to use the `bindgen` macro from Wasmtime for
generating the server's bindings.

Fixes bytecodealliance#937.
peterhuene added a commit to peterhuene/wasm-tools that referenced this issue Feb 22, 2023
This commit updates the `wasm-compose` example to the latest tooling.

It updates the examples for the latest `cargo-component` and updates Wasmtime
and dependencies to latest.

The server also has been updated to use the `bindgen` macro from Wasmtime for
generating the server's bindings.

Fixes bytecodealliance#937.
peterhuene added a commit to peterhuene/wasm-tools that referenced this issue Feb 22, 2023
This commit updates the `wasm-compose` example to the latest tooling.

It updates the examples for the latest `cargo-component` and updates Wasmtime
and dependencies to latest.

The server also has been updated to use the `bindgen` macro from Wasmtime for
generating the server's bindings.

Fixes bytecodealliance#937.
@peterhuene
Copy link
Member

peterhuene commented Feb 22, 2023

Hi @KoltesDigital.

I've put up a PR for fixing the example with the latest cargo-component (caveat: it does require bytecodealliance/cargo-component#52 merged to work).

I'll be tracking down the panic issue with using the service component as a direct dependency (as you have it above) too.

@KoltesDigital
Copy link
Author

@peterhuene Thanks! Obviously I would never have been able to do that :)

I installed the mentioned rev of cargo component, and successfully compiled service and middleware. However server is failing to compile:

error: the wasm32-unknown-unknown target is not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support
   --> C:\Users\X\.cargo\registry\src\github.com-1ecc6299db9ec823\getrandom-0.2.8\src\lib.rs:263:9
    |
263 | /         compile_error!("the wasm32-unknown-unknown target is not supported by \
264 | |                         default, you may need to enable the \"js\" feature. \
265 | |                         For more information see: \
266 | |                         https://docs.rs/getrandom/#webassembly-support");
    | |________________________________________________________________________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> C:\Users\X\.cargo\registry\src\github.com-1ecc6299db9ec823\getrandom-0.2.8\src\lib.rs:290:5
    |
290 |     imp::getrandom_inner(dest)
    |     ^^^ use of undeclared crate or module `imp`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `getrandom` due to 2 previous errors

getrandom is not a direct dependency and there are even two versions of it. However something tells me not to add the js feature anyway. Can you please document how you've been able to compile it?

@peterhuene
Copy link
Member

peterhuene commented Feb 23, 2023

Hi @KoltesDigital.

For the server, make sure you're not building it with cargo component build as it is intended to build natively for your platform and not be a component.

The docs just use cargo run: cargo run --release -- ../service/target/wasm32-unknown-unknown/release/svc.wasm to build and run it.

Let me know if that isn't the problem and I can look into it.

@KoltesDigital
Copy link
Author

Agreed, I was too quick to press Up Enter whereas it totally makes sense that the server is a regular binary. That also explains the use of wasmtime_component_macro::bindgen!.

Thanks for your efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants