Skip to content

Commit 20fc1ad

Browse files
omajidJohn Luo
authored and
John Luo
committed
Support building for arm64 on arm64 (*nix) (#15354)
This commit allows ASP.NET Core to be built on arm64 machines directly, without relying on cross-compilation. There's a few changes in here: 1. Ask msbuild to look into the BuildArchitecture By default, our build systems assums the machine is x64. This modifies the build configuration to check the architecture of the currently running build machine, and set BuildArchitecture to that. 2. Fix crossgen in Microsoft.AspNetCore.App.Runtime We run crossgen for supported architectures (including x64 and arm64). For that, we need a jit that we can point crossgen to. Generally, we can rely on the build scripts to find the right `libclrjit.so`. However, arm64 has multiple `libclirjit.so`, for different use-cases. There's one for arm64 (for running on arm64) and there's another one for cross-compiling for arm64 on x64. We need to figure out and use the right one explicitly rather than assuming the right one gets picked up. See dotnet/core-setup#8468 for similar changes made in core-setup. This also needs #14790 to fully work on arm64.
1 parent ed5b721 commit 20fc1ad

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
<TargetOsName Condition=" '$(TargetOsName)' == '' AND $([MSBuild]::IsOSPlatform('Windows'))">win</TargetOsName>
109109
<TargetOsName Condition=" '$(TargetOsName)' == '' AND $([MSBuild]::IsOSPlatform('OSX'))">osx</TargetOsName>
110110
<TargetOsName Condition=" '$(TargetOsName)' == '' AND $([MSBuild]::IsOSPlatform('Linux'))">linux</TargetOsName>
111+
<BuildArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant())</BuildArchitecture>
111112
<TargetArchitecture Condition="'$(TargetArchitecture)' == ''">x64</TargetArchitecture>
112113
<TargetRuntimeIdentifier>$(TargetOsName)-$(TargetArchitecture)</TargetRuntimeIdentifier>
113114

src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,17 @@ This package is an internal implementation of the .NET Core SDK and is not meant
9090
<PathSeparator Condition="'$(PathSeparator)' == ''">:</PathSeparator>
9191
<PathSeparator Condition=" '$(TargetOsName)' == 'win' ">%3B</PathSeparator>
9292

93+
<CrossCompileDirectory Condition=" '$(TargetRuntimeIdentifier)' == 'linux-arm' ">x64_arm</CrossCompileDirectory>
94+
<CrossCompileDirectory Condition=" '$(TargetArchitecture)' == 'arm64' AND '$(BuildArchitecture)' != 'arm64' ">x64_arm64</CrossCompileDirectory>
95+
<CrossCompileDirectory Condition=" '$(TargetRuntimeIdentifier)' == 'win-arm' ">x86_arm</CrossCompileDirectory>
96+
9397
<!-- Crossgen executable name -->
9498
<CrossgenToolFileName>crossgen</CrossgenToolFileName>
9599
<CrossgenToolFileName Condition=" '$(TargetOsName)' == 'win' ">$(CrossgenToolFileName).exe</CrossgenToolFileName>
96100
<!-- Default crossgen executable relative path -->
97101
<CrossgenToolPackagePath>$(CrossgenToolFileName)</CrossgenToolPackagePath>
98102
<!-- Disambiguated RID-specific crossgen executable relative path -->
99-
<CrossgenToolPackagePath Condition=" '$(TargetRuntimeIdentifier)' == 'linux-arm' ">x64_arm\$(CrossgenToolPackagePath)</CrossgenToolPackagePath>
100-
<CrossgenToolPackagePath Condition=" '$(TargetRuntimeIdentifier)' == 'linux-arm64' OR '$(TargetRuntimeIdentifier)' == 'linux-musl-arm64' ">x64_arm64\$(CrossgenToolPackagePath)</CrossgenToolPackagePath>
101-
<CrossgenToolPackagePath Condition=" '$(TargetRuntimeIdentifier)' == 'win-arm' ">x86_arm\$(CrossgenToolPackagePath)</CrossgenToolPackagePath>
103+
<CrossgenToolPackagePath Condition=" '$(CrossCompileDirectory)' != '' ">$(CrossCompileDirectory)\$(CrossgenToolPackagePath)</CrossgenToolPackagePath>
102104

103105
<RuntimePackageRoot>$([System.IO.Path]::Combine('$(NuGetPackageRoot)', 'microsoft.netcore.app.runtime.$(RuntimeIdentifier)', '$(MicrosoftNETCoreAppRuntimeVersion)'))</RuntimePackageRoot>
104106
<RuntimePackageRoot>$([MSBuild]::EnsureTrailingSlash('$(RuntimePackageRoot)'))</RuntimePackageRoot>
@@ -293,7 +295,9 @@ This package is an internal implementation of the .NET Core SDK and is not meant
293295
-->
294296
<PropertyGroup>
295297
<CrossgenToolDir>$(IntermediateOutputPath)crossgen\</CrossgenToolDir>
296-
<CoreCLRJitPath>$(CrossgenToolDir)$(LibPrefix)clrjit$(LibExtension)</CoreCLRJitPath>
298+
<!-- Pick the right coreclr jit based on whether we are cross-compiling or not -->
299+
<CoreCLRJitPath Condition="'$(CrossCompileDirectory)' == ''">$(RuntimePackageRoot)runtimes\$(RuntimeIdentifier)\native\$(LibPrefix)clrjit$(LibExtension)</CoreCLRJitPath>
300+
<CoreCLRJitPath Condition="'$(CrossCompileDirectory)' != ''">$(RuntimepackageRoot)runtimes\$(CrossCompileDirectory)\native\$(LibPrefix)clrjit$(LibExtension)</CoreCLRJitPath>
297301
</PropertyGroup>
298302

299303
<ItemGroup>

0 commit comments

Comments
 (0)