Skip to content

Commit

Permalink
Use implicit package reference for ILC build package (#28690)
Browse files Browse the repository at this point in the history
This removes the bundled ILCompiler bits from the SDK, and
instead uses implicit PackageReference to import targets that
correctly match the ILCompiler package version.

Also adds validation that the explict PackageReference scenario
uses the expected ILCompiler host and target bits. It doesn't
include 8.0 tests.
  • Loading branch information
sbomer authored Oct 26, 2022
1 parent 5c54021 commit dac29ee
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 29 deletions.
5 changes: 0 additions & 5 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@
<Sha>4db6ac94ffa8bf6dae8ad9c5c68f94b58de917fd</Sha>
<SourceBuild RepoName="linker" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.DotNet.ILCompiler" Version="8.0.0-alpha.1.22524.5">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>5108757b997c59ab8ba1fc5309ab0d4e730e2b77</Sha>
<SourceBuildTarball RepoName="runtime" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.NET.ILLink.Analyzers" Version="7.0.100-1.22525.3">
<Uri>https://github.com/dotnet/linker</Uri>
<Sha>4db6ac94ffa8bf6dae8ad9c5c68f94b58de917fd</Sha>
Expand Down
1 change: 0 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
<SystemCodeDomPackageVersion>8.0.0-alpha.1.22524.5</SystemCodeDomPackageVersion>
<SystemTextEncodingCodePagesPackageVersion>8.0.0-alpha.1.22524.5</SystemTextEncodingCodePagesPackageVersion>
<SystemResourcesExtensionsPackageVersion>8.0.0-alpha.1.22524.5</SystemResourcesExtensionsPackageVersion>
<MicrosoftDotNetILCompilerPackageVersion>8.0.0-alpha.1.22524.5</MicrosoftDotNetILCompilerPackageVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/dotnet/format -->
Expand Down
1 change: 0 additions & 1 deletion src/Layout/redist/targets/BundledSdks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
<BundledSdk Include="FSharp.NET.Sdk" Version="1.0.4-bundled-0100" />
<BundledSdk Include="Microsoft.Docker.Sdk" Version="1.1.0" />
<BundledSdk Include="Microsoft.NET.ILLink.Tasks" Version="$(MicrosoftNETILLinkTasksPackageVersion)" />
<BundledSdk Include="Microsoft.DotNet.ILCompiler" Version="$(MicrosoftDotNetILCompilerPackageVersion)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public class ProcessFrameworkReferences : TaskBase
[Output]
public ITaskItem[] TargetILCompilerPacks { get; set; }

[Output]
public ITaskItem[] ImplicitPackageReferences { get; set; }

// Runtime packs which aren't available for the specified RuntimeIdentifier
[Output]
public ITaskItem[] UnavailableRuntimePacks { get; set; }
Expand Down Expand Up @@ -621,6 +624,9 @@ private bool AddAotOrR2RRuntimePackage(AotPackageType packageType, Version norma
else
{
HostILCompilerPacks = new[] { newItem };
var ilCompilerBuildPackageReference = new TaskItem(knownPack.ItemSpec);
ilCompilerBuildPackageReference.SetMetadata(MetadataKeys.Version, packVersion);
ImplicitPackageReferences = new[] { ilCompilerBuildPackageReference };
// ILCompiler supports cross target compilation. If there is a cross-target request, we need to download that package as well
// We expect RuntimeIdentifier to be defined during publish but can allow during build
if (RuntimeIdentifier != null)
Expand All @@ -633,17 +639,13 @@ private bool AddAotOrR2RRuntimePackage(AotPackageType packageType, Version norma
if (!hostRuntimeIdentifier.Equals(targetRuntimeIdentifier))
{
var runtimeIlcPackName = packPattern.Replace("**RID**", targetRuntimeIdentifier);
TaskItem targetIlcPackToDownload = new TaskItem(runtimeIlcPackName);
targetIlcPackToDownload.SetMetadata(MetadataKeys.Version, packVersion);
packagesToDownload.Add(targetIlcPackToDownload);

var newItem2 = new TaskItem(runtimeIlcPackName);
newItem2.SetMetadata(MetadataKeys.NuGetPackageId, runtimeIlcPackName);
newItem2.SetMetadata(MetadataKeys.NuGetPackageVersion, packVersion);
TargetILCompilerPacks = new[] { newItem2 };
}
}
}
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
***********************************************************************************************
Microsoft.NET.Sdk.FrameworkReferenceResolution.targets
Expand Down Expand Up @@ -123,6 +123,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<Output TaskParameter="HostILCompilerPacks" ItemName="HostILCompilerPack" />
<Output TaskParameter="TargetILCompilerPacks" ItemName="TargetILCompilerPack" />
<Output TaskParameter="UnavailableRuntimePacks" ItemName="UnavailableRuntimePack" />
<Output TaskParameter="ImplicitPackageReferences" ItemName="_ImplicitPackageReference" />

</ProcessFrameworkReferences>

Expand Down Expand Up @@ -175,6 +176,14 @@ Copyright (c) .NET Foundation. All rights reserved.
PrivateAssets="all"
ExcludeAssets="all" />
</ItemGroup>

<!-- Add implicit package references that don't already exist in PackageReference. -->
<ItemGroup>
<_ImplicitPackageReference Remove="@(PackageReference)" />
<PackageReference Include="@(_ImplicitPackageReference)"
IsImplicitlyDefined="true"
PrivateAssets="all" />
</ItemGroup>
</Target>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.CSharp.props" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.VisualBasic.props" Condition="'$(MSBuildProjectExtension)' == '.vbproj'" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.FSharp.props" Condition="'$(MSBuildProjectExtension)' == '.fsproj'" />
<Import Project="Sdk.props" Sdk="Microsoft.DotNet.ILCompiler" />
<Import Project="Sdk.props" Sdk="Microsoft.NET.ILLink.Tasks" />

<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.PackTool.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1158,11 +1158,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<ProjectCapability Remove="ReferenceManagerAssemblies" />
</ItemGroup>

<!-- Temporary workaround for https://github.com/dotnet/runtime/issues/75468. Delete once the issue is fixed. -->
<PropertyGroup>
<LinkStandardCPlusPlusLibrary Condition="'$(OS)' != 'Windows_NT' and '$(LinkStandardCPlusPlusLibrary)' == ''">true</LinkStandardCPlusPlusLibrary>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DisableStandardFrameworkResolution.targets" Condition="'$(DisableStandardFrameworkResolution)' == 'true'" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DesignerSupport.targets" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.GenerateAssemblyInfo.targets" Condition="'$(UsingNETSdkDefaults)' == 'true'"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class GivenThatWeWantToPublishAnAotApp : SdkTest
{
private readonly string RuntimeIdentifier = $"/p:RuntimeIdentifier={RuntimeInformation.RuntimeIdentifier}";

private readonly string ExplicitPackageVersion = "7.0.0-rc.2.22456.11";

public GivenThatWeWantToPublishAnAotApp(ITestOutputHelper log) : base(log)
{
}
Expand Down Expand Up @@ -272,7 +274,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string
testProject.AdditionalProperties["PublishAot"] = "true";

// This will add a reference to a package that will also be automatically imported by the SDK
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));

// Linux symbol files are embedded and require additional steps to be stripped to a separate file
// assumes /bin (or /usr/bin) are in the PATH
Expand All @@ -282,7 +284,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string
}
var testAsset = _testAssetsManager.CreateTestProject(testProject);

var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));
var publishCommand= new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));
publishCommand
.Execute($"/p:RuntimeIdentifier={rid}")
.Should().Pass()
Expand All @@ -307,6 +309,8 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string
var command = new RunExeCommand(Log, publishedExe)
.Execute().Should().Pass()
.And.HaveStdOutContaining("Hello World");

CheckIlcVersions(Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, ExplicitPackageVersion);
}
}

Expand All @@ -322,7 +326,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_empty(string t
var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true);

// This will add a reference to a package that will also be automatically imported by the SDK
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));

// Linux symbol files are embedded and require additional steps to be stripped to a separate file
// assumes /bin (or /usr/bin) are in the PATH
Expand Down Expand Up @@ -373,7 +377,6 @@ public void NativeAot_hw_runs_with_cross_target_PublishAot_is_enabled(string tar
var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}");
File.Exists(publishedDll).Should().BeFalse();
File.Exists(publishedExe).Should().BeTrue();

}
}

Expand All @@ -391,8 +394,8 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled(
testProject.AdditionalProperties["PublishAot"] = "true";

// This will add a reference to a package that will also be automatically imported by the SDK
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));
testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));

var testAsset = _testAssetsManager.CreateTestProject(testProject);

Expand All @@ -409,6 +412,8 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled(
var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}");
File.Exists(publishedDll).Should().BeFalse();
File.Exists(publishedExe).Should().BeTrue();

CheckIlcVersions(Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, ExplicitPackageVersion);
}
}

Expand All @@ -424,8 +429,8 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st
var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true);

// This will add a reference to a package that will also be automatically imported by the SDK
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));
testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));

var testAsset = _testAssetsManager.CreateTestProject(testProject);

Expand All @@ -438,7 +443,6 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(st
var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName;
var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll");
File.Exists(publishedDll).Should().BeTrue();

}
}

Expand Down Expand Up @@ -476,7 +480,7 @@ public void NativeAot_hw_fails_with_sdk6_PackageReference_PublishAot_is_enabled(
var testProject = CreateHelloWorldTestProject("net6.0", projectName, true);
testProject.AdditionalProperties["PublishAot"] = "true";

testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-rc.2.22456.11"));
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", ExplicitPackageVersion));

var testAsset = _testAssetsManager.CreateTestProject(testProject);

Expand Down Expand Up @@ -700,6 +704,30 @@ public void It_publishes_with_implicit_rid_with_NativeAotApp(string targetFramew
}
}

private void CheckIlcVersions(string projectPath, string targetFramework, string expectedVersion)
{
// Compiler version matches expected version
var ilcToolsPathCommand = new GetValuesCommand(Log, projectPath, targetFramework, "IlcToolsPath")
{
DependsOnTargets = "WriteIlcRspFileForCompilation"
};
ilcToolsPathCommand.Execute().Should().Pass();
var ilcToolsPath = ilcToolsPathCommand.GetValues()[0];
var ilcVersion = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(ilcToolsPath)));
ilcVersion.Should().Be(ExplicitPackageVersion);

// Compilation references (corelib) match expected version
var ilcReferenceCommand = new GetValuesCommand(Log, projectPath, targetFramework, "IlcReference", GetValuesCommand.ValueType.Item)
{
DependsOnTargets = "WriteIlcRspFileForCompilation"
};
ilcReferenceCommand.Execute().Should().Pass();
var ilcReference = ilcReferenceCommand.GetValues();
var corelibReference = ilcReference.Where(r => Path.GetFileName(r).Equals("System.Private.CoreLib.dll")).Single();
var ilcReferenceVersion = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(corelibReference)));
ilcReferenceVersion.Should().Be(ExplicitPackageVersion);
}

private TestProject CreateHelloWorldTestProject(string targetFramework, string projectName, bool isExecutable)
{
var testProject = new TestProject()
Expand Down

0 comments on commit dac29ee

Please sign in to comment.