Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: tools/gn/docs/cross_compiles.md

Issue 2038733003: 💹 Update GN docs about target_cpu to encourage use of current_cpu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change target_cpu example Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/gn/variables.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # How GN handles cross-compiling 1 # How GN handles cross-compiling
2 2
3 ## As a GN user 3 ## As a GN user
4 4
5 GN has robust support for doing cross compiles and building things for 5 GN has robust support for doing cross compiles and building things for
6 multiple architectures in a single build (e.g., to build some things to 6 multiple architectures in a single build (e.g., to build some things to
7 run locally and some things to run on an embedded device). In fact, 7 run locally and some things to run on an embedded device). In fact,
8 there is no limit on the number of different architectures you can build 8 there is no limit on the number of different architectures you can build
9 at once; the Chromium build uses at least four in some configurations. 9 at once; the Chromium build uses at least four in some configurations.
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 The `is_linux`, `is_win` etc. variables are updated to reflect the 66 The `is_linux`, `is_win` etc. variables are updated to reflect the
67 current settings, and changes to `cflags`, `ldflags` and so forth also 67 current settings, and changes to `cflags`, `ldflags` and so forth also
68 only apply to the current toolchain and the current thing being built. 68 only apply to the current toolchain and the current thing being built.
69 69
70 You can also refer to the `target_cpu` and `target_os` variables. This 70 You can also refer to the `target_cpu` and `target_os` variables. This
71 is useful if you need to do something different on the host depending on 71 is useful if you need to do something different on the host depending on
72 which target\_arch is requested; the values are constant across all 72 which target\_arch is requested; the values are constant across all
73 toolchains. You can do similar things for the `host_cpu` and `host_os` 73 toolchains. You can do similar things for the `host_cpu` and `host_os`
74 variables, but should generally never need to. 74 variables, but should generally never need to.
75 75
76 For the default toolchain, `target_cpu` and `current_cpu` are the same. For a
77 secondary toolchain, `current_cpu` is set based on the toolchain definition
78 and `target_cpu` remains the same. When writing rules, **`current_cpu` should
79 be used rather than `target_cpu` most of the time**.
80
76 By default, dependencies listed in the `deps` variable of a rule use the 81 By default, dependencies listed in the `deps` variable of a rule use the
77 same (currently active) toolchain. You may specify a different toolchain 82 same (currently active) toolchain. You may specify a different toolchain
78 using the `foo(bar)` label notation as described in 83 using the `foo(bar)` label notation as described in
79 [GNLanguage#Labels](language.md#Labels). 84 [GNLanguage#Labels](language.md#Labels).
80 85
86 Here's an example of when to use `target_cpu` vs `current_cpu`:
87
88 ```
89 declare_args() {
90 # Applies only to toolchains targeting target_cpu.
91 sysroot = ""
92 }
93
94 config("my_config") {
95 # Uses current_cpu because compile flags are toolchain-dependent.
96 if (current_cpu == "arm") {
97 defines = [ "CPU_IS_32_BIT" ]
98 } else {
99 defines = [ "CPU_IS_64_BIT" ]
100 }
101 # Compares current_cpu with target_cpu to see whether current_toolchain
102 # has the same architecture as target_toolchain.
103 if (sysroot != "" && current_cpu == target_cpu) {
104 cflags = [
105 "-isysroot",
106 sysroot,
107 ]
108 }
109 }
110 ```
111
81 ## As a //build/config or //build/toolchain author 112 ## As a //build/config or //build/toolchain author
82 113
83 As described in 114 As described in
84 [GNLanguage#Overall-build-flow](language.md#Overall-build-flow), the 115 [GNLanguage#Overall-build-flow](language.md#Overall-build-flow), the
85 `default_toolchain` is declared in the `//build/config/BUILDCONFIG.gn` 116 `default_toolchain` is declared in the `//build/config/BUILDCONFIG.gn`
86 file. Usually the `default_toolchain` should be the toolchain for the 117 file. Usually the `default_toolchain` should be the toolchain for the
87 `target_os` and `target_cpu`. The `current_toolchain` reflects the 118 `target_os` and `target_cpu`. The `current_toolchain` reflects the
88 toolchain that is currently in effect for a rule. 119 toolchain that is currently in effect for a rule.
89 120
90 Be sure you understand the differences between `host_cpu`, `target_cpu`, 121 Be sure you understand the differences between `host_cpu`, `target_cpu`,
91 `current_cpu`, and `toolchain_cpu` (and the os equivalents). The first 122 `current_cpu`, and `toolchain_cpu` (and the os equivalents). The first
92 two are set as described above. You are responsible for making sure that 123 two are set as described above. You are responsible for making sure that
93 `current_cpu` is set appropriately in your toolchain definitions; if you 124 `current_cpu` is set appropriately in your toolchain definitions; if you
94 are using the stock templates like `gcc_toolchain` and `msvc_toolchain`, 125 are using the stock templates like `gcc_toolchain` and `msvc_toolchain`,
95 that means you are responsible for making sure that `toolchain_cpu` and 126 that means you are responsible for making sure that `toolchain_cpu` and
96 `toolchain_os` are set as appropriate in the template invocations. 127 `toolchain_os` are set as appropriate in the template invocations.
OLDNEW
« no previous file with comments | « no previous file | tools/gn/variables.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698