OLD | NEW |
---|---|
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 Loading... | |
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 config("my_config") { | |
90 # Uses current_cpu because compile flags are toolchain-dependent. | |
91 if (current_cpu == "arm") { | |
92 defines = [ "CPU_IS_32_BIT" ] | |
93 } else { | |
94 defines = [ "CPU_IS_64_BIT" ] | |
95 } | |
96 } | |
97 | |
98 group("fat_bundle") { | |
agrieve
2016/06/08 17:43:56
hmm, actually, I don't think this example is corre
| |
99 deps = [ | |
100 ":shared_library", | |
101 ] | |
102 # Uses target_cpu because 64 bit devices require both 64 bit and 32 bit | |
103 # libraries, but 32 bit devices require only 32 bit libraries. | |
104 if (target_cpu == "arm64") { | |
105 deps += [ | |
106 ":shared_library(//build/toolchain/android:arm)", | |
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. |
OLD | NEW |