Reputation: 66
I have been following the steps detailed in the page below to cross compile and build chromium (v87) for a Linux ARM device: https://chromium.googlesource.com/chromium/src/+/master/docs/linux/build_instructions.md
I have successfully built the chrome binary for an ARM target, but my goal now is to try and reduce the size of the chrome binary output which is given after a successful build. At the moment the chrome binary is sized at 190mb which is too large considering the previous chromium (v70) build which was performed years ago had the chrome binary output sized at ~80mb.
I believe the drastic size increase could be due to the large amount of dependencies included in the newer chromium release meaning additional deps files generated by gn gen out/***
or gn args out/***
and I have been looking for ways to try and cut out unneeded libraries to generate a smaller chrome binary. I attempted to modify the root file BUILD.GN
found in the root of the chromium directory, to set certain vars to false in an attempt to stop the gn command from adding unwanted library/dependency deps files, however this still causes the same number of dependency files to be placed in my build output folder and performing autoninja -C out/*** chrome
to build chrome results in a large chrome binary (190mb) to be given again:
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This is the root build file for GN. GN will start processing by loading this
# file, and recursively load all dependencies until all dependencies are either
# resolved or known not to exist (which will cause the build to fail). So if
# you add a new build file, there must be some path of dependencies from this
# file to your new one or GN won't know about it.
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/features.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/ui.gni")
import("//build/gn_logs.gni")
import("//build/util/generate_wrapper.gni")
import("//chrome/browser/buildflags.gni")
import("//chrome/browser/media/router/features.gni")
import("//components/nacl/features.gni")
import("//device/vr/buildflags/buildflags.gni")
import("//extensions/buildflags/buildflags.gni")
import("//gpu/vulkan/features.gni")
import("//media/gpu/args.gni")
import("//media/media_options.gni")
import("//remoting/remoting_enable.gni")
import("//third_party/closure_compiler/compile_js.gni")
import("//third_party/openh264/openh264_args.gni")
import("//tools/ipc_fuzzer/ipc_fuzzer.gni")
import("//ui/base/ui_features.gni")
import("//ui/gl/features.gni")
import("//v8/gni/snapshot_toolchain.gni")
import("//v8/gni/v8.gni")
#Variable declarations in an attempt to stop building certain dependencies/packages:
#enable_openscreen = false
#enable_remoting = false
#enable_nacl = false
#media_use_ffmpeg = false
#use_openh264 = false
#enable_vulkan = false
#enable_ipc_fuzzer = false
#enable_vr = false
Below is my args.gn parameters which I have used to build the 190mb chromium binary:
target_cpu="arm"
arm_version=7
target_os="linux"
arm_arch="armv7-a"
arm_float_abi="hard"
arm_fpu="neon"
arm_tune="cortex-a9"
arm_use_neon=true
arm_use_thumb=true
use_alsa=false
use_jumbo_build=true
use_gnome_keyring=false
is_debug = false
symbol_level = 0
enable_nacl = false
blink_symbol_level=0
# Set build arguments here. See `gn help buildargs`.
Any help or guidance on how I can reduce the size of the chrome output file would be greatly appreciated.
Upvotes: 2
Views: 3028
Reputation: 66
The reason why the Chrome process is large is because of containing debugging information which has not been taken out, I found that by stripping the process of the debugging information (even after it was built), I was able to cut it down from 190MB to 102MB.
The strip utility is available as part of the host GNU toolchain however if the chrome process is cross compiled for another platform (in my case ARM), then we need to use the cross compiler toolchain's equivalent strip utility to achieve this. At present I am not sure if there is an argument you can use in args.gn for your build directory to do this during the build of chrome.
(For example) As I build for my device using the toolchain fs-toolchain-8.3-armv7ahf, the program arm-linux-strip equivalent is found in fs-toolchain-8.3-armv7ahf/bin/arm-linux-strip. Once I have added the PATH location of the program and have changed directory to where my chrome process is located, I can then run the following below to strip chrome:
arm-linux-strip -o chrome_stripped chrome (-o means to store stripped version of chrome as chrome_stripped without affecting original file).
(Credit for this knowledge goes to my Senior)
Upvotes: 0
Reputation: 3361
Looks like you are building debug version of Chromium. You should build release version if you want smaller executables or for distributing it to end-users.
You can follow the steps below to build release version of Chromium:
From the src
directory
gn args out/YourBuildFolder
It will open args.gn
in an editor. Paste one or more of the flags below in that editor:
is_debug = false # Release version
# Other optional flags for reducing executable size
symbol_level = 0 # You won't be able to debug your app from source, if it's level is 0. It's range: 0-2
blink_symbol_level=0 # No symbols from the Blink rendering engine
Save that file and close the editor. GN
will prepare the build folder accordingly and start compiling again by executing:
ninja -C out/YourBuildFolder chrome
FYI you can see all the supported build flags for your target by executing:
gn args out/YourBuildFolder --list
Upvotes: 1