Construction of chromium GN system

GN chromium in the build system
original stone cloud Mizuki finally released on 2017-06-23 17:16:35 read the number 6924 collection
launched
Read the latest source of chromium, found the project to build the system has been fully switched from the GYP to GN. In software development, people often advice: Do not re-create the wheel. However, Google may spite of this, made the wheel one by one, Why do the cattle it? Why would toss chromiumi project build system? Because Google chrome browser pursuing a word: fast. Not only the browser faster, but also the pursuit to build systems faster.

Build System Introduction
Before discussing the latest GN chromium build system, review the software development build system. The system is constructed with the increasing demand for software size proposed. If you just do software programming training, usually smaller than the code, source code written in only a few files. For example, you write a piece of code into helloworld.c file to compile the code, just execute the following command:

helloworld.c gcc
1
when the increasing size of software, then there may be dozens of source code files, but also with the module division, and some to be compiled into a static library, some want compiled DLL, the last link to the executable code , then stretched on the command line, we need to build a system. Common build system has GNU Make. It should be noted that the build system does not replace tools such as chain gcc, but the definition of the compiler rule, eventually calling toolchain compiled code.

When further expand the scale of software, especially when multiple platform support needs to write GNU Makefile would be a cumbersome and tedious, and error-prone. Then appeared Makefile generation tool, such as cmake, AutoMake like, this construct system is called a meta-build system (meta build system). The concept of Linux software repository is not yet universal, they usually step we installed the software are:

./configure
the make
the make install
1
2
3
The first step is to call AutoTool tools (many Linux versions of the software installation is not the same) depending on system environment, generate GNU Makefile.

Chromium in the build system
when I was in contact with chromium open source project a few years ago, chromium is used in GYP (Generate Your Projects) building system, which is a meta build system. GYP software engineers to write according to the rules of construction of the project file (usually gyp, gypi suffix), GYP tool generates GNU Makefile according to gyp file. Then the whole project has a chromium Ninja build system, but this is not intended to replace GYP Ninja, but replace GNU make, according to Google's official statement is the speed has improved several times. For developers, we do not need to learn more about Ninja or GNU Makefile to build such a system, because it is only an intermediate output, ninja emergence us little to do, how to write original gyp, now or how to write, but build commands do a little change.

Look at the recent chromium source code found inside the familiar GYP files are gone, replaced by GN file (with gn and gni file name suffix), the instantaneous feeling of night returned to liberation. However, a little research GN files, or those familiar with the module, depending on the conditions, etc. elements, and GYP not very different, but generally sharper than the original GYP file.

Construction system GN
GN element is a building system generates Ninja build file (Ninja build files), compared GYP, it has the following advantages:

More readable and easier to write and maintain.
Faster, Google to official data 20 times faster.
GN modified file, the file is automatically updated when performing ninja Ninja constructed building. GYP previously used when there had modified GYP, but forget to use gyp to rebuild the Ninja build embarrassing files.
Simpler module dependency provided public_deps, data_deps the like, in GYP, only one target-dependent, resulting in complex dependencies, easy to introduce unnecessary dependencies of the modules.
Providing better tools to query module dependency map. This is a nightmare GYP build system, which module to check a certain dependency or a module which is dependent on the target is almost impossible.
Better debugging support. In order to print variable values GYP, I had also specifically wrote a blog post How to Print << gyp build system variable values >> in GN, we only need a print statement can be resolved.
Getting started
running GN
run from the command line gn, which is actually a script that is depot_tools, it is necessary to ensure depot_tools path is contained in the environment variable $ PATH.

Construction of a configuration
in GYP, there are two specific directories Debug and Release directories, respectively, and for generating Debug version Release version. In GN, using a more flexible way, you just specify a directory, such as for testing, define a test output directory, the following command can be used:

Gen OUT GN / the Test
1
that if I want to build Debug version and Release versions, respectively, how to do? GN solved by passing parameters. In other words, now the light is not determined by the output directory in the end is Debug version and Release version, and build parameters depends on delivery.

Construction of transmission parameters
to slightly modify the above command, to set the build parameters:

args OUT GN / the Test
1
, you can use the following command to list the build parameters and their default values are available:

args --list OUT GN / the Test
1
I run in chromium source, so many parameters, to turn several screens, so do not need to remember all the parameters, only need to know some of the more commonly used parameters:

= to true is_component_build
is_debug = to false
. 1
2
in front of a dynamic parameter determines whether sub-library build, chrome for android now contains the build out of dozens so, that way, the advantage is to save build time code is modified. Behind a parameter decision was build Debug or Release version version.

From writing code to the Build
/ write code, such as code files for the test hello_world.cc
write GN files, such as placed in the code above and under the same directory.

Executable ( "the hello_world") {
Sources = [
"hello_world.cc",
]
}
. 1
2
. 3
. 4
. 5
opens at the root source BUILD.gn added dependent on the goals:

Group ( "the root") {
deps = [
...
"// URL",
"// Test: the hello_world",
]
}
. 1
2
. 3
. 4
. 5
. 6
. 7
where the representative source // root.

Construct

gn gen out/Default
ninja -C out/Default hello_world
out/Default/hello_world
1
2
3
调试
打印

static_library ( "Hello") {
...
Print (configs)
}
. 1
2
. 3
. 4
can print the configuration information this goal.

View target information

desc OUT GN / // the Test the Default: hello_world
1
This will list a lot of detailed information, including configuration parameters, target depends, through a more complex command parameters, you can also view a macro definition is defined in which the target, target depends the tree structure, such as:

desc OUT GN / // the Default Base: base_i18n deps --tree
1
Description more parameters can be used to view gn help desc.

Summary
because no write complex GN files, so the advantages and disadvantages of the GN also experience is not deep, but for a few GYP's deep feelings of pain points:
- nested, leading GYP difficult to read and modify files, think about chromium build / common.gypi how awful this document under
- printing support
- for complex dependencies lack of effective means to locate and troubleshoot

This was the perfect solution in the GN, which rushed it, but also for Google thumbs up. Although it is reinventing the wheel, but the wheel easy to use than the original ah!


Reference documents
the What IS GN?
GN Quick Start Guide
----------------
Disclaimer: This article is the original article CSDN bloggers "cloud Mizuki stone", and follow CC 4.0 BY-SA Copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/mogoweb/article/details/73650218

Guess you like

Origin www.cnblogs.com/bigben0123/p/12558003.html