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

WASI components import wasi:cli/environemnt and wasi:cli/exit when not being used #107405

Open
jsturtevant opened this issue Sep 5, 2024 · 5 comments
Labels
arch-wasm WebAssembly architecture area-Build-mono os-wasi Related to WASI variant of arch-wasm
Milestone

Comments

@jsturtevant
Copy link
Contributor

problem statement

When building a component for wasi:http when running in wasmtime I get the following error:

wasmtime serve .\bin\Debug\net8.0\wasi-wasm\native\MyApp.wasm --addr 127.0.0.1:3000
Error: component imports instance `wasi:cli/[email protected]`, but a matching implementation was not found in the linker

Caused by:
    0: instance export `get-environment` has the wrong type
    1: function implementation is missing

When inspecting the component built I see imports for wasi:cli/environemnt and wasi:cli/exit, even though I only built against the wasi:http world:

wasm-tools.exe component wit .\bin\Debug\net8.0\wasi-wasm\native\MyApp.wasm
package root:component;

world root {
  import wasi:cli/[email protected];
  import wasi:cli/[email protected];
....

I was able to work around it by telling wasmtime to provide the cli imports:

wasmtime serve -S cli ...

question

Should these imports be included in the component? Is there a way to detect during compilation if the env/exit are being used and not include them?

Discussion in Bytecode Alliance Zulip: https://bytecodealliance.zulipchat.com/#narrow/stream/407028-C.23.2F.2Enet-collaboration/topic/missing.20implementation.20was.20not.20found.20in.20linker

example

https://github.com/jsturtevant/wasi-http-oci

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Sep 5, 2024
@dicej
Copy link
Contributor

dicej commented Sep 5, 2024

Note that you can specify -Wl,--wasi-adapter,proxy to the linker (e.g. as a CustomLinkerArg) when targeting wasi-http, which will stub out those imports.

@SingleAccretion
Copy link
Contributor

It is by design that the actual imports is a superset of "used" imports (including from other worlds). I expect that in the long term, as both WASI and .NET's use of it mature, this set will only grow.

CustomLinkerArg

CustomLinkerArg -> LinkerArg (#107194 (comment)).

@pavelsavara pavelsavara added arch-wasm WebAssembly architecture os-wasi Related to WASI variant of arch-wasm labels Sep 5, 2024
@pavelsavara pavelsavara added this to the 10.0.0 milestone Sep 5, 2024
Copy link
Contributor

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Sep 5, 2024
@jsturtevant
Copy link
Contributor Author

It is by design that the actual imports is a superset of "used" imports (including from other worlds). I expect that in the long term, as both WASI and .NET's use of it mature, this set will only grow.

I guess I am not following this fully. In this case the component implements wasi-http not wasi-cli. Why would it have wasi-cli imports if it's not using it?

@SingleAccretion
Copy link
Contributor

I guess I am not following this fully. In this case the component implements wasi-http not wasi-cli

The .NET runtime assumes that it has access to the full "system library"; it differentiates these libraries by the OS component of the RID. Since we only have wasi-wasm, there is one and only monolithic WASI.

Why would it have wasi-cli imports if it's not using it?

There is a path somewhere (which could be dynamically unreachable) that eventually calls the imports. Consider e. g. that a lot of knobs that .NET exposes are configured via environment variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-Build-mono os-wasi Related to WASI variant of arch-wasm
Projects
None yet
Development

No branches or pull requests

4 participants