1

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.

  • What are the build flags you used when building it? If there's arg.gn file in your build folder, then can you post it's contents as it will include build flags – Asesh Jan 08 '21 at 17:29
  • Hi @Asesh, thanks for coming back to me. I have updated the comment above with the args.gn file I have used to generate my chromium file. – Balwinder Singh Jan 09 '21 at 23:04
  • I've run into the same problem on my embedded device. Chromium is ten times bigger than any other executable on the box. I feel like there's got to be tons of stuff in there that I don't need, but I can't figure out how to get rid of. – Aaron Wright Jan 19 '21 at 04:45

2 Answers2

1

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
Asesh
  • 3,186
  • 2
  • 21
  • 31
  • Thanks for taking your time to give your answer, it is greatly appreciated. I am sorry for not providing the args.gn file commands earlier to show what I have done so far, but I have already done a build using those 3 build arguments you mentioned which still gave me a 190mb sized chrome binary. I have already had a look at the "--list" outputs as well and there are quite a lot of parameters I can customize, finding out which parameters affects which libraries or dependencies to not use isn't straight forward. – Balwinder Singh Jan 09 '21 at 23:12
  • Your comment above states `args.txt`, actually it should be args.gn. You should try to rebuild by following the steps above. Run `gn clean out\YourBuildFolder` then start over again by following the steps above – Asesh Jan 10 '21 at 03:43
  • Thank you @Asesh. I attached a txt file containing the copy of arguments, I use the contents in the file to copy over to the .gn . If I can ask, how big was your chromium binary after you did your build and did you consider finding ways to reduce it's size? – Balwinder Singh Jan 10 '21 at 13:49
  • Well it depends on the platform, on Windows it's a few MB and macOS, it's a few KB. I see you are using `use_jumbo_build`, looks like it might be responsible for that increase in size: https://chromium.googlesource.com/chromium/src/+/refs/tags/65.0.3320.0/docs/jumbo.md I might be wrong though but try setting it to false and let us know the result – Asesh Jan 10 '21 at 14:51
0

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)