From ef3a4221c5079c79600aba0d6336672690ca8b6c Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 29 Apr 2026 15:55:51 +0200 Subject: [PATCH] Add --strip-il-bodies crossgen2 arg for Apple mobile RIDs Mirror the changes from https://github.com/dotnet/runtime/pull/125647. For Apple mobile RIDs (ios-, tvos-, iossimulator-, tvossimulator-, maccatalyst-), pass --strip-il-bodies to crossgen2 by default via PublishReadyToRunCrossgen2CompositeExtraArgs when composite R2R is enabled (PublishReadyToRunComposite=true), controllable via the PublishReadyToRunStripILBodies MSBuild property. The composite gate is required because crossgen2 only accepts --strip-il-bodies in composite mode. This re-applies #53947 (reverted in #54135) with the MSB4099 fix: the property assignments that reference @(PublishReadyToRunPartialAssemblies) and @(PublishReadyToRunCompositeExclusions) items are placed inside the _PrepareForReadyToRunCompilation target body so the item references are evaluated at target time rather than at import time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../RunReadyToRunCompiler.cs | 12 +++++++ .../targets/Microsoft.NET.CrossGen.targets | 36 +++++++++++++------ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/RunReadyToRunCompiler.cs b/src/Tasks/Microsoft.NET.Build.Tasks/RunReadyToRunCompiler.cs index e7a36b556429..e35ead24aece 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/RunReadyToRunCompiler.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/RunReadyToRunCompiler.cs @@ -23,6 +23,7 @@ public class RunReadyToRunCompiler : ToolTask public bool ShowCompilerWarnings { get; set; } public bool UseCrossgen2 { get; set; } public string Crossgen2ExtraCommandLineArgs { get; set; } + public string Crossgen2CompositeExtraCommandLineArgs { get; set; } public ITaskItem[] Crossgen2PgoFiles { get; set; } public string Crossgen2ContainerFormat { get; set; } @@ -362,6 +363,17 @@ private string GenerateCrossgen2ResponseFile() } } + // Arguments that are only valid for full composite builds (e.g. --strip-il-bodies). + // These arguments will not be applied to any assemblies that have been excluded from the composite image. + if (_createCompositeImage && !_partialCompile + && !string.IsNullOrEmpty(Crossgen2CompositeExtraCommandLineArgs)) + { + foreach (string extraArg in Crossgen2CompositeExtraCommandLineArgs.Split([';'], StringSplitOptions.RemoveEmptyEntries)) + { + result.AppendLine(extraArg); + } + } + if (_partialCompile) { result.AppendLine("--partial"); diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.CrossGen.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.CrossGen.targets index 8e39f25b7cd1..278ec5ea3493 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.CrossGen.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.CrossGen.targets @@ -35,17 +35,26 @@ Copyright (c) .NET Foundation. All rights reserved. false false - $(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info - $(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info - $(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info - $(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info - $(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info - - $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info - $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info - $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info - $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info - $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info + true + true + true + true + true + + true + true + true + true + true + + true + true + true + true + true + + $(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info + $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info @@ -469,6 +478,10 @@ Copyright (c) .NET Foundation. All rights reserved. <_ReadyToRunNativeObjectOutputs Include="@(_ReadyToRunFilesToPublish->WithMetadataValue('RequiresNativeLink', 'true'))" /> <_ReadyToRunNativeObjectOutputs OutputPath="%(Identity)" /> + + + $(PublishReadyToRunCrossgen2CompositeExtraArgs);--strip-il-bodies + @@ -505,6 +518,7 @@ Copyright (c) .NET Foundation. All rights reserved. Crossgen2PgoFiles="@(_ReadyToRunPgoFiles)" Crossgen2ContainerFormat="$(PublishReadyToRunContainerFormat)" Crossgen2ExtraCommandLineArgs="$(PublishReadyToRunCrossgen2ExtraArgs)" + Crossgen2CompositeExtraCommandLineArgs="$(PublishReadyToRunCrossgen2CompositeExtraArgs)" ImplementationAssemblyReferences="@(_ReadyToRunAssembliesToReference)" ShowCompilerWarnings="$(PublishReadyToRunShowWarnings)" CompilationEntry="@(_ReadyToRunCompileList)"