-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Can't import Component Model functions in WASI apps #94513
Comments
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsDescriptionWhile you can import functions in WASI apps (see #90786), the process breaks down when the imported namespace contains (component
(import "custom-hook" (func (param string) (result string)))
(import "wasi:http/handler" (instance
(export "request" (type $request (sub resource)))
(export "response" (type $response (sub resource)))
(export "handle" (func (param (own $request)) (result (own $response))))
))
(import "url=<https://mycdn.com/my-component.wasm>" (component ...))
(import "relative-url=<./other-component.wasm>,integrity=<sha256-X9ArH3k...>" (component ...))
(import "locked-dep=<my-registry:sqlite@1.2.3>,integrity=<sha256-H8BRh8j...>" (component ...))
(import "unlocked-dep=<my-registry:imagemagick@{>=1.0.0}>" (instance ...))
(import "integrity=<sha256-Y3BsI4l...>" (component ...))
... impl
(export "wasi:http/handler" (instance $http_handler_impl))
(export "get-JSON" (func $get_json_impl))
) Reproduction Stepscsproj: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
<OutputType>Exe</OutputType>
<PublishTrimmed>true</PublishTrimmed>
<WasmSingleFileBundle>true</WasmSingleFileBundle>
<WasmBuildNative>true</WasmBuildNative>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<NativeFileReference Include="$(MSBuildThisFileDirectory)extism.c" />
<_WasmNativeFileForLinking Include="@(NativeFileReference)" />
</ItemGroup>
</Project> Program.cs: using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
public class Program
{
[DllImport("extism:host/user")]
public static extern void do_something();
public static void Main(string[] args)
{
}
} extism.c: #include <string.h>
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#define IMPORT(a, b) __attribute__((import_module(a), import_name(b)))
IMPORT("extism:host/user", "do_something")
extern void do_something_wrapper();
void do_something() {
return do_something_wrapper();
} Then run:
And then:
Full Repro: Expected behavior
Actual behavior
Notice: Also, in Regression?No response Known WorkaroundsSimplify the import statemet in Program.cs: [DllImport("extism")]
public static extern void do_something(); But keep #include <string.h>
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#define IMPORT(a, b) __attribute__((import_module(a), import_name(b)))
IMPORT("extism:host/user", "do_something")
extern void do_something_wrapper();
void do_something() {
return do_something_wrapper();
} Configuration
Other informationNo response
|
cc @maraf |
The |
Imports directly in C# without a .c wrapper will be supported once #93824 is implemented. We should ensure that all valid wasm import names are supported |
WasmImportLinkageAttribute is in now, we should add this to the wasm interop work. |
The problem is, |
@maraf was suggesting you try [DllImport("extism")] that should resolve to the correct thing given the declarations in the csproj. I believe it should work after that. |
But the wasm import still appears to be being removed. We will take a look |
Sorry, hadn't looked closely enough at this. When you use NativeFileReference you are adding that code to be statically linked and if you specify a ".c" file it will use the filename (without .c) as the module name. What you are effectively doing with extism.c is making a stub library that then calls the wasm import and as @maraf pointed out If your request is to make [WasmImportLinkage]
[DllImport("extism:host/user")]
public static extern void do_something(); in the future. I hope that answers your question and sorry for any additional confusion my replies caused. |
@lewing thank you for your reply. I had already listed that as a workaround in the issue and have implemented it in our PDK: I opened this issue for 2 reasons:
I understand that .NET 8 release is close and you might not want to change anything especially since this will get fixed for good in .NET 9 |
#94615 is a quick fix that should resolve the issue. It may not land as is but it works. |
fixed in #94615 any additional issues should be tracked separately. |
Description
While you can import functions in WASI apps (see #90786), the process breaks down when the imported namespace contains
:
and/
. This is problematic because these are valid characters and are used widely in Wasm Component Model spec. For example,wasi:http/handler
is a valid import namespace:Reproduction Steps
csproj:
Program.cs:
extism.c:
Then run:
And then:
Full Repro:
https://github.com/mhmd-azeez/component-model-repro
Expected behavior
Actual behavior
Notice:
extism:host/user.do_something
is not imported.Also, in
pinvoke-table.h
there is no entry fordo_something
.Regression?
No response
Known Workarounds
Simplify the import statemet in Program.cs:
But keep
extism.c
as is:Configuration
Other information
No response
The text was updated successfully, but these errors were encountered: