Skip to content

Commit f511b3a

Browse files
committed
Enable building on arm64
This chnage 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 To support using darc on arm64, this commit removes the customizations of LD_LIBRARY_PATH and instead forces darc to run again a .NET Core 3.0 runtime. This in-turn makes darc pick up the right libgit2sharp automatically for the right set of platforms and architectures. 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 3aaca4d commit f511b3a

15 files changed

+417
-25
lines changed

build-source-tarball.sh

Lines changed: 36 additions & 13 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

@@ -148,9 +174,6 @@ git submodule foreach --quiet --recursive '
148174
# Now re-uberclone into the tarball src directory. Since we reuse the .gitdirs, this shouldn't hit the network at all.
149175
ignored_repos="https://dev.azure.com/dnceng/internal/_git/dotnet-optimization;https://dev.azure.com/devdiv/DevDiv/_git/DotNet-Trusted;https://devdiv.visualstudio.com/DevDiv/_git/DotNet-Trusted;https://[email protected]/dnceng/internal/_git/dotnet-optimization;https://dev.azure.com/dnceng/internal/_git/dotnet-core-setup;https://github.com/dotnet/source-build-reference-packages"
150176

151-
#export the LC_LIB_PATH for libgit2 so file as fedora fails to find it in the repodir
152-
export LD_LIBRARY_PATH=$CLI_PATH/tools/.store/microsoft.dotnet.darc/$DarcVersion/microsoft.dotnet.darc/$DarcVersion/tools/netcoreapp2.1/any/runtimes/rhel-x64/native/
153-
154177
"$CLI_PATH/dotnet" "$DARC_DLL" clone --repos-folder=$TARBALL_ROOT/src/ --git-dir-folder $SCRIPT_ROOT/.git/modules/src/ --include-toolset --ignore-repos "$ignored_repos" --azdev-pat bogus --github-pat bogus --depth 0 --debug
155178

156179
# now we don't need .git/modules/src or Darc anymore
@@ -208,28 +231,28 @@ cp $SCRIPT_ROOT/support/tarball/build.sh $TARBALL_ROOT/build.sh
208231
mkdir -p $TARBALL_ROOT/packages/prebuilt
209232
mkdir -p $TARBALL_ROOT/packages/source-built
210233
find $SCRIPT_ROOT/packages/restored/ -name '*.nupkg' -exec cp {} $TARBALL_ROOT/packages/prebuilt/ \;
211-
find $SCRIPT_ROOT/bin/obj/x64/Release/nuget-packages -name '*.nupkg' -exec cp {} $TARBALL_ROOT/packages/prebuilt/ \;
234+
find $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/nuget-packages -name '*.nupkg' -exec cp {} $TARBALL_ROOT/packages/prebuilt/ \;
212235

213236
# Copy reference-packages from bin dir to reference-packages directory.
214237
# See corresponding change in dir.props to change ReferencePackagesBasePath conditionally in offline build.
215238
mkdir -p $TARBALL_ROOT/packages/reference
216-
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/reference-packages/source $TARBALL_ROOT/packages/reference/source
217-
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/reference-packages/staging $TARBALL_ROOT/packages/reference/staging
239+
cp -r $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/reference-packages/source $TARBALL_ROOT/packages/reference/source
240+
cp -r $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/reference-packages/staging $TARBALL_ROOT/packages/reference/staging
218241

219242
# Copy tarballs to ./packages/archive directory
220243
mkdir -p $TARBALL_ROOT/packages/archive
221-
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/external-tarballs/*.tar.gz $TARBALL_ROOT/packages/archive/
244+
cp -r $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/external-tarballs/*.tar.gz $TARBALL_ROOT/packages/archive/
222245

223246
# Copy generated source from bin to src/generatedSrc
224-
cp -r $SCRIPT_ROOT/bin/obj/x64/Release/generatedSrc $TARBALL_ROOT/src/generatedSrc
247+
cp -r $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/generatedSrc $TARBALL_ROOT/src/generatedSrc
225248

226249
if [ -e $SCRIPT_ROOT/testing-smoke/smoke-test-packages ]; then
227250
cp -rf $SCRIPT_ROOT/testing-smoke/smoke-test-packages $TARBALL_ROOT/packages
228251
fi
229252

230253
echo 'Removing source-built packages from tarball prebuilts...'
231254

232-
for built_package in $(find $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
255+
for built_package in $(find $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/blob-feed/packages/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
233256
do
234257
if [ -e $TARBALL_ROOT/packages/prebuilt/$(basename $built_package) ]; then
235258
rm $TARBALL_ROOT/packages/prebuilt/$(basename $built_package)
@@ -250,8 +273,8 @@ cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*DotNetHost*.nupkg $TARBA
250273
cp $SCRIPT_ROOT/bin/obj/x64/Release/blob-feed/packages/*DotNetAppHost*.nupkg $TARBALL_ROOT/packages/source-built/
251274

252275
# Setup package version props to include both source-built and running PackageVersions.props
253-
mkdir --parents $TARBALL_ROOT/bin/obj/x64/Release/
254-
cp $SCRIPT_ROOT/support/tarball/PackageVersions.props $TARBALL_ROOT/bin/obj/x64/Release/
276+
mkdir --parents $TARBALL_ROOT/bin/obj/$targetArchitecture/Release/
277+
cp $SCRIPT_ROOT/support/tarball/PackageVersions.props $TARBALL_ROOT/bin/obj/$targetArchitecture/Release/
255278

256279
if [ $INCLUDE_LEAK_DETECTION -eq 1 ]; then
257280
echo 'Building leak detection MSBuild tasks...'
@@ -261,7 +284,7 @@ fi
261284

262285
echo 'Removing reference-only packages from tarball prebuilts...'
263286

264-
for ref_package in $(find $SCRIPT_ROOT/bin/obj/x64/Release/reference-packages/packages-to-delete/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
287+
for ref_package in $(find $SCRIPT_ROOT/bin/obj/$targetArchitecture/Release/reference-packages/packages-to-delete/ -name '*.nupkg' | tr '[:upper:]' '[:lower:]')
265288
do
266289
if [ -e $TARBALL_ROOT/packages/prebuilt/$(basename $ref_package) ]; then
267290
rm $TARBALL_ROOT/packages/prebuilt/$(basename $ref_package)
@@ -292,7 +315,7 @@ done
292315
echo 'Removing source-built, previously source-built packages and reference packages from il pkg src...'
293316
OLDIFS=$IFS
294317

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

build.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ export NUGET_PACKAGES="$scriptroot/packages/restored/"
6969
set -x
7070
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
7171

72-
# runtime 2.1.0 required for darc
73-
"$scriptroot/eng/common/dotnet-install.sh" -runtime dotnet -version 2.1.0
72+
# HACK ALERT. runtime 2.1.0 required for darc. But that doesn't work too well on arm64. Instead, pretend 3.0.0 is 2.1.0.
73+
"$scriptroot/eng/common/dotnet-install.sh" -runtime dotnet -version 3.0.0
74+
if [ ! -e $scriptroot/.dotnet/shared/Microsoft.NETCore.App/2.1.0 ]; then
75+
ln -s 3.0.0 $scriptroot/.dotnet/shared/Microsoft.NETCore.App/2.1.0
76+
fi
7477

7578
if [ "$alternateTarget" == "true" ]; then
7679
CLIPATH="$scriptroot/.dotnet"

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 -->
@@ -198,7 +201,7 @@
198201
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftNETCoreAppRuntimePackageVersion" Version="%24(MicrosoftNETCoreDotNetAppHostPackageVersion)" />
199202
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftNETCoreAppRuntimeVersion" Version="%24(MicrosoftNETCoreDotNetAppHostPackageVersion)" />
200203
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftNETCoreAppHostPackageVersion" Version="%24(MicrosoftNETCoreDotNetAppHostPackageVersion)" />
201-
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftAspNetCoreAppRuntimePackageVersion" Version="%24(MicrosoftAspNetCoreAppRuntimeLinuxX64PackageVersion)" />
204+
<ExtraPackageVersionPropsPackageInfo Include="MicrosoftAspNetCoreAppRuntimePackageVersion" Version="%24(MicrosoftAspNetCoreAppRuntimeLinux$(Platform)PackageVersion)" />
202205
<!-- core-sdk uses this property for ASP.NET blob directory -->
203206
<ExtraPackageVersionPropsPackageInfo Include="VSRedistCommonAspNetCoreTargetingPackx6430PackageVersion" Version="$(aspnetcoreOutputPackageVersion)" />
204207
<!-- 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.0.100",
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+
<PropertyGroup>
77+
<CrossgenToolDir>$(IntermediateOutputPath)crossgen\</CrossgenToolDir>
78+
<CrossgenPlatformAssembliesDir>$(IntermediateOutputPath)platformAssemblies\</CrossgenPlatformAssembliesDir>
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)