the Chromium logo

The Chromium Projects

GN in ChromeOS

New packages should use GN as their build system.

See the official step-by-step introduction for the GN basics. This article discusses ChromeOS specific stuff.

How to build your package with GN

Example: arc/adbd/

How to write ebuilds

Example: arc-adbd-9999.ebuild

Note we should add .gn in CROS_WORKON_SUBTREE so that the platform2 build system can access the file.

Packages outside platform2

For packages outside platform2, use CROS_WORKON_DESTDIR to copy the package under <workspace>/platform2/ while building it. (example)

How to install files

Installing Targets defined in

A file built by a GN target, either by executable, shared_library or static_library, can be installed by specifying install_path.

A target that install the output must be a dependency of group("all").


Installing executable targets

Installing Shared Library Targets

Installing shared library requires specifying install_path in the shared_library target.

Installing Static Library Targets

Installing static libraries requires specifying install_path in the static_library target.

Installing files not defined in

You can install files that are not generated by GN and ninja by using install_config target.



How to check USE flags in GN

In GN files, USE flags can be referred as (example)

Only allowed USE flags can be used. If you need to use new USE flags, update:

You can confirm that the USE flag is available for your package by running

equery-{board} uses {package-name}

How to write unit tests

use.test flag is set to true on unit testing. Enclose test only targets with if (use.test) {} to reduce compile time on production. The test targets are typically executables which depend on //common-mk:test to use gtest and gmock.

How to run unit tests doesn't change: In chroot, run cros_workon --board=$BOARD start $package_name if you haven't. Then run

FEATURES=test emerge-$BOARD $package_name

Prepend VERBOSE=1 to see GN and ninja commands (plus other logs).

Declaring tests in


How to create standalone static library?

Static libraries are compiled with thin archive enabled by default i.e. not standalone. Remove use_thin_archive from configs and add nouse_thin_archive to generate a standalone static library (example).

TODO( consider making standalone library the default and replace static_library with source_set whenever possible.