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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/gn/variables.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/docs/cross_compiles.md
diff --git a/tools/gn/docs/cross_compiles.md b/tools/gn/docs/cross_compiles.md
index 68d9bcb8570a3b623bb35ad0b1ecc2f426a64807..2d7e8a3c81d190bee85f9c2c9519520383a3ca4c 100644
--- a/tools/gn/docs/cross_compiles.md
+++ b/tools/gn/docs/cross_compiles.md
@@ -73,11 +73,42 @@ which target\_arch is requested; the values are constant across all
toolchains. You can do similar things for the `host_cpu` and `host_os`
variables, but should generally never need to.
+For the default toolchain, `target_cpu` and `current_cpu` are the same. For a
+secondary toolchain, `current_cpu` is set based on the toolchain definition
+and `target_cpu` remains the same. When writing rules, **`current_cpu` should
+be used rather than `target_cpu` most of the time**.
+
By default, dependencies listed in the `deps` variable of a rule use the
same (currently active) toolchain. You may specify a different toolchain
using the `foo(bar)` label notation as described in
[GNLanguage#Labels](language.md#Labels).
+Here's an example of when to use `target_cpu` vs `current_cpu`:
+
+```
+declare_args() {
+ # Applies only to toolchains targeting target_cpu.
+ sysroot = ""
+}
+
+config("my_config") {
+ # Uses current_cpu because compile flags are toolchain-dependent.
+ if (current_cpu == "arm") {
+ defines = [ "CPU_IS_32_BIT" ]
+ } else {
+ defines = [ "CPU_IS_64_BIT" ]
+ }
+ # Compares current_cpu with target_cpu to see whether current_toolchain
+ # has the same architecture as target_toolchain.
+ if (sysroot != "" && current_cpu == target_cpu) {
+ cflags = [
+ "-isysroot",
+ sysroot,
+ ]
+ }
+}
+```
+
## As a //build/config or //build/toolchain author
As described in
« 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