-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[wasm/wasi] Consolidate build targets #95775
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
be9a2d7
[wasm/wasi] Consolidate build targets
radical 74ee7cd
[wasi] WBT: Use TestOutputWrapper
radical 0f72775
[wasm] WBT: Track target name changes
radical c6408c3
[wasi] WBT: Add new tests
radical 25ab062
cleanup
radical 961df64
cleanup
radical cc221c8
Merge remote-tracking branch 'origin/main' into wasm-build-consolidat…
radical b6914c9
address feedback
radical 260bc0b
address feedback
radical 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
Wasi.Build.Tests.InvariantTests | ||
Wasi.Build.Tests.WasiTemplateTests | ||
Wasi.Build.Tests.ILStripTests | ||
Wasi.Build.Tests.SdkMissingTests | ||
Wasi.Build.Tests.RuntimeConfigTests | ||
Wasi.Build.Tests.WasiTemplateTests |
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,128 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.IO; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Wasm.Build.Tests; | ||
|
||
#nullable enable | ||
|
||
namespace Wasi.Build.Tests; | ||
|
||
public class ILStripTests : BuildTestBase | ||
{ | ||
public ILStripTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
fanyang-mono marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: base(output, buildContext) | ||
{ | ||
} | ||
|
||
[Theory] | ||
[InlineData("", /*expectILStripping*/ true, /*singleFileBundle*/false)] // Default case | ||
[InlineData("", /*expectILStripping*/ true, /*singleFileBundle*/true)] // Default case | ||
[InlineData("false", /*expectILStripping*/ false, /*singleFileBundle*/false)] // the opposite of the default case | ||
[InlineData("false", /*expectILStripping*/ false, /*singleFileBundle*/true)] // the opposite of the default case | ||
public void WasmStripILAfterAOT_TestDefaultAndOverride(string stripILAfterAOT, bool expectILStripping, bool singleFileBundle) | ||
{ | ||
string config = "Release"; | ||
string id = $"{config}_{GetRandomId()}"; | ||
string projectFile = CreateWasmTemplateProject(id, "wasiconsole"); | ||
string projectName = Path.GetFileNameWithoutExtension(projectFile); | ||
|
||
string extraProperties = "<RunAOTCompilation>true</RunAOTCompilation>"; | ||
if (singleFileBundle) | ||
extraProperties += "<WasmSingleFileBundle>true</WasmSingleFileBundle>"; | ||
if (!string.IsNullOrEmpty(stripILAfterAOT)) | ||
extraProperties += $"<WasmStripILAfterAOT>{stripILAfterAOT}</WasmStripILAfterAOT>"; | ||
AddItemsPropertiesToProject(projectFile, extraProperties); | ||
|
||
var buildArgs = new BuildArgs(projectName, config, AOT: true, ProjectFileContents: id, ExtraBuildArgs: null); | ||
buildArgs = ExpandBuildArgs(buildArgs); | ||
|
||
BuildProject(buildArgs, | ||
id: id, | ||
new BuildProjectOptions( | ||
DotnetWasmFromRuntimePack: false, | ||
CreateProject: false, | ||
Publish: true, | ||
TargetFramework: BuildTestBase.DefaultTargetFramework, | ||
UseCache: false)); | ||
|
||
string runArgs = $"run --no-silent --no-build -c {config}"; | ||
new RunCommand(s_buildEnv, _testOutput, label: id) | ||
.WithWorkingDirectory(_projectDir!) | ||
.ExecuteWithCapturedOutput(runArgs) | ||
.EnsureSuccessful(); | ||
|
||
string frameworkDir = singleFileBundle ? "" : Path.Combine(_projectDir!, "bin", config, DefaultTargetFramework, "wasi-wasm", "AppBundle", "managed"); | ||
string objBuildDir = Path.Combine(_projectDir!, "obj", config, DefaultTargetFramework, "wasi-wasm", "wasm", "for-publish"); | ||
TestWasmStripILAfterAOTOutput(objBuildDir, frameworkDir, expectILStripping, singleFileBundle, _testOutput); | ||
} | ||
|
||
private static void TestWasmStripILAfterAOTOutput(string objBuildDir, string appBundleFrameworkDir, bool expectILStripping, bool singleFileBundle, ITestOutputHelper testOutput) | ||
{ | ||
string origAssemblyDir = Path.Combine(objBuildDir, "aot-in"); | ||
string strippedAssemblyDir = Path.Combine(objBuildDir, "stripped"); | ||
Assert.True(Directory.Exists(origAssemblyDir), $"Could not find the original AOT input assemblies dir: {origAssemblyDir}"); | ||
if (expectILStripping) | ||
Assert.True(Directory.Exists(strippedAssemblyDir), $"Could not find the stripped assemblies dir: {strippedAssemblyDir}"); | ||
else | ||
Assert.False(Directory.Exists(strippedAssemblyDir), $"Expected {strippedAssemblyDir} to not exist"); | ||
|
||
string assemblyToExamine = "System.Private.CoreLib.dll"; | ||
string originalAssembly = Path.Combine(objBuildDir, origAssemblyDir, assemblyToExamine); | ||
string strippedAssembly = Path.Combine(objBuildDir, strippedAssemblyDir, assemblyToExamine); | ||
string includedAssembly = Path.Combine(appBundleFrameworkDir, assemblyToExamine); | ||
|
||
Assert.True(File.Exists(originalAssembly), $"Expected {nameof(originalAssembly)} {originalAssembly} to exist"); | ||
if (!singleFileBundle) | ||
Assert.True(File.Exists(includedAssembly), $"Expected {nameof(includedAssembly)} {includedAssembly} to exist"); | ||
if (expectILStripping) | ||
Assert.True(File.Exists(strippedAssembly), $"Expected {nameof(strippedAssembly)} {strippedAssembly} to exist"); | ||
else | ||
Assert.False(File.Exists(strippedAssembly), $"Expected {strippedAssembly} to not exist"); | ||
|
||
string compressedOriginalAssembly = Utils.GZipCompress(originalAssembly); | ||
string? compressedIncludedAssembly = null; | ||
FileInfo compressedOriginalAssembly_fi = new FileInfo(compressedOriginalAssembly); | ||
FileInfo? compressedincludedAssembly_fi = null; | ||
|
||
testOutput.WriteLine ($"compressedOriginalAssembly_fi: {compressedOriginalAssembly_fi.Length}, {compressedOriginalAssembly}"); | ||
if (!singleFileBundle) | ||
{ | ||
compressedIncludedAssembly = Utils.GZipCompress(includedAssembly)!; | ||
compressedincludedAssembly_fi = new FileInfo(compressedIncludedAssembly); | ||
testOutput.WriteLine ($"compressedincludedAssembly_fi: {compressedincludedAssembly_fi.Length}, {compressedIncludedAssembly}"); | ||
} | ||
|
||
if (expectILStripping) | ||
{ | ||
string compressedStrippedAssembly = Utils.GZipCompress(strippedAssembly); | ||
FileInfo compressedStrippedAssembly_fi = new FileInfo(compressedStrippedAssembly); | ||
testOutput.WriteLine ($"compressedStrippedAssembly_fi: {compressedStrippedAssembly_fi.Length}, {compressedStrippedAssembly}"); | ||
|
||
// original > stripped assembly | ||
Assert.True(compressedOriginalAssembly_fi.Length > compressedStrippedAssembly_fi.Length, | ||
$"Expected original assembly ({compressedOriginalAssembly}) size ({compressedOriginalAssembly_fi.Length}) " + | ||
$"to be bigger than the stripped assembly ({compressedStrippedAssembly}) size ({compressedStrippedAssembly_fi.Length})"); | ||
|
||
if (!singleFileBundle) | ||
{ | ||
// included == stripped assembly | ||
Assert.True(compressedincludedAssembly_fi!.Length == compressedStrippedAssembly_fi.Length, | ||
$"Expected included assembly ({compressedIncludedAssembly}) size ({compressedincludedAssembly_fi.Length}) " + | ||
$"to be the same as the stripped assembly ({compressedStrippedAssembly}) size ({compressedStrippedAssembly_fi.Length})"); | ||
} | ||
} | ||
else | ||
{ | ||
if (!singleFileBundle) | ||
{ | ||
// original == included assembly | ||
Assert.True(compressedincludedAssembly_fi!.Length == compressedOriginalAssembly_fi.Length, | ||
$"Expected included assembly ({compressedIncludedAssembly}) size ({compressedincludedAssembly_fi.Length}) " + | ||
$"to be the same as the original assembly ({compressedOriginalAssembly}) size ({compressedOriginalAssembly_fi.Length})"); | ||
} | ||
} | ||
} | ||
} |
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,52 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.IO; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Wasm.Build.Tests; | ||
|
||
#nullable enable | ||
|
||
namespace Wasi.Build.Tests; | ||
|
||
public class RuntimeConfigTests : BuildTestBase | ||
{ | ||
public RuntimeConfigTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
: base(output, buildContext) | ||
{ | ||
} | ||
|
||
[Theory] | ||
[ActiveIssue("https://github.com/dotnet/runtime/issues/95345")] | ||
[InlineData(false)] | ||
[InlineData(true)] | ||
public void MissingRuntimeConfigTemplateJson(bool singleFileBundle) | ||
{ | ||
string config = "Release"; | ||
string id = $"{config}_{GetRandomId()}"; | ||
string projectFile = CreateWasmTemplateProject(id, "wasiconsole"); | ||
string projectName = Path.GetFileNameWithoutExtension(projectFile); | ||
|
||
File.Delete(Path.Combine(_projectDir!, "runtimeconfig.template.json")); | ||
|
||
var buildArgs = new BuildArgs(projectName, config, AOT: true, ProjectFileContents: id, ExtraBuildArgs: null); | ||
buildArgs = ExpandBuildArgs(buildArgs); | ||
AddItemsPropertiesToProject(projectFile, singleFileBundle ? "<WasmSingleFileBundle>true</WasmSingleFileBundle>" : ""); | ||
|
||
BuildProject(buildArgs, | ||
id: id, | ||
new BuildProjectOptions( | ||
DotnetWasmFromRuntimePack: false, | ||
CreateProject: false, | ||
Publish: true, | ||
TargetFramework: BuildTestBase.DefaultTargetFramework, | ||
UseCache: false)); | ||
|
||
string runArgs = $"run --no-silent --no-build -c {config}"; | ||
new RunCommand(s_buildEnv, _testOutput, label: id) | ||
.WithWorkingDirectory(_projectDir!) | ||
.ExecuteWithCapturedOutput(runArgs) | ||
.EnsureSuccessful(); | ||
} | ||
} |
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,82 @@ | ||
// 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 Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
using Wasm.Build.Tests; | ||
using System.Collections.Generic; | ||
|
||
#nullable enable | ||
|
||
namespace Wasi.Build.Tests; | ||
|
||
public class SdkMissingTests : BuildTestBase | ||
{ | ||
public SdkMissingTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
: base(output, buildContext) | ||
{ | ||
} | ||
|
||
public static TheoryData<string, string, bool> TestDataForNativeBuildFails(string extraProperties) | ||
=> new TheoryData<string, string, bool> | ||
{ | ||
{ "Debug", extraProperties, false }, | ||
{ "Debug", extraProperties, true }, | ||
{ "Release", extraProperties, false }, | ||
{ "Release", extraProperties, true } | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(TestDataForNativeBuildFails), "<WasmSingleFileBundle>true</WasmSingleFileBundle>")] | ||
[MemberData(nameof(TestDataForNativeBuildFails), "<InvariantGlobalization>true</InvariantGlobalization>")] | ||
public void NativeBuildOrPublishFails(string config, string extraProperties, bool publish) | ||
{ | ||
string output = BuildWithInvalidSdkPath(config, extraProperties, publish, expectSuccess: false); | ||
Assert.Contains("SDK is required for building native files.", output); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Debug", "<RunAOTCompilation>true</RunAOTCompilation>", false)] | ||
[InlineData("Release", "<RunAOTCompilation>true</RunAOTCompilation>", true)] | ||
public void AOTFailsOnlyOnPublish(string config, string extraProperties, bool publish) | ||
{ | ||
string output = BuildWithInvalidSdkPath(config, extraProperties, publish, expectSuccess: !publish); | ||
if (publish) | ||
Assert.Contains("SDK is required for AOT'ing assemblies", output); | ||
else | ||
Assert.DoesNotContain("SDK is required", output); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Debug")] | ||
[InlineData("Release")] | ||
public void SimpleBuildDoesNotFail(string config) | ||
=> BuildWithInvalidSdkPath(config, "", publish: false, expectSuccess: true); | ||
|
||
private string BuildWithInvalidSdkPath(string config, string extraProperties, bool publish, bool expectSuccess) | ||
{ | ||
string id = $"{config}_{GetRandomId()}"; | ||
string projectFile = CreateWasmTemplateProject(id, "wasiconsole"); | ||
string projectName = Path.GetFileNameWithoutExtension(projectFile); | ||
|
||
var buildArgs = new BuildArgs(projectName, config, /*aot*/ true, id, null); | ||
buildArgs = ExpandBuildArgs(buildArgs); | ||
AddItemsPropertiesToProject(projectFile, extraProperties); | ||
|
||
(_, string output) = BuildProject(buildArgs, | ||
id: id, | ||
new BuildProjectOptions( | ||
DotnetWasmFromRuntimePack: true, | ||
CreateProject: false, | ||
Publish: publish, | ||
TargetFramework: BuildTestBase.DefaultTargetFramework, | ||
ExtraBuildEnvironmentVariables: new Dictionary<string, string> { { "WASI_SDK_PATH", "x" } }, | ||
ExpectSuccess: expectSuccess)); | ||
|
||
return 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
Oops, something went wrong.
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.
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.
should we rename
wasm
->browser
(OS) and usewasm
for the (architecture) ?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.
Yeah, I avoided those renames in this PR. We are following the pattern you suggested in most places now, like
tests.{wasm,browser,wasi}.targets
, and recentlysendtohelix-{wasm,browser,wasi}.proj
.