|
| 1 | +From 0b326d7d0d266808c6109282c6417d26835ef648 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jeremy Koritzinsky < [email protected]> |
| 3 | +Date: Thu, 2 Jan 2025 12:19:02 -0800 |
| 4 | +Subject: [PATCH] Infer the projects runtime identifier as the vertical's RID |
| 5 | + when doing a vertical build and filter down RID lists to the target RID in |
| 6 | + such a scenario. |
| 7 | + |
| 8 | +Backport: https://github.com/dotnet/arcade/pull/15371 |
| 9 | + |
| 10 | +--- |
| 11 | + .../UnifiedBuild/Unified-Build-Controls.md | 1 + |
| 12 | + .../tools/BeforeNETSdkTargets.targets | 4 + |
| 13 | + ...ifierInference.BeforeNETSdkTargets.targets | 79 +++++++++++++++++++ |
| 14 | + .../tools/Settings.props | 1 + |
| 15 | + .../SourceBuildArcadeBuild.targets | 1 + |
| 16 | + 5 files changed, 86 insertions(+) |
| 17 | + create mode 100644 src/Microsoft.DotNet.Arcade.Sdk/tools/BeforeNETSdkTargets.targets |
| 18 | + create mode 100644 src/Microsoft.DotNet.Arcade.Sdk/tools/RuntimeIdentifierInference.BeforeNETSdkTargets.targets |
| 19 | + |
| 20 | +diff --git a/Documentation/UnifiedBuild/Unified-Build-Controls.md b/Documentation/UnifiedBuild/Unified-Build-Controls.md |
| 21 | +index 809d94443..872e14167 100644 |
| 22 | +--- a/Documentation/UnifiedBuild/Unified-Build-Controls.md |
| 23 | ++++ b/Documentation/UnifiedBuild/Unified-Build-Controls.md |
| 24 | +@@ -135,6 +135,7 @@ These controls may be used for **infrastructure or product purposes**. |
| 25 | + | -------- | -------- | -------- | -------- | |
| 26 | + | DotNetBuildWithOnlineSources | "true", "false", "" | "false" by default when `SourceOnly` switch is active. | When "true", do not remove non-local input sources. Infrastructure switch only. This switch is only exposed at the orchestrator level.</br>This replaces the existing `DotNetBuildOffline` switch. | |
| 27 | + | DotNetBuildSourceOnly | "true", "false", "" | "" | When "true", build only from source. Online sources may remain unless `DotNetBuildOffline` is set to true. This is both an infrastructure and a product switch.<br/>This is roughly equivalent to `DotNetBuildFromSource` in the current infrastructure, though other controls may be better suited. | |
| 28 | ++| DotNetBuildTargetRidOnly | "true", "false", "" | "" | When not set, defaults to "true" if the repository build transitively depends on dotnet/runtime and `DotNetBuildOrchestrator` == "true"; otherwise "false". When "true", builds projects for the current `TargetRid` instead of using the current runtime identifier. | |
| 29 | + |
| 30 | + ### Output Controls |
| 31 | + |
| 32 | +diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/BeforeNETSdkTargets.targets b/src/Microsoft.DotNet.Arcade.Sdk/tools/BeforeNETSdkTargets.targets |
| 33 | +new file mode 100644 |
| 34 | +index 000000000..84b2020b6 |
| 35 | +--- /dev/null |
| 36 | ++++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/BeforeNETSdkTargets.targets |
| 37 | +@@ -0,0 +1,4 @@ |
| 38 | ++<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. --> |
| 39 | ++<Project> |
| 40 | ++ <Import Project="RuntimeIdentifierInference.BeforeNETSdkTargets.targets" /> |
| 41 | ++</Project> |
| 42 | +diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/RuntimeIdentifierInference.BeforeNETSdkTargets.targets b/src/Microsoft.DotNet.Arcade.Sdk/tools/RuntimeIdentifierInference.BeforeNETSdkTargets.targets |
| 43 | +new file mode 100644 |
| 44 | +index 000000000..9eba3fad9 |
| 45 | +--- /dev/null |
| 46 | ++++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/RuntimeIdentifierInference.BeforeNETSdkTargets.targets |
| 47 | +@@ -0,0 +1,79 @@ |
| 48 | ++<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. --> |
| 49 | ++<Project> |
| 50 | ++ <PropertyGroup> |
| 51 | ++ <_EnableArcadeRuntimeIdentifierInference Condition="'$(_EnableArcadeRuntimeIdentifierInference)' == ''">$(EnableArcadeRuntimeIdentifierInference)</_EnableArcadeRuntimeIdentifierInference> |
| 52 | ++ |
| 53 | ++ <!-- If the user has specified a RID for their project, don't overwrite it. --> |
| 54 | ++ <_EnableArcadeRuntimeIdentifierInference Condition="'$(_EnableArcadeRuntimeIdentifierInference)' == '' and '$(RuntimeIdentifier)' != ''">false</_EnableArcadeRuntimeIdentifierInference> |
| 55 | ++ |
| 56 | ++ <!-- |
| 57 | ++ If the SDK will infer this project as "RID agnostic", don't infer RIDs. |
| 58 | ++ This should generally match the logic for setting IsRidAgnostic in the SDK. |
| 59 | ++ --> |
| 60 | ++ <_RidAgnosticProject Condition="('$(OutputType)' == 'Library' or '$(IsTestProject)' == 'true') and '$(RuntimeIdentifiers)' == ''">true</_RidAgnosticProject> |
| 61 | ++ |
| 62 | ++ <!-- If this project is RID-agnostic, don't infer RIDs. --> |
| 63 | ++ <_EnableArcadeRuntimeIdentifierInference Condition="'$(_EnableArcadeRuntimeIdentifierInference)' == '' and ('$(IsRidAgnostic)' == 'true' or '$(_RidAgnosticProject)' == 'true')">false</_EnableArcadeRuntimeIdentifierInference> |
| 64 | ++ |
| 65 | ++ <!-- |
| 66 | ++ We only need to infer if the project would use the RID |
| 67 | ++ --> |
| 68 | ++ <_BuildFlavorRequiredRid |
| 69 | ++ Condition=" |
| 70 | ++ '$(SelfContained)' == 'true' or |
| 71 | ++ ('$(_IsPublishing)' == 'true' and |
| 72 | ++ ( |
| 73 | ++ '$(PublishReadyToRun)' == 'true' or |
| 74 | ++ '$(PublishSingleFile)' == 'true' or |
| 75 | ++ '$(PublishAot)' == 'true' |
| 76 | ++ ) |
| 77 | ++ )">true</_BuildFlavorRequiredRid> |
| 78 | ++ <_EnableArcadeRuntimeIdentifierInference Condition="'$(_EnableArcadeRuntimeIdentifierInference)' == '' and '$(_BuildFlavorRequiredRid)' != 'true'">false</_EnableArcadeRuntimeIdentifierInference> |
| 79 | ++ |
| 80 | ++ <!-- |
| 81 | ++ When we're doing a build of a single vertical, we may not have a runtime or host available for any RID outside of our current target. |
| 82 | ++ For many of our projects, we don't actually need to build any RID-specific assets, but the SDK may still try to pull down assets for other RIDs, |
| 83 | ++ in particular for the RID matching the SDK's RID. |
| 84 | ++ To avoid this, we'll default to setting the RID to the vertical's target RID. |
| 85 | ++ To preserve expected behavior for projects that don't specify a RID in a non-vertical build, we won't append the RID to the output path if the user hasn't explicitly requested it. |
| 86 | ++ --> |
| 87 | ++ <_EnableArcadeRuntimeIdentifierInference Condition="'$(_EnableArcadeRuntimeIdentifierInference)' == '' and '$(DotNetBuildTargetRidOnly)' == 'true'">true</_EnableArcadeRuntimeIdentifierInference> |
| 88 | ++ |
| 89 | ++ <_EnableArcadeRuntimeIdentifierFilters Condition="'$(EnableArcadeRuntimeIdentifierFilters)' != ''">$(EnableArcadeRuntimeIdentifierFilters)</_EnableArcadeRuntimeIdentifierFilters> |
| 90 | ++ |
| 91 | ++ <!-- |
| 92 | ++ If we infer a RID for the project, default to filtering down the list of RIDs the project specifies and automatically excluding projects that don't build for this RID. |
| 93 | ++ --> |
| 94 | ++ <_EnableArcadeRuntimeIdentifierFilters Condition="'$(_EnableArcadeRuntimeIdentifierFilters)' == '' and '$(_EnableArcadeRuntimeIdentifierInference)' == 'true'">$(_EnableArcadeRuntimeIdentifierFilters)</_EnableArcadeRuntimeIdentifierFilters> |
| 95 | ++ </PropertyGroup> |
| 96 | ++ |
| 97 | ++ <PropertyGroup Condition="'$(_EnableArcadeRuntimeIdentifierInference)' == 'true'"> |
| 98 | ++ <!-- If we're inferring a RID, regular builds wouldn't have appended the RID to the output path. Default to not appending to the output path to preserve expected output locations. --> |
| 99 | ++ <AppendRuntimeIdentifierToOutputPath Condition="'$(AppendRuntimeIdentifierToOutputPath)' == ''">false</AppendRuntimeIdentifierToOutputPath> |
| 100 | ++ <RuntimeIdentifier>$(TargetRid)</RuntimeIdentifier> |
| 101 | ++ |
| 102 | ++ <!-- If this project would have been inferred as "RID agnostic", preserve that as well. --> |
| 103 | ++ <IsRidAgnostic Condition="'$(_RidAgnosticProject)' == 'true'">true</IsRidAgnostic> |
| 104 | ++ </PropertyGroup> |
| 105 | ++ |
| 106 | ++ <PropertyGroup Condition="'$(_EnableArcadeRuntimeIdentifierFilters)' == 'true' and '$(RuntimeIdentifiers)' != ''"> |
| 107 | ++ <!-- Prepend and append with semicolons to make the Contains call below simpler. --> |
| 108 | ++ <_ExplicitlySpecifiedRuntimeIdentifiers>;$(RuntimeIdentifiers);</_ExplicitlySpecifiedRuntimeIdentifiers> |
| 109 | ++ |
| 110 | ++ <!-- |
| 111 | ++ Sometimes we may need to filter the RuntimeIdentifiers list by a RID that is not TargetRid. |
| 112 | ++ Determine which RID to filter on here. |
| 113 | ++ |
| 114 | ++ We can't actually use the RID graph here as RID graph filtering is only possible in a task, and we need to do this during property evaluation. |
| 115 | ++ --> |
| 116 | ++ <_FilterRuntimeIdentifier>$(TargetRid)</_FilterRuntimeIdentifier> |
| 117 | ++ <!-- If we're introducing a new runtime identifier with TargetRid, filter instead on BaseOS. --> |
| 118 | ++ <_FilterRuntimeIdentifier Condition="'$(BaseOS)' != ''">$(BaseOS)</_FilterRuntimeIdentifier> |
| 119 | ++ |
| 120 | ++ <!-- If a project builds for a set of RIDs specified in the project file and this vertical isn't in the list, suppress building this project. --> |
| 121 | ++ <_SuppressAllTargets Condition="'$(DisableArcadeExcludeFromBuildSupport)' != 'true' and $(_ExplicitlySpecifiedRuntimeIdentifiers).Contains(';$(_FilterRuntimeIdentifier);')) == 'false'">true</_SuppressAllTargets> |
| 122 | ++ |
| 123 | ++ <!-- The .NET SDK will try to restore for all specified RIDs. Change the list of RIDs to only our inferred RID to ensure that restore only restores assets that could be available. --> |
| 124 | ++ <RuntimeIdentifiers>$(RuntimeIdentifier)</RuntimeIdentifiers> |
| 125 | ++ </PropertyGroup> |
| 126 | ++</Project> |
| 127 | +diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/Settings.props b/src/Microsoft.DotNet.Arcade.Sdk/tools/Settings.props |
| 128 | +index b19ed1c3e..0b1d6c41d 100644 |
| 129 | +--- a/src/Microsoft.DotNet.Arcade.Sdk/tools/Settings.props |
| 130 | ++++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/Settings.props |
| 131 | +@@ -6,6 +6,7 @@ |
| 132 | + <_ArcadeOverriddenCustomBeforeMicrosoftCommonCrossTargetingTargets>$(CustomBeforeMicrosoftCommonCrossTargetingTargets)</_ArcadeOverriddenCustomBeforeMicrosoftCommonCrossTargetingTargets> |
| 133 | + <CustomBeforeMicrosoftCommonTargets>$(MSBuildThisFileDirectory)BeforeCommonTargets.targets</CustomBeforeMicrosoftCommonTargets> |
| 134 | + <CustomBeforeMicrosoftCommonCrossTargetingTargets>$(MSBuildThisFileDirectory)BeforeCommonTargets.CrossTargeting.targets</CustomBeforeMicrosoftCommonCrossTargetingTargets> |
| 135 | ++ <BeforeMicrosoftNETSdkTargets>$(BeforeMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)BeforeNETSdkTargets.targets</BeforeMicrosoftNETSdkTargets> |
| 136 | + <!-- MSBuild has "global" variables (ie command-line or MSBuild task properties) override local declarations. That's generally not the behavior that we want in Arcade. |
| 137 | + We want to be able to have Arcade MSBuild a project / target with the property set as a default, but let the project override that value. To work around MSBuild, |
| 138 | + we pass in `_blah` and set it to a local property (`blah`) which is not global. --> |
| 139 | +diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/SourceBuild/SourceBuildArcadeBuild.targets b/src/Microsoft.DotNet.Arcade.Sdk/tools/SourceBuild/SourceBuildArcadeBuild.targets |
| 140 | +index 76e314d1f..a94d4e5ac 100644 |
| 141 | +--- a/src/Microsoft.DotNet.Arcade.Sdk/tools/SourceBuild/SourceBuildArcadeBuild.targets |
| 142 | ++++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/SourceBuild/SourceBuildArcadeBuild.targets |
| 143 | +@@ -55,6 +55,7 @@ |
| 144 | + - DotNetBuildSourceOnly - Build from source only. Pass through outer build value if present. --> |
| 145 | + <InnerBuildArgs Condition="'$(DotNetBuildRepo)' == 'true'">$(InnerBuildArgs) /p:DotNetBuildInnerRepo=true</InnerBuildArgs> |
| 146 | + <InnerBuildArgs Condition="'$(DotNetBuildSourceOnly)' != ''">$(InnerBuildArgs) /p:DotNetBuildSourceOnly=$(DotNetBuildSourceOnly)</InnerBuildArgs> |
| 147 | ++ <InnerBuildArgs Condition="'$(DotNetBuildTargetRidOnly)' != ''">$(InnerBuildArgs) /p:DotNetBuildTargetRidOnly=$(DotNetBuildTargetRidOnly)</InnerBuildArgs> |
| 148 | + <!-- Use a fresh clone of the repo so that source-build modifications are isolated. --> |
| 149 | + <InnerBuildArgs>$(InnerBuildArgs) /p:RepoRoot="$(InnerSourceBuildRepoRoot)$(_DirSeparatorEscapedCharForExecArg)"</InnerBuildArgs> |
| 150 | + <!-- Override the artifacts dir to cleanly separate the inner build from outer build. --> |
0 commit comments