Closed silesmo closed 5 months ago
Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.
Author: | silesmo |
---|---|
Assignees: | - |
Labels: | `arch-wasm`, `untriaged`, `area-Build-mono`, `os-wasi` |
Milestone: | - |
Similar requirement tracked for browser in https://github.com/dotnet/runtime/issues/77191
See the notes https://github.com/dotnet/runtimelab/blob/feature/NativeAOT-LLVM/src/coreclr/nativeaot/Bootstrap/main.cpp#L179-L229 and some background here https://dylibso.com/blog/wasi-command-reactor/ cc @pavelsavara
This should be triggered by <OuputType>library</OutputType>
One problem I encountered last year was IL trimmer complaining about missing root
Implementation has two parts
OutputType=Library
_initialize
should work. Naot is calling it in case it wasn't called by the host from static struct ctor _initialize
? So that well-behaving hosts can manage when the "app" is initialized?ManagedToNativeGenerator
to generate initialization call when OutputType=Library
We probably might need a different mechanism to compile library as wasm library. Currently we need RuntimeIdentifier=*-wasm
+ OutputType=exe
.
In typicaly solution user would have several library projects and (one or some) exe projects that are applications. Those library projects might have RID set to *-wasm to enable wasm API. Currenly only the application projects would do the wasm build. Which is correct IMO. If we support wasm build on OutputType=library, it would a lot of additional steps in such solution.
Other parts of .NETE SDK include special steps in build by including a special SDKs in project definition (like Microsoft.NET.Sdk.Razor
). We should do the same and do wasm library only when the project references Microsoft.NET.Sdk.WebAssembly
.
The Microsoft.NET.Sdk.WebAssembly
lives in SDK and wasi build lives in workload, but we can use UsingMicrosoftNETSdkWebAssembly
to check it the wasm SDK being used
Currently Wasm SDK always imports web related SDKs https://github.com/dotnet/sdk/blob/main/src/WasmSdk/Sdk/Sdk.props#L32. We need to add a guard to do it only for browser-wasm. In the meantime we can workaround it by explicitly setting UsingMicrosoftNETSdkStaticWebAssets=true
in the csproj.
Description
Currently mono requires a main function when building for wasi. This shouldn't be required.
Related: https://github.com/dotnet/runtime/issues/96419
@AaronRobinsonMSFT @lewing @yowl @jsturtevant
Reproduction Steps
Try to build example with
main
removed. Example: https://github.com/silesmo/wasm-unmanaged-callers-bug/blob/main/mono-example/MonoEntrypoint.csExpected behavior
No main function should be required for a library.
Actual behavior
Main function is required.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response