Skip to content

Commit

Permalink
Use shipping runtime.json for RID targeting (#80074)
Browse files Browse the repository at this point in the history
* Use shipping runtime.json for RID targeting

- Use the shipping runtime.json file to target RIDs when building
  instead of the custom OSGroups.json which only contained a subset of
  the available rids.
- To facilitate that, lower-case the existing platforms in the target
  frameworks strings which is the expected format anyway by the SDK and
  msbuild. This will eventually make it possible to bring some of the
  custom build infrastructure back into the SDK.
- Remove a few outdated code pieces and update docs.
  • Loading branch information
ViktorHofer committed Jan 2, 2023
1 parent 88dd8c7 commit 212fb54
Show file tree
Hide file tree
Showing 106 changed files with 307 additions and 366 deletions.
12 changes: 6 additions & 6 deletions docs/coding-guidelines/project-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Non cross-targeting project that targets .NETStandard:
A cross-targeting project which targets specific platform with `$(NetCoreAppCurrent)` and one .NETFramework tfm:
```
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetFrameworkMinimum)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetFrameworkMinimum)</TargetFrameworks>
<PropertyGroup>
```

Expand Down Expand Up @@ -103,17 +103,17 @@ Example:
Example:
```
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">...</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'OSX'">...</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'osx'">...</ItemGroup>
```
Important: In contrast to the old `Targets*` checks, `TargetPlatformIdentifier` conditions apply to a single tfm only, inheritance between target frameworks can't be expressed. See the example below for Unix:
```
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-android;$(NetCoreAppCurrent)-windows</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-android;$(NetCoreAppCurrent)-windows</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'Unix' or '$(TargetPlatformIdentifier)' == 'Linux' or '$(TargetPlatformIdentifier)' == 'android'">...</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'unix' or '$(TargetPlatformIdentifier)' == 'linux' or '$(TargetPlatformIdentifier)' == 'android'">...</ItemGroup>
<!-- Negations make such conditions easier to write and read. -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'windows'">...</ItemGroup>
```
Expand Down Expand Up @@ -190,7 +190,7 @@ All test outputs should be under
In the gen directory any source generator related to the assembly should exist. This does not mean the source generator is only used for that assembly only that it is conceptually apart of that assembly. For example, the assembly may provide attributes or low-level types the source generator uses.
To consume a source generator, simply add a `<ProjectReference Include="..." ReferenceOutputAssembly="false" OutputItemType="Analyzer" />` item to the project, usually next to the `Reference` and `ProjectReference` items.

A source generator must target `netstandard2.0` as such assemblies are loaded into the compiler's process which might run on either .NET Framework or modern .NET depending on the tooling being used (CLI vs Visual Studio). While that's true, a source project can still multi-target and include `$(NetCoreAppToolCurrent)` (which is the latest non live-built .NETCoreApp tfm that is supported by the SDK) to benefit from the ehancanced nullable reference type warnings emitted by the compiler. For an example see [System.Text.Json's roslyn4.4 source generator](/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.Roslyn4.4.csproj). While the repository's infrastructure makes sure that only the source generator's `netstandard2.0` build output is included in packages, to consume such a multi-targeting source generator via a `ProjectReference` (as described above), you need to add the `ReferringTargetFramework=netstandard2.0` metadata to the ProjectReference item to guarantee that the netstandard2.0 asset is chosen.
A source generator must target `netstandard2.0` as such assemblies are loaded into the compiler's process which might run on either .NET Framework or modern .NET depending on the tooling being used (CLI vs Visual Studio). While that's true, a source project can still multi-target and include `$(NetCoreAppToolCurrent)` (which is the latest non live-built .NETCoreApp tfm that is supported by the SDK) to benefit from the ehancanced nullable reference type warnings emitted by the compiler. For an example see [System.Text.Json's roslyn4.4 source generator](/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.Roslyn4.4.csproj). While the repository's infrastructure makes sure that only the source generator's `netstandard2.0` build output is included in packages, to consume such a multi-targeting source generator via a `ProjectReference` (as described above), you need to add the `SetTargetFramework="TargetFramework=netstandard2.0"` metadata to the ProjectReference item to guarantee that the netstandard2.0 asset is chosen.

## Facades
Facade are unique in that they don't have any code and instead are generated by finding a contract reference assembly with the matching identity and generating type forwards for all the types to where they live in the implementation assemblies (aka facade seeds). There are also partial facades which contain some type forwards as well as some code definitions. All the various build configurations should be contained in the one csproj file per library.
Expand Down
2 changes: 1 addition & 1 deletion eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>3003926e4126f827bca50d5b3ee179afc86d8a7b</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.Build.Tasks.TargetFramework" Version="8.0.0-beta.22621.1">
<Dependency Name="Microsoft.DotNet.Build.Tasks.TargetFramework" Version="8.0.0-beta.22630.1">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>3003926e4126f827bca50d5b3ee179afc86d8a7b</Sha>
</Dependency>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<MicrosoftDotNetBuildTasksArchivesVersion>8.0.0-beta.22621.1</MicrosoftDotNetBuildTasksArchivesVersion>
<MicrosoftDotNetBuildTasksInstallersVersion>8.0.0-beta.22621.1</MicrosoftDotNetBuildTasksInstallersVersion>
<MicrosoftDotNetBuildTasksPackagingVersion>8.0.0-beta.22621.1</MicrosoftDotNetBuildTasksPackagingVersion>
<MicrosoftDotNetBuildTasksTargetFrameworkVersion>8.0.0-beta.22621.1</MicrosoftDotNetBuildTasksTargetFrameworkVersion>
<MicrosoftDotNetBuildTasksTargetFrameworkVersion>8.0.0-beta.23052.2</MicrosoftDotNetBuildTasksTargetFrameworkVersion>
<MicrosoftDotNetBuildTasksTemplatingVersion>8.0.0-beta.22621.1</MicrosoftDotNetBuildTasksTemplatingVersion>
<MicrosoftDotNetBuildTasksWorkloadsPackageVersion>8.0.0-beta.22621.1</MicrosoftDotNetBuildTasksWorkloadsPackageVersion>
<MicrosoftDotNetRemoteExecutorVersion>8.0.0-beta.22621.1</MicrosoftDotNetRemoteExecutorVersion>
Expand Down
14 changes: 7 additions & 7 deletions eng/illink.targets
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@
Must be enabled by setting BinPlaceILLinkTrimAssembly=true
-->
<ItemGroup Condition="'$(BinPlaceILLinkTrimAssembly)' == 'true'">
<BinPlaceTargetFramework Include="$(NetCoreAppCurrentBuildSettings)">
<BinPlaceTargetFrameworks Include="$(NetCoreAppCurrentBuildSettings)">
<RuntimePath>$(ILLinkTrimAssemblyArtifactsRootDir)trimmed</RuntimePath>
<ItemName>TrimmedItem</ItemName>
</BinPlaceTargetFramework>
<BinPlaceTargetFramework Include="$(NetCoreAppCurrentBuildSettings)">
</BinPlaceTargetFrameworks>
<BinPlaceTargetFrameworks Include="$(NetCoreAppCurrentBuildSettings)">
<RuntimePath>$(ILLinkTrimAssemblyArtifactsRootDir)reports</RuntimePath>
<ItemName>TrimmingReport</ItemName>
</BinPlaceTargetFramework>
<BinPlaceTargetFramework Include="$(NetCoreAppCurrentBuildSettings)">
</BinPlaceTargetFrameworks>
<BinPlaceTargetFrameworks Include="$(NetCoreAppCurrentBuildSettings)">
<RuntimePath>$(ILLinkTrimAssemblyArtifactsRootDir)pretrimmed</RuntimePath>
<ItemName>PreTrimmedItem</ItemName>
</BinPlaceTargetFramework>
</BinPlaceTargetFrameworks>
</ItemGroup>

<ItemGroup>
Expand All @@ -89,7 +89,7 @@
<RuntimePath>$(ILLinkTrimAssemblySuppressionsXmlsDir)</RuntimePath>
<ItemName>ILLinkSuppressionsXmls</ItemName>
</BinPlaceTargetFrameworks>
<BinPlaceTargetFrameworks Include="$(NetCoreAppCurrent)-$(TargetOS)">
<BinPlaceTargetFrameworks Include="$(NetCoreAppCurrent)-$(TargetOS.ToLowerInvariant())">
<RuntimePath>$(ILLinkTrimAssemblySuppressionsXmlsDir)</RuntimePath>
<ItemName>ILLinkSuppressionsXmls</ItemName>
</BinPlaceTargetFrameworks>
Expand Down
20 changes: 14 additions & 6 deletions eng/packaging.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<BeforePack>$(BeforePack);IncludeAnalyzersInPackage;AddNETStandardCompatErrorFileForPackaging</BeforePack>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);AddRuntimeSpecificFilesToPackage;IncludeProjectReferencesWithPackAttributeInPackage</TargetsForTfmSpecificContentInPackage>
<!-- Don't include target platform specific dependencies, since we use the target platform to represent RIDs instead -->
<IncludeBuildOutput Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">false</IncludeBuildOutput>
<SuppressDependenciesWhenPacking Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">true</SuppressDependenciesWhenPacking>
<IncludeBuildOutput Condition="'$(PackageUsePlatformTargeting)' != 'true' and '$(TargetPlatformIdentifier)' != '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">false</IncludeBuildOutput>
<SuppressDependenciesWhenPacking Condition="'$(PackageUsePlatformTargeting)' != 'true' and '$(TargetPlatformIdentifier)' != '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">true</SuppressDependenciesWhenPacking>
<PackageDesignerMarkerFile>$(MSBuildThisFileDirectory)useSharedDesignerContext.txt</PackageDesignerMarkerFile>
<PackageReadmeFile Condition="'$(PackageReadmeFile)' == '' and Exists('PACKAGE.md')">PACKAGE.md</PackageReadmeFile>
<!-- Generate packages for rid specific projects or for allconfigurations during build. -->
Expand All @@ -31,6 +31,8 @@
<!-- Search for the documentation file in the intellisense package and otherwise pick up the generated one. -->
<LibIntellisenseDocumentationFilePath>$(XmlDocFileRoot)1033\$(AssemblyName).xml</LibIntellisenseDocumentationFilePath>
<UseIntellisenseDocumentationFile Condition="'$(UseIntellisenseDocumentationFile)' == '' and Exists('$(LibIntellisenseDocumentationFilePath)')">true</UseIntellisenseDocumentationFile>
<!-- During NoBuild pack invocations, skip project reference build. Necessary for the IncludeProjectReferencesWithPackAttributeInPackage target. -->
<BuildProjectReferences Condition="'$(NoBuild)' == 'true'">false</BuildProjectReferences>
</PropertyGroup>

<PropertyGroup Condition="'$(PreReleaseVersionLabel)' == 'servicing' and
Expand Down Expand Up @@ -122,7 +124,8 @@
DocumentationProjectOutputGroup;
SatelliteDllsProjectOutputGroup;
$(TargetsForTfmSpecificBuildOutput)"
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
Condition="'$(PackageUsePlatformTargeting)' != 'true' and
'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
'$(TargetPlatformIdentifier)' != ''">
<PropertyGroup>
<RuntimeSymbolPath>$(TargetDir)$(TargetName).pdb</RuntimeSymbolPath>
Expand Down Expand Up @@ -244,14 +247,19 @@
<Target Name="IncludeProjectReferencesWithPackAttributeInPackage"
Condition="'@(ProjectReference)' != '' and @(ProjectReference->AnyHaveMetadataValue('Pack', 'true'))"
DependsOnTargets="BuildOnlySettings;ResolveReferences">
<PropertyGroup>
<_referringTargetFramework>$(TargetFramework)</_referringTargetFramework>
<_referringTargetFramework Condition="'$(PackageUsePlatformTargeting)' != 'true' and $(TargetFramework.Contains('-'))">$(TargetFramework.SubString(0, $(TargetFramework.IndexOf('-'))))</_referringTargetFramework>
</PropertyGroup>

<ItemGroup>
<!-- Add ReferenceCopyLocalPaths for ProjectReferences which are flagged as Pack="true" into the package. -->
<_projectReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('Pack', 'true'))" />
<TfmSpecificPackageFile Include="@(_projectReferenceCopyLocalPaths)"
PackagePath="$([MSBuild]::ValueOrDefault('%(ReferenceCopyLocalPaths.PackagePath)', '$(BuildOutputTargetFolder)\$(TargetFramework)\'))" />
PackagePath="$([MSBuild]::ValueOrDefault('%(ReferenceCopyLocalPaths.PackagePath)', '$(BuildOutputTargetFolder)\$(_referringTargetFramework)\'))" />
<TfmSpecificDebugSymbolsFile Include="@(TfmSpecificPackageFile->WithMetadataValue('Extension', '.pdb'))"
TargetPath="/%(TfmSpecificPackageFile.PackagePath)/%(Filename)%(Extension)"
TargetFramework="$(TargetFramework)"
TargetFramework="$(_referringTargetFramework)"
Condition="'$(IncludeSymbols)' == 'true'" />
<!-- Remove symbol from the non symbol package. -->
<TfmSpecificPackageFile Remove="@(TfmSpecificPackageFile->WithMetadataValue('Extension', '.pdb'))" />
Expand All @@ -264,7 +272,7 @@
<_referenceAssemblyPaths Include="@(_projectReferenceCopyLocalPaths->WithMetadataValue('Extension', '.dll')->WithMetadataValue('IncludeReferenceAssemblyInPackage', 'true')->Metadata('ReferenceAssembly'))" />
<_referenceAssemblyPaths Include="@(_projectReferenceCopyLocalPaths->WithMetadataValue('Extension', '.xml')->WithMetadataValue('IncludeReferenceAssemblyInPackage', 'true'))" />
<TfmSpecificPackageFile Include="@(_referenceAssemblyPaths)"
PackagePath="ref\$(TargetFramework)\" />
PackagePath="ref\$(_referringTargetFramework)\" />
</ItemGroup>
</Target>

Expand Down
12 changes: 10 additions & 2 deletions eng/resolveContract.targets
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@

<ItemGroup Condition="'$(HasMatchingContract)' == 'true' and '$(ContractProject)' != ''">
<ProjectReference Include="$(ContractProject)" ReferenceOutputAssembly="false" OutputItemType="ResolvedMatchingContract" />
<!-- We aren't referencing the contract, but make sure it's considered as an input to Compile so that if it changes we rebuild and rerun API compat -->
<ProjectReference Include="$(ContractProject)" ReferenceOutputAssembly="false" OutputItemType="CustomAdditionalCompileInputs" />
</ItemGroup>

<!-- We aren't referencing the contract, but make sure it's considered as an input to Compile so that if it changes we rebuild and rerun API compat -->
<Target Name="AddResolvedMatchingContractToCompileInput"
BeforeTargets="CoreCompile"
AfterTargets="ResolveProjectReferences"
Condition="'@(ResolvedMatchingContract)' != ''">
<ItemGroup>
<CustomAdditionalCompileInputs Include="@(ResolvedMatchingContract)" />
</ItemGroup>
</Target>

<!-- Allow P2Ps that target a source project to build against the corresponding ref project. -->
<Target Name="AnnotateTargetPathWithTargetPlatformMonikerWithReferenceAssembly"
Condition="'$(AnnotateTargetPathWithContract)' == 'true'"
Expand Down
10 changes: 5 additions & 5 deletions eng/versioning.targets
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</ItemGroup>
</Target>

<PropertyGroup Condition="'$(TargetPlatformIdentifier)' == '' and !$(TargetFrameworks.Contains('$(TargetFramework)-Browser'))">
<PropertyGroup Condition="'$(TargetPlatformIdentifier)' == '' and !$(TargetFrameworks.Contains('$(TargetFramework)-browser'))">
<CrossPlatformAndHasNoBrowserTarget>true</CrossPlatformAndHasNoBrowserTarget>
</PropertyGroup>

Expand All @@ -75,17 +75,17 @@
</ItemGroup>

<!-- Enables browser warnings for cross platform or Browser targeted builds -->
<ItemGroup Condition="('$(TargetPlatformIdentifier)' == 'Browser' or '$(CrossPlatformAndHasNoBrowserTarget)' == 'true') and '$(IsTestProject)' != 'true'">
<ItemGroup Condition="('$(TargetPlatformIdentifier)' == 'browser' or '$(CrossPlatformAndHasNoBrowserTarget)' == 'true') and '$(IsTestProject)' != 'true'">
<SupportedPlatform Include="browser"/>
</ItemGroup>

<!-- Add target platforms into MSBuild SupportedPlatform list -->
<ItemGroup Condition="'$(IsTestProject)' != 'true'">
<SupportedPlatform Condition="'$(TargetPlatformIdentifier)' == 'illumos'" Include="illumos" />
<SupportedPlatform Condition="'$(TargetPlatformIdentifier)' == 'Solaris'" Include="Solaris" />
<SupportedPlatform Condition="'$(TargetPlatformIdentifier)' == 'tvOS'" Include="tvOS" />
<SupportedPlatform Condition="'$(TargetPlatformIdentifier)' == 'solaris'" Include="Solaris" />
<SupportedPlatform Condition="'$(TargetPlatformIdentifier)' == 'tvos'" Include="tvOS" />
<SupportedPlatform Condition="'$(TargetPlatformIdentifier)' != '' and
'$(TargetPlatformIdentifier)' != 'Browser' and
'$(TargetPlatformIdentifier)' != 'browser' and
'$(TargetPlatformIdentifier)' != 'wasi' and
'$(TargetPlatformIdentifier)' != 'windows'" Include="Unix" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/Common/tests/Common.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-browser;$(NetCoreAppCurrent)-osx</TargetFrameworks>
<EnableLibraryImportGenerator>true</EnableLibraryImportGenerator>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -139,12 +139,12 @@
Link="System\PasteArguments.Unix.cs" />
</ItemGroup>
<!-- Linux specific files -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'Linux' or '$(TargetPlatformIdentifier)' == 'Browser'">
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'linux' or '$(TargetPlatformIdentifier)' == 'browser'">
<Compile Include="$(CommonPath)Interop\Linux\Interop.Libraries.cs"
Link="Common\Interop\Linux\Interop.Libraries.cs" />
</ItemGroup>
<!-- OSX specific files -->
<ItemGroup Condition=" '$(TargetPlatformIdentifier)' == 'OSX' ">
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'osx'">
<Compile Include="$(CommonPath)Interop\OSX\Interop.Libraries.cs"
Link="Common\Interop\OSX\Interop.Libraries.cs" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

<PropertyGroup>
<BeforeTargetFrameworkInferenceTargets>$(RepositoryEngineeringDir)BeforeTargetFrameworkInference.targets</BeforeTargetFrameworkInferenceTargets>
<RuntimeGraph>$(LibrariesProjectRoot)OSGroups.json</RuntimeGraph>
<ShouldUnsetParentConfigurationAndPlatform>false</ShouldUnsetParentConfigurationAndPlatform>
<GeneratePlatformNotSupportedAssemblyHeaderFile>$(RepositoryEngineeringDir)LicenseHeader.txt</GeneratePlatformNotSupportedAssemblyHeaderFile>
</PropertyGroup>
Expand Down
Loading

0 comments on commit 212fb54

Please sign in to comment.