-
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
[wasm] Integrate naot-llvm into workload manifest #101801
Changes from 22 commits
9f4447b
5904423
c7be3fa
051deab
f260eea
88be64a
08a98d9
d8f8bed
8ec46fa
3a8808a
30824f6
7946571
4c3c351
b51f621
7efc56b
7bfead3
a13f2a0
065a103
9b080bb
0096144
c72e9f4
93e54b0
255ec70
b8fb22a
2aa832f
4e94ebd
5bd7bf2
4ac36fd
5091f1b
5c684e6
9841eb0
b797fad
1a21a15
2c4c818
28ebf99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
Wasi.Build.Tests.InvariantTests | ||
Wasi.Build.Tests.ILStripTests | ||
Wasi.Build.Tests.SdkMissingTests | ||
Wasi.Build.Tests.RuntimeConfigTests | ||
Wasi.Build.Tests.WasiTemplateTests | ||
Wasi.Build.Tests.PInvokeTableGeneratorTests | ||
Wasi.Build.Tests.NativeAOTTests |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1 @@ | ||
Wasm.Build.NativeRebuild.Tests.FlagsChangeRebuildTests | ||
Wasm.Build.NativeRebuild.Tests.NoopNativeRebuildTest | ||
Wasm.Build.NativeRebuild.Tests.OptimizationFlagChangeTests | ||
Wasm.Build.NativeRebuild.Tests.ReferenceNewAssemblyRebuildTest | ||
Wasm.Build.NativeRebuild.Tests.SimpleSourceChangeRebuildTest | ||
Wasm.Build.Tests.TestAppScenarios.InterpPgoTests | ||
Wasm.Build.Templates.Tests.NativeBuildTests | ||
Wasm.Build.Tests.Blazor.AppsettingsTests | ||
Wasm.Build.Tests.Blazor.BuildPublishTests | ||
Wasm.Build.Tests.Blazor.SimpleRunTests | ||
Wasm.Build.Tests.Blazor.CleanTests | ||
Wasm.Build.Tests.Blazor.MiscTests | ||
Wasm.Build.Tests.Blazor.MiscTests2 | ||
Wasm.Build.Tests.Blazor.MiscTests3 | ||
Wasm.Build.Tests.Blazor.NativeTests | ||
Wasm.Build.Tests.Blazor.NoopNativeRebuildTest | ||
Wasm.Build.Tests.Blazor.WorkloadRequiredTests | ||
Wasm.Build.Tests.Blazor.IcuTests | ||
Wasm.Build.Tests.Blazor.IcuShardingTests | ||
Wasm.Build.Tests.Blazor.SignalRClientTests | ||
Wasm.Build.Tests.BuildPublishTests | ||
Wasm.Build.Tests.ConfigSrcTests | ||
Wasm.Build.Tests.HybridGlobalizationTests | ||
Wasm.Build.Tests.IcuShardingTests | ||
Wasm.Build.Tests.IcuShardingTests2 | ||
Wasm.Build.Tests.IcuTests | ||
Wasm.Build.Tests.InvariantGlobalizationTests | ||
Wasm.Build.Tests.InvariantTimezoneTests | ||
Wasm.Build.Tests.MainWithArgsTests | ||
Wasm.Build.Tests.NativeBuildTests | ||
Wasm.Build.Tests.NativeLibraryTests | ||
Wasm.Build.Tests.NonWasmTemplateBuildTests | ||
Wasm.Build.Tests.PInvokeTableGeneratorTests | ||
Wasm.Build.Tests.RebuildTests | ||
Wasm.Build.Tests.SatelliteAssembliesTests | ||
Wasm.Build.Tests.TestAppScenarios.AppSettingsTests | ||
Wasm.Build.Tests.TestAppScenarios.LazyLoadingTests | ||
Wasm.Build.Tests.TestAppScenarios.LibraryInitializerTests | ||
Wasm.Build.Tests.TestAppScenarios.SatelliteLoadingTests | ||
Wasm.Build.Tests.TestAppScenarios.ModuleConfigTests | ||
Wasm.Build.Tests.AspNetCore.SignalRClientTests | ||
Wasm.Build.Tests.WasmBuildAppTest | ||
Wasm.Build.Tests.WasmNativeDefaultsTests | ||
Wasm.Build.Tests.WasmRunOutOfAppBundleTests | ||
Wasm.Build.Tests.WasmSIMDTests | ||
Wasm.Build.Tests.WasmTemplateTests | ||
Wasm.Build.Tests.WorkloadTests | ||
Wasm.Build.Tests.MT.Blazor.SimpleMultiThreadedTests | ||
Wasm.Build.Tests.TestAppScenarios.DebugLevelTests | ||
Wasm.Build.Tests.NativeAOTTests |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. --> | ||
<Project> | ||
<PropertyGroup> | ||
<_IsUsingNativeAOT Condition="'$(PublishAot)' == 'true'">true</_IsUsingNativeAOT> | ||
<_RuntimePackInWorkloadVersionCurrent>${PackageVersion}</_RuntimePackInWorkloadVersionCurrent> | ||
<_RuntimePackInWorkloadVersion8>${PackageVersionNet8}</_RuntimePackInWorkloadVersion8> | ||
<_RuntimePackInWorkloadVersion7>${PackageVersionNet7}</_RuntimePackInWorkloadVersion7> | ||
|
@@ -65,6 +66,26 @@ | |
<UsingBrowserRuntimeWorkload Condition="'$(UsingBrowserRuntimeWorkload)' == ''">$(WasmNativeWorkloadAvailable)</UsingBrowserRuntimeWorkload> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(_IsUsingNativeAOT)' == 'true'"> | ||
<UseAppHost>false</UseAppHost> | ||
<UsingBrowserRuntimeWorkload Condition="'$(RuntimeIdentifier)' == 'browser-wasm'">false</UsingBrowserRuntimeWorkload> | ||
<UsingWasiRuntimeWorkload Condition="'$(RuntimeIdentifier)' == 'wasi-wasm'">false</UsingWasiRuntimeWorkload> | ||
<BrowserWorkloadDisabled>true</BrowserWorkloadDisabled> | ||
<OverrideImportRuntimeIlcPackageTarget>false</OverrideImportRuntimeIlcPackageTarget> | ||
<WasmExperimentalNativeAOTLLVMILCompilerVersion Condition="'$(WasmExperimentalNativeAOTLLVMILCompilerVersion)' == ''">${WasmExperimentalNativeAOTLLVMILCompilerVersion}</WasmExperimentalNativeAOTLLVMILCompilerVersion> | ||
<RestoreAdditionalProjectSources>$(RestoreAdditionalProjectSources);https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json</RestoreAdditionalProjectSources> | ||
maraf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(_IsUsingNativeAOT)' == 'true' and ('$(RuntimeIdentifier)' == 'browser-wasm' or '$(RuntimeIdentifier)' == 'wasi-wasm')"> | ||
<KnownILCompilerPack Remove="Microsoft.DotNet.ILCompiler" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is me being nit-picky - I would move this down near where we set |
||
<KnownILCompilerPack Include="Microsoft.DotNet.ILCompiler.LLVM" | ||
TargetFramework="${NetCoreAppCurrent}" | ||
ILCompilerPackNamePattern="runtime.**RID**.Microsoft.DotNet.ILCompiler.LLVM" | ||
ILCompilerPackVersion="$(WasmExperimentalNativeAOTLLVMILCompilerVersion)" | ||
ILCompilerRuntimeIdentifiers="wasi-wasm;browser-wasm;win-x64" | ||
/> | ||
</ItemGroup> | ||
|
||
<PropertyGroup Condition="'$(NativeLib)' != ''"> | ||
<_IsAndroidLibraryMode Condition="'$(RuntimeIdentifier)' == 'android-arm64' or '$(RuntimeIdentifier)' == 'android-arm' or '$(RuntimeIdentifier)' == 'android-x64' or '$(RuntimeIdentifier)' == 'android-x86'">true</_IsAndroidLibraryMode> | ||
<_IsAppleMobileLibraryMode Condition="'$(RuntimeIdentifier)' == 'ios-arm64' or '$(RuntimeIdentifier)' == 'iossimulator-arm64' or '$(RuntimeIdentifier)' == 'iossimulator-x64' or '$(RuntimeIdentifier)' == 'maccatalyst-arm64' or '$(RuntimeIdentifier)' == 'maccatalyst-x64' or '$(RuntimeIdentifier)' == 'tvos-arm64'">true</_IsAppleMobileLibraryMode> | ||
|
@@ -185,7 +206,7 @@ | |
<!-- Overrides for wasm threading support --> | ||
<RuntimePackNamePatterns Condition="'$(RuntimeIdentifier)' == 'browser-wasm' and '$(WasmEnableThreads)' == 'true'">Microsoft.NETCore.App.Runtime.Mono.multithread.**RID**</RuntimePackNamePatterns> | ||
</KnownRuntimePack> | ||
<KnownFrameworkReference Update="Microsoft.NETCore.App"> | ||
<KnownFrameworkReference Update="Microsoft.NETCore.App" Condition="'$(_IsUsingNativeAOT)' != 'true'"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should override it to the naot version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That version doesn't exit. The naot-llvm produces only ILC-LLVM packages |
||
<TargetingPackVersion Condition="'$(TargetsCurrent)' == 'true'">$(_MonoWorkloadRuntimePackPackageVersion)</TargetingPackVersion> | ||
</KnownFrameworkReference> | ||
<KnownWebAssemblySdkPack Update="@(KnownWebAssemblySdkPack)"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// 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 System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Wasm.Build.Tests; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
#nullable enable | ||
|
||
namespace Wasi.Build.Tests; | ||
|
||
public class NativeAOTTests : BuildTestBase | ||
{ | ||
public NativeAOTTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
: base(output, buildContext) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void PublishAndRun() | ||
{ | ||
const string config = "Release"; | ||
string id = $"nativeaot_{GetRandomId()}"; | ||
string projectFile = CreateWasmTemplateProject(id, "wasiconsole"); | ||
string projectName = Path.GetFileNameWithoutExtension(projectFile); | ||
|
||
string programCsContent = File.ReadAllText(Path.Combine(BuildEnvironment.TestAssetsPath, "SimpleMainWithArgs.cs")); | ||
programCsContent = programCsContent.Replace("return 42;", "return 0;"); | ||
File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), programCsContent); | ||
File.Delete(Path.Combine(_projectDir!, "runtimeconfig.template.json")); | ||
|
||
var buildArgs = ExpandBuildArgs(new BuildArgs(projectName, config, AOT: false, id, null)); | ||
|
||
AddItemsPropertiesToProject(projectFile, extraProperties: "<PublishAot>true</PublishAot>"); | ||
|
||
try | ||
{ | ||
bool isWindowsPlatform = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); | ||
(_, string buildOutput) = BuildProject( | ||
buildArgs, | ||
id: id, | ||
new BuildProjectOptions( | ||
AssertAppBundle: false, | ||
CreateProject: false, | ||
Publish: true, | ||
TargetFramework: DefaultTargetFramework, | ||
ExpectSuccess: isWindowsPlatform | ||
) | ||
); | ||
|
||
if (isWindowsPlatform) | ||
{ | ||
string outputDir = Path.Combine(_projectDir!, "bin", config, DefaultTargetFramework, BuildEnvironment.DefaultRuntimeIdentifier, "native"); | ||
string outputFileName = $"{id}.wasm"; | ||
|
||
Assert.True(File.Exists(Path.Combine(outputDir, outputFileName)), $"Expected {outputFileName} to exist in {outputDir}"); | ||
Assert.Contains("Generating native code", buildOutput); | ||
|
||
using var runCommand = new ToolCommand(BuildEnvironment.GetExecutableName(@"wasmtime"), _testOutput) | ||
.WithWorkingDirectory(outputDir); | ||
|
||
var result = runCommand.Execute(outputFileName).EnsureSuccessful(); | ||
Assert.Contains("Hello, Wasi Console!", result.Output); | ||
} | ||
else | ||
{ | ||
Assert.Contains("NETSDK1204", buildOutput); // Ahead-of-time compilation is not supported on the current platform 'linux-x64' | ||
} | ||
} | ||
finally | ||
{ | ||
_testOutput.WriteLine($"Content of {_nugetPackagesDir}"); | ||
foreach (string file in Directory.EnumerateFiles(_nugetPackagesDir, "*", SearchOption.AllDirectories)) | ||
_testOutput.WriteLine(file); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// 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.Collections.Generic; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Wasm.Build.Tests.Blazor; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
#nullable enable | ||
|
||
namespace Wasm.Build.Tests; | ||
|
||
public class NativeAOTTests : BlazorWasmTestBase | ||
{ | ||
public NativeAOTTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
: base(output, buildContext) | ||
{ | ||
} | ||
|
||
[Theory] | ||
[InlineData("NativeAOT")] | ||
[InlineData("NativeAOT2")] | ||
public async Task PublishAndRun(string assetName) | ||
{ | ||
string config = "Release"; | ||
string id = $"browser_{config}_{GetRandomId()}"; | ||
|
||
InitBlazorWasmProjectDir(id); | ||
Utils.DirectoryCopy(Path.Combine(BuildEnvironment.TestAssetsPath, assetName), Path.Combine(_projectDir!)); | ||
string projectName = Path.GetFileNameWithoutExtension(_projectDir!); | ||
|
||
try | ||
{ | ||
bool isWindowsPlatform = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); | ||
(_, string buildOutput) = BuildTemplateProject( | ||
ExpandBuildArgs(new BuildArgs(projectName, config, AOT: false, id, null)), | ||
id: id, | ||
new BuildProjectOptions( | ||
AssertAppBundle: false, | ||
CreateProject: false, | ||
Publish: true, | ||
TargetFramework: DefaultTargetFramework, | ||
ExpectSuccess: isWindowsPlatform | ||
) | ||
); | ||
|
||
if (isWindowsPlatform) | ||
{ | ||
string outputDir = Path.Combine(_projectDir!, "bin", config, DefaultTargetFramework, BuildEnvironment.DefaultRuntimeIdentifier, "native"); | ||
|
||
List<string> consoleOutput = new(); | ||
BlazorRunOptions blazorRunOptions = new( | ||
CheckCounter: false, | ||
Config: config, | ||
OnConsoleMessage: (_, message) => consoleOutput.Add(message.Text), | ||
Host: BlazorRunHost.WebServer | ||
); | ||
await BlazorRunTest($"{s_xharnessRunnerCommand} wasm webserver --app=. --web-server-use-default-files", outputDir, blazorRunOptions); | ||
|
||
Assert.True(consoleOutput.Contains("Hello, NativeAOT!"), $"Expected 'Hello, NativeAOT!' wasn't emitted by the test app. Output was: {String.Join(", ", consoleOutput)}"); | ||
} | ||
else | ||
{ | ||
Assert.Contains("NETSDK1204", buildOutput); // Ahead-of-time compilation is not supported on the current platform 'linux-x64' | ||
} | ||
} | ||
finally | ||
{ | ||
_testOutput.WriteLine($"Content of {_nugetPackagesDir}"); | ||
foreach (string file in Directory.EnumerateFiles(_nugetPackagesDir, "*", SearchOption.AllDirectories)) | ||
_testOutput.WriteLine(file); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier> | ||
<OutputType>Exe</OutputType> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<DotNetJsApi>true</DotNetJsApi> | ||
<PublishAot>true</PublishAot> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<WasmExtraFilesToDeploy Include="wwwroot\*" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.InteropServices.JavaScript; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
Console.WriteLine("Hello, NativeAOT!"); | ||
Console.WriteLine($"Args {String.Join(", ", args)}"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!doctype html> | ||
<html lang="en-us"> | ||
<head> | ||
<script type='module' src="./main.js"></script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
import { dotnet } from './dotnet.js' | ||
|
||
await dotnet | ||
.withApplicationArguments("A", "B", "C") | ||
.withMainAssembly("NativeAOT") | ||
.create(); | ||
|
||
await dotnet.run(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier> | ||
<OutputType>Exe</OutputType> | ||
<PublishTrimmed>true</PublishTrimmed> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<DotNetJsApi>true</DotNetJsApi> | ||
<UsingBrowserRuntimeWorkload>false</UsingBrowserRuntimeWorkload> | ||
<UsingWasiRuntimeWorkload>false</UsingWasiRuntimeWorkload> | ||
<RestoreAdditionalProjectSources>$(RestoreAdditionalProjectSources);https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json</RestoreAdditionalProjectSources> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<WasmExtraFilesToDeploy Include="wwwroot\*" /> | ||
<PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-preview.4.24257.3" /> | ||
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-preview.4.24257.3" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.InteropServices.JavaScript; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
Console.WriteLine("Hello, NativeAOT!"); | ||
Console.WriteLine($"Args {String.Join(", ", args)}"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!doctype html> | ||
<html lang="en-us"> | ||
<head> | ||
<script type='module' src="./main.js"></script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not use PublishAot == true condition directly? MSBuild evaluates it the same way (since there is no use in any target), so it seems redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can. I wanted to extract it, because we weren't sure if using
PublishAot
for this highly experimental thing is the right choice.