-
Notifications
You must be signed in to change notification settings - Fork 210
[NativeAOT LLVM] DllImport / LibraryImport doesn't automatically produce imports on wasi-wasm #2383
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
Comments
I worked on this a bit. After adding in the obviously missing
For HelloWasm. As can be seen, not too bad. The challenge with importing anything unresolved on not-Browser is that the default behavior of engines is to hard fail loading the module if the imports cannot be satisfied. It means that with our limited test matrix we are practically bound to "test" this feature "in production" as some new upstream or existing dynamically unreachable runtime code decides to do something like PI into Win32 (this can be trivially seen if you try to compile a libraries test, there will be dozens of unresolved yet dynamically unreachable PIs). |
You can define those functions with |
Ah sorry that doesn't help with this part, yeah... |
I'd say assemblies compiled to Wasm shouldn't have those // this would be compiled to a trap
[DllImport("foo")]
public static void Bar();
// this would be propagated to the linker
[DllImport("foo", WasmImport = true)]
public static void Baz(); |
That said, wouldn't the mentioned issue be a problem for upstream Wasm support in Blazor too? If they're okay with emitting those PIs as imports, maybe best to match that behaviour? |
Upstream art in this area is not yet established, I would expect them to hit this problem as well of course.
I think it's basically impractical to require this. .NET assemblies are by their nature cross-platform, so constructs such as below: [DllImport("kernel32.dll")]
void win32_api();
[DllImport("*")]
void wasi_api();
public void Api()
{
if (OperatingSystem.IsWindows()) { win32_api(); } else { wasi_api() };
} Are both the recommended way to write code and lead to this problem. I agree the solution lies somewhere around custom annotations and restricting the set of automatically imported code, it just needs more thought. Now we have |
|
For WIT (component model) we have more options perhaps as we have a source generator. |
Hm yeah that actually sounds like a reasonable tradeoff too. But will something like |
I was thinking it'd work similar to
|
Yes, I believe we'd want that long-term, as also mentioned by Steve in #2266. Having to declare imports in multiple places is somewhat inconvenient. Although if we have to add another element to csproj one way or another, and can't make |
This has been fixed upstream and downstream via |
As per discussion in #2235 (comment), looks like wasi-wasm currently gets passed
--unresolved-symbols=ignore-all
which means that you need explicit<WasmImport ...>
annotations for any native imports.The text was updated successfully, but these errors were encountered: