Skip to content

Commit 14e8b82

Browse files
[nativeaot] Add Native AOT cross-build support for iOS-like platforms (#88242)
* Add Native AOT cross-build support for iOS-like platforms * Add -hostos parameter for cross-components build --------- Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
1 parent eabea90 commit 14e8b82

File tree

10 files changed

+59
-62
lines changed

10 files changed

+59
-62
lines changed

eng/Subsets.props

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,13 @@
254254
</ItemGroup>
255255

256256
<!-- Build the CoreCLR cross tools when we're doing a cross build and either we're building any CoreCLR native tools for platforms CoreCLR fully supports or when someone explicitly requests them -->
257-
<ItemGroup Condition="(('$(ClrRuntimeBuildSubsets)' != '' and '$(PrimaryRuntimeFlavor)' == 'CoreCLR' and '$(TargetsMobile)' != 'true') or $(_subset.Contains('+clr.crossarchtools+'))) and ('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)')">
257+
<ItemGroup Condition="(('$(ClrRuntimeBuildSubsets)' != '' and '$(PrimaryRuntimeFlavor)' == 'CoreCLR') or $(_subset.Contains('+clr.crossarchtools+'))) and ('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)')">
258258
<ProjectToBuild
259259
Include="$(CoreClrProjectRoot)runtime.proj"
260260
AdditionalProperties="%(AdditionalProperties);
261261
ClrCrossComponentsSubset=true;
262262
HostArchitecture=$(BuildArchitecture);
263+
HostCrossOS=$(HostOS);
263264
PgoInstrument=false;
264265
NoPgoOptimize=true;
265266
CrossBuild=false;
@@ -300,26 +301,6 @@
300301
CMakeArgs=$(CMakeArgs) -DCLR_CROSS_COMPONENTS_BUILD=1" Category="clr" />
301302
</ItemGroup>
302303

303-
<!-- When targeting the iOS platforms with Native AOT, build the ClrAllJitsSubset and the Ilc for the host -->
304-
<PropertyGroup>
305-
<IsNativeAOTHostBuildEnabled Condition="$(_subset.Contains('+clr.nativeaotruntime+')) and '$(NativeAotSupported)' == 'true' and '$(PrimaryRuntimeFlavor)' == 'CoreCLR' and '$(TargetsAppleMobile)' == 'true'">true</IsNativeAOTHostBuildEnabled>
306-
<NativeAOTAdditionalProperties Condition="'$(IsNativeAOTHostBuildEnabled)' == 'true'">TargetOS=osx;TargetArchitecture=$(BuildArchitecture)</NativeAOTAdditionalProperties>
307-
</PropertyGroup>
308-
<ItemGroup Condition="'$(IsNativeAOTHostBuildEnabled)' == 'true'">
309-
<ProjectToBuild
310-
Include="$(CoreClrProjectRoot)runtime.proj"
311-
AdditionalProperties="%(AdditionalProperties);
312-
$(NativeAOTAdditionalProperties);
313-
ClrAllJitsSubset=true;
314-
ClrCrossComponentsSubset=true;
315-
PgoInstrument=false;
316-
NoPgoOptimize=true;
317-
CMakeArgs=$(CMakeArgs) -DCLR_CROSS_COMPONENTS_BUILD=1"
318-
Category="clr" />
319-
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\ILCompiler\ILCompiler.csproj" Category="clr" AdditionalProperties="$(NativeAOTAdditionalProperties)" />
320-
<ProjectToBuild Include="$(CoreClrProjectRoot)nativeaot\BuildIntegration\BuildIntegration.proj" Category="clr" AdditionalProperties="$(NativeAOTAdditionalProperties)" />
321-
</ItemGroup>
322-
323304
<ItemGroup Condition="$(_subset.Contains('+crossdacpack+'))">
324305
<ProjectToBuild Include="$(CoreClrProjectRoot).nuget\Microsoft.CrossOsDiag.Private.CoreCLR\Microsoft.CrossOsDiag.Private.CoreCLR.proj" Category="clr" />
325306
</ItemGroup>
@@ -336,8 +317,8 @@
336317
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\ILCompiler\ILCompiler.csproj" Category="clr" Condition="'$(NativeAotSupported)' == 'true'" />
337318
<ProjectToBuild Include="$(CoreClrProjectRoot)nativeaot\BuildIntegration\BuildIntegration.proj" Category="clr" Condition="'$(NativeAotSupported)' == 'true'" />
338319

339-
<ProjectToBuild Condition="'$(NativeAotSupported)' == 'true' and ('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)')" Include="$(CoreClrProjectRoot)tools\aot\ILCompiler\ILCompiler_crossarch.csproj" Category="clr" />
340-
<ProjectToBuild Condition="'$(TargetArchitecture)' != '$(BuildArchitecture)'" Include="$(CoreClrProjectRoot)tools\aot\crossgen2\crossgen2_crossarch.csproj" Category="clr" />
320+
<ProjectToBuild Condition="'$(NativeAotSupported)' == 'true' and ('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)')" Include="$(CoreClrProjectRoot)tools\aot\ILCompiler\ILCompiler_crossarch.csproj" Category="clr" />
321+
<ProjectToBuild Condition="'$(TargetArchitecture)' != '$(BuildArchitecture)' or '$(HostOS)' != '$(TargetOS)'" Include="$(CoreClrProjectRoot)tools\aot\crossgen2\crossgen2_crossarch.csproj" Category="clr" />
341322

342323
<ProjectToBuild Condition="'$(TargetOS)' == 'windows' or ('$(TargetOS)' == 'linux' and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64')) or '$(TargetOS)' == 'osx'" Include="$(CoreClrProjectRoot)tools\SuperFileCheck\SuperFileCheck.csproj" Category="clr" />
343324
</ItemGroup>

eng/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ initDistroRid()
140140
local isCrossBuild="$3"
141141
local isPortableBuild="$4"
142142

143-
# Only pass ROOTFS_DIR if __DoCrossArchBuild is specified and the current platform is not OSX that doesn't use rootfs
144-
if [[ $isCrossBuild == 1 && "$targetOs" != "osx" ]]; then
143+
# Only pass ROOTFS_DIR if __DoCrossArchBuild is specified and the current platform is not an Apple platform (that doesn't use rootfs)
144+
if [[ $isCrossBuild == 1 && "$targetOs" != "osx" && "$targetOs" != "ios" && "$targetOs" != "iossimulator" && "$targetOs" != "tvos" && "$targetOs" != "tvossimulator" && "$targetOs" != "maccatalyst" ]]; then
145145
passedRootfsDir=${ROOTFS_DIR}
146146
fi
147147
initDistroRidGlobal "${targetOs}" "${targetArch}" "${isPortableBuild}" "${passedRootfsDir}"

eng/liveBuilds.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<CoreCLRSharedFrameworkDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'sharedFramework'))</CoreCLRSharedFrameworkDir>
2626
<CoreCLRCrossgen2Dir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'crossgen2'))</CoreCLRCrossgen2Dir>
2727
<CoreCLRILCompilerDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'ilc-published'))</CoreCLRILCompilerDir>
28-
<CoreCLRCrossILCompilerDir Condition="'$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)'">$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', '$(BuildArchitecture)', 'ilc'))</CoreCLRCrossILCompilerDir>
28+
<CoreCLRCrossILCompilerDir Condition="'$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)'">$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', '$(BuildArchitecture)', 'ilc'))</CoreCLRCrossILCompilerDir>
2929
<CoreCLRAotSdkDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'aotsdk'))</CoreCLRAotSdkDir>
3030
<CoreCLRBuildIntegrationDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'build'))</CoreCLRBuildIntegrationDir>
3131

eng/native/build-commons.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ build_native()
104104
echo "Error: Unknown Android architecture $hostArch."
105105
exit 1
106106
fi
107-
elif [[ "$__TargetOS" == iossimulator ]]; then
107+
elif [[ "$targetOS" == iossimulator ]]; then
108108
cmakeArgs="-C $__RepoRootDir/eng/native/tryrun_ios_tvos.cmake $cmakeArgs"
109109

110110
# set default iOS simulator deployment target
@@ -118,7 +118,7 @@ build_native()
118118
echo "Error: Unknown iOS Simulator architecture $__TargetArch."
119119
exit 1
120120
fi
121-
elif [[ "$__TargetOS" == ios ]]; then
121+
elif [[ "$targetOS" == ios ]]; then
122122
cmakeArgs="-C $__RepoRootDir/eng/native/tryrun_ios_tvos.cmake $cmakeArgs"
123123

124124
# set default iOS device deployment target
@@ -130,7 +130,7 @@ build_native()
130130
echo "Error: Unknown iOS architecture $__TargetArch."
131131
exit 1
132132
fi
133-
elif [[ "$__TargetOS" == tvossimulator ]]; then
133+
elif [[ "$targetOS" == tvossimulator ]]; then
134134
cmakeArgs="-C $__RepoRootDir/eng/native/tryrun_ios_tvos.cmake $cmakeArgs"
135135

136136
# set default tvOS simulator deployment target
@@ -144,7 +144,7 @@ build_native()
144144
echo "Error: Unknown tvOS Simulator architecture $__TargetArch."
145145
exit 1
146146
fi
147-
elif [[ "$__TargetOS" == tvos ]]; then
147+
elif [[ "$targetOS" == tvos ]]; then
148148
cmakeArgs="-C $__RepoRootDir/eng/native/tryrun_ios_tvos.cmake $cmakeArgs"
149149

150150
# set default tvOS device deployment target
@@ -285,7 +285,6 @@ source "$__RepoRootDir/eng/native/init-os-and-arch.sh"
285285

286286
__TargetArch=$arch
287287
__TargetOS=$os
288-
__HostOS=$os
289288
__OutputRid=''
290289

291290
# Get the number of processors available to the scheduler
@@ -482,6 +481,16 @@ while :; do
482481
fi
483482
;;
484483

484+
hostos|-hostos)
485+
if [[ -n "$2" ]]; then
486+
__HostOS="$2"
487+
shift
488+
else
489+
echo "ERROR: 'hostos' requires a non-empty option argument"
490+
exit 1
491+
fi
492+
;;
493+
485494
*)
486495
handle_arguments "$1" "$2"
487496
if [[ "$__ShiftArgs" == 1 ]]; then
@@ -498,6 +507,10 @@ if [[ -z "$__HostArch" ]]; then
498507
__HostArch=$__TargetArch
499508
fi
500509

510+
if [[ -z "$__HostOS" ]]; then
511+
__HostOS=$__TargetOS
512+
fi
513+
501514
__CommonMSBuildArgs="/p:TargetArchitecture=$__TargetArch /p:Configuration=$__BuildType /p:TargetOS=$__TargetOS /nodeReuse:false $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg"
502515

503516
# Configure environment if we are doing a verbose build

src/coreclr/build-runtime.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fi
173173

174174
eval "$__RepoRootDir/eng/native/version/copy_version_files.sh"
175175

176-
build_native "$__TargetOS" "$__HostArch" "$__ProjectRoot" "$__IntermediatesDir" "$__CMakeTarget" "$__CMakeArgs" "CoreCLR component"
176+
build_native "$__HostOS" "$__HostArch" "$__ProjectRoot" "$__IntermediatesDir" "$__CMakeTarget" "$__CMakeArgs" "CoreCLR component"
177177

178178
# Build complete
179179

src/coreclr/crosscomponents.cmake

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
# Add targets to the crosscomponents subcomponent build
2-
if (CLR_CMAKE_HOST_OS STREQUAL CLR_CMAKE_TARGET_OS)
2+
if (CLR_CMAKE_HOST_OS STREQUAL CLR_CMAKE_TARGET_OS OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS OR CLR_CMAKE_TARGET_MACCATALYST)
33
install_clr (TARGETS
44
jitinterface_${ARCH_HOST_NAME}
55
DESTINATIONS .
66
COMPONENT crosscomponents
77
)
88

9-
if (CLR_CMAKE_TARGET_OSX AND ARCH_TARGET_NAME STREQUAL arm64)
10-
install_clr (TARGETS
11-
clrjit_universal_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
12-
DESTINATIONS .
13-
COMPONENT crosscomponents
14-
)
15-
elseif (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64)
16-
install_clr (TARGETS
17-
clrjit_universal_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
18-
DESTINATIONS .
19-
COMPONENT crosscomponents
20-
)
21-
elseif (CLR_CMAKE_TARGET_UNIX)
22-
install_clr (TARGETS
23-
clrjit_unix_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
24-
DESTINATIONS .
25-
COMPONENT crosscomponents
26-
)
27-
else()
28-
install_clr (TARGETS
29-
clrjit_win_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
30-
DESTINATIONS .
31-
COMPONENT crosscomponents
32-
)
9+
if (NOT (CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS OR CLR_CMAKE_TARGET_MACCATALYST))
10+
if (CLR_CMAKE_TARGET_OSX AND ARCH_TARGET_NAME STREQUAL arm64)
11+
install_clr (TARGETS
12+
clrjit_universal_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
13+
DESTINATIONS .
14+
COMPONENT crosscomponents
15+
)
16+
elseif (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64)
17+
install_clr (TARGETS
18+
clrjit_universal_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
19+
DESTINATIONS .
20+
COMPONENT crosscomponents
21+
)
22+
elseif (CLR_CMAKE_TARGET_UNIX)
23+
install_clr (TARGETS
24+
clrjit_unix_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
25+
DESTINATIONS .
26+
COMPONENT crosscomponents
27+
)
28+
else()
29+
install_clr (TARGETS
30+
clrjit_win_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
31+
DESTINATIONS .
32+
COMPONENT crosscomponents
33+
)
34+
endif()
3335
endif()
3436
endif()
3537

src/coreclr/runtime.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<_CoreClrBuildArg Condition="'$(PgoInstrument)' == 'true'" Include="-pgoinstrument" />
4646
<_CoreClrBuildArg Condition="'$(NativeOptimizationDataSupported)' == 'true' and '$(NoPgoOptimize)' != 'true' and '$(PgoInstrument)' != 'true'" Include="-pgodatapath &quot;$(PgoPackagePath)&quot;" />
4747
<_CoreClrBuildArg Condition="'$(HostArchitecture)' != ''" Include="-hostarch $(HostArchitecture)" />
48+
<_CoreClrBuildArg Condition="'$(HostCrossOS)' != ''" Include="-hostos $(HostCrossOS)" />
4849
<_CoreClrBuildArg Include="-outputrid $(OutputRID)" />
4950
</ItemGroup>
5051

src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</PropertyGroup>
4343

4444
<ItemGroup>
45-
<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetOS)' != 'osx' and '$(TargetTriple)' != ''" />
45+
<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(_IsApplePlatform)' != 'true' and '$(TargetTriple)' != ''" />
4646
</ItemGroup>
4747
</Target>
4848

@@ -68,7 +68,7 @@
6868
</Target>
6969

7070
<ItemGroup Condition="'$(NativeAotSupported)' == 'true'">
71-
<CustomLinkerArg Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(_hostOS)' != 'windows'" Include="--gcc-toolchain=$(ROOTFS_DIR)/usr" />
71+
<CustomLinkerArg Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(_hostOS)' != 'windows' and '$(_IsApplePlatform)' != 'true'" Include="--gcc-toolchain=$(ROOTFS_DIR)/usr" />
7272
</ItemGroup>
7373

7474
<Target Name="PublishCompiler"

src/coreclr/tools/aot/crossgen2/crossgen2.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</PropertyGroup>
4141

4242
<ItemGroup Condition="'$(NativeAotSupported)' == 'true'">
43-
<CustomLinkerArg Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(_hostOS)' != 'windows'" Include="--gcc-toolchain=$(ROOTFS_DIR)/usr" />
43+
<CustomLinkerArg Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(_IsApplePlatform)' != 'true' and '$(_hostOS)' != 'windows'" Include="--gcc-toolchain=$(ROOTFS_DIR)/usr" />
4444
</ItemGroup>
4545

4646
<Import Project="$(R2ROverridePath)" Condition="'$(R2ROverridePath)' != ''" />
@@ -81,7 +81,7 @@
8181
</PropertyGroup>
8282

8383
<ItemGroup>
84-
<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetOS)' != 'osx' and '$(TargetTriple)' != ''" />
84+
<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(_IsApplePlatform)' != 'true' and '$(TargetTriple)' != ''" />
8585
</ItemGroup>
8686
</Target>
8787

src/mono/sample/iOS-NativeAOT/Program.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<Target Name="ConfigureIlcPathsForiOSCrossCompilation" Condition="'$(PublishAotUsingRuntimePack)' != 'true'"
4848
BeforeTargets="SetupProperties">
4949
<PropertyGroup>
50-
<IlcPath>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', '$(HostOS).$(BuildArchitecture).$(CoreCLRConfiguration)', 'ilc'))</IlcPath>
50+
<IlcPath>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(CoreCLRConfiguration)', '$(BuildArchitecture)' ,'ilc'))</IlcPath>
5151
<IlcToolsPath>$(IlcPath)</IlcToolsPath>
5252
<IlcSdkPath>$(CoreCLRAotSdkDir)</IlcSdkPath>
5353
<IlcFrameworkPath>$(LibrariesAllBinArtifactsPath)</IlcFrameworkPath>

0 commit comments

Comments
 (0)