Skip to content

Commit 03496f2

Browse files
omajidcrummel
authored andcommitted
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 733b4fd commit 03496f2

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

@@ -217,28 +243,28 @@ cp $SCRIPT_ROOT/support/tarball/build.sh $TARBALL_ROOT/build.sh
217243
mkdir -p $TARBALL_ROOT/packages/prebuilt
218244
mkdir -p $TARBALL_ROOT/packages/source-built
219245
find $SCRIPT_ROOT/packages/restored/ -name '*.nupkg' -exec cp {} $TARBALL_ROOT/packages/prebuilt/ \;
220-
find $SCRIPT_ROOT/bin/obj/x64/Release/nuget-packages -name '*.nupkg' -exec cp {} $TARBALL_ROOT/packages/prebuilt/ \;
246+
find $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/nuget-packages -name '*.nupkg' -exec cp {} $TARBALL_ROOT/packages/prebuilt/ \;
221247

222248
# Copy reference-packages from bin dir to reference-packages directory.
223249
# See corresponding change in dir.props to change ReferencePackagesBasePath conditionally in offline build.
224250
mkdir -p $TARBALL_ROOT/packages/reference
225-
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/reference-packages/source $TARBALL_ROOT/packages/reference/source
226-
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/reference-packages/staging $TARBALL_ROOT/packages/reference/staging
251+
cp -r $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/reference-packages/source $TARBALL_ROOT/packages/reference/source
252+
cp -r $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/reference-packages/staging $TARBALL_ROOT/packages/reference/staging
227253

228254
# Copy tarballs to ./packages/archive directory
229255
mkdir -p $TARBALL_ROOT/packages/archive
230-
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/external-tarballs/*.tar.gz $TARBALL_ROOT/packages/archive/
256+
cp -r $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/external-tarballs/*.tar.gz $TARBALL_ROOT/packages/archive/
231257

232258
# Copy generated source from bin to src/generatedSrc
233-
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/generatedSrc $TARBALL_ROOT/src/generatedSrc
259+
cp -r $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/generatedSrc $TARBALL_ROOT/src/generatedSrc
234260

235261
if [ -e $SCRIPT_ROOT/testing-smoke/smoke-test-packages ]; then
236262
cp -rf $SCRIPT_ROOT/testing-smoke/smoke-test-packages $TARBALL_ROOT/packages
237263
fi
238264

239265
echo 'Removing source-built packages from tarball prebuilts...'
240266

241-
for built_package in $(find $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
267+
for built_package in $(find $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
242268
do
243269
if [ -e $TARBALL_ROOT/packages/prebuilt/$(basename $built_package) ]; then
244270
rm $TARBALL_ROOT/packages/prebuilt/$(basename $built_package)
@@ -251,16 +277,16 @@ done
251277
echo 'Copying source-built packages to tarball to replace packages needed before they are built...'
252278
mkdir -p $TARBALL_ROOT/packages/source-built
253279
cp -r $SCRIPT_ROOT/Tools/source-built/coreclr-tools $TARBALL_ROOT/packages/source-built/
254-
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*Arcade*.nupkg $TARBALL_ROOT/packages/source-built/
255-
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*SourceLink*.nupkg $TARBALL_ROOT/packages/source-built/
256-
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*Build*Tasks*.nupkg $TARBALL_ROOT/packages/source-built/
257-
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/runtime*.nupkg $TARBALL_ROOT/packages/source-built/
258-
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*DotNetHost*.nupkg $TARBALL_ROOT/packages/source-built/
259-
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*DotNetAppHost*.nupkg $TARBALL_ROOT/packages/source-built/
280+
cp $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/*Arcade*.nupkg $TARBALL_ROOT/packages/source-built/
281+
cp $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/*SourceLink*.nupkg $TARBALL_ROOT/packages/source-built/
282+
cp $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/*Build*Tasks*.nupkg $TARBALL_ROOT/packages/source-built/
283+
cp $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/runtime*.nupkg $TARBALL_ROOT/packages/source-built/
284+
cp $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/*DotNetHost*.nupkg $TARBALL_ROOT/packages/source-built/
285+
cp $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/*DotNetAppHost*.nupkg $TARBALL_ROOT/packages/source-built/
260286

261287
# Setup package version props to include both source-built and running PackageVersions.props
262-
mkdir --parents $TARBALL_ROOT/bin/obj/x64/Release/
263-
cp $SCRIPT_ROOT/support/tarball/PackageVersions.props $TARBALL_ROOT/bin/obj/x64/Release/
288+
mkdir --parents $TARBALL_ROOT/bin/obj/$targetArchitecture/Release/
289+
cp $SCRIPT_ROOT/support/tarball/PackageVersions.props $TARBALL_ROOT/bin/obj/$targetArchitecture/Release/
264290

265291
if [ $INCLUDE_LEAK_DETECTION -eq 1 ]; then
266292
echo 'Building leak detection MSBuild tasks...'
@@ -270,7 +296,7 @@ fi
270296

271297
echo 'Removing reference-only packages from tarball prebuilts...'
272298

273-
for ref_package in $(find $SCRIPT_ROOT/bin/obj/x64/Release/reference-packages/packages-to-delete/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
299+
for ref_package in $(find $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/reference-packages/packages-to-delete/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
274300
do
275301
if [ -e $TARBALL_ROOT/packages/prebuilt/$(basename $ref_package) ]; then
276302
rm $TARBALL_ROOT/packages/prebuilt/$(basename $ref_package)
@@ -328,7 +354,7 @@ fi
328354
echo 'Removing source-built, previously source-built packages and reference packages from il pkg src...'
329355
OLDIFS=$IFS
330356

331-
allBuiltPkgs=(`ls $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*.nupkg | xargs -n1 basename | tr '[:upper:]' '[:lower:]'`)
357+
allBuiltPkgs=(`ls $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/*.nupkg | xargs -n1 basename | tr '[:upper:]' '[:lower:]'`)
332358
pushd $TARBALL_ROOT/packages/reference/staging/
333359
ilSrcPaths=(`find . -maxdepth 2 -mindepth 2`)
334360
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 -->
@@ -201,7 +204,7 @@
201204
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftNETCoreAppRuntimePackageVersion" Version="%24(MicrosoftNETCoreDotNetAppHostPackageVersion)" />
202205
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftNETCoreAppRuntimeVersion" Version="%24(MicrosoftNETCoreDotNetAppHostPackageVersion)" />
203206
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftNETCoreAppHostPackageVersion" Version="%24(MicrosoftNETCoreDotNetAppHostPackageVersion)" />
204-
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftAspNetCoreAppRuntimePackageVersion" Version="%24(MicrosoftAspNetCoreAppRuntimeLinuxX64PackageVersion)" />
207+
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftAspNetCoreAppRuntimePackageVersion" Version="%24(MicrosoftAspNetCoreAppRuntimeLinux$(Platform)PackageVersion)" />
205208
<!-- core-sdk uses this property for ASP.NET blob directory -->
206209
<ExtraPackageVersionPropsPackageInfo Include="VSRedistCommonAspNetCoreTargetingPackx6430PackageVersion" Version="$(aspnetcoreOutputPackageVersion)" />
207210
<!-- 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)