Skip to content

Instantly share code, notes, and snippets.

@ardera
Created February 19, 2020 14:00
Show Gist options
  • Save ardera/06e8057aa04eb3e28516612737d1e6d2 to your computer and use it in GitHub Desktop.
Save ardera/06e8057aa04eb3e28516612737d1e6d2 to your computer and use it in GitHub Desktop.
My script for building the flutter engine binaries for Raspberry Pi using LLVM 9, LLVM 10, libcxx, libcxxabi & GNU binutils.
#!/bin/bash
function prettyEcho {
_date=$(date '+%d.%m.%Y %X')
echo -e "[$_date] \e[92m$1\e[0m"
echo "[$_date] $1" >> /home/hannes/develd/upgrade.log
}
function prettyTime {
time (($@) && echo "run-time:")
}
function runExt {
$@ &>> /home/hannes/develd/upgrade.log
}
function upgradeBinutils {
set -e
cd /home/hannes/develd
prettyEcho "checking out latest binutils..."
cd binutils
runExt git pull
prettyEcho "removing old binutils build files..."
cd ..
rm -rf ./binutils-build
mkdir binutils-build
cd ./binutils-build
prettyEcho "generating binutils build files..."
runExt ../binutils/configure --enable-ld --enable-gold --enable-lto --target=arm-linux-gnueabihf \
--prefix="/home/hannes/develd/rpi-toolchain"
prettyEcho "building binutils..."
runExt make -j8
prettyEcho "installing binutils..."
runExt make install
prettyEcho "done upgrading binutils!"
set +e
}
function upgradeLLVM {
set -e
cd /home/hannes/develd/llvm-src-9
prettyEcho "checking out latest LLVM 9.x..."
runExt git pull
prettyEcho "removing old LLVM build files..."
cd /home/hannes/develd/llvm-build
rm -rf ./llvm
mkdir llvm
cd llvm
prettyEcho "generating LLVM build files..."
runExt cmake /home/hannes/develd/llvm-src-9/llvm \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/hannes/develd/rpi-toolchain \
-DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf \
-DLLVM_ENABLE_PROJECTS="llvm;clang" -DLLVM_TARGETS_TO_BUILD=ARM -GNinja
prettyEcho "building LLVM..."
runExt ninja
prettyEcho "installing LLVM"
runExt ninja install
prettyEcho "done upgrading LLVM!"
set +e
}
function upgradeLibcxx {
set -e
cd /home/hannes/develd/llvm-src-latest
prettyEcho "checking out latest LLVM..."
runExt git pull
prettyEcho "removing old libcxxabi build files..."
cd /home/hannes/develd/llvm-build
rm -rf libcxxabi
mkdir libcxxabi
cd libcxxabi
prettyEcho "generating libcxxabi build files..."
runExt cmake /home/hannes/develd/llvm-src-latest/libcxxabi -GNinja \
-DCMAKE_CROSSCOMPILING=True -DCMAKE_SYSROOT=/home/hannes/develd/rpi-sysroot -DCMAKE_INSTALL_PREFIX=/home/hannes/develd/rpi-toolchain \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=ARM \
-DCMAKE_C_COMPILER=/home/hannes/develd/rpi-toolchain/bin/clang -DCMAKE_CXX_COMPILER=/home/hannes/develd/rpi-toolchain/bin/clang++ \
-DCMAKE_AR=/home/hannes/develd/rpi-toolchain/bin/arm-linux-gnueabihf-ar \
-DCMAKE_RANLIB=/home/hannes/develd/rpi-toolchain/bin/arm-linux-gnueabihf-ranlib \
-DCMAKE_LINKER=/home/hannes/develd/rpi-toolchain/bin/clang \
-DCMAKE_MT=/home/hannes/develd/rpi-toolchain/bin/arm-linux-gnueabihf-mt \
-DCMAKE_STRIP=/home/hannes/develd/rpi-toolchain/bin/arm-linux-gnueabihf-strip \
-DLLVM_TARGETS_TO_BUILD=ARM -DLIBCXXABI_ENABLE_EXCEPTIONS=False \
-DCMAKE_MAKE_PROGRAM=/usr/bin/ninja \
-DLIBCXX_ENABLE_SHARED=False
prettyEcho "building libcxxabi..."
runExt ninja
prettyEcho "installing libcxxabi..."
runExt ninja install
prettyEcho "done upgrading libxxabi!"
prettyEcho "removing old libcxx build files..."
cd ..
rm -rf libcxx
mkdir libcxx
cd libcxx
prettyEcho "generating libcxx build files..."
runExt cmake /home/hannes/develd/llvm-src-latest/libcxx -GNinja \
-DCMAKE_CROSSCOMPILING=True -DCMAKE_SYSROOT=/home/hannes/develd/rpi-sysroot -DCMAKE_INSTALL_PREFIX=/home/hannes/develd/rpi-toolchain \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=ARM \
-DCMAKE_C_COMPILER=/home/hannes/develd/rpi-toolchain/bin/clang \
-DCMAKE_CXX_COMPILER=/home/hannes/develd/rpi-toolchain/bin/clang++ \
-DCMAKE_AR=/home/hannes/develd/rpi-toolchain/bin/arm-linux-gnueabihf-ar \
-DCMAKE_RANLIB=/home/hannes/develd/rpi-toolchain/bin/arm-linux-gnueabihf-ranlib \
-DCMAKE_LINKER=/home/hannes/develd/rpi-toolchain/bin/clang \
-DCMAKE_MT=/home/hannes/develd/rpi-toolchain/bin/arm-linux-gnueabihf-mt \
-DCMAKE_STRIP=/home/hannes/develd/rpi-toolchain/bin/arm-linux-gnueabihf-strip \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DLLVM_TARGETS_TO_BUILD=ARM -DLIBCXX_CXX_ABI=libcxxabi -DLIBCXX_CXX_ABI_INCLUDE_PATHS=/home/hannes/develd/rpi-toolchain/include/c++/v1 \
-DLIBCXX_CXX_ABI_LIBRARY_PATH=/home/hannes/develd/rpi-toolchain/lib \
-DCMAKE_MAKE_PROGRAM=/usr/bin/ninja \
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=True -DLIBCXX_ENABLE_EXCEPTIONS=False -DLIBCXX_ENABLE_RTTI=False
prettyEcho "building libcxx..."
runExt ninja
prettyEcho "installing libcxx..."
runExt ninja install
prettyEcho "done upgrading libcxx!"
set +e
}
function upgradeEngine {
set +e
channel=$1
[ -z "$channel" ] && channel="stable"
enginecommit=$(wget https://raw.githubusercontent.com/flutter/flutter/$channel/bin/internal/engine.version -q -O -)
[ -z "$enginecommit" ] && { echo "channel $channel does not exist"; exit 1; }
set -e
prettyEcho "updating engine sources to latest $channel commit $enginecommit..."
cd /home/hannes/develd/engine
runExt gclient sync --revision=https://github.com/flutter/engine.git@$enginecommit
prettyEcho "removing old engine build files..."
cd /home/hannes/develd
rm -rf ./engine-out
mkdir engine-out
prettyEcho "generating engine build files..."
runExt ./engine/src/flutter/tools/gn \
--target-sysroot /home/hannes/develd/rpi-sysroot \
--target-toolchain /home/hannes/develd/rpi-toolchain \
--target-triple arm-linux-gnueabihf \
--linux-cpu arm \
--runtime-mode debug \
--embedder-for-target \
--lto \
--target-os linux \
--arm-float-abi hard \
--out /home/hannes/develd/engine-out
prettyEcho "building engine..."
cd ./engine-out/out/linux_debug_arm/
runExt ninja
prettyEcho "copying engine binaries to engine-binaries directory..."
runExt cp libflutter_engine.so flutter_embedder.h icudtl.dat /home/hannes/develd/engine-binaries
echo "$enginecommit" > /home/hannes/develd/engine-binaries/engine.version
prettyEcho "done upgrading engine!"
set +e
}
function upgradeAll {
prettyEcho "upgrading LLVM, binutils, libcxx and flutter engine"
upgradeLLVM
upgradeBinutils
upgradeLibcxx
upgradeEngine
prettyEcho "all done!"
}
function printUsage {
echo "upgrade-tool.sh usage:"
echo " upgrade-tool.sh <command>"
echo ""
echo " where <command> may be one of:"
echo " llvm: upgrades LLVM/Clang to the newest commit of the stable 9 release"
echo " libcxx: upgrades libcxx to the newest commit"
echo " binutils: upgrades binutils to the newest version"
echo " engine: upgrades engine to the newest stable version"
echo " all: all of the above."
}
echo "" > upgrade.log
case $1 in
llvm)
prettyTime upgradeLLVM
;;
libcxx)
prettyTime upgradeLibcxx
;;
binutils)
prettyTime upgradeBinutils
;;
engine)
prettyTime upgradeEngine
;;
all)
prettyTime upgradeAll
;;
*)
echo "invalid command: $1"
printUsage
exit 1
;;
esac
@kristian-krasamo
Copy link

I think using $HOME instead of /home/hannes would be a good idea.

@ardera
Copy link
Author

ardera commented May 14, 2021

true, but this is meant as an example. changing /home/hannes to $HOME is not the only thing you have to change to get it working, but at least it showcases the flags and arguments you have to use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment