-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[wasm][wasi] Allow to build wasi in library mode #102806
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6af2653
Allow to build wasi app in library mode
mkhamoyan f98cfa3
Move function definition inside runtime.h
mkhamoyan 295a6ca
Fix LibraryTests failure
mkhamoyan a7130fc
Implement changes requested by @maraf
mkhamoyan fab9e6c
Use wasm sdk in sample
mkhamoyan da249bb
Run also library mode tests on CI
mkhamoyan 6167091
update test case
mkhamoyan 7aa9161
allow unsafe in test
mkhamoyan f21bfa9
Update test case
mkhamoyan f6c9c38
Update wasm sdk to handle wasi flow correctly
mkhamoyan cb2c613
Remove extra line
mkhamoyan c8d8d93
set outputtype in browser.props
mkhamoyan 4d50681
Revert changes from sample app
mkhamoyan 8edb01e
Apply feedback changes
mkhamoyan 0c56cf8
Guard the "_initialize"
mkhamoyan e2cbbfb
Update IsWasiProject, IsBrowserWasmProject checks
mkhamoyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
| using Xunit.Sdk; | ||
| using Wasm.Build.Tests; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Wasi.Build.Tests; | ||
|
|
||
| public class WasiLibraryModeTests : BuildTestBase | ||
| { | ||
| public WasiLibraryModeTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
| : base(output, buildContext) | ||
| { | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ConsoleBuildLibraryMode() | ||
| { | ||
| string config = "Release"; | ||
| string id = $"{config}_{GetRandomId()}"; | ||
| string projectFile = CreateWasmTemplateProject(id, "wasiconsole"); | ||
| string code = | ||
| """ | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
| public unsafe class Test | ||
| { | ||
| [UnmanagedCallersOnly(EntryPoint = "MyCallback")] | ||
| public static int MyCallback() | ||
| { | ||
| Console.WriteLine("WASM Library MyCallback is called"); | ||
| return 100; | ||
| } | ||
| } | ||
| """; | ||
| string csprojCode = | ||
| """ | ||
| <Project Sdk="Microsoft.NET.Sdk.WebAssembly"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
mkhamoyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <RuntimeIdentifier>wasi-wasm</RuntimeIdentifier> | ||
| <TargetOs>wasi</TargetOs> | ||
| <WasmBuildNative>true</WasmBuildNative> | ||
| <WasmNativeStrip>false</WasmNativeStrip> | ||
| <IsBrowserWasmProject>false</IsBrowserWasmProject> | ||
| <WasmSingleFileBundle>true</WasmSingleFileBundle> | ||
| <OutputType>Library</OutputType> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
| </PropertyGroup> | ||
| </Project> | ||
| """; | ||
| File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), code); | ||
| File.WriteAllText(Path.Combine(_projectDir!, $"{id}.csproj"), csprojCode); | ||
| string projectName = Path.GetFileNameWithoutExtension(projectFile); | ||
| var buildArgs = new BuildArgs(projectName, config, AOT: false, ProjectFileContents: id, ExtraBuildArgs: null); | ||
| buildArgs = ExpandBuildArgs(buildArgs); | ||
| (_, string output) = BuildProject(buildArgs, | ||
| id: id, | ||
| new BuildProjectOptions( | ||
| DotnetWasmFromRuntimePack: false, | ||
| CreateProject: false, | ||
| Publish: false, | ||
| TargetFramework: BuildTestBase.DefaultTargetFramework | ||
| )); | ||
|
|
||
| Assert.Contains("Build succeeded.", output); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.