Skip to content

Commit 485b906

Browse files
lewingCopilot
andcommitted
Keep the instruction-set argument when extra args are a global property
PublishReadyToRunCrossgen2ExtraArgs set with -p: is a global property, so appending to it at evaluation time was ignored and PublishReadyToRunInstructionSet was silently dropped. Pass it through an internal property consumed by both compiler invocations and the arguments cache hash. Co-authored-by: Copilot App <[email protected]>
1 parent 43a7ba3 commit 485b906

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.CrossGen.targets‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ Copyright (c) .NET Foundation. All rights reserved.
4242
<PublishReadyToRunCrossgen2ExtraArgs Condition="'$(PublishReadyToRunStripInliningInfo)' == 'true'">$(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info</PublishReadyToRunCrossgen2ExtraArgs>
4343
<PublishReadyToRunCrossgen2ExtraArgs Condition="'$(PublishReadyToRunStripDebugInfo)' == 'true'">$(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info</PublishReadyToRunCrossgen2ExtraArgs>
4444

45-
<!-- Overrides the target's default instruction sets, as IlcInstructionSet does for NativeAOT. -->
46-
<PublishReadyToRunCrossgen2ExtraArgs Condition="'$(PublishReadyToRunInstructionSet)' != ''">$(PublishReadyToRunCrossgen2ExtraArgs);--instruction-set:$(PublishReadyToRunInstructionSet)</PublishReadyToRunCrossgen2ExtraArgs>
45+
<!-- Overrides the target's default instruction sets, as IlcInstructionSet does for NativeAOT. This is kept out of
46+
PublishReadyToRunCrossgen2ExtraArgs so that it still applies when that property is set on the command line. -->
47+
<_ReadyToRunInstructionSetArgs Condition="'$(PublishReadyToRunInstructionSet)' != ''">--instruction-set:$(PublishReadyToRunInstructionSet)</_ReadyToRunInstructionSetArgs>
4748
</PropertyGroup>
4849

4950
<PropertyGroup>
@@ -507,7 +508,7 @@ Copyright (c) .NET Foundation. All rights reserved.
507508
<_ReadyToRunCompilerArgumentsCacheFile>$(IntermediateOutputPath)$(MSBuildProjectName).ReadyToRunCompilerArguments.cache</_ReadyToRunCompilerArgumentsCacheFile>
508509
</PropertyGroup>
509510

510-
<Hash ItemsToHash="$(PublishReadyToRunCrossgen2ExtraArgs);$(_PublishReadyToRunCrossgen2ExtraArgs);CompositeExtraArgs=$(PublishReadyToRunCrossgen2CompositeExtraArgs);Composite=$(PublishReadyToRunComposite);ContainerFormat=$(PublishReadyToRunContainerFormat);UseCrossgen2=$(PublishReadyToRunUseCrossgen2);PerfmapFormatVersion=$(PublishReadyToRunPerfmapFormatVersion)">
511+
<Hash ItemsToHash="$(PublishReadyToRunCrossgen2ExtraArgs);$(_PublishReadyToRunCrossgen2ExtraArgs);InstructionSet=$(_ReadyToRunInstructionSetArgs);CompositeExtraArgs=$(PublishReadyToRunCrossgen2CompositeExtraArgs);Composite=$(PublishReadyToRunComposite);ContainerFormat=$(PublishReadyToRunContainerFormat);UseCrossgen2=$(PublishReadyToRunUseCrossgen2);PerfmapFormatVersion=$(PublishReadyToRunPerfmapFormatVersion)">
511512
<Output TaskParameter="HashResult" PropertyName="_ReadyToRunCompilerArgumentsHash" />
512513
</Hash>
513514

@@ -528,7 +529,7 @@ Copyright (c) .NET Foundation. All rights reserved.
528529
UseCrossgen2="$(PublishReadyToRunUseCrossgen2)"
529530
Crossgen2PgoFiles="@(_ReadyToRunPgoFiles)"
530531
Crossgen2ContainerFormat="$(PublishReadyToRunContainerFormat)"
531-
Crossgen2ExtraCommandLineArgs="$(PublishReadyToRunCrossgen2ExtraArgs);$(_PublishReadyToRunCrossgen2ExtraArgs)"
532+
Crossgen2ExtraCommandLineArgs="$(PublishReadyToRunCrossgen2ExtraArgs);$(_PublishReadyToRunCrossgen2ExtraArgs);$(_ReadyToRunInstructionSetArgs)"
532533
Crossgen2CompositeExtraCommandLineArgs="$(PublishReadyToRunCrossgen2CompositeExtraArgs)"
533534
ImplementationAssemblyReferences="@(_ReadyToRunAssembliesToReference)"
534535
ShowCompilerWarnings="$(PublishReadyToRunShowWarnings)"
@@ -566,7 +567,7 @@ Copyright (c) .NET Foundation. All rights reserved.
566567
<RunReadyToRunCompiler CrossgenTool="@(CrossgenTool)"
567568
Crossgen2Tool="@(Crossgen2Tool)"
568569
UseCrossgen2="$(PublishReadyToRunUseCrossgen2)"
569-
Crossgen2ExtraCommandLineArgs="$(PublishReadyToRunCrossgen2ExtraArgs);$(_PublishReadyToRunCrossgen2ExtraArgs)"
570+
Crossgen2ExtraCommandLineArgs="$(PublishReadyToRunCrossgen2ExtraArgs);$(_PublishReadyToRunCrossgen2ExtraArgs);$(_ReadyToRunInstructionSetArgs)"
570571
ImplementationAssemblyReferences="@(_ReadyToRunAssembliesToReference)"
571572
ShowCompilerWarnings="$(PublishReadyToRunShowWarnings)"
572573
CompilationEntry="@(_ReadyToRunSymbolsCompileList)"

‎test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishReadyToRun.cs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,12 +678,15 @@ public void It_passes_PublishReadyToRunInstructionSet_to_crossgen2(string target
678678

679679
var testProjectInstance = TestAssetsManager.CreateTestProject(testProject, identifier: targetFramework);
680680

681-
new PublishCommand(testProjectInstance).Execute().Should().Pass();
681+
new PublishCommand(testProjectInstance)
682+
.Execute("-p:PublishReadyToRunCrossgen2ExtraArgs=--Ot")
683+
.Should().Pass();
682684

683685
// An instruction set that is invalid on every architecture shows that the property reaches crossgen2,
684-
// and that changing it reruns the compiler after an up-to-date publish.
686+
// including when the extra args are a global property, and that changing it reruns the compiler after
687+
// an up-to-date publish.
685688
new PublishCommand(testProjectInstance)
686-
.Execute("-p:PublishReadyToRunInstructionSet=not-an-instruction-set")
689+
.Execute("-p:PublishReadyToRunCrossgen2ExtraArgs=--Ot", "-p:PublishReadyToRunInstructionSet=not-an-instruction-set")
687690
.Should().Fail()
688691
.And.HaveStdOutContaining("not-an-instruction-set");
689692
}

0 commit comments

Comments
 (0)