Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Microsoft.Android.Sdk.CoreCLR.targets
This file contains the CoreCLR-specific MSBuild logic for .NET for Android.
***********************************************************************************************
-->
<Project>
<Project TreatAsLocalProperty="PublishReadyToRunCrossgen2ExtraArgs">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI keeps putting this TreatAsLocalProperty value for me, too, but it should just stop doing that.

Can we update copilot-instructions.md to say that we don't care about global property override behavior (that's default MSBuild!) and most of the time TreatAsLocalProperty is not needed.


<UsingTask TaskName="Xamarin.Android.Tasks.GenerateMibcProfile" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />

Expand All @@ -25,6 +25,18 @@ This file contains the CoreCLR-specific MSBuild logic for .NET for Android.
<AllowReadyToRunWithoutRuntimeIdentifier Condition=" '$(PublishReadyToRun)' == 'true' and '$(RuntimeIdentifiers)' != '' ">true</AllowReadyToRunWithoutRuntimeIdentifier>
</PropertyGroup>

<Target Name="_AndroidAddReadyToRunGenericCycleLimits"
BeforeTargets="_PrepareForReadyToRunCompilation"
Condition=" '$(AndroidApplication)' == 'true' and '$(PublishReadyToRun)' == 'true' ">
<!-- Bound recursive generic expansion while preserving explicit crossgen2 overrides. -->
<PropertyGroup>
<PublishReadyToRunCrossgen2ExtraArgs
Condition="!$([System.Text.RegularExpressions.Regex]::IsMatch('$(PublishReadyToRunCrossgen2ExtraArgs)', '(^|[;\s])--maxgenericcycle([:=;\s]|$)'))">$(PublishReadyToRunCrossgen2ExtraArgs);--maxgenericcycle:2</PublishReadyToRunCrossgen2ExtraArgs>
<PublishReadyToRunCrossgen2ExtraArgs
Condition="!$([System.Text.RegularExpressions.Regex]::IsMatch('$(PublishReadyToRunCrossgen2ExtraArgs)', '(^|[;\s])--maxgenericcyclebreadth([:=;\s]|$)'))">$(PublishReadyToRunCrossgen2ExtraArgs);--maxgenericcyclebreadth:1</PublishReadyToRunCrossgen2ExtraArgs>
</PropertyGroup>
Comment on lines +33 to +37

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to do this without a bunch of inlined regex?

Should we make a C# task for modifying $(PublishReadyToRunCrossgen2ExtraArgs), that could parse them and reformat them?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, we can do that. let's first agree if we even want this as the default and if yes, I'll update the PR.

</Target>

<!-- Default feature switches -->
<ItemGroup>
<RuntimeHostConfigurationOption Include="Microsoft.Android.Runtime.RuntimeFeature.IsCoreClrRuntime"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,66 @@ public void BasicApplicationPublishReadyToRun ([Values] bool isComposite, [Value
StringAssert.Contains ("@uncompressed_assemblies_data_buffer = dso_local local_unnamed_addr global [0 x i8] zeroinitializer, align 1", compressedAssembliesSourceText);
}

[TestCase ("", "--maxgenericcycle:2;--maxgenericcyclebreadth:1")]
[TestCase ("--partial", "--partial;--maxgenericcycle:2;--maxgenericcyclebreadth:1")]
[TestCase ("--maxgenericcycle:7", "--maxgenericcycle:7;--maxgenericcyclebreadth:1")]
[TestCase ("--maxgenericcycle=7", "--maxgenericcycle=7;--maxgenericcyclebreadth:1")]
[TestCase ("--maxgenericcycle;7", "--maxgenericcycle;7;--maxgenericcyclebreadth:1")]
[TestCase ("--maxgenericcyclebreadth:5", "--maxgenericcyclebreadth:5;--maxgenericcycle:2")]
[TestCase ("--maxgenericcyclebreadth=5", "--maxgenericcyclebreadth=5;--maxgenericcycle:2")]
[TestCase ("--maxgenericcyclebreadth;5", "--maxgenericcyclebreadth;5;--maxgenericcycle:2")]
[TestCase ("--maxgenericcycle:7;--maxgenericcyclebreadth:5", "--maxgenericcycle:7;--maxgenericcyclebreadth:5")]
[NonParallelizable]
public void ReadyToRunGenericCycleLimits (string extraArguments, string expectedArguments)
{
const string output = "ready-to-run-extra-arguments.txt";
var proj = new DotNetStandard {
IsRelease = true,
ProjectName = "ReadyToRunGenericCycleLimits",
Sdk = "Microsoft.NET.Sdk",
TargetFramework = "net10.0",
};
proj.SetProperty ("AndroidApplication", "true");
proj.SetProperty ("PublishReadyToRun", "true");
proj.SetProperty ("PublishTrimmed", "true");
proj.SetProperty ("_XamarinAndroidBuildTasksAssembly", typeof (GenerateMibcProfile).Assembly.Location);
proj.Imports.Add (new Import (Path.Combine (
XABuildPaths.TopDirectory,
"src",
"Xamarin.Android.Build.Tasks",
"Microsoft.Android.Sdk",
"targets",
"Microsoft.Android.Sdk.CoreCLR.targets"
)));
proj.Imports.Add (new Import ("capture-ready-to-run-arguments.targets") {
TextContent = () => $"""
<Project>
<Target Name="_CaptureReadyToRunGenericCycleLimits"
DependsOnTargets="_AndroidAddReadyToRunGenericCycleLimits">
<WriteLinesToFile
File="$(MSBuildProjectDirectory)/{output}"
Lines="$([MSBuild]::Escape('$(PublishReadyToRunCrossgen2ExtraArgs)'))"
Overwrite="true" />
</Target>
</Project>
""",
});

using var b = CreateDllBuilder ();
b.Target = "_CaptureReadyToRunGenericCycleLimits";
var parameters = extraArguments.IsNullOrEmpty () ?
[] :
new [] { $"PublishReadyToRunCrossgen2ExtraArgs={extraArguments.Replace (";", "%3B")}" };
Assert.IsTrue (b.Build (proj, parameters: parameters), "Build should have succeeded.");

var outputPath = Path.Combine (Root, b.ProjectDirectory, output);
FileAssert.Exists (outputPath);
var actualArguments = File.ReadAllText (outputPath).Trim ()
.Split (new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
var expected = expectedArguments.Split (new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
CollectionAssert.AreEquivalent (expected, actualArguments);
}

[Test]
public void AndroidEnableMarshalMethodsWithReadyToRunFailsBuild ()
{
Expand Down
Loading