Restore IBC data and embed during Windows release builds
authorEric St. John <ericstj@microsoft.com>
Wed, 20 Feb 2019 00:35:49 +0000 (16:35 -0800)
committerEric StJohn <ericstj@microsoft.com>
Thu, 21 Feb 2019 21:08:34 +0000 (13:08 -0800)
See the following docs.
https://github.com/dotnet/arcade/blob/dotnet/corefx@bac85242024ba867b6204b90c1522793093f5e31/Documentation/ArcadeSdk.md#ibc-optimization-data-embedding

We are using IBC data produced by our perf team and embedding into all builds of a DLL;
currently we don't distinguish cross-compiles of the same DLL, nor does arcade define any
conventions to do so.  I've disabled it for references and not-supported assemblies.

Commit migrated from https://github.com/dotnet/corefx/commit/96661fad0e63a7869539fa0981c8b8be2f3824d3

eng/codeOptimization.targets [new file with mode: 0644]
eng/depProj.targets
eng/dependencies.props
src/libraries/build.proj
src/libraries/external/Directory.Build.props
src/libraries/external/dir.proj
src/libraries/external/netstandard/netstandard.depproj
src/libraries/external/optimizationData/Configurations.props [new file with mode: 0644]
src/libraries/external/optimizationData/optimizationData.depproj [new file with mode: 0644]
src/libraries/pkg/Directory.Build.targets

diff --git a/eng/codeOptimization.targets b/eng/codeOptimization.targets
new file mode 100644 (file)
index 0000000..39bb002
--- /dev/null
@@ -0,0 +1,19 @@
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+
+  <PropertyGroup Condition="'$(ApplyPartialNgenOptimization)' == ''">
+     <ApplyPartialNgenOptimization Condition="'$(IsReferenceAssembly)' == 'true'">false</ApplyPartialNgenOptimization>
+     <ApplyPartialNgenOptimization Condition="'$(GeneratePlatformNotSupportedAssembly)' == 'true' OR '$(GeneratePlatformNotSupportedAssemblyMessage)' != ''">false</ApplyPartialNgenOptimization>
+  </PropertyGroup>
+
+  <Target Name="SetApplyPartialNgenOptimization"
+          Condition="'$(ApplyPartialNgenOptimization)' == ''"
+          BeforeTargets="CoreCompile">
+    <ItemGroup>
+      <_optimizationDataAssembly Include="$(IbcOptimizationDataDir)**\$(TargetFileName)" />
+    </ItemGroup>
+    <PropertyGroup>
+      <ApplyPartialNgenOptimization Condition="'@(_optimizationDataAssembly)' != ''">true</ApplyPartialNgenOptimization>
+    </PropertyGroup>
+  </Target>
+
+</Project>
\ No newline at end of file
index d032988..65837df 100644 (file)
@@ -100,7 +100,7 @@ See the LICENSE file in the project root for more information.
     </ItemGroup>
 
     <Error Condition="'@(NuGetDeploy)' == ''" Text="Error no assets were resolved from NuGet packages." />
-    <Message Importance="High" Text="%(FullPath) (%(NuGetPackageId).%(NuGetPackageVersion)) -&gt; @(NuGetDeploy->'$(TargetDir)%(FileName)%(Extension)')" />
+    <Message Importance="High" Text="%(FullPath) (%(NuGetPackageId).%(NuGetPackageVersion)) -&gt; @(NuGetDeploy->'$(TargetDir)%(SubFolder)%(FileName)%(Extension)')" />
 
     <!-- Include marker files if an extension has been provided -->
     <!-- internal builds use this to distinguish files which have already been signed -->
index 511e864..8dcdc42 100644 (file)
@@ -23,6 +23,9 @@
 
     <!-- SNI runtime package -->
     <RuntimeWinX64RuntimeNativeSystemDataSqlClientSniPackageVersion>4.4.0</RuntimeWinX64RuntimeNativeSystemDataSqlClientSniPackageVersion>
+
+    <CoreFxOptimizationDataPackageId>optimization.windows_nt-x64.IBC.CoreFx</CoreFxOptimizationDataPackageId>
+    <CoreFxOptimizationDataPackageId Condition="'$(IBCTarget)'=='Linux'">optimization.linux-x64.IBC.CoreFx</CoreFxOptimizationDataPackageId>
   </PropertyGroup>
 
   <!-- Tests/infrastructure dependency versions. -->
     <CoverletConsolePackageVersion>1.4.0</CoverletConsolePackageVersion>
     <DotNetReportGeneratorGlobalToolPackageVersion>4.0.5</DotNetReportGeneratorGlobalToolPackageVersion>
 
-    <!-- Roslyn optimization data package version -->
     <MicrosoftDotNetIBCMergePackageVersion>4.6.0-alpha-00001</MicrosoftDotNetIBCMergePackageVersion>
     <TestILCAmd64retPackageVersion>$(ProjectNTfsTestILCPackageVersion)</TestILCAmd64retPackageVersion>
     <TestILCArmretPackageVersion>$(ProjectNTfsTestILCPackageVersion)</TestILCArmretPackageVersion>
     <TestILCX86retPackageVersion>$(ProjectNTfsTestILCPackageVersion)</TestILCX86retPackageVersion>
-    <OptimizationDataVersion>2.0.0-rc-61101-17</OptimizationDataVersion>
     <CoreFxOptimizationDataVersion>99.99.99-master-20190221.1</CoreFxOptimizationDataVersion>
   </PropertyGroup>
 
index 6445761..6e23026 100644 (file)
@@ -22,7 +22,7 @@
 
   <Import Project="Directory.Build.targets" />
 
-  <Target Name="Restore" DependsOnTargets="GenerateConfigurationProps;RestoreOptimizationDataPackage">
+  <Target Name="Restore" DependsOnTargets="GenerateConfigurationProps">
     <ItemGroup>
       <_RestoreProjects Include="external\dir.proj" />
     </ItemGroup>
index f807f83..5971cb9 100644 (file)
@@ -5,6 +5,7 @@
     <!-- We need configuration-specific assets files. -->
     <RestoreOutputPath>$(IntermediateOutputPath)</RestoreOutputPath>
     <ProjectAssetsFile>$(RestoreOutputPath)/project.assets.json</ProjectAssetsFile>
+    <MSBuildProjectExtensionsPath>$(IntermediateOutputPath)</MSBuildProjectExtensionsPath>
     <!-- let us control the output path -->
     <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
   </PropertyGroup>
index 74ea96f..2f388b2 100644 (file)
@@ -17,6 +17,7 @@
     <Project Include="harvestPackages/harvestPackages.depproj" />
     <Project Include="binplacePackages/binplacePackages.depproj" />
     <Project Include="docs/docs.depproj" Condition="'$(DotNetBuildFromSource)' != 'true'" />
+    <Project Include="optimizationData/optimizationData.depproj" Condition="'$(EnablePartialNgenOptimization)' == 'true' AND '$(DotNetBuildFromSource)' != 'true'" />
     <Project Condition="'$(ILLinkTrimAssembly)' != 'false'" Include="ILLink/ILLink.depproj" />
   </ItemGroup>
 
index efc29e5..3827443 100644 (file)
@@ -10,7 +10,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="NETStandard.Library">
+    <PackageReference Include="NETStandard.Library" ExcludeAssets="Build">
       <Version>$(NETStandardLibraryPackageVersion)</Version>
     </PackageReference>
   </ItemGroup>
diff --git a/src/libraries/external/optimizationData/Configurations.props b/src/libraries/external/optimizationData/Configurations.props
new file mode 100644 (file)
index 0000000..c398e42
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <BuildConfigurations>
+      netstandard;
+    </BuildConfigurations>
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/libraries/external/optimizationData/optimizationData.depproj b/src/libraries/external/optimizationData/optimizationData.depproj
new file mode 100644 (file)
index 0000000..f4f6347
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <RestoreSources>
+      https://dotnet.myget.org/F/dotnet-core-optimization-data/api/v3/index.json;
+      $(RestoreSources);
+    </RestoreSources>
+    <!-- Copy to IBC directory -->
+    <OutputPath>$(IbcOptimizationDataDir)</OutputPath>
+    <EnableBinPlacing>false</EnableBinPlacing>
+  </PropertyGroup>
+  <ItemGroup>
+    <!-- IBC data -->
+    <IBCPackage Include="$(CoreFxOptimizationDataPackageId)" Version="$(CoreFxOptimizationDataVersion)" AddDirectory="true" />
+    <PackageReference Include="@(IBCPackage)" GeneratePathProperty="true" />
+  </ItemGroup>
+  
+  <!-- IBC data packages don't follow NuGet conventions, so grab the contents
+       using the NuGet-generated-property that points to the restored package.  -->
+  <Target Name="GetIBCData"
+          Inputs="%(IBCPackage.Identity)"
+          Outputs="unused"
+          AfterTargets="ResolveReferences">
+    <ItemGroup>
+      <IBCPackage>
+        <!-- Assign metadata using the nuget convention for property naming -->
+        <PropertyName>Pkg$([System.String]::new('%(IBCPackage.Identity)').Replace('.', '_'))</PropertyName>
+      </IBCPackage>
+    </ItemGroup>
+    <PropertyGroup>
+      <!-- evaluate the package property -->
+      <_ibcPkgSrc>$(%(IBCPackage.PropertyName))</_ibcPkgSrc>
+      <_ibcPkgDest>%(IBCPackage.Identity)</_ibcPkgDest>
+      <_includeFileDir>%(IBCPackage.AddDirectory)</_includeFileDir>
+    </PropertyGroup>
+
+    <Error Condition="!Exists('$(_ibcPkgSrc)')" Text="Package '%(IBCPackage.Identity)' was not restored!" />
+
+    <ItemGroup>
+      <_optimizationDataSourceFile Include="$(_ibcPkgSrc)\**\*.dll;$(_ibcPkgSrc)\**\*.ibc" 
+                                   NuGetPackageId="%(IBCPackage.Identity)"
+                                   NuGetPackageVersion="%(IBCPackage.Version)" />
+      <_optimizationDataSourceFile SubFolder="$(_ibcPkgDest)\%(RecursiveDir)" />
+      <_optimizationDataSourceFile Condition="'$(_includeFileDir)' == 'true'" SubFolder="%(SubFolder)%(FileName).dll\" />
+      <ReferenceCopyLocalPaths Include="@(_optimizationDataSourceFile)" />
+    </ItemGroup>
+  </Target>
+
+</Project>
\ No newline at end of file
index 568cdb3..6d1a644 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="14.0" InitialTargets="CheckForBuildTools" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
   <Import Condition="'$(IsFrameworkPackage)' == 'true'" Project="frameworkPackage.targets" />