Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using NativeAOT. #17374

Merged
merged 46 commits into from
Jun 22, 2023
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d605221
Bump MonoTouch.Dialog and Touch.Unit.
rolfbjarne Jun 21, 2023
f964b5a
[runtime] Create a version of our runtime that can be used with Nativ…
rolfbjarne Jun 21, 2023
a766901
[dotnet] Choose the correct runtime library depending on which runtim…
rolfbjarne Jun 21, 2023
7f15d86
[xharness] Add a NativeAOT variation of monotouch-test.
rolfbjarne Jun 21, 2023
d584840
[dotnet] Force the managed static registrar when using NativeAot.
rolfbjarne Jun 21, 2023
607cc78
[dotnet] Use the correct package infix for NativeAOT
rolfbjarne Jun 21, 2023
ca6f2e4
[Foundation] Use the correct toggle ref implementation on !macOS sinc…
rolfbjarne Jun 21, 2023
94c96ec
[dotnet] Don't run Mono's AOT compiler if we're using NativeAOT.
rolfbjarne Jun 21, 2023
a3b466b
[tools] Don't allow keeping the dynamic registrar when using NativeAOT.
rolfbjarne Jun 21, 2023
ab8f928
[tools] Don't call mono_jit_set_aot_mode from main when using NativeAOT
rolfbjarne Jun 21, 2023
60e4936
[tools] Don't generate calls to mono_aot_register_module in main when…
rolfbjarne Jun 21, 2023
9b24c5d
[runtime] NativeAOT does not support dynamic registration
rolfbjarne Jun 21, 2023
d5a53d6
[runtime] Add a native IsNativeAOT flag.
rolfbjarne Jun 21, 2023
b4a67c6
[src] Make the Runtime.IsNativeAOT property a constant in the linker.
rolfbjarne Jun 21, 2023
e0e4b77
[dotnet] Set AutoreleasePoolSupport earlier so that the linker doesn'…
rolfbjarne Jun 21, 2023
901be39
[ObjCRuntime] Avoid using Assembly.Location for NativeAOT, use an alt…
rolfbjarne Jun 21, 2023
3105214
[tests] Detect NativeAOT correctly in the Symbols test
rolfbjarne Jun 21, 2023
5b8d60b
[tests] Adjust RegistrarTest to always expected the dynamic registrar…
rolfbjarne Jun 21, 2023
890d3ca
[tests] Adjust asserts since some collection assert doesn't work with…
rolfbjarne Jun 21, 2023
0db2c5c
[dotnet] Rework feature detection and notification a bit.
rolfbjarne Jun 21, 2023
595bcdb
[dotnet] Don't call ComputeResolvedFilesToPublishList when using Nati…
rolfbjarne Jun 21, 2023
13fa769
[dotnet] Disable our own IL stripping when using NativeAOT, because N…
rolfbjarne Jun 21, 2023
b36db05
[dotnet] Call ILC, the NativeAOT compiler, before we link the native …
rolfbjarne Jun 21, 2023
00b2865
[dotnet] Adjust ILC's build dependencies to cope with the fact that I…
rolfbjarne Jun 21, 2023
8cfee8b
[dotnet] Ask ILC to treat all P/Invokes to __Internal as direct P/Inv…
rolfbjarne Jun 21, 2023
6bd8915
[dotnet] Rearrange items in item groups so that ILC gets the output f…
rolfbjarne Jun 21, 2023
3977493
[dotnet] Ask ILC to process all unmanaged callers only methods from a…
rolfbjarne Jun 21, 2023
79b7657
[dotnet] Ask ILC to only trim assemblies if trimming is explicitly en…
rolfbjarne Jun 21, 2023
c48d583
[dotnet] Link the output from ILC into the native executable
rolfbjarne Jun 21, 2023
2ee5326
[dotnet] Collect all the native linker arguments ILC would have used …
rolfbjarne Jun 21, 2023
617f64e
[dotnet] Enforce that the linker must be enabled for all assemblies w…
rolfbjarne Jun 21, 2023
d601e51
[dotnet] Set PublishAotUsingRuntimePack=true when using NativeAOT to …
rolfbjarne Jun 21, 2023
183c76a
[dotnet] Use a different min OS version when building with NativeAOT.
rolfbjarne Jun 21, 2023
e3228d0
[dotnet] Turn off some publishing behavior we don't need
rolfbjarne Jun 21, 2023
a1d707c
[dotnet] Fix items in TrimmerRootAssembly to follow docs and what ILC…
rolfbjarne Jun 21, 2023
0adbf77
[tests] Fix computing when the dynamic registrar is used.
rolfbjarne Jun 21, 2023
7d65804
[dotnet/tests] Only use NativeAOT when publishing.
rolfbjarne Jun 21, 2023
97b91f1
[dotnet] Remove libSystem.Net.Security.Native from tvOS builds when u…
rolfbjarne Jun 21, 2023
c49888b
[tests] Adjust ConfigTest to cope with different behavior when using …
rolfbjarne Jun 21, 2023
264be70
[dotnet] Disable SelfContained for the outer build of a universal app…
rolfbjarne Jun 21, 2023
8ac35ba
[tests] Disable the NUnitLite and Touch.Unit references for the .NET …
rolfbjarne Jun 21, 2023
e31b0a6
[xharness] Disable NativeAOT test variations for macOS for now, we're…
rolfbjarne Jun 21, 2023
94cdec2
[xharness] Disable NativeAOT test variations for Mac Catalyst for now…
rolfbjarne Jun 21, 2023
42d6121
[dotnet] Set a flag to avoid a bug with the NativeAOT compiler
rolfbjarne Jun 21, 2023
3c912d7
[dotnet] Treat the ICU data file as a resource instead of an assembly.
rolfbjarne Jun 21, 2023
b4e3361
[dotnet] Tell ILC about any satellite assemblies.
rolfbjarne Jun 21, 2023
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
6 changes: 3 additions & 3 deletions dotnet/generate-target-platforms.csharp
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ using (TextWriter writer = new StreamWriter (outputPath)) {
if (parsedVersion < minSdkVersion)
continue;
if (parsedVersion < minNativeAotSdkVersion) {
writer.WriteLine ($"\t\t<{platform}SdkSupportedTargetPlatformVersion Include=\"{n.InnerText}\" Condition=\"'$(PublishAot)' != 'true'\" />");
writer.WriteLine ($"\t\t<{platform}SdkSupportedTargetPlatformVersion Include=\"{n.InnerText}\" Condition=\"!('$(PublishAot)' == 'true' And '$(_IsPublishing)' == 'true')\" />");
} else {
writer.WriteLine ($"\t\t<{platform}SdkSupportedTargetPlatformVersion Include=\"{n.InnerText}\" />");
}
@@ -57,8 +57,8 @@ using (TextWriter writer = new StreamWriter (outputPath)) {
writer.WriteLine ($"\t\t<SdkSupportedTargetPlatformVersion Condition=\"'$(TargetPlatformIdentifier)' == '{platform}'\" Include=\"@({platform}SdkSupportedTargetPlatformVersion)\" />");
writer.WriteLine ("\t</ItemGroup>");
writer.WriteLine ("\t<PropertyGroup>");
writer.WriteLine ($"\t\t<{platform}MinSupportedOSPlatformVersion Condition=\"'$(PublishAot)' != 'true'\">{minSdkVersionString}</{platform}MinSupportedOSPlatformVersion>");
writer.WriteLine ($"\t\t<{platform}MinSupportedOSPlatformVersion Condition=\"'$(PublishAot)' == 'true'\">{minNativeAotSdkVersionString}</{platform}MinSupportedOSPlatformVersion>");
writer.WriteLine ($"\t\t<{platform}MinSupportedOSPlatformVersion Condition=\"!('$(PublishAot)' == 'true' And '$(_IsPublishing)' == 'true')\">{minSdkVersionString}</{platform}MinSupportedOSPlatformVersion>");
writer.WriteLine ($"\t\t<{platform}MinSupportedOSPlatformVersion Condition=\"'$(PublishAot)' == 'true' And '$(_IsPublishing)' == 'true'\">{minNativeAotSdkVersionString}</{platform}MinSupportedOSPlatformVersion>");
writer.WriteLine ("\t</PropertyGroup>");
writer.WriteLine ("</Project>");
}
10 changes: 9 additions & 1 deletion dotnet/targets/Xamarin.Shared.Sdk.DefaultItems.targets
Original file line number Diff line number Diff line change
@@ -11,9 +11,17 @@
<EnableDefaultmacOSItems Condition=" '$(_PlatformName)' == 'macOS' And '$(EnableDefaultmacOSItems)' == '' ">$(EnableDefaultItems)</EnableDefaultmacOSItems>
<EnableDefaultMacCatalystItems Condition=" '$(_PlatformName)' == 'MacCatalyst' And '$(EnableDefaultMacCatalystItems)' == '' ">$(EnableDefaultItems)</EnableDefaultMacCatalystItems>

<!--
PublishAot should only take effect when doing 'dotnet publish', not when doing 'dotnet build'. We distinguish these cases using the '_IsPublishing' property,
but it's rather annoying to always have to check both PublishAot and _IsPublishing to see if we're using NativeAOT, so introduce a third property that's
only set to true if both PublishAot=true and _IsPublishing=true
-->
<_UseNativeAot Condition="'$(PublishAot)' == 'true' And '$(_IsPublishing)' == 'true'">true</_UseNativeAot>

<UseMonoRuntime Condition=" '$(UseMonoRuntime)' == '' And '$(_PlatformName)' == 'macOS'">false</UseMonoRuntime>
<UseMonoRuntime Condition=" '$(UseMonoRuntime)' == '' And '$(PublishAot)' == 'true'">false</UseMonoRuntime>
<UseMonoRuntime Condition=" '$(UseMonoRuntime)' == '' And '$(_UseNativeAot)' == 'true'">false</UseMonoRuntime>
<UseMonoRuntime Condition=" '$(UseMonoRuntime)' == ''">true</UseMonoRuntime>

</PropertyGroup>

<ItemGroup>
2 changes: 1 addition & 1 deletion dotnet/targets/Xamarin.Shared.Sdk.props
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@
</PropertyGroup>

<!-- Various options when using NativeAOT -->
<PropertyGroup Condition="'$(PublishAot)' == 'true'">
<PropertyGroup Condition="'$(PublishAot)' == 'true' And '$(_IsPublishing)' == 'true'">
<!-- Disable our own assembly IL stripping logic, because ILC does that already -->
<EnableAssemblyILStripping>false</EnableAssemblyILStripping>

34 changes: 17 additions & 17 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
@@ -425,7 +425,7 @@
_ComputeFrameworkVariables;
_ComputeFrameworkAssemblies;
</_ComputeLinkerArgumentsDependsOn>
<_ComputeLinkerArgumentsDependsOn Condition="'$(PublishAot)' != 'true'">
<_ComputeLinkerArgumentsDependsOn Condition="'$(_UseNativeAot)' != 'true'">
$(_ComputeLinkerArgumentsDependsOn);
ComputeResolvedFilesToPublishList;
</_ComputeLinkerArgumentsDependsOn>
@@ -443,12 +443,12 @@
</_ComputeLinkerArgumentsDependsOn>
</PropertyGroup>

<PropertyGroup Condition="'$(PublishAot)' == 'true'">
<PropertyGroup Condition="'$(_UseNativeAot)' == 'true'">
<IlcCompileDependsOn>Compile;_ComputeLinkerArguments;_ComputeManagedAssemblyToLink;SetupOSSpecificProps;PrepareForILLink;_XamarinComputeIlcCompileInputs</IlcCompileDependsOn>
</PropertyGroup>

<Target Name="_ComputeLinkerFeatures">
<PropertyGroup Condition="'$(PublishAot)' == 'true'">
<PropertyGroup Condition="'$(_UseNativeAot)' == 'true'">
<!-- The one and only registrar is 'managed-static' when using NativeAOT -->
<Registrar Condition="'$(Registrar)' == ''">managed-static</Registrar>

@@ -490,10 +490,10 @@
<!-- it's invariant or it's one of the ICU data files, not both -->
<Error Text="Can not set values for both InvariantGlobalization '$(InvariantGlobalization)' and _GlobalizationDataFile '$(_GlobalizationDataFile)'" Condition="'$(_GlobalizationDataFile)' != '' And '$(InvariantGlobalization)' == 'true'" />

<Error Text="The only valid registrar when using NativeAOT is 'managed-static' (current value: '$(Registrar)'). Please either delete the 'Registrar' property, or change it to be 'managed-static'." Condition="'$(PublishAot)' == 'true' And '$(Registrar)' != '' And '$(Registrar)' != 'managed-static'" />
<Error Text="The only valid registrar when using NativeAOT is 'managed-static' (current value: '$(Registrar)'). Please either delete the 'Registrar' property, or change it to be 'managed-static'." Condition="'$(_UseNativeAot)' == 'true' And '$(Registrar)' != '' And '$(Registrar)' != 'managed-static'" />

<Warning Text="Only the managed static registrar is supported when using NativeAOT." Condition="'$(PublishAot)' == 'true' And '$(Registrar)' != 'managed-static'" />
<Warning Text="All assemblies must be processed by the linker when using NativeAOT. Please don't set neither the '$(_LinkModeProperty)' nor the 'TrimMode' property, so that the build can default to linking all assemblies." Condition="'$(PublishAot)' == 'true' And '$(_LinkMode)' != 'Full'" />
<Warning Text="Only the managed static registrar is supported when using NativeAOT." Condition="'$(_UseNativeAot)' == 'true' And '$(Registrar)' != 'managed-static'" />
<Warning Text="All assemblies must be processed by the linker when using NativeAOT. Please don't set neither the '$(_LinkModeProperty)' nor the 'TrimMode' property, so that the build can default to linking all assemblies." Condition="'$(_UseNativeAot)' == 'true' And '$(_LinkMode)' != 'Full'" />

<PropertyGroup>
<!-- Pass the custom options to our custom steps -->
@@ -895,8 +895,8 @@
<Target Name="_ComputeFrameworkVariables" DependsOnTargets="ResolveRuntimePackAssets;ResolveFrameworkReferences">
<PropertyGroup>
<_XamarinRuntime Condition="'$(UseMonoRuntime)' == 'true'">MonoVM</_XamarinRuntime>
<_XamarinRuntime Condition="'$(UseMonoRuntime)' != 'true' And '$(PublishAot)' != 'true'">CoreCLR</_XamarinRuntime>
<_XamarinRuntime Condition="'$(UseMonoRuntime)' != 'true' And '$(PublishAot)' == 'true'">NativeAOT</_XamarinRuntime>
<_XamarinRuntime Condition="'$(UseMonoRuntime)' != 'true' And '$(_UseNativeAot)' != 'true'">CoreCLR</_XamarinRuntime>
<_XamarinRuntime Condition="'$(UseMonoRuntime)' != 'true' And '$(_UseNativeAot)' == 'true'">NativeAOT</_XamarinRuntime>

<_PackageIdInfix Condition="'$(_XamarinRuntime)' == 'MonoVM'">Mono.</_PackageIdInfix>
<_PackageIdInfix Condition="'$(_XamarinRuntime)' == 'NativeAOT'">NativeAOT.</_PackageIdInfix>
@@ -948,7 +948,7 @@
publish (except the merged app bundle, which we'll handle
ourselves).
-->
<_ComputeVariablesDependsOn Condition="'$(RuntimeIdentifiers)' == '' And '$(PublishAot)' != 'true'">$(_ComputeVariablesDependsOn);ComputeResolvedFilesToPublishList</_ComputeVariablesDependsOn>
<_ComputeVariablesDependsOn Condition="'$(RuntimeIdentifiers)' == '' And '$(_UseNativeAot)' != 'true'">$(_ComputeVariablesDependsOn);ComputeResolvedFilesToPublishList</_ComputeVariablesDependsOn>
</PropertyGroup>

<Target Name="_ComputeVariables" DependsOnTargets="$(_ComputeVariablesDependsOn)">
@@ -957,7 +957,7 @@
<_RunAotCompiler>false</_RunAotCompiler>
</PropertyGroup>
<!-- We don't run Mono's AOT compiler if we're using NativeAOT -->
<PropertyGroup Condition="'$(PublishAot)' != 'true'" >
<PropertyGroup Condition="'$(_UseNativeAot)' != 'true'" >
<!-- We need it for device builds for mobile platforms -->
<_RunAotCompiler Condition="'$(_SdkIsSimulator)' != 'true' And '$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'">true</_RunAotCompiler>
<!-- We need it if the interpreter is enabled, no matter where -->
@@ -1314,7 +1314,7 @@
_AOTCompile;
</_CompileNativeExecutableDependsOn>

<_CompileNativeExecutableDependsOn Condition="'$(PublishAot)' == 'true'">
<_CompileNativeExecutableDependsOn Condition="'$(_UseNativeAot)' == 'true'">
$(_CompileNativeExecutableDependsOn);
IlcCompile;
</_CompileNativeExecutableDependsOn>
@@ -1531,12 +1531,12 @@
<_DefaultLinkMode>TrimMode</_DefaultLinkMode>
</PropertyGroup>
<PropertyGroup Condition="'$(TrimMode)' == ''">
<_DefaultLinkMode Condition="'$(PublishAot)' != 'true'">Full</_DefaultLinkMode> <!-- Linking is always on for all assemblies when using NativeAOT - this is because we need to modify all assemblies in the linker for them to be compatible with NativeAOT -->
<_DefaultLinkMode Condition="'$(PublishAot)' != 'true' And '$(_PlatformName)' == 'macOS'">None</_DefaultLinkMode> <!-- Linking is off by default for macOS apps -->
<_DefaultLinkMode Condition="'$(PublishAot)' != 'true' And '$(_PlatformName)' == 'MacCatalyst' And '$(Configuration)' == 'Release'">SdkOnly</_DefaultLinkMode> <!-- Default linking is on for release builds for Mac Catalyst apps -->
<_DefaultLinkMode Condition="'$(PublishAot)' != 'true' And '$(_PlatformName)' == 'MacCatalyst' And '$(Configuration)' != 'Release'">None</_DefaultLinkMode> <!-- Default linking is off for non-release builds for Mac Catalyst apps -->
<_DefaultLinkMode Condition="'$(PublishAot)' != 'true' And '$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst' And '$(_SdkIsSimulator)' == 'true'">None</_DefaultLinkMode> <!-- Linking is off by default in the simulator -->
<_DefaultLinkMode Condition="'$(PublishAot)' != 'true' And '$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst' And '$(_SdkIsSimulator)' != 'true'">SdkOnly</_DefaultLinkMode> <!-- Linking is SdkOnly for iOS/tvOS/watchOS apps on device -->
<_DefaultLinkMode Condition="'$(_UseNativeAot)' != 'true'">Full</_DefaultLinkMode> <!-- Linking is always on for all assemblies when using NativeAOT - this is because we need to modify all assemblies in the linker for them to be compatible with NativeAOT -->
<_DefaultLinkMode Condition="'$(_UseNativeAot)' != 'true' And '$(_PlatformName)' == 'macOS'">None</_DefaultLinkMode> <!-- Linking is off by default for macOS apps -->
<_DefaultLinkMode Condition="'$(_UseNativeAot)' != 'true' And '$(_PlatformName)' == 'MacCatalyst' And '$(Configuration)' == 'Release'">SdkOnly</_DefaultLinkMode> <!-- Default linking is on for release builds for Mac Catalyst apps -->
<_DefaultLinkMode Condition="'$(_UseNativeAot)' != 'true' And '$(_PlatformName)' == 'MacCatalyst' And '$(Configuration)' != 'Release'">None</_DefaultLinkMode> <!-- Default linking is off for non-release builds for Mac Catalyst apps -->
<_DefaultLinkMode Condition="'$(_UseNativeAot)' != 'true' And '$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst' And '$(_SdkIsSimulator)' == 'true'">None</_DefaultLinkMode> <!-- Linking is off by default in the simulator -->
<_DefaultLinkMode Condition="'$(_UseNativeAot)' != 'true' And '$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst' And '$(_SdkIsSimulator)' != 'true'">SdkOnly</_DefaultLinkMode> <!-- Linking is SdkOnly for iOS/tvOS/watchOS apps on device -->
</PropertyGroup>
</Target>
<PropertyGroup>
4 changes: 3 additions & 1 deletion tests/xharness/Jenkins/TestVariationsFactory.cs
Original file line number Diff line number Diff line change
@@ -296,8 +296,10 @@ public IEnumerable<T> CreateTestVariations<T> (IEnumerable<T> tests, Func<MSBuil
clone.Xml.SetProperty ("RuntimeIdentifier", runtime_identifer);
if (!string.IsNullOrEmpty (registrar))
clone.Xml.SetProperty ("Registrar", registrar);
if (publishaot)
if (publishaot) {
clone.Xml.SetProperty ("PublishAot", "true");
clone.Xml.SetProperty ("_IsPublishing", "true"); // quack like "dotnet publish", otherwise PublishAot=true has no effect.
}
clone.Xml.Save (clone.Path);
});