Use SDK NativeCompile hook for ILC publish integration#125629
Use SDK NativeCompile hook for ILC publish integration#125629sbomer wants to merge 6 commits intodotnet:mainfrom
Conversation
…ILC publish integration Redefine the SDK's empty NativeCompile placeholder target with the actual NativeAOT compilation pipeline, replacing the fragile BeforeTargets/AfterTargets hooks that previously sequenced ILC into the publish flow. - Rename ComputeLinkedFilesToPublish to NativeCompile in Publish.targets, removing AfterTargets="ComputeResolvedFilesToPublishList" - Remove BeforeTargets="Publish" from SetupProperties, ComputeIlcCompileInputs, and ImportRuntimeIlcPackageTarget (all reachable via DependsOnTargets chains) - Keep empty ComputeLinkedFilesToPublish and CopyNativeBinary for back-compat
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
There was a problem hiding this comment.
Pull request overview
This PR updates NativeAOT publish integration to use the .NET SDK’s NativeCompile hook as the primary publish pipeline entry point, replacing prior sequencing via BeforeTargets/AfterTargets to make ordering more explicit and less fragile.
Changes:
- Redefines the SDK
NativeCompileplaceholder target to run the NativeAOT pipeline and updateResolvedFileToPublish. - Renames the prior publish hook target (
ComputeLinkedFilesToPublish) out of the execution path and keeps it as an empty back-compat target. - Removes
BeforeTargets="Publish"from several targets, relying onDependsOnTargetschains instead.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets | Removes BeforeTargets="Publish" from SetupProperties and ComputeIlcCompileInputs, relying on dependency chains to run them when needed. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets | Implements NativeAOT publish integration by redefining NativeCompile; adds empty ComputeLinkedFilesToPublish for compatibility. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets | Removes BeforeTargets="Publish" from ImportRuntimeIlcPackageTarget, relying on dependency chains. |
src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Refactors NativeAOT publish integration to use the .NET SDK’s NativeCompile hook (instead of BeforeTargets/AfterTargets-based sequencing) so the ILC + native link pipeline runs at an explicit, stable point in the publish target graph.
Changes:
- Replaces the previous
ComputeLinkedFilesToPublishpublish hook with an implementation ofNativeCompilethat runs NativeAOT compilation and updatesResolvedFileToPublish. - Removes
BeforeTargets="Publish"from several preparatory targets so they execute via dependency chains rather than fragile publish hooks. - Keeps
ComputeLinkedFilesToPublish(and existingCopyNativeBinary) as empty/back-compat targets.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets | Stops forcing SetupProperties/ComputeIlcCompileInputs to run via BeforeTargets="Publish"; relies on existing dependency flow. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets | Implements NativeCompile as the NativeAOT publish integration point; leaves ComputeLinkedFilesToPublish as an empty compatibility target. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets | Removes BeforeTargets="Publish" from runtime ILC pack import target to rely on dependency chains. |
The test infrastructure directly imported SingleEntry.targets from Directory.Build.targets, which is evaluated before Microsoft.NET.Sdk.targets. This caused the SDK's empty NativeCompile placeholder (in Publish.targets) to overwrite the NativeAOT redefinition (MSBuild last-definition-wins), resulting in no native compilation during NativeAOT test runs. Use AfterMicrosoftNETSdkTargets to defer the import to after all SDK targets, matching the pattern already used for ReadyToRun targets in tests.singlefile.targets.
agocke
left a comment
There was a problem hiding this comment.
Everything looks good except the stuff about AfterMicrosoftNETSdkTargets -- I'm not sure I understand well enough what's going on there to say whether or not it's correct.
|
The import order is:
We needed a way to ensure the repo testing imports SingleEntry.targets after the empty NativeCompile target is defined, like what happens in the nuget flow. Hopefully using AfterMicrosoftNETSdkTargets to delay the import doesn't cause other ordering issues... |
… load Deferring the ILC import via AfterMicrosoftNETSdkTargets also deferred the PublishTrimmed=true that Microsoft.NETCore.Native.targets sets at evaluation time. This caused liveILLink.targets to compute _RequiresLiveILLink=false (since PublishTrimmed was not yet set), so ILLink targets were never loaded, and _PrepareTrimConfiguration was missing at build time. Set PublishTrimmed=true explicitly in the NativeAOT test PropertyGroups before liveILLink.targets is imported. NativeAOT always enables trimming, so this is semantically correct.
There was a problem hiding this comment.
Pull request overview
Switches NativeAOT publish integration to use the SDK’s NativeCompile placeholder hook instead of BeforeTargets/AfterTargets, improving sequencing reliability in the publish pipeline.
Changes:
- Redefines
NativeCompileto run the NativeAOT compilation/linking pipeline and updates publish items accordingly. - Removes
BeforeTargets="Publish"hooks from several NativeAOT targets, relying on dependency chains instead. - Defers importing ILC targets via
AfterMicrosoftNETSdkTargetsand setsPublishTrimmedearlier to ensure trim configuration targets are available.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tests/Directory.Build.targets | Defers ILC target import via AfterMicrosoftNETSdkTargets and sets PublishTrimmed early for NativeAOT test builds. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets | Removes BeforeTargets="Publish" from NativeAOT setup/inputs targets. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets | Moves publish integration work into NativeCompile, leaving an empty ComputeLinkedFilesToPublish for back-compat. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets | Removes BeforeTargets="Publish" from runtime pack import target. |
| eng/testing/tests.singlefile.targets | Defers ILC import via AfterMicrosoftNETSdkTargets and sets PublishTrimmed early for single-file NativeAOT tests. |
src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets
Show resolved
Hide resolved
|
@sbomer I believe this should fix the forward flow build failure in dotnet/dotnet#5506, correct? |
|
No, that's not the intention (though it might help) - I think that needs a separate fix. |
…ILC import Replace the AfterMicrosoftNETSdkTargets hook with the SDK's ILCompilerTargetsPath extension point to import ILC targets in the correct order (before ILLink), fixing the DynamicCodeSupport property evaluation error. Gate IlcSetupPropertiesDependsOn on _IlcReferencedAsPackage to skip NuGet package resolution when using live ILC targets.
756e72e to
4a3adf6
Compare
There was a problem hiding this comment.
Pull request overview
Updates NativeAOT publish integration to use the .NET SDK’s NativeCompile hook (instead of BeforeTargets/AfterTargets), aligning the in-repo ILC pipeline with the SDK’s publish sequencing and making the integration less order-fragile.
Changes:
- Redefines the SDK placeholder
NativeCompiletarget to run the NativeAOT publish pipeline and keepsComputeLinkedFilesToPublishas an empty back-compat target. - Removes
BeforeTargets="Publish"hooks from key ILC setup/inputs targets so ordering is driven by dependency chains + SDK sequencing. - Updates test build infrastructure to use the SDK’s
ILCompilerTargetsPathimport hook (and removes direct imports ofMicrosoft.DotNet.ILCompiler.SingleEntry.targets).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/tests/Directory.Build.targets | Switches nativeaot test builds to use ILCompilerTargetsPath / PublishAot hook instead of directly importing ILC targets. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets | Removes BeforeTargets="Publish" from SetupProperties / ComputeIlcCompileInputs to rely on dependency sequencing. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets | Moves publish-time work from ComputeLinkedFilesToPublish to NativeCompile and keeps an empty ComputeLinkedFilesToPublish for back-compat. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets | Makes IlcSetupPropertiesDependsOn conditional on package-based toolchain usage and removes BeforeTargets="Publish" from runtime pack import. |
| eng/testing/tests.singlefile.targets | Switches single-file test publish (NativeAOT) to use ILCompilerTargetsPath hook instead of directly importing ILC targets. |
PublishAot=true (added for SDK import order) enables EnableSingleFileAnalyzer, which promotes IL3000 (Assembly.Location usage) to an error in tracing tests. Disable it alongside the existing EnableTrimAnalyzer and EnableAotAnalyzer suppressions.
...instead of BeforeTargets/AfterTargets.
Redefine the SDK's empty NativeCompile placeholder target with the actual NativeAOT compilation pipeline, replacing the fragile BeforeTargets/AfterTargets hooks that previously sequenced ILC into the publish flow.