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

experiment: mechanism for interacting with external Wasm components #4580

Draft
wants to merge 40 commits into
base: master
Choose a base branch
from

Conversation

rvanasa
Copy link
Contributor

@rvanasa rvanasa commented Jun 27, 2024

This PR introduces a standardized import which can be used for cross-language interoperability via the Wasm component model specification.

Progress:

  • Import component.call in compiled Wasm module
  • Add componentCall prim function
  • Enable this feature with the -import-component flag (e.g. moc -wasi-system-api -import-component ...)
  • Use new error code (M0200) when trying to use this feature without the -import-component flag
  • Add unit test
  • Replace Nat32 arg with Blob
  • Replace Nat32 return type with Blob

Next steps

  • Generalize wit:component:call to support arbitrary component imports?

Note that this only works in runtimes with support for the component model:

An alternate approach would be to enable passing the names of arbitrary Wasm imports. While this seems like it would be beneficial at first glance, the component model architecture tends to favor a pattern of defining a standard interface (for example, the WASI CLI world) and then "plugging" exports into corresponding imports (see WAC for how this specifically works).

The current approach follows this pattern with the following WIT world:

package motoko:component;

world motoko {
    import component: interface {
        call: func(value: list<u8>) -> list<u8>;
    }
}

It's possible to plug a Rust component into this interface using something similar to the following WAC composition:

package motoko:composition;

let rust = new rust:component {};

let motoko = new motoko:component {
    component: rust,
    ...
};

export motoko.run;

@crusso
Copy link
Contributor

crusso commented Jun 28, 2024

@rvanasa I took a look and (hopefully) got CI working for you in #4584.

The problem was that moc -t doesn't even enter compile.ml, so you weren't generating the error when just running moc -t (as the tests in test/fail (which are mostly type checker test do).

Feel free to merge into your branch or ignore...

Copy link

github-actions bot commented Jul 9, 2024

Comparing from 75c59e1 to 80ebfef:
In terms of gas, 2 tests regressed and the mean change is +0.0%.
In terms of size, 5 tests regressed and the mean change is +0.1%.

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 this pull request may close these issues.

2 participants