Skip to content

Commit a27945a

Browse files
committed
Merge branch 'CleanPublishAot' of https://github.com/LakshanF/sdk into CleanPublishAot
2 parents 2685ee9 + 0631fac commit a27945a

File tree

3 files changed

+159
-2
lines changed

3 files changed

+159
-2
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ public class ProcessFrameworkReferences : TaskBase
9999
public ITaskItem[] Crossgen2Packs { get; set; }
100100

101101
[Output]
102-
public ITaskItem[] ILCompilerPacks { get; set; }
102+
public ITaskItem[] ILCompilerPacks { get; set; }
103+
104+
[Output]
105+
public ITaskItem[] ILCompilerPacks2 { get; set; }
103106

104107
// Runtime packs which aren't available for the specified RuntimeIdentifier
105108
[Output]
@@ -618,6 +621,20 @@ private bool AddAotOrR2RRuntimePackage(AotPackageType packageType, Version norma
618621
else
619622
{
620623
ILCompilerPacks = new[] { newItem };
624+
// ILCompiler supports cross target compilation. If there is a cross-target request, we need to download that package as well
625+
var targetsRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, RuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph2);
626+
if (!hostRuntimeIdentifier.Equals(targetsRuntimeIdentifier))
627+
{
628+
var runtimeIlcPackName = packPattern.Replace("**RID**", targetsRuntimeIdentifier);
629+
TaskItem runtime2PackToDownload = new TaskItem(runtimeIlcPackName);
630+
runtime2PackToDownload.SetMetadata(MetadataKeys.Version, packVersion);
631+
packagesToDownload.Add(runtime2PackToDownload);
632+
633+
var newItem2 = new TaskItem(runtimeIlcPackName);
634+
newItem2.SetMetadata(MetadataKeys.NuGetPackageId, runtimeIlcPackName);
635+
newItem2.SetMetadata(MetadataKeys.NuGetPackageVersion, packVersion);
636+
ILCompilerPacks2 = new[] { newItem2 };
637+
}
621638
}
622639

623640
return true;

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Copyright (c) .NET Foundation. All rights reserved.
121121
<Output TaskParameter="RuntimePacks" ItemName="RuntimePack" />
122122
<Output TaskParameter="Crossgen2Packs" ItemName="Crossgen2Pack" />
123123
<Output TaskParameter="ILCompilerPacks" ItemName="ILCompilerPack" />
124+
<Output TaskParameter="ILCompilerPacks2" ItemName="ILCompilerPack2" />
124125
<Output TaskParameter="UnavailableRuntimePacks" ItemName="UnavailableRuntimePack" />
125126

126127
</ProcessFrameworkReferences>
@@ -257,7 +258,14 @@ Copyright (c) .NET Foundation. All rights reserved.
257258

258259
<Output TaskParameter="Output" ItemName="ResolvedILCompilerPack" />
259260
</GetPackageDirectory>
260-
261+
262+
<GetPackageDirectory
263+
Items="@(ILCompilerPack2)"
264+
PackageFolders="@(AssetsFilePackageFolder)">
265+
266+
<Output TaskParameter="Output" ItemName="ResolvedILCompilerPack2" />
267+
</GetPackageDirectory>
268+
261269
<GetPackageDirectory
262270
Items="@(PackAsToolShimAppHostPack)"
263271
PackageFolders="@(AssetsFilePackageFolder)">

src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,41 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string
7878
}
7979
}
8080

81+
[RequiresMSBuildVersionTheory("17.0.0.32901")]
82+
[InlineData(ToolsetInfo.CurrentTargetFramework)]
83+
public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_false(string targetFramework)
84+
{
85+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
86+
{
87+
var projectName = "HellowWorldNativeAotApp";
88+
var rid = EnvironmentInfo.GetCompatibleRid(targetFramework);
89+
90+
var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true);
91+
testProject.AdditionalProperties["PublishAot"] = "false";
92+
var testAsset = _testAssetsManager.CreateTestProject(testProject);
93+
94+
var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));
95+
publishCommand
96+
.Execute($"/p:RuntimeIdentifier={rid}")
97+
.Should().Pass()
98+
.And.NotHaveStdOutContaining("IL2026")
99+
.And.NotHaveStdErrContaining("NETSDK1179")
100+
.And.NotHaveStdErrContaining("warning");
101+
102+
var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName;
103+
var sharedLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" : ".so";
104+
var publishedDll = Path.Combine(publishDirectory, $"{projectName}{sharedLibSuffix}");
105+
var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}");
106+
107+
// PublishAot=false will be a normal publish
108+
File.Exists(publishedDll).Should().BeTrue();
109+
110+
var command = new RunExeCommand(Log, publishedExe)
111+
.Execute().Should().Pass()
112+
.And.HaveStdOutContaining("Hello World");
113+
}
114+
}
115+
81116
[RequiresMSBuildVersionTheory("17.0.0.32901")]
82117
[InlineData(ToolsetInfo.CurrentTargetFramework)]
83118
public void NativeAot_app_runs_in_debug_with_no_config_when_PublishAot_is_enabled(string targetFramework)
@@ -274,6 +309,103 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string
274309
}
275310
}
276311

312+
[RequiresMSBuildVersionTheory("17.0.0.32901")]
313+
[InlineData(ToolsetInfo.CurrentTargetFramework)]
314+
public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_empty(string targetFramework)
315+
{
316+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
317+
{
318+
var projectName = "HellowWorldNativeAotApp";
319+
var rid = EnvironmentInfo.GetCompatibleRid(targetFramework);
320+
321+
var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true);
322+
323+
// This will add a reference to a package that will also be automatically imported by the SDK
324+
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-*"));
325+
326+
// Linux symbol files are embedded and require additional steps to be stripped to a separate file
327+
// assumes /bin (or /usr/bin) are in the PATH
328+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
329+
{
330+
testProject.AdditionalProperties["StripSymbols"] = "true";
331+
testProject.AdditionalProperties["ObjCopyName"] = "objcopy";
332+
}
333+
var testAsset = _testAssetsManager.CreateTestProject(testProject);
334+
335+
var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));
336+
publishCommand
337+
.Execute($"/p:RuntimeIdentifier={rid}")
338+
.Should().Pass();
339+
340+
var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName;
341+
var sharedLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" : ".so";
342+
var publishedDll = Path.Combine(publishDirectory, $"{projectName}{sharedLibSuffix}");
343+
var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}");
344+
var symbolSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".pdb" : ".dbg";
345+
var publishedDebugFile = Path.Combine(publishDirectory, $"{testProject.Name}{symbolSuffix}");
346+
347+
// NativeAOT published dir should not contain a non-host stand alone package
348+
File.Exists(publishedDll).Should().BeFalse();
349+
// The exe exist and should be native
350+
File.Exists(publishedExe).Should().BeTrue();
351+
File.Exists(publishedDebugFile).Should().BeTrue();
352+
IsNativeImage(publishedExe).Should().BeTrue();
353+
354+
var command = new RunExeCommand(Log, publishedExe)
355+
.Execute().Should().Pass()
356+
.And.HaveStdOutContaining("Hello World");
357+
}
358+
}
359+
360+
[RequiresMSBuildVersionTheory("17.0.0.32901")]
361+
[InlineData(ToolsetInfo.CurrentTargetFramework)]
362+
public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled(string targetFramework)
363+
{
364+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64))
365+
{
366+
var projectName = "HellowWorldNativeAotApp";
367+
var rid = "win-arm64";
368+
369+
var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true);
370+
testProject.AdditionalProperties["PublishAot"] = "true";
371+
372+
// This will add a reference to a package that will also be automatically imported by the SDK
373+
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-*"));
374+
testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", "7.0.0-*"));
375+
376+
var testAsset = _testAssetsManager.CreateTestProject(testProject);
377+
378+
var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));
379+
publishCommand
380+
.Execute($"/p:RuntimeIdentifier={rid}")
381+
.Should().Pass();
382+
}
383+
}
384+
385+
[RequiresMSBuildVersionTheory("17.0.0.32901")]
386+
[InlineData(ToolsetInfo.CurrentTargetFramework)]
387+
public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty(string targetFramework)
388+
{
389+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64))
390+
{
391+
var projectName = "HellowWorldNativeAotApp";
392+
var rid = "win-arm64";
393+
394+
var testProject = CreateHelloWorldTestProject(targetFramework, projectName, true);
395+
396+
// This will add a reference to a package that will also be automatically imported by the SDK
397+
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.DotNet.ILCompiler", "7.0.0-*"));
398+
testProject.PackageReferences.Add(new TestPackageReference("runtime.win-x64.Microsoft.DotNet.ILCompiler", "7.0.0-*"));
399+
400+
var testAsset = _testAssetsManager.CreateTestProject(testProject);
401+
402+
var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));
403+
publishCommand
404+
.Execute($"/p:RuntimeIdentifier={rid}")
405+
.Should().Pass();
406+
}
407+
}
408+
277409
[RequiresMSBuildVersionTheory("17.0.0.32901")]
278410
[InlineData(ToolsetInfo.CurrentTargetFramework)]
279411
public void Only_Aot_warnings_are_produced_if_EnableAotAnalyzer_is_set(string targetFramework)

0 commit comments

Comments
 (0)