Skip to content

Commit db34848

Browse files
committed
Enable building on arm64
This change allows source-build to be cloned and built on arm64 machines. It shouldn't affect cross compilation at all, however. I have tested this on RHEL 8 aarch64. This change includes backports of the following pull-requests which have been merged into their respective master branches: - dotnet/aspnetcore#14790 - dotnet/aspnetcore#15354 - dotnet/installer#4102 - dotnet/core-setup#8468 - dotnet/corefx#40453 There's a number of existing build configuration that are conditionalized on arm64, such as setting up a root file system. Those they are actually only meant to be invoked when cross-compiling for arm64 (on x86_64). This commit modifies those conditions to not apply when building on an arm64 machine.
1 parent 6957df8 commit db34848

14 files changed

+405
-26
lines changed

build-source-tarball.sh

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,32 @@ if [ -z "${1:-}" ]; then
1212
exit 1
1313
fi
1414

15+
# Use uname to determine what the CPU is.
16+
cpuname=$(uname -p)
17+
# Some Linux platforms report unknown for platform, but the arch for machine.
18+
if [[ "$cpuname" == "unknown" ]]; then
19+
cpuname=$(uname -m)
20+
fi
21+
22+
case $cpuname in
23+
aarch64)
24+
targetArchitecture=arm64
25+
;;
26+
amd64|x86_64)
27+
targetArchitecture=x64
28+
;;
29+
armv7l)
30+
targetArchitecture=arm
31+
;;
32+
i686)
33+
targetArchitecture=x86
34+
;;
35+
*)
36+
echo "Unknown CPU $cpuname detected, treating it as x64"
37+
targetArchitecture=x64
38+
;;
39+
esac
40+
1541
TARBALL_ROOT=$1
1642
shift
1743

@@ -201,28 +227,28 @@ cp $SCRIPT_ROOT/support/tarball/build.sh $TARBALL_ROOT/build.sh
201227
mkdir -p $TARBALL_ROOT/packages/prebuilt
202228
mkdir -p $TARBALL_ROOT/packages/source-built
203229
find $SCRIPT_ROOT/packages/restored/ -name '*.nupkg' -exec cp {} $TARBALL_ROOT/packages/prebuilt/ \;
204-
find $SCRIPT_ROOT/bin/obj/x64/Release/nuget-packages -name '*.nupkg' -exec cp {} $TARBALL_ROOT/packages/prebuilt/ \;
230+
find $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/nuget-packages -name '*.nupkg' -exec cp {} $TARBALL_ROOT/packages/prebuilt/ \;
205231

206232
# Copy reference-packages from bin dir to reference-packages directory.
207233
# See corresponding change in dir.props to change ReferencePackagesBasePath conditionally in offline build.
208234
mkdir -p $TARBALL_ROOT/packages/reference
209-
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/reference-packages/source $TARBALL_ROOT/packages/reference/source
210-
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/reference-packages/staging $TARBALL_ROOT/packages/reference/staging
235+
cp -r $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/reference-packages/source $TARBALL_ROOT/packages/reference/source
236+
cp -r $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/reference-packages/staging $TARBALL_ROOT/packages/reference/staging
211237

212238
# Copy tarballs to ./packages/archive directory
213239
mkdir -p $TARBALL_ROOT/packages/archive
214-
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/external-tarballs/*.tar.gz $TARBALL_ROOT/packages/archive/
240+
cp -r $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/external-tarballs/*.tar.gz $TARBALL_ROOT/packages/archive/
215241

216242
# Copy generated source from bin to src/generatedSrc
217-
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/generatedSrc $TARBALL_ROOT/src/generatedSrc
243+
cp -r $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/generatedSrc $TARBALL_ROOT/src/generatedSrc
218244

219245
if [ -e $SCRIPT_ROOT/testing-smoke/smoke-test-packages ]; then
220246
cp -rf $SCRIPT_ROOT/testing-smoke/smoke-test-packages $TARBALL_ROOT/packages
221247
fi
222248

223249
echo 'Removing source-built packages from tarball prebuilts...'
224250

225-
for built_package in $(find $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
251+
for built_package in $(find $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
226252
do
227253
if [ -e $TARBALL_ROOT/packages/prebuilt/$(basename $built_package) ]; then
228254
rm $TARBALL_ROOT/packages/prebuilt/$(basename $built_package)
@@ -235,16 +261,16 @@ done
235261
echo 'Copying source-built packages to tarball to replace packages needed before they are built...'
236262
mkdir -p $TARBALL_ROOT/packages/source-built
237263
cp -r $SCRIPT_ROOT/Tools/source-built/coreclr-tools $TARBALL_ROOT/packages/source-built/
238-
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*Arcade*.nupkg $TARBALL_ROOT/packages/source-built/
239-
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*SourceLink*.nupkg $TARBALL_ROOT/packages/source-built/
240-
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*Build*Tasks*.nupkg $TARBALL_ROOT/packages/source-built/
241-
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/runtime*.nupkg $TARBALL_ROOT/packages/source-built/
242-
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*DotNetHost*.nupkg $TARBALL_ROOT/packages/source-built/
243-
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*DotNetAppHost*.nupkg $TARBALL_ROOT/packages/source-built/
264+
cp $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/*Arcade*.nupkg $TARBALL_ROOT/packages/source-built/
265+
cp $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/*SourceLink*.nupkg $TARBALL_ROOT/packages/source-built/
266+
cp $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/*Build*Tasks*.nupkg $TARBALL_ROOT/packages/source-built/
267+
cp $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/runtime*.nupkg $TARBALL_ROOT/packages/source-built/
268+
cp $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/*DotNetHost*.nupkg $TARBALL_ROOT/packages/source-built/
269+
cp $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/*DotNetAppHost*.nupkg $TARBALL_ROOT/packages/source-built/
244270

245271
# Setup package version props to include both source-built and running PackageVersions.props
246-
mkdir --parents $TARBALL_ROOT/bin/obj/x64/Release/
247-
cp $SCRIPT_ROOT/support/tarball/PackageVersions.props $TARBALL_ROOT/bin/obj/x64/Release/
272+
mkdir --parents $TARBALL_ROOT/bin/obj/$targetArchitecture/Release/
273+
cp $SCRIPT_ROOT/support/tarball/PackageVersions.props $TARBALL_ROOT/bin/obj/$targetArchitecture/Release/
248274

249275
if [ $INCLUDE_LEAK_DETECTION -eq 1 ]; then
250276
echo 'Building leak detection MSBuild tasks...'
@@ -254,7 +280,7 @@ fi
254280

255281
echo 'Removing reference-only packages from tarball prebuilts...'
256282

257-
for ref_package in $(find $SCRIPT_ROOT/bin/obj/x64/Release/reference-packages/packages-to-delete/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
283+
for ref_package in $(find $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/reference-packages/packages-to-delete/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
258284
do
259285
if [ -e $TARBALL_ROOT/packages/prebuilt/$(basename $ref_package) ]; then
260286
rm $TARBALL_ROOT/packages/prebuilt/$(basename $ref_package)
@@ -285,7 +311,7 @@ done
285311
echo 'Removing source-built, previously source-built packages and reference packages from il pkg src...'
286312
OLDIFS=$IFS
287313

288-
allBuiltPkgs=(`ls $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*.nupkg | xargs -n1 basename | tr '[:upper:]' '[:lower:]'`)
314+
allBuiltPkgs=(`ls $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/*.nupkg | xargs -n1 basename | tr '[:upper:]' '[:lower:]'`)
289315
pushd $TARBALL_ROOT/packages/reference/staging/
290316
ilSrcPaths=(`find . -maxdepth 2 -mindepth 2`)
291317
popd

dir.props

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition="$(Configuration) == ''">Release</Configuration>
5+
6+
<BuildArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant())</BuildArchitecture>
7+
<Platform Condition="'$(Platform)' == '' AND '$(BuildArchitecture)' == 'arm64'">$(BuildArchitecture)</Platform>
58
<Platform Condition="'$(Platform)' == ''">x64</Platform>
69

710
<!-- true if we have bootstrapped buildtools (usually on an unsupported platform -->
@@ -200,7 +203,7 @@
200203
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftNETCoreAppRuntimePackageVersion" Version="%24(MicrosoftNETCoreDotNetAppHostPackageVersion)" />
201204
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftNETCoreAppRuntimeVersion" Version="%24(MicrosoftNETCoreDotNetAppHostPackageVersion)" />
202205
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftNETCoreAppHostPackageVersion" Version="%24(MicrosoftNETCoreDotNetAppHostPackageVersion)" />
203-
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftAspNetCoreAppRuntimePackageVersion" Version="%24(MicrosoftAspNetCoreAppRuntimeLinuxX64PackageVersion)" />
206+
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftAspNetCoreAppRuntimePackageVersion" Version="%24(MicrosoftAspNetCoreAppRuntimeLinux$(Platform)PackageVersion)" />
204207
<!-- core-sdk uses this property for ASP.NET blob directory -->
205208
<ExtraPackageVersionPropsPackageInfo Include="VSRedistCommonAspNetCoreTargetingPackx6430PackageVersion" Version="$(aspnetcoreOutputPackageVersion)" />
206209
<!-- OSX needs the OSX version instead of Linux. We don't have a lot of flexibility in how we output these properties so we're relying on the previous one being blank if the Linux version of the package is missing. -->
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
From 84d274a8f3d416b0a5bd999e3d1c43ae1535e38f Mon Sep 17 00:00:00 2001
2+
From: Omair Majid <[email protected]>
3+
Date: Wed, 23 Oct 2019 15:43:57 -0400
4+
Subject: [PATCH] Support global.json on arm64 as well
5+
6+
arcade uses the runtime section of global.json to decide which
7+
architecture + runtime combination needs to be installed.
8+
9+
With https://github.com/dotnet/arcade/pull/4132 arcade can install
10+
foreign SDKs in separate locations correctly.
11+
12+
This change, suggested by @dougbu, makes arcade always install the
13+
runtime for the local architecture (which means it should work on arm64
14+
and x64) as well as the x86 architecture (skipped on Linux).
15+
16+
This gets us a working SDK/Runtime combo on arm64.
17+
---
18+
global.json | 2 +-
19+
1 file changed, 1 insertion(+), 1 deletion(-)
20+
21+
diff --git a/global.json b/global.json
22+
index 602f4f44e17..40dec559cc9 100644
23+
--- a/global.json
24+
+++ b/global.json
25+
@@ -5,7 +5,7 @@
26+
"tools": {
27+
"dotnet": "3.1.100-preview1-014400",
28+
"runtimes": {
29+
- "dotnet/x64": [
30+
+ "dotnet": [
31+
"$(MicrosoftNETCoreAppRuntimeVersion)"
32+
],
33+
"dotnet/x86": [
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
From e2946a26c11be7f7f0c223721a5b14f58f2ea240 Mon Sep 17 00:00:00 2001
2+
From: Omair Majid <[email protected]>
3+
Date: Mon, 11 Nov 2019 13:37:40 -0500
4+
Subject: [PATCH] Support building for arm64 on arm64 (*nix)
5+
6+
This commit allows ASP.NET Core to be built on arm64 machines directly,
7+
without relying on cross-compilation.
8+
9+
There's a few changes in here:
10+
11+
1. Ask msbuild to look into the BuildArchitecture
12+
13+
By default, our build systems assums the machine is x64. This
14+
modifies the build configuration to check the architecture of the
15+
currently running build machine, and set BuildArchitecture to that.
16+
17+
2. Fix crossgen in Microsoft.AspNetCore.App.Runtime
18+
19+
We run crossgen for supported architectures (including x64 and
20+
arm64). For that, we need a jit that we can point crossgen to.
21+
Generally, we can rely on the build scripts to find the right
22+
`libclrjit.so`. However, arm64 has multiple `libclirjit.so`, for
23+
different use-cases. There's one for arm64 (for running on arm64) and
24+
there's another one for cross-compiling for arm64 on x64. We need to
25+
figure out and use the right one explicitly rather than assuming the
26+
right one gets picked up.
27+
28+
See https://github.com/dotnet/core-setup/pull/8468 for similar
29+
changes made in core-setup.
30+
31+
This also needs https://github.com/aspnet/AspNetCore/pull/14790 to fully
32+
work on arm64.
33+
---
34+
Directory.Build.props | 1 +
35+
.../src/Microsoft.AspNetCore.App.Runtime.csproj | 12 ++++++++----
36+
2 files changed, 9 insertions(+), 4 deletions(-)
37+
38+
diff --git a/Directory.Build.props b/Directory.Build.props
39+
index b3dc903387f..1bd59d73121 100644
40+
--- a/Directory.Build.props
41+
+++ b/Directory.Build.props
42+
@@ -108,6 +108,7 @@
43+
<TargetOsName Condition=" '$(TargetOsName)' == '' AND $([MSBuild]::IsOSPlatform('Windows'))">win</TargetOsName>
44+
<TargetOsName Condition=" '$(TargetOsName)' == '' AND $([MSBuild]::IsOSPlatform('OSX'))">osx</TargetOsName>
45+
<TargetOsName Condition=" '$(TargetOsName)' == '' AND $([MSBuild]::IsOSPlatform('Linux'))">linux</TargetOsName>
46+
+ <BuildArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant())</BuildArchitecture>
47+
<TargetArchitecture Condition="'$(TargetArchitecture)' == ''">x64</TargetArchitecture>
48+
<TargetRuntimeIdentifier>$(TargetOsName)-$(TargetArchitecture)</TargetRuntimeIdentifier>
49+
50+
diff --git a/src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj b/src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj
51+
index 4c4298a92da..f843ded1241 100644
52+
--- a/src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj
53+
+++ b/src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj
54+
@@ -90,15 +90,17 @@ This package is an internal implementation of the .NET Core SDK and is not meant
55+
<PathSeparator Condition="'$(PathSeparator)' == ''">:</PathSeparator>
56+
<PathSeparator Condition=" '$(TargetOsName)' == 'win' ">%3B</PathSeparator>
57+
58+
+ <CrossCompileDirectory Condition=" '$(TargetRuntimeIdentifier)' == 'linux-arm' ">x64_arm</CrossCompileDirectory>
59+
+ <CrossCompileDirectory Condition=" '$(TargetArchitecture)' == 'arm64' AND '$(BuildArchitecture)' != 'arm64' ">x64_arm64</CrossCompileDirectory>
60+
+ <CrossCompileDirectory Condition=" '$(TargetRuntimeIdentifier)' == 'win-arm' ">x86_arm</CrossCompileDirectory>
61+
+
62+
<!-- Crossgen executable name -->
63+
<CrossgenToolFileName>crossgen</CrossgenToolFileName>
64+
<CrossgenToolFileName Condition=" '$(TargetOsName)' == 'win' ">$(CrossgenToolFileName).exe</CrossgenToolFileName>
65+
<!-- Default crossgen executable relative path -->
66+
<CrossgenToolPackagePath>$(CrossgenToolFileName)</CrossgenToolPackagePath>
67+
<!-- Disambiguated RID-specific crossgen executable relative path -->
68+
- <CrossgenToolPackagePath Condition=" '$(TargetRuntimeIdentifier)' == 'linux-arm' ">x64_arm\$(CrossgenToolPackagePath)</CrossgenToolPackagePath>
69+
- <CrossgenToolPackagePath Condition=" '$(TargetRuntimeIdentifier)' == 'linux-arm64' OR '$(TargetRuntimeIdentifier)' == 'linux-musl-arm64' ">x64_arm64\$(CrossgenToolPackagePath)</CrossgenToolPackagePath>
70+
- <CrossgenToolPackagePath Condition=" '$(TargetRuntimeIdentifier)' == 'win-arm' ">x86_arm\$(CrossgenToolPackagePath)</CrossgenToolPackagePath>
71+
+ <CrossgenToolPackagePath Condition=" '$(CrossCompileDirectory)' != '' ">$(CrossCompileDirectory)\$(CrossgenToolPackagePath)</CrossgenToolPackagePath>
72+
73+
<MicrosoftNETCoreAppRuntimeIdentifier>$(RuntimeIdentifier)</MicrosoftNETCoreAppRuntimeIdentifier>
74+
<MicrosoftNETCoreAppRuntimeIdentifier Condition="'$(TargetOsName)' != 'osx'">$(SourceBuildRuntimeIdentifier)</MicrosoftNETCoreAppRuntimeIdentifier>
75+
@@ -293,7 +295,9 @@ This package is an internal implementation of the .NET Core SDK and is not meant
76+
-->
77+
<PropertyGroup>
78+
<CrossgenToolDir>$(IntermediateOutputPath)crossgen\</CrossgenToolDir>
79+
- <CoreCLRJitPath>$(CrossgenToolDir)$(LibPrefix)clrjit$(LibExtension)</CoreCLRJitPath>
80+
+ <!-- Pick the right coreclr jit based on whether we are cross-compiling or not -->
81+
+ <CoreCLRJitPath Condition="'$(CrossCompileDirectory)' == ''">$(RuntimePackageRoot)runtimes\$(RuntimeIdentifier)\native\$(LibPrefix)clrjit$(LibExtension)</CoreCLRJitPath>
82+
+ <CoreCLRJitPath Condition="'$(CrossCompileDirectory)' != ''">$(RuntimepackageRoot)runtimes\$(CrossCompileDirectory)\native\$(LibPrefix)clrjit$(LibExtension)</CoreCLRJitPath>
83+
</PropertyGroup>
84+
85+
<ItemGroup>

0 commit comments

Comments
 (0)