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

Use better AOT defaults in Web SDK #29984

Merged
merged 4 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private void RecordProperties(string projectPath, XDocument project, string[] pr
}
}

public Dictionary<string, string> GetPropertyValues(string testRoot, string project, string configuration = "Debug", string targetFramework = null)
public Dictionary<string, string> GetPropertyValues(string testRoot, string project, string targetFramework = null, string configuration = "Debug")
{
var propertyValues = new Dictionary<string, string>();

Expand Down
25 changes: 20 additions & 5 deletions src/Tests/Microsoft.NET.Sdk.Web.Tests/PublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public PublishTests(ITestOutputHelper log) : base(log)
{
}

[Theory()]
[Theory]
[MemberData(nameof(SupportedTfms))]
public void TrimmingOptions_Are_Defaulted_Correctly_On_Trimmed_Apps(string targetFramework)
{
Expand All @@ -29,11 +29,16 @@ public void TrimmingOptions_Are_Defaulted_Correctly_On_Trimmed_Apps(string targe

var testProject = CreateTestProjectForILLinkTesting(targetFramework, projectName);
testProject.AdditionalProperties["PublishTrimmed"] = "true";
testProject.AdditionalProperties["RuntimeIdentifier"] = rid;
testProject.PropertiesToRecord.Add("TrimMode");

var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: projectName + targetFramework);

var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));
publishCommand.Execute($"/p:RuntimeIdentifier={rid}").Should().Pass();
publishCommand.Execute().Should().Pass();

var buildProperties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework);
buildProperties["TrimMode"].Should().Be("partial");

string outputDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName;
string runtimeConfigFile = Path.Combine(outputDirectory, $"{projectName}.runtimeconfig.json");
Expand All @@ -46,7 +51,7 @@ public void TrimmingOptions_Are_Defaulted_Correctly_On_Trimmed_Apps(string targe
.Should().BeTrue();
}

[Theory()]
[Theory]
[MemberData(nameof(SupportedTfms))]
public void TrimmingOptions_Are_Defaulted_Correctly_On_Aot_Apps(string targetFramework)
{
Expand All @@ -55,16 +60,26 @@ public void TrimmingOptions_Are_Defaulted_Correctly_On_Aot_Apps(string targetFra

var testProject = CreateTestProjectForILLinkTesting(targetFramework, projectName);
testProject.AdditionalProperties["PublishAOT"] = "true";
testProject.AdditionalProperties["RuntimeIdentifier"] = rid;
testProject.PropertiesToRecord.Add("PublishTrimmed");
testProject.PropertiesToRecord.Add("TrimMode");
testProject.PropertiesToRecord.Add("PublishIISAssets");

var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: projectName + targetFramework);
var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));
publishCommand.Execute($"/p:RuntimeIdentifier={rid}").Should().Pass();
publishCommand.Execute().Should().Pass();

var buildProperties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework);
buildProperties["PublishTrimmed"].Should().Be("true");
buildProperties["TrimMode"].Should().Be("");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This verifies we don't set TrimMode to "partial" like we do in the PublishTrimmed-only case. Does anyone know of a better way to verify we get "full" trimming?

buildProperties["PublishIISAssets"].Should().Be("false");

string outputDirectory = publishCommand.GetIntermediateDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName;
string outputDirectory = publishCommand.GetIntermediateDirectory(targetFramework, runtimeIdentifier: rid).FullName;
string responseFile = Path.Combine(outputDirectory, "native", $"{projectName}.ilc.rsp");
var responseFileContents = File.ReadLines(responseFile);

responseFileContents.Should().Contain("--feature:Microsoft.AspNetCore.EnsureJsonTrimmability=true");
File.Exists(Path.Combine(outputDirectory, "web.config")).Should().BeFalse();
}

public static IEnumerable<object[]> SupportedTfms { get; } = new List<object[]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public void RecordProperties(params string[] propertyNames)
/// A dictionary of property keys to property value strings, case sensitive.
/// Only properties added to the <see cref="PropertiesToRecord"/> member will be observed.
/// </returns>
public Dictionary<string, string> GetPropertyValues(string testRoot, string configuration = "Debug", string targetFramework = null)
public Dictionary<string, string> GetPropertyValues(string testRoot, string targetFramework = null, string configuration = "Debug")
{
var propertyValues = new Dictionary<string, string>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
And '$(RuntimeIdentifier)' != ''
And !$(RuntimeIdentifier.StartsWith('win'))
And '$(PublishIISAssets)' == ''">false</PublishIISAssets>
<PublishIISAssets Condition="'$(PublishIISAssets)' == '' and '$(PublishAot)' == 'true'">false</PublishIISAssets>
</PropertyGroup>

<!-- Extension points for BeforePublish and AfterPublish-->
Expand Down Expand Up @@ -87,7 +88,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<EFSQLScriptsFolderName Condition="$(EFSQLScriptsFolderName) == ''">EFSQLScripts</EFSQLScriptsFolderName>

<!-- If TrimMode has not already been set, default to partial trimming, as AspNet is not currently fully trim-compatible -->
<TrimMode Condition="'$(PublishTrimmed)' == 'true' and '$(TrimMode)' == ''">partial</TrimMode>
<!-- We allow the full trimming default with PublishAot enabled, because the parts that are not trim-compatible are not aot-compatible either -->
<TrimMode Condition="'$(TrimMode)' == '' and '$(PublishTrimmed)' == 'true' and '$(PublishAot)' != 'true'">partial</TrimMode>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should think about defaulting to full with PublishTrimmed true as well

cc @DamianEdwards @eerhardt

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this came up in the original issue and discussion but it seems a bit premature right now given the state of trimmability across all of ASP.NET Core. Not ruling it out for .NET 8 though if we think we get far enough to make it the better default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we track it in an issue and punt it to the next release if we decide?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reopened #30059 and put it in the Goldilocks project for tracking.

</PropertyGroup>

<!--
Expand Down