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

[nativeaot] Add Native AOT cross-build support for iOS-like platforms #88242

Merged
merged 5 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
40 changes: 18 additions & 22 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,22 @@
Category="clr" />
</ItemGroup>

<!-- Build the CoreCLR cross tools when we're doing a cross OS build for apple device targets -->
Copy link
Member

Choose a reason for hiding this comment

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

Could this be folded into the above Build the CoreCLR cross tools when we're doing a cross build block? We currently exclude it with '$(TargetsMobile)' != 'true' but it looks pretty much the same. The additional TargetOS and OutputRIDOS properties will probably not harm anything if we add them.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so. Initially, I didn't want to extend the cross-build for unsupported scenarios.

<ItemGroup Condition="('$(ClrRuntimeBuildSubsets)' != '' and '$(PrimaryRuntimeFlavor)' == 'CoreCLR' and '$(NativeAotSupported)' == 'true' and '$(TargetsAppleMobile)' == 'true')">
<ProjectToBuild
Include="$(CoreClrProjectRoot)runtime.proj"
AdditionalProperties="%(AdditionalProperties);
ClrCrossComponentsSubset=true;
HostArchitecture=$(BuildArchitecture);
TargetOS=$(HostOS);
OutputRIDOS=$(TargetOS);
PgoInstrument=false;
NoPgoOptimize=true;
CrossBuild=false;
CMakeArgs=$(CMakeArgs) -DCLR_CROSS_COMPONENTS_BUILD=1"
Category="clr" />
</ItemGroup>

<ItemGroup Condition="$(_subset.Contains('+clr.paltestlist+'))">
<ProjectToBuild Include="$(CoreClrProjectRoot)pal/tests/palsuite/producepaltestlist.proj" />
</ItemGroup>
Expand Down Expand Up @@ -300,26 +316,6 @@
CMakeArgs=$(CMakeArgs) -DCLR_CROSS_COMPONENTS_BUILD=1" Category="clr" />
</ItemGroup>

<!-- When targeting the iOS platforms with Native AOT, build the ClrAllJitsSubset and the Ilc for the host -->
<PropertyGroup>
<IsNativeAOTHostBuildEnabled Condition="$(_subset.Contains('+clr.nativeaotruntime+')) and '$(NativeAotSupported)' == 'true' and '$(PrimaryRuntimeFlavor)' == 'CoreCLR' and '$(TargetsAppleMobile)' == 'true'">true</IsNativeAOTHostBuildEnabled>
<NativeAOTAdditionalProperties Condition="'$(IsNativeAOTHostBuildEnabled)' == 'true'">TargetOS=osx;TargetArchitecture=$(BuildArchitecture)</NativeAOTAdditionalProperties>
</PropertyGroup>
<ItemGroup Condition="'$(IsNativeAOTHostBuildEnabled)' == 'true'">
<ProjectToBuild
Include="$(CoreClrProjectRoot)runtime.proj"
AdditionalProperties="%(AdditionalProperties);
$(NativeAOTAdditionalProperties);
ClrAllJitsSubset=true;
ClrCrossComponentsSubset=true;
PgoInstrument=false;
NoPgoOptimize=true;
CMakeArgs=$(CMakeArgs) -DCLR_CROSS_COMPONENTS_BUILD=1"
Category="clr" />
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\ILCompiler\ILCompiler.csproj" Category="clr" AdditionalProperties="$(NativeAOTAdditionalProperties)" />
<ProjectToBuild Include="$(CoreClrProjectRoot)nativeaot\BuildIntegration\BuildIntegration.proj" Category="clr" AdditionalProperties="$(NativeAOTAdditionalProperties)" />
</ItemGroup>

<ItemGroup Condition="$(_subset.Contains('+crossdacpack+'))">
<ProjectToBuild Include="$(CoreClrProjectRoot).nuget\Microsoft.CrossOsDiag.Private.CoreCLR\Microsoft.CrossOsDiag.Private.CoreCLR.proj" Category="clr" />
</ItemGroup>
Expand All @@ -336,8 +332,8 @@
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\ILCompiler\ILCompiler.csproj" Category="clr" Condition="'$(NativeAotSupported)' == 'true'" />
<ProjectToBuild Include="$(CoreClrProjectRoot)nativeaot\BuildIntegration\BuildIntegration.proj" Category="clr" Condition="'$(NativeAotSupported)' == 'true'" />

<ProjectToBuild Condition="'$(NativeAotSupported)' == 'true' and ('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)')" Include="$(CoreClrProjectRoot)tools\aot\ILCompiler\ILCompiler_crossarch.csproj" Category="clr" />
<ProjectToBuild Condition="'$(TargetArchitecture)' != '$(BuildArchitecture)'" Include="$(CoreClrProjectRoot)tools\aot\crossgen2\crossgen2_crossarch.csproj" Category="clr" />
<ProjectToBuild Condition="'$(NativeAotSupported)' == 'true' and ('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or ('$(HostOS)' != '$(TargetOS)' and '$(TargetsAppleMobile)' == 'true'))" Include="$(CoreClrProjectRoot)tools\aot\ILCompiler\ILCompiler_crossarch.csproj" Category="clr" />
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the '$(TargetsAppleMobile)' == 'true' condition here and below? It feels like extending it to HostOS != TargetOS should be general goodness.

<ProjectToBuild Condition="'$(TargetArchitecture)' != '$(BuildArchitecture)' or ('$(HostOS)' != '$(TargetOS)' and '$(TargetsAppleMobile)' == 'true')" Include="$(CoreClrProjectRoot)tools\aot\crossgen2\crossgen2_crossarch.csproj" Category="clr" />

<ProjectToBuild Condition="'$(TargetOS)' == 'windows' or ('$(TargetOS)' == 'linux' and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64')) or '$(TargetOS)' == 'osx'" Include="$(CoreClrProjectRoot)tools\SuperFileCheck\SuperFileCheck.csproj" Category="clr" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion eng/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ initDistroRid()
local isPortableBuild="$4"

# Only pass ROOTFS_DIR if __DoCrossArchBuild is specified and the current platform is not OSX that doesn't use rootfs
kotlarmilos marked this conversation as resolved.
Show resolved Hide resolved
if [[ $isCrossBuild == 1 && "$targetOs" != "osx" ]]; then
if [[ $isCrossBuild == 1 && "$targetOs" != "osx" && "$targetOs" != "ios" && "$targetOs" != "iossimulator" && "$targetOs" != "tvos" && "$targetOs" != "tvossimulator" && "$targetOs" != "maccatalyst" ]]; then
passedRootfsDir=${ROOTFS_DIR}
fi
initDistroRidGlobal "${targetOs}" "${targetArch}" "${isPortableBuild}" "${passedRootfsDir}"
Expand Down
4 changes: 2 additions & 2 deletions eng/liveBuilds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<CoreCLRSharedFrameworkDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'sharedFramework'))</CoreCLRSharedFrameworkDir>
<CoreCLRCrossgen2Dir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'crossgen2'))</CoreCLRCrossgen2Dir>
<CoreCLRILCompilerDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'ilc-published'))</CoreCLRILCompilerDir>
<CoreCLRCrossILCompilerDir Condition="'$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)'">$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', '$(BuildArchitecture)', 'ilc'))</CoreCLRCrossILCompilerDir>
<CoreCLRCrossILCompilerDir Condition="'$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or ('$(HostOS)' != '$(TargetOS)' and '$(TargetsAppleMobile)' == 'true')">$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', '$(BuildArchitecture)', 'ilc'))</CoreCLRCrossILCompilerDir>
Copy link
Member

Choose a reason for hiding this comment

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

Same question about the TargetsAppleMobile condition.

<CoreCLRAotSdkDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'aotsdk'))</CoreCLRAotSdkDir>
<CoreCLRBuildIntegrationDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'build'))</CoreCLRBuildIntegrationDir>

Expand Down Expand Up @@ -71,7 +71,7 @@
<CoreCLRSharedFrameworkDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)','sharedFramework'))</CoreCLRSharedFrameworkDir>
<CoreCLRSharedFrameworkPdbDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRSharedFrameworkDir)','PDB'))</CoreCLRSharedFrameworkPdbDir>
<CoreCLRCrossTargetComponentDir
Condition="'$(CoreCLRCrossTargetComponentDirName)' != ''">$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)','$(CoreCLRCrossTargetComponentDirName)','sharedFramework'))</CoreCLRCrossTargetComponentDir>
Condition="'$(CoreCLRCrossTargetComponentDirName)' != ''">$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)','$(BuildArchitecture)','sharedFramework'))</CoreCLRCrossTargetComponentDir>
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this change (I was not able to find a use of this property that looked relevant)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not needed, it was a temporary change.

</PropertyGroup>
<PropertyGroup Condition="'$(RuntimeFlavor)' == 'Mono'">
<MonoArtifactsPath>$([MSBuild]::NormalizeDirectory('$(MonoArtifactsPath)'))</MonoArtifactsPath>
Expand Down
11 changes: 11 additions & 0 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ __TargetArch=$arch
__TargetOS=$os
__HostOS=$os
__OutputRid=''
__OutputRIDOS=''

# Get the number of processors available to the scheduler
platform="$(uname -s | tr '[:upper:]' '[:lower:]')"
Expand Down Expand Up @@ -482,6 +483,16 @@ while :; do
fi
;;

outputridos|-outputridos)
if [[ -n "$2" ]]; then
__OutputRIDOS="$2"
shift
else
echo "ERROR: 'outputridos' requires a non-empty option argument"
exit 1
fi
;;

*)
handle_arguments "$1" "$2"
if [[ "$__ShiftArgs" == 1 ]]; then
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/build-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ __ConfigTriplet="$__TargetOS.$__TargetArch.$__BuildType"
if [[ "$__TargetOS" == "linux-bionic" ]]; then
__ConfigTriplet="linux.$__TargetArch.$__BuildType"
fi
if [[ ! -z "$__OutputRIDOS" ]]; then
__ConfigTriplet="$__OutputRIDOS.$__TargetArch.$__BuildType"
Copy link
Member

Choose a reason for hiding this comment

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

Instead of introducing this override for output path, would it be better to keep the compiler in its default path and invoke it from there?

Copy link
Member Author

@kotlarmilos kotlarmilos Jul 10, 2023

Choose a reason for hiding this comment

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

In that case, the default path for the cross-compiler is $(TargetOS).$(TargetArchitecture).$(Configuration)/$(BuildArchitecture), while the jitinterface and clrjit cross-components are generated in $(HostOS).$(TargetArchitecture).$(Configuration)/$(BuildArchitecture), and these components cannot be found.

<CoreCLRArtifactsPath Condition="'$(CoreCLRArtifactsPath)' == ''">$(RuntimeBinDir)$(CrossHostArch)</CoreCLRArtifactsPath>

When building cross-components for cross-arch scenarios, the DCLR_CMAKE_TARGET_ARCH is used for the output path.

if [[ "$__TargetArch" != "$__HostArch" ]]; then
__CMakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__TargetArch $__CMakeArgs"
fi

One approach that I will try is to introduce the -hostos parameter along with -hostarch to indicate the target platform for the cross-components build. Another approach would be to adjust the components path in the _crossarch projects.

fi
__BinDir="$__RootBinDir/bin/coreclr/$__ConfigTriplet"
__ArtifactsObjDir="$__RepoRootDir/artifacts/obj"
__ArtifactsIntermediatesDir="$__ArtifactsObjDir/coreclr"
Expand Down
52 changes: 27 additions & 25 deletions src/coreclr/crosscomponents.cmake
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
# Add targets to the crosscomponents subcomponent build
if (CLR_CMAKE_HOST_OS STREQUAL CLR_CMAKE_TARGET_OS)
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)
install_clr (TARGETS
jitinterface_${ARCH_HOST_NAME}
DESTINATIONS .
COMPONENT crosscomponents
)

if (CLR_CMAKE_TARGET_OSX AND ARCH_TARGET_NAME STREQUAL arm64)
install_clr (TARGETS
clrjit_universal_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
DESTINATIONS .
COMPONENT crosscomponents
)
elseif (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64)
install_clr (TARGETS
clrjit_universal_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
DESTINATIONS .
COMPONENT crosscomponents
)
elseif (CLR_CMAKE_TARGET_UNIX)
install_clr (TARGETS
clrjit_unix_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
DESTINATIONS .
COMPONENT crosscomponents
)
else()
install_clr (TARGETS
clrjit_win_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
DESTINATIONS .
COMPONENT crosscomponents
)
if (NOT (CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS OR CLR_CMAKE_TARGET_MACCATALYST))
if (CLR_CMAKE_TARGET_OSX AND ARCH_TARGET_NAME STREQUAL arm64)
install_clr (TARGETS
clrjit_universal_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
DESTINATIONS .
COMPONENT crosscomponents
)
elseif (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64)
install_clr (TARGETS
clrjit_universal_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
DESTINATIONS .
COMPONENT crosscomponents
)
elseif (CLR_CMAKE_TARGET_UNIX)
install_clr (TARGETS
clrjit_unix_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
DESTINATIONS .
COMPONENT crosscomponents
)
else()
install_clr (TARGETS
clrjit_win_${ARCH_TARGET_NAME}_${ARCH_HOST_NAME}
DESTINATIONS .
COMPONENT crosscomponents
)
endif()
endif()
endif()

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<_CoreClrBuildArg Condition="'$(PgoInstrument)' == 'true'" Include="-pgoinstrument" />
<_CoreClrBuildArg Condition="'$(NativeOptimizationDataSupported)' == 'true' and '$(NoPgoOptimize)' != 'true' and '$(PgoInstrument)' != 'true'" Include="-pgodatapath &quot;$(PgoPackagePath)&quot;" />
<_CoreClrBuildArg Condition="'$(HostArchitecture)' != ''" Include="-hostarch $(HostArchitecture)" />
<_CoreClrBuildArg Condition="'$(OutputRIDOS)' != ''" Include="-outputridos $(OutputRIDOS)" />
<_CoreClrBuildArg Include="-outputrid $(OutputRID)" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</PropertyGroup>

<ItemGroup>
<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetOS)' != 'osx' and '$(TargetTriple)' != ''" />
<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetOS)' != 'osx' and '$(TargetsAppleMobile)' != 'true' and '$(TargetTriple)' != ''" />
Copy link
Member

Choose a reason for hiding this comment

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

Would this work?

Suggested change
<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetOS)' != 'osx' and '$(TargetsAppleMobile)' != 'true' and '$(TargetTriple)' != ''" />
<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(_IsApplePlatform)' != 'true' and '$(TargetTriple)' != ''" />

</ItemGroup>
</Target>

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/aot/crossgen2/crossgen2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</PropertyGroup>

<ItemGroup Condition="'$(NativeAotSupported)' == 'true'">
<CustomLinkerArg Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(_hostOS)' != 'windows'" Include="--gcc-toolchain=$(ROOTFS_DIR)/usr" />
<CustomLinkerArg Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(TargetsAppleMobile)' != 'true' and '$(_hostOS)' != 'windows'" Include="--gcc-toolchain=$(ROOTFS_DIR)/usr" />
</ItemGroup>

<Import Project="$(R2ROverridePath)" Condition="'$(R2ROverridePath)' != ''" />
Expand Down
2 changes: 1 addition & 1 deletion src/mono/sample/iOS-NativeAOT/Program.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<Target Name="ConfigureIlcPathsForiOSCrossCompilation" Condition="'$(PublishAotUsingRuntimePack)' != 'true'"
BeforeTargets="SetupProperties">
<PropertyGroup>
<IlcPath>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', '$(HostOS).$(BuildArchitecture).$(CoreCLRConfiguration)', 'ilc'))</IlcPath>
<IlcPath>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(CoreCLRConfiguration)', '$(BuildArchitecture)' ,'ilc'))</IlcPath>
<IlcToolsPath>$(IlcPath)</IlcToolsPath>
<IlcSdkPath>$(CoreCLRAotSdkDir)</IlcSdkPath>
<IlcFrameworkPath>$(LibrariesAllBinArtifactsPath)</IlcFrameworkPath>
Expand Down