Skip to content
Merged
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
51 changes: 40 additions & 11 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,35 @@
</PropertyGroup>

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

<Target Name="_XamarinComputeIlcProps" DependsOnTargets="_DetectSdkLocations;_ComputeLinkerProperties">
<!-- Set a few properties needed by SetupOSSpecificProps -->
<PropertyGroup>
<!-- Set the 'SysRoot' variable, so that NativeAOT's build logic doesn't try to compute it, which doesn't work when building remotely from Windows. -->
<SysRoot Condition="'$(SysRoot)' == ''">$(_SdkRoot)</SysRoot>

<!-- default 'UseLdClassicXCodeLinker' to our value for '_UseClassicLinker', and in case it's still not set, default to 'false', since typically the new linker will work. -->
<UseLdClassicXCodeLinker Condition="'$(UseLdClassicXCodeLinker)' == ''">$(_UseClassicLinker)</UseLdClassicXCodeLinker>
<UseLdClassicXCodeLinker Condition="'$(UseLdClassicXCodeLinker)' == ''">false</UseLdClassicXCodeLinker>

<!-- Ask ILC to produce a static library -->
<NativeLib>static</NativeLib>

<!-- We will handle stripping ourselves, because NativeAOT's logic doesn't work when executing remotely from Windows -->
<StripSymbols>false</StripSymbols>
</PropertyGroup>
</Target>

<Target Name="SelectRegistrar" DependsOnTargets="_ComputeLinkMode">
<PropertyGroup>
<!--
Expand Down Expand Up @@ -1512,9 +1538,6 @@

<Target Name="_XamarinComputeIlcCompileInputs">
<PropertyGroup>
<!-- Ask ILC to produce a static library -->
<NativeLib>static</NativeLib>

<!-- Always enable trim warnings by default with NativeAOT -->
<SuppressTrimAnalysisWarnings Condition="'$(_OriginalSuppressTrimAnalysisWarnings)' != 'true'">false</SuppressTrimAnalysisWarnings>
</PropertyGroup>
Expand Down Expand Up @@ -1681,6 +1704,7 @@
_CompileNativeExecutable;
_ReidentifyDynamicLibraries;
_AddSwiftLinkerFlags;
_ComputeLinkerProperties;
_ComputeLinkNativeExecutableInputs;
_ForceLinkNativeExecutable;
</_LinkNativeExecutableDependsOn>
Expand Down Expand Up @@ -1711,6 +1735,18 @@
</ItemGroup>
</Target>

<Target Name="_ComputeLinkerProperties"
DependsOnTargets="_DetectSdkLocations"
Condition="'$(IsMacEnabled)' == 'true'"
>
<PropertyGroup>
<!-- There are known bugs in the classic linker with Xcode 15, so keep use the classic linker in that case -->
<!-- In Xcode 16 we don't know of any problems for now, so enable the new linker by default -->
<_UseClassicLinker Condition="'$(_UseClassicLinker)' == '' And $([MSBuild]::VersionGreaterThanOrEquals('$(_XcodeVersion)', '16.0'))">false</_UseClassicLinker>
<_UseClassicLinker Condition="'$(_UseClassicLinker)' == '' And $([MSBuild]::VersionGreaterThanOrEquals('$(_XcodeVersion)', '15.0'))">true</_UseClassicLinker>
</PropertyGroup>
</Target>

<Target Name="_ComputeLinkNativeExecutableInputs" Condition="'$(IsMacEnabled)' == 'true'">
<PropertyGroup>
<_ExportedSymbolsFile Condition="'$(_ExportedSymbolsFile)' == '' and '$(_MtouchSymbolsList)' == ''">/dev/null</_ExportedSymbolsFile> <!-- nothing to export -->
Expand Down Expand Up @@ -1769,13 +1805,6 @@

<WriteLinesToFile File="$(_MtouchSymbolsList)" Lines="@(_ProcessedReferenceNativeSymbol)" Overwrite="true" />

<PropertyGroup>
<!-- There are known bugs in the classic linker with Xcode 15, so keep use the classic linker in that case -->
<!-- In Xcode 16 we don't know of any problems for now, so enable the new linker by default -->
<_UseClassicLinker Condition="'$(_UseClassicLinker)' == '' And $([MSBuild]::VersionGreaterThanOrEquals('$(_XcodeVersion)', '16.0'))">false</_UseClassicLinker>
<_UseClassicLinker Condition="'$(_UseClassicLinker)' == '' And $([MSBuild]::VersionGreaterThanOrEquals('$(_XcodeVersion)', '15.0'))">true</_UseClassicLinker>
</PropertyGroup>

<ItemGroup>
<_AllLinkerFlags Include="@(_AssemblyLinkerFlags);@(_MainLinkerFlags);@(_CustomLinkFlags)" />
<_AllLinkerFlags Condition="'$(_ExportSymbolsExplicitly)' != 'true'" Include="@(_ProcessedReferenceNativeSymbol->'-u%(Identity)')" />
Expand Down
14 changes: 14 additions & 0 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,20 @@ public void BuildMyNativeAotAppWithTrimAnalysisWarning (ApplePlatform platform,
[TestCase (ApplePlatform.TVOS, "tvossimulator-x64", "Debug")]
[TestCase (ApplePlatform.TVOS, "tvossimulator-x64", "Release")]
public void PublishAot (ApplePlatform platform, string runtimeIdentifiers, string configuration)
{
PublishAotImpl (platform, runtimeIdentifiers, configuration);
}

[TestCase (ApplePlatform.iOS, "ios-arm64", "Release")]
[Category ("RemoteWindows")]
public void PublishAotOnWindows (ApplePlatform platform, string runtimeIdentifiers, string configuration)
{
Configuration.IgnoreIfNotOnWindows ();

PublishAotImpl (platform, runtimeIdentifiers, configuration);
}

void PublishAotImpl (ApplePlatform platform, string runtimeIdentifiers, string configuration)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Expand Down
Loading