bytecodealliance / bytecodealliance/cargo-component

Resource Static Methods Cause Build Failure When Imported

Open
#284 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
593
Forks
68
PR merge metrics
No merged PRs in 30d

Description

Hey all, I ran into an issue where I couldn't import static resource functions which were defined in another wasm component. I have a minimal example attached as a zip file below.

In the project, I have an cdylib called `exporter` that exports a single wit resource, called 'my-resource' with a single static method called 'get-static' which returns a string. I also have an project called importer that creates an executable that imports the resource with the static method. I find that when I build the importing package, I get the following error:

```
error: failed to validate component output

Caused by:
export name `[static]my-resource.get-static` is not valid
static resource name is not known in this context (at offset 0xb)
```

This issue doesn't happen when I change the static method to a normal method. Any idea what's going wrong here?

The steps to reproduce using the package below are as follows:

1. unzip the folder.
2. `cd exporter`
3. `cargo component build`. You should see this output:
```
Generating bindings for exporter (src\bindings.rs)
Compiling wit-bindgen-rt v0.24.0
Compiling exporter v0.1.0 (C:\Users\bnhei\source\min-ex\exporter)
Finished dev [unoptimized + debuginfo] target(s) in 1.72s
Creating component target\wasm32-wasi\debug\exporter.wasm
```
5. `cd ../importer`
6. `cargo component build`. You should see this output:
```
Compiling wit-bindgen-rt v0.24.0
Compiling importer v0.1.0 (C:\Users\bnhei\source\min-ex\importer)
Finished dev [unoptimized + debuginfo] target(s) in 1.57s
Creating component target\wasm32-wasi\debug\importer.wasm
error: failed to validate component output

Caused by:
export name `[static]my-resource.get-static` is not valid
static resource name is not known in this context (at offset 0xb)
```

[min-ex.zip](https://github.com/bytecodealliance/cargo-component/files/15184543/min-ex.zip)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.