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

[wasm][wasi] No main function should be required when building a library #96869

Closed
silesmo opened this issue Jan 11, 2024 · 6 comments · Fixed by #102806
Closed

[wasm][wasi] No main function should be required when building a library #96869

silesmo opened this issue Jan 11, 2024 · 6 comments · Fixed by #102806
Assignees
Labels
arch-wasm WebAssembly architecture area-Build-mono in-pr There is an active PR which will close this issue when it is merged os-wasi Related to WASI variant of arch-wasm
Milestone

Comments

@silesmo
Copy link

silesmo commented Jan 11, 2024

Description

Currently mono requires a main function when building for wasi. This shouldn't be required.

Related: #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.cs

Expected 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

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 11, 2024
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 11, 2024
@teo-tsirpanis teo-tsirpanis added area-Build-mono os-wasi Related to WASI variant of arch-wasm and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 11, 2024
@radical radical added the arch-wasm WebAssembly architecture label Jan 12, 2024
@ghost
Copy link

ghost commented Jan 12, 2024

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

Issue Details

Description

Currently mono requires a main function when building for wasi. This shouldn't be required.

Related: #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.cs

Expected 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

Author: silesmo
Assignees: -
Labels:

arch-wasm, untriaged, area-Build-mono, os-wasi

Milestone: -

@radical radical removed the untriaged New issue has not been triaged by the area owner label Jan 12, 2024
@radical radical self-assigned this Jan 12, 2024
@maraf
Copy link
Member

maraf commented Jan 12, 2024

Similar requirement tracked for browser in #77191

@lewing lewing added this to the 9.0.0 milestone Jan 26, 2024
@lewing lewing assigned maraf and unassigned radical Jan 26, 2024
@lewing
Copy link
Member

lewing commented May 21, 2024

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

@pavelsavara
Copy link
Member

This should be triggered by <OuputType>library</OutputType>

@maraf
Copy link
Member

maraf commented May 21, 2024

One problem I encountered last year was IL trimmer complaining about missing root

Implementation has two parts

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label May 29, 2024
@maraf
Copy link
Member

maraf commented May 31, 2024

We probably might need a different mechanism to compile library as wasm library. Currently we need RuntimeIdentifier=*-wasm + OutputType=exe.

  • RuntimeIndentifier defines API surface that we can use (like JS interop)
  • OutputType=exe ensures that wasm build happen.

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Build-mono in-pr There is an active PR which will close this issue when it is merged os-wasi Related to WASI variant of arch-wasm
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants