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

Infer the projects runtime identifier as the vertical's RID when doing a vertical build and filter down RID lists to the target RID in such a scenario #15371

Merged
merged 4 commits into from
Jan 23, 2025
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
1 change: 1 addition & 0 deletions Documentation/UnifiedBuild/Unified-Build-Controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ These controls may be used for **infrastructure or product purposes**.
| -------- | -------- | -------- | -------- |
| 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. |
| 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. |
| 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. |

### Output Controls

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Project>
<Import Project="RuntimeIdentifierInference.BeforeNETSdkTargets.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Project>
<PropertyGroup>
<_EnableArcadeRuntimeIdentifierInference Condition="'$(_EnableArcadeRuntimeIdentifierInference)' == ''">$(EnableArcadeRuntimeIdentifierInference)</_EnableArcadeRuntimeIdentifierInference>

<!-- If the user has specified a RID for their project, don't overwrite it. -->
<_EnableArcadeRuntimeIdentifierInference Condition="'$(_EnableArcadeRuntimeIdentifierInference)' == '' and '$(RuntimeIdentifier)' != ''">false</_EnableArcadeRuntimeIdentifierInference>

<!--
If the SDK will infer this project as "RID agnostic", don't infer RIDs.
This should generally match the logic for setting IsRidAgnostic in the SDK.
-->
<_RidAgnosticProject Condition="('$(OutputType)' == 'Library' or '$(IsTestProject)' == 'true') and '$(RuntimeIdentifiers)' == ''">true</_RidAgnosticProject>

<!-- If this project is RID-agnostic, don't infer RIDs. -->
<_EnableArcadeRuntimeIdentifierInference Condition="'$(_EnableArcadeRuntimeIdentifierInference)' == '' and ('$(IsRidAgnostic)' == 'true' or '$(_RidAgnosticProject)' == 'true')">false</_EnableArcadeRuntimeIdentifierInference>

<!--
We only need to infer if the project would use the RID
-->
<_BuildFlavorRequiredRid
Condition="
'$(SelfContained)' == 'true' or
('$(_IsPublishing)' == 'true' and
(
'$(PublishReadyToRun)' == 'true' or
'$(PublishSingleFile)' == 'true' or
'$(PublishAot)' == 'true'
)
)">true</_BuildFlavorRequiredRid>
<_EnableArcadeRuntimeIdentifierInference Condition="'$(_EnableArcadeRuntimeIdentifierInference)' == '' and '$(_BuildFlavorRequiredRid)' != 'true'">false</_EnableArcadeRuntimeIdentifierInference>

<!--
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.
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,
in particular for the RID matching the SDK's RID.
To avoid this, we'll default to setting the RID to the vertical's target RID.
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.
-->
<_EnableArcadeRuntimeIdentifierInference Condition="'$(_EnableArcadeRuntimeIdentifierInference)' == '' and '$(DotNetBuildTargetRidOnly)' == 'true'">true</_EnableArcadeRuntimeIdentifierInference>

<_EnableArcadeRuntimeIdentifierFilters Condition="'$(EnableArcadeRuntimeIdentifierFilters)' != ''">$(EnableArcadeRuntimeIdentifierFilters)</_EnableArcadeRuntimeIdentifierFilters>

<!--
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.
-->
<_EnableArcadeRuntimeIdentifierFilters Condition="'$(_EnableArcadeRuntimeIdentifierFilters)' == '' and '$(_EnableArcadeRuntimeIdentifierInference)' == 'true'">$(_EnableArcadeRuntimeIdentifierFilters)</_EnableArcadeRuntimeIdentifierFilters>
</PropertyGroup>

<PropertyGroup Condition="'$(_EnableArcadeRuntimeIdentifierInference)' == 'true'">
<!-- 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. -->
<AppendRuntimeIdentifierToOutputPath Condition="'$(AppendRuntimeIdentifierToOutputPath)' == ''">false</AppendRuntimeIdentifierToOutputPath>
<RuntimeIdentifier>$(TargetRid)</RuntimeIdentifier>

<!-- If this project would have been inferred as "RID agnostic", preserve that as well. -->
<IsRidAgnostic Condition="'$(_RidAgnosticProject)' == 'true'">true</IsRidAgnostic>
</PropertyGroup>

<PropertyGroup Condition="'$(_EnableArcadeRuntimeIdentifierFilters)' == 'true' and '$(RuntimeIdentifiers)' != ''">
<!-- Prepend and append with semicolons to make the Contains call below simpler. -->
<_ExplicitlySpecifiedRuntimeIdentifiers>;$(RuntimeIdentifiers);</_ExplicitlySpecifiedRuntimeIdentifiers>

<!--
Sometimes we may need to filter the RuntimeIdentifiers list by a RID that is not TargetRid.
Determine which RID to filter on here.

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.
-->
<_FilterRuntimeIdentifier>$(TargetRid)</_FilterRuntimeIdentifier>
<!-- If we're introducing a new runtime identifier with TargetRid, filter instead on BaseOS. -->
<_FilterRuntimeIdentifier Condition="'$(BaseOS)' != ''">$(BaseOS)</_FilterRuntimeIdentifier>

<!-- 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. -->
<_SuppressAllTargets Condition="'$(DisableArcadeExcludeFromBuildSupport)' != 'true' and $(_ExplicitlySpecifiedRuntimeIdentifiers).Contains(';$(_FilterRuntimeIdentifier);')) == 'false'">true</_SuppressAllTargets>

<!-- 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. -->
<RuntimeIdentifiers>$(RuntimeIdentifier)</RuntimeIdentifiers>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions src/Microsoft.DotNet.Arcade.Sdk/tools/Settings.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<_ArcadeOverriddenCustomBeforeMicrosoftCommonCrossTargetingTargets>$(CustomBeforeMicrosoftCommonCrossTargetingTargets)</_ArcadeOverriddenCustomBeforeMicrosoftCommonCrossTargetingTargets>
<CustomBeforeMicrosoftCommonTargets>$(MSBuildThisFileDirectory)BeforeCommonTargets.targets</CustomBeforeMicrosoftCommonTargets>
<CustomBeforeMicrosoftCommonCrossTargetingTargets>$(MSBuildThisFileDirectory)BeforeCommonTargets.CrossTargeting.targets</CustomBeforeMicrosoftCommonCrossTargetingTargets>
<BeforeMicrosoftNETSdkTargets>$(BeforeMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)BeforeNETSdkTargets.targets</BeforeMicrosoftNETSdkTargets>
<!-- 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.
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,
we pass in `_blah` and set it to a local property (`blah`) which is not global. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
- DotNetBuildSourceOnly - Build from source only. Pass through outer build value if present. -->
<InnerBuildArgs Condition="'$(DotNetBuildRepo)' == 'true'">$(InnerBuildArgs) /p:DotNetBuildInnerRepo=true</InnerBuildArgs>
<InnerBuildArgs Condition="'$(DotNetBuildSourceOnly)' != ''">$(InnerBuildArgs) /p:DotNetBuildSourceOnly=$(DotNetBuildSourceOnly)</InnerBuildArgs>
<InnerBuildArgs Condition="'$(DotNetBuildTargetRidOnly)' != ''">$(InnerBuildArgs) /p:DotNetBuildTargetRidOnly=$(DotNetBuildTargetRidOnly)</InnerBuildArgs>
<!-- Use a fresh clone of the repo so that source-build modifications are isolated. -->
<InnerBuildArgs>$(InnerBuildArgs) /p:RepoRoot="$(InnerSourceBuildRepoRoot)$(_DirSeparatorEscapedCharForExecArg)"</InnerBuildArgs>
<!-- Override the artifacts dir to cleanly separate the inner build from outer build. -->
Expand Down
Loading