With the rapid development of domestic information technology systems, an increasing number of devices are adopting non-x86 architecture CPUs, such as ARM, Loongson, Shenwei, and RISC-V. Among them, the ARM architecture holds a significant market share due to its wide application, with Feiteng and Huawei Kirin being the main representatives of ARM architecture. When developing software for these domestic systems, supporting multiple architectures has become an essential skill.
In the past, directly compiling and debugging code on ARM machines was a common practice. This approach seems straightforward, but for large applications, especially complex systems like browsers, it presents numerous challenges. Taking the Chromium browser as an example, its codebase is vast and complex, requiring substantial computational resources and memory support during the build process. Compiling on ARM architecture devices with weaker processors and limited memory often leads to issues such as compilation stalls and insufficient memory. For instance, many devices equipped with Feiteng processors and only 8GB of memory experience extremely slow compilation speeds, and may even fail due to insufficient memory.
In the field of embedded development, cross-compilation is a commonly used development model. It compiles applications on more powerful machines and then ports the compiled applications to the target ARM devices for testing and optimization. Similarly, we can use this method to compile the ARM version of the Chromium browser on an x86 architecture development machine. Next, I will provide a detailed introduction on how to accomplish this on the Deepin Linux system.
1. System Preparation
1.Hardware Requirements: An x86-64 architecture machine with at least 8GB of RAM (16GB or more is recommended). If using an SSD, it is advisable to allocate ≥32GB of swap space for machines with 8GB of RAM, and ≥16GB of swap space for machines with 16GB of RAM. For disk space, at least 100GB of available space is required, which does not need to be on the same drive; allocating about 50-80GB on an HDD for building is appropriate.
2.Software Requirements: You must have git and Python v3.8+ installed, and ensure that<span>python3</span>
points to the executable of that version. If the appropriate version is not available in the system,<span>depot_tools</span>
will bundle a compatible version in<span>$depot_tools/python-bin</span>
. Additionally, the only supported STL is<span>libc++</span>
, and the recommended compiler is<span>clang</span>
. This article uses Deepin V23 as the operating system for explanation, but systems like Open Kylin and Ubuntu 24.04 are also applicable.
2. Download depot_tools
Chromium uses its own code management and build system, depot_tools, so the first step is to download it.
1.Clone the Repository: Enter the following command in the terminal<span>$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git</span>
to clone the depot_tools repository.
2.Set Environment Variables: Add depot_tools to the front of the PATH environment variable, preferably by writing it into the ~/.bashrc file. Assuming depot_tools is cloned to<span>/path/to/depot_tools</span>
, execute<span>$ export PATH="/path/to/depot_tools:$PATH"</span>
. Note that if depot_tools is cloned to the user home directory (e.g.,<span>/home/username/depot_tools</span>
), do not use the<span>~</span>
symbol in the PATH, as it may cause the<span>gclient runhooks</span>
command to fail; instead, use<span>$HOME</span>
or an absolute path, for example,<span>$ export PATH="$HOME/depot_tools:$PATH"</span>
.
3. Download the Specified Version of Chromium Source Code
The Chromium git repository is very large, and if you clone it completely, it is easy to interrupt during the download process, and git does not support resuming downloads; once interrupted, you have to start over, which is very time-consuming. Typically, we develop based on a specific release version, so we only need to clone the source code of the specified branch without the complete git history. If you need to view the history of Chromium, you can find it online athttps://source.chromium.org/chromium/chromium/.
1.Download the Specified Version of Source Code (without git log): Execute<span>$ git clone --depth 1 --branch</span>
<span>127.0.6533.100 https://chromium.googlesource.com/chromium/src.git</span>
to download the source code of Chromium version 127.0.6533.100.
2.Create a Branch: Enter the downloaded src directory and execute<span>$ cd src</span>
, then create a branch<span>$ git branch branch-127</span>
.
3.Create a .gclient File: In the same level directory as src, create a .gclient file with the following content:
Collapse
plaintext
solutions = [
{
"name": "src",
"url": "https://chromium.googlesource.com/chromium/src.git",
"managed": False,
"custom_deps": {},
"custom_vars": {}
}
]
target_cpu="arm64"
1.Sync Related Modules and Third-Party Library Source Code: Execute<span>$ gclient sync --nohooks --no-history</span>
to sync the modules associated with Chromium and the source code of third-party libraries.
2.Sync Tools or Binary Files: Execute<span>$ gclient runhooks</span>
. This step theoretically downloads the sysroot for the arm64 architecture. You can check if the directory<span>build/linux/debian_bullseye_arm64-sysroot</span>
exists; if not, download it manually using the command<span>./build/linux/sysroot_scripts/install-sysroot.py --arch=arm64</span>
.
4. Install System Libraries Required for Building
Chromium provides the<span>./build/install-build-deps.sh</span>
script to download the required system libraries, but executing it on Deepin V23 will result in an error. This is because the script developers did not consider other Linux distributions; we can add the<span>--unsupported</span>
parameter. After adding this parameter, other errors may also occur, which can be cumbersome to modify. A more straightforward solution is to directly install the required dependency packages. On Deepin V23, you can execute the following command:
Collapse
bash
sudo apt install -y \
debhelper \
devscripts \
lld-16 \
clang-16 \
clang-format-16 \
libclang-rt-16-dev \
libc++-16-dev \
libc++abi-16-dev \
rustc-web \
bindgen \
python3 \
pkg-config \
ninja-build \
python3-jinja2 \
python3-pkg-resources \
ca-certificates \
elfutils \
wget \
flex \
yasm \
xvfb \
wdiff \
gperf \
bison \
nodejs \
rollup \
valgrind \
xz-utils \
x11-apps \
xcb-proto \
xfonts-base \
libdav1d-dev \
libx11-xcb-dev \
libxshmfence-dev \
libgl-dev \
libglu1-mesa-dev \
libegl1-mesa-dev \
libgles2-mesa-dev \
libopenh264-dev \
generate-ninja \
mesa-common-dev \
rapidjson-dev \
libva-dev \
libxt-dev \
libgbm-dev \
libpng-dev \
libxss-dev \
libelf-dev \
libpci-dev \
libcap-dev \
libdrm-dev \
libffi-dev \
libhwy-dev \
libkrb5-dev \
libexif-dev \
libflac-dev \
libudev-dev \
libpipewire-0.3-dev \
libopus-dev \
libxtst-dev \
libjpeg-dev \
libxml2-dev \
libgtk-3-dev \
libxslt1-dev \
liblcms2-dev \
libpulse-dev \
libpam0g-dev \
libdouble-conversion-dev \
libxnvctrl-dev \
libglib2.0-dev \
libasound2-dev \
libsecret-1-dev \
libspeechd-dev \
libminizip-dev \
libhunspell-dev \
libharfbuzz-dev \
libxcb-dri3-dev \
libusb-1.0-0-dev \
libopenjp2-7-dev \
libmodpbase64-dev \
libnss3-dev \
libnspr4-dev \
libcups2-dev \
libevent-dev \
libevdev-dev \
libgcrypt20-dev \
libcurl4-openssl-dev \
libzstd-dev \
fonts-ipafont-gothic \
fonts-ipafont-mincho
5. Build the ARM64 Version of Chromium
1.Pass Build Parameters: To cross-compile Chromium for the ARM64 architecture, you need to pass build parameters to gn by executing<span>gn gen out/Default-arm64 --args="target_cpu = \"arm64\""</span>
.
2.Execute the Build: Execute<span>autoninja -C out/Default-arm64 chrome</span>
to start compiling Chromium. This process may take a while, so you can take a break and wait patiently.
3.Copy Files: After the compilation is complete, the<span>chrome</span>
executable file will be generated in the<span>out/Default-arm64</span>
directory. Use the following script to copy the<span>chrome</span>
executable file and related resource files to the target device:
cp -a ${build_dir}/chrome ${TARGET}
cp -a ${build_dir}/chrome_sandbox ${TARGET}
cp -a ${build_dir}/chrome_100_percent.pak ${TARGET}
cp -a ${build_dir}/chrome_200_percent.pak ${TARGET}
cp -a ${build_dir}/chrome_crashpad_handler ${TARGET}
cp -a ${build_dir}/icudtl.dat ${TARGET}
cp -a ${build_dir}/libEGL.so ${TARGET}
cp -a ${build_dir}/libGLESv2.so ${TARGET}
cp -a ${build_dir}/libvk_swiftshader.so ${TARGET}
cp -a ${build_dir}/libvulkan.so.1 ${TARGET}
cp -r ${build_dir}/locales/ ${TARGET}
cp -a ${build_dir}/resources.pak ${TARGET}
cp -a ${build_dir}/v8_context_snapshot.bin ${TARGET}
cp -a ${build_dir}/vk_swiftshader_icd.json ${TARGET}
After copying is complete, you can run the ARM64 version of Chromium on the target device.
By following the above steps, you can successfully cross-compile an ARM architecture browser on the Deepin system and deploy it to the target device. I hope this article helps those who are engaged in related development. If you have any questions during the process, feel free to discuss in the comments section!