Skip to main content

Build Flutter engine for linux-arm/arm64

HW:

OS:



caution

Make sure the command ran successfully before running the next command!!

Dependencies#

Host(Linux x86_64)#

mkdir -p $HOME/flutter-engine/sdk/toolchain \
&& mkdir -p $HOME/flutter-engine/sdk/sysroot \
&& mkdir -p $HOME/flutter-engine/engine
info

Using docker, run
docker run -it --volume="$HOME/flutter-engine:/root/flutter-engine:shared" ubuntu:18.04 /bin/bash.
Then, run apt update && apt install sudo on the container before following what is shown below.

sudo apt update -y \
&& sudo apt install -y bison build-essential cmake curl flex gcc git \
lsb-release libgmp-dev make ninja-build pkg-config python python3 \
rsync subversion texinfo vim wget \
&& sudo apt autoremove -y

Target(Linux ARM/ARM64)#

Connect the SD card or eMMC with OS to your SBC.

sudo apt update -y \
&& sudo apt install -y build-essential clang cmake git libblkid-dev \
libfreetype6-dev libglib2.0-dev libgtk-3-dev liblzma-dev ninja-build \
pkg-config rsync symlinks vim \
&& sudo apt autoremove -y

sysroot#

It may vary depending on various conditions. If symbolic links are broken, you will get some errors when following the steps below.

info

When I tested this, most of the errors occured for this reason.

Target(Linux ARM/ARM64)#

sudo symlinks -crs /*
sudo rsync -a -e 'ssh -p <host port>' /lib /usr /etc /opt \
<host user>@<host ip>:~/flutter-engine/sdk/sysroot

Host(Linux x86_64)#

When I built all successfully, the directory structure is shown below. Since / (root) is copied to $HOME/flutter-engine/sdk/sysroot, setting a symbolic link path to an absolute path can break symbolic links.

$HOME/flutter-engine/sdk/sysroot
โ”œโ”€โ”€ lib -> usr/lib
โ””โ”€โ”€ usr
โ”œโ”€โ”€ include
โ”‚ โ””โ”€โ”€ ...
โ””โ”€โ”€ lib
โ”œโ”€โ”€ aarch64-linux-gnu
โ”‚ย ย  โ”œโ”€โ”€ crt1.o
โ”‚ย ย  โ”œโ”€โ”€ crti.o
โ”‚ย ย  โ”œโ”€โ”€ crtn.o
โ”‚ย ย  โ”œโ”€โ”€ ld-2.29.so
โ”‚ย ย  โ”œโ”€โ”€ ld-linux-aarch64.so.1 -> ld-2.29.so
โ”‚ย ย  โ”œโ”€โ”€ libc-2.29.so
โ”‚ย ย  โ”œโ”€โ”€ libc_nonshared.a
โ”‚ย ย  โ”œโ”€โ”€ libc.so
โ”‚ย ย  โ”œโ”€โ”€ libc.so.6 -> libc-2.29.so
โ”‚ย ย  โ”œโ”€โ”€ libdl-2.29.so
โ”‚ย ย  โ”œโ”€โ”€ libdl.so -> ../../../lib/aarch64-linux-gnu/libdl.so.2
โ”‚ย ย  โ”œโ”€โ”€ libdl.so.2 -> libdl-2.29.so
โ”‚ย ย  โ”œโ”€โ”€ libgcc_s.so.1
โ”‚ย ย  โ”œโ”€โ”€ libm-2.29.so
โ”‚ย ย  โ”œโ”€โ”€ libm.so -> libm.so.6
โ”‚ย ย  โ”œโ”€โ”€ libm.so.6 -> libm-2.29.so
โ”‚ย ย  โ”œโ”€โ”€ libpthread-2.29.so
โ”‚ย ย  โ”œโ”€โ”€ libpthread.so -> ../../../lib/aarch64-linux-gnu/libpthread.so.0
โ”‚ย ย  โ”œโ”€โ”€ libpthread.so.0 -> libpthread-2.29.so
โ”‚ย ย  โ”œโ”€โ”€ librt-2.29.so
โ”‚ย ย  โ”œโ”€โ”€ librt.so -> ../../../lib/aarch64-linux-gnu/librt.so.1
โ”‚ย ย  โ”œโ”€โ”€ librt.so.1 -> librt-2.29.so
โ”‚ย ย  โ”œโ”€โ”€ libstdc++.so.6 -> libstdc++.so.6.0.26
โ”‚ย ย  โ””โ”€โ”€ libstdc++.so.6.0.26
โ””โ”€โ”€ gcc
โ””โ”€โ”€ aarch64-linux-gnu
โ””โ”€โ”€ 8
โ”œโ”€โ”€ crtbegin.o
โ”œโ”€โ”€ crtbeginS.o
โ”œโ”€โ”€ crtend.o
โ”œโ”€โ”€ crtendS.o
โ”œโ”€โ”€ libgcc.a
โ”œโ”€โ”€ libgcc_s.so -> ../../../aarch64-linux-gnu/libgcc_s.so.1
โ””โ”€โ”€ libstdc++.so -> ../../../aarch64-linux-gnu/libstdc++.so.6

Host(Linux x86_64)#

Clang installation#

Clang and LLVM#

git clone --branch=llvmorg-11.1.0 --depth=1 \
https://github.com/llvm/llvm-project.git $HOME/flutter-engine/llvm-project
cd $HOME/flutter-engine/llvm-project
[ -d build_llvm ] && sudo rm -r build_llvm ;\
cmake -G Ninja \
-S llvm \
-B build_llvm \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CROSSCOMPILING=True \
-DCMAKE_INSTALL_PREFIX=$HOME/flutter-engine/sdk/toolchain \
-DLLVM_ENABLE_PROJECTS=clang \
-DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu \
-DLLVM_TARGET_ARCH=AArch64 \
-DLLVM_TARGETS_TO_BUILD=AArch64
cmake --build build_llvm \
&& sudo cmake --install build_llvm

binutils-gdb#

git clone --depth=1 git://sourceware.org/git/binutils-gdb.git \
$HOME/flutter-engine/binutils-gdb
cd $HOME/flutter-engine/binutils-gdb
./configure --prefix="$HOME/flutter-engine/sdk/toolchain" \
--enable-gold \
--enable-ld \
--target=aarch64-linux-gnu
make -j$(expr $(expr $(nproc) \* 6) \/ 5) \
&& sudo make install

libcxxabi and libcxx#

libcxx is statically linked to the engine for minimal dependencies.

cd $HOME/flutter-engine/llvm-project
[ -d build_libcxxabi ] && sudo rm -r build_libcxxabi ;\
cmake -G Ninja \
-S libcxxabi \
-B build_libcxxabi \
-DCMAKE_MAKE_PROGRAM=$(which ninja) \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSROOT=$HOME/flutter-engine/sdk/sysroot \
-DCMAKE_INSTALL_PREFIX=$HOME/flutter-engine/sdk/toolchain \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=AArch64 \
-DCMAKE_C_COMPILER=$HOME/flutter-engine/sdk/toolchain/bin/clang \
-DCMAKE_CXX_COMPILER=$HOME/flutter-engine/sdk/toolchain/bin/clang++ \
-DCMAKE_AR=$HOME/flutter-engine/sdk/toolchain/bin/aarch64-linux-gnu-ar \
-DCMAKE_RANLIB=$HOME/flutter-engine/sdk/toolchain/bin/aarch64-linux-gnu-ranlib \
-DLLVM_TARGETS_TO_BUILD=AArch64 \
-DLIBCXX_ENABLE_SHARED=False \
-DLIBCXXABI_ENABLE_EXCEPTIONS=False
cmake --build build_libcxxabi \
&& sudo cmake --install build_libcxxabi
[ -d build_libcxx ] && sudo rm -r build_libcxx ;\
cmake -G Ninja \
-S libcxx \
-B build_libcxx \
-DCMAKE_MAKE_PROGRAM=$(which ninja) \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSROOT=$HOME/flutter-engine/sdk/sysroot \
-DCMAKE_INSTALL_PREFIX=$HOME/flutter-engine/sdk/toolchain \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=AArch64 \
-DCMAKE_C_COMPILER=$HOME/flutter-engine/sdk/toolchain/bin/clang \
-DCMAKE_CXX_COMPILER=$HOME/flutter-engine/sdk/toolchain/bin/clang++ \
-DCMAKE_AR=$HOME/flutter-engine/sdk/toolchain/bin/aarch64-linux-gnu-ar \
-DCMAKE_RANLIB=$HOME/flutter-engine/sdk/toolchain/bin/aarch64-linux-gnu-ranlib \
-DLLVM_TARGETS_TO_BUILD=AArch64 \
-DLIBCXX_ENABLE_EXCEPTIONS=False \
-DLIBCXX_ENABLE_SHARED=False \
-DLIBCXX_ENABLE_RTTI=False \
-DLIBCXX_CXX_ABI=libcxxabi \
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=$HOME/flutter-engine/llvm-project/libcxxabi/include \
-DLIBCXX_CXX_ABI_LIBRARY_PATH=$HOME/flutter-engine/sdk/toolchain/lib \
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=True
cmake --build build_libcxx \
&& sudo cmake --install build_libcxx

depot_tools#

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git \
$HOME/flutter-engine/depot_tools
export PATH=$PATH:$HOME/flutter-engine/depot_tools

flutter-engine#

Ref: https://github.com/flutter/flutter/wiki/Setting-up-the-Engine-development-environment

info

After reading the Ref above, follow flutter-engine part.

echo 'solutions = [
{
"managed": False,
"name": "src/flutter",
"url": "git@github.com:hhk7734/engine.git",
"custom_deps": {},
"deps_file": "DEPS",
"safesync_url": "",
},
]' >> $HOME/flutter-engine/engine/.gclient \
&& cd $HOME/flutter-engine/engine \
&& gclient sync -D

Select engine revision#

cd $HOME/flutter-engine/engine/src/flutter \
&& git remote add upstream git@github.com:flutter/engine.git
git checkout master \
&& git pull upstream master \
&& git push origin master
git checkout <engine revision>
gclient sync -D

Dependencies#

cd $HOME/flutter-engine/engine/src \
&& sudo ./build/install-build-deps-android.sh
sudo ./build/install-build-deps.sh
sudo ./flutter/build/install-build-deps-linux-desktop.sh

Build#

cd $HOME/flutter-engine/engine/src
cp $HOME/flutter-engine/sdk/sysroot/usr/lib/aarch64-linux-gnu/pkgconfig/* \
$HOME/flutter-engine/sdk/sysroot/usr/share/pkgconfig
[ -d out/linux_debug_arm64 ] && sudo rm -r out/linux_debug_arm64 ;\
./flutter/tools/gn \
--target-sysroot $HOME/flutter-engine/sdk/sysroot \
--target-toolchain $HOME/flutter-engine/sdk/toolchain \
--target-triple aarch64-linux-gnu \
--target-os linux \
--linux-cpu arm64 \
--embedder-for-target \
--no-lto \
--no-goma \
--runtime-mode debug
ninja -C out/linux_debug_arm64
[ -d out/linux_profile_arm64 ] && sudo rm -r out/linux_profile_arm64 ;\
./flutter/tools/gn \
--target-sysroot $HOME/flutter-engine/sdk/sysroot \
--target-toolchain $HOME/flutter-engine/sdk/toolchain \
--target-triple aarch64-linux-gnu \
--target-os linux \
--linux-cpu arm64 \
--embedder-for-target \
--no-lto \
--no-goma \
--runtime-mode profile
ninja -C out/linux_profile_arm64
[ -d out/linux_release_arm64 ] && sudo rm -r out/linux_release_arm64 ;\
./flutter/tools/gn \
--target-sysroot $HOME/flutter-engine/sdk/sysroot \
--target-toolchain $HOME/flutter-engine/sdk/toolchain \
--target-triple aarch64-linux-gnu \
--target-os linux \
--linux-cpu arm64 \
--embedder-for-target \
--no-lto \
--no-goma \
--runtime-mode release
ninja -C out/linux_release_arm64
Last updated on