Skip to content

Commit 20b3bab

Browse files
stewdkwkozaczuk
authored andcommitted
Add script to download aarch64 cross compiler toolchain
This is a source-able script that downloads the aarch64 toolchain from developer.arm.com, extracts it, and, when being sourced, adds the path to PATH. If ccache is installed, it will also add the ccache directory to the front of PATH. Add a check in the OSv build script to source the toolchain if arch=aarch64 and the toolchain has been downloaded to the build directory. Add "centos" as an option in download_aarch64_packages.py to download the toolchain. I did not change the logic for Ubuntu here due to the possibility of ending up with unvetted combinations of this GCC version with various Ubuntu system libraries that could be built with different versions of GCC. This toolchain can still be used on Ubuntu by sourcing it directly, but in this case I recommend building Boost and other dependent libraries from source to ensure they are built with the same toolchain that is being used to build OSv and your apps/modules. This toolchain should work on any distribution that ARM supports, which is Ubuntu 16.04 LTS or later, or RHEL 7 or later. I've tested this on CentOS 7 and Ubuntu 18.04. My primary motivation for this is to support the aarch64 build on CentOS 7. While the EPEL repository for CentOS 7 does have an aarch64 cross compiler toolchain available, it is quite an old version (4.8.5). On Ubuntu, the aarch64 cross compiler toolchain conflicts with the gcc-multilib package. Using the ARM toolchain allows us to avoid these particular issues. This toolchain does not provide Boost, so Boost will need to be built. Boost can be built with the script download_and_build_boost.sh in the scripts/ directory, or it can be built manually. Here are instructions I used for building Boost from source. Ensure that the current working directory is the root of the OSv repository, then run the following commands: $ source scripts/download_aarch64_toolchain.sh $ mkdir -p build/downloaded_packages/aarch64/boost $ pushd build/downloaded_packages/aarch64/boost $ wget https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz $ tar -xf boost_1_70_0.tar.gz $ cd boost_1_70_0/ $ BOOST_DIR=$(pwd) $ ./bootstrap.sh $ echo "using gcc : arm : aarch64-none-linux-gnu-g++ ;" > user-config.jam $ ./b2 --user-config=${BOOST_DIR}/user-config.jam toolset=gcc-arm architecture=arm address-model=64 -j$(nproc) After building Boost, we need to set up some symlinks so that OSv can find the Boost headers and libraries. Ensure your current working directory is the Boost source directory BOOST_DIR (it should be already), then run the following commands: $ ln -s boost_1_70_0/stage ../install $ mkdir -p stage/usr/include $ ln -s ../../../boost stage/usr/include/boost $ popd After building Boost and setting up the symlinks, we should be ready to build OSv with the aarch64 toolchain: $ scripts/build arch=aarch64 fs=ramfs --create-disk image=native-example -j$(nproc) Signed-off-by: Stewart Hildebrand <[email protected]> Message-Id: <[email protected]>
1 parent a796c9a commit 20b3bab

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

scripts/build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ do
8888
esac
8989
done
9090

91+
if [[ "${arch-}" == "aarch64" && -d "build/downloaded_packages/aarch64/toolchain/" ]]; then
92+
. scripts/download_aarch64_toolchain.sh
93+
export CROSS_PREFIX=aarch64-none-linux-gnu-
94+
fi
95+
9196
make "${args[@]}" ${stage1_args} | tee build.out
9297
# check exit status of make
9398
status=${PIPESTATUS[0]}

scripts/download_aarch64_packages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def ubuntu_identify_boost_version(codename, index):
7878
print("Cound not find boost version from neither main nor universe ports index!")
7979
sys.exit(1)
8080
commands_to_download = ubuntu_download_commands(boost_version)
81+
elif name.lower() == "centos":
82+
commands_to_download = [ 'bash -eu %s/scripts/download_aarch64_toolchain.sh' % osv_root ]
8183
else:
8284
print("The distribution %s is not supported for cross-compiling aarch64 version of OSv" % name)
8385
sys.exit(1)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash -eu
2+
3+
# Copyright (c) 2021, DornerWorks, Ltd.
4+
# Author: Stewart Hildebrand
5+
# SPDX-License-Identifier: BSD-3-Clause OR MIT
6+
7+
# Usage:
8+
# $ source download_aarch64_toolchain.sh
9+
# or
10+
# $ . download_aarch64_toolchain.sh
11+
12+
# https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads
13+
14+
ARM64_TOOLCHAIN_SCRIPTDIR="$(cd $(dirname ${BASH_SOURCE}) && pwd)/"
15+
ARM64_TOOLCHAIN_DESTINATION="${ARM64_TOOLCHAIN_SCRIPTDIR}../build/downloaded_packages/aarch64/toolchain/"
16+
ARM64_TOOLCHAIN_VERSION=9.2-2019.12
17+
ARM64_TOOLCHAIN_FILENAME=gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu
18+
19+
if [ ! -d ${ARM64_TOOLCHAIN_DESTINATION}${ARM64_TOOLCHAIN_FILENAME} ]; then
20+
mkdir -p "${ARM64_TOOLCHAIN_DESTINATION}"
21+
pushd "${ARM64_TOOLCHAIN_DESTINATION}" >/dev/null
22+
if [ ! -s ${ARM64_TOOLCHAIN_FILENAME}.tar.xz ]; then
23+
wget https://developer.arm.com/-/media/Files/downloads/gnu-a/${ARM64_TOOLCHAIN_VERSION}/binrel/${ARM64_TOOLCHAIN_FILENAME}.tar.xz
24+
fi
25+
tar -xf ${ARM64_TOOLCHAIN_FILENAME}.tar.xz
26+
popd >/dev/null
27+
fi
28+
29+
if [ -d /usr/lib64/ccache ]; then
30+
CCACHE_SYMLINK_DIR=/usr/lib64/ccache
31+
fi
32+
if [ -d /usr/lib/ccache ]; then
33+
CCACHE_SYMLINK_DIR=/usr/lib/ccache
34+
fi
35+
36+
PATH=${ARM64_TOOLCHAIN_DESTINATION}${ARM64_TOOLCHAIN_FILENAME}/bin:${PATH}
37+
if [ ! -z "${CCACHE_SYMLINK_DIR-}" ]; then
38+
PATH=${CCACHE_SYMLINK_DIR}:$(echo ${PATH} | sed "s|${CCACHE_SYMLINK_DIR}:||g")
39+
fi
40+
41+
if [ -z "${CCACHE_SYMLINK_DIR-}" ]; then
42+
echo "It is recommended to install ccache and create symlinks for the"
43+
echo "aarch64 toolchain in order to significantly speed up the build."
44+
else
45+
if [ ! -h "${CCACHE_SYMLINK_DIR}/aarch64-none-linux-gnu-g++" ] || [ ! -h "${CCACHE_SYMLINK_DIR}/aarch64-none-linux-gnu-gcc" ]; then
46+
echo "It is recommended to create ccache symlinks for the aarch64"
47+
echo "toolchain in order to significantly speed up the build. Run the"
48+
echo "following commands to create the appropriate symlinks:"
49+
echo ""
50+
echo " sudo ln -s ../../bin/ccache \"${CCACHE_SYMLINK_DIR}/aarch64-none-linux-gnu-gcc\""
51+
echo " sudo ln -s ../../bin/ccache \"${CCACHE_SYMLINK_DIR}/aarch64-none-linux-gnu-g++\""
52+
echo ""
53+
echo "After this, please re-source the toolchain script to enable ccache."
54+
fi
55+
fi

0 commit comments

Comments
 (0)