blob: 331780abdd0a787100cdedd3546d4ae0a3e1678c [file] [log] [blame] [view]
spomorskiab39ffb2018-10-02 11:19:32 -07001---
2layout: documentation
3title: Understanding CROSSTOOL
4---
5
spomorski37391682018-10-08 09:25:34 -07006# Understanding CROSSTOOL
spomorskiab39ffb2018-10-02 11:19:32 -07007
laurentlb27bb9482018-11-12 12:50:34 -08008* ToC
9{:toc}
10
spomorskiab39ffb2018-10-02 11:19:32 -070011
spomorski37391682018-10-08 09:25:34 -070012To get hands-on with `CROSSTOOL`, see the
13[Configuring `CROSSTOOL`](tutorial/crosstool.html) tutorial.
spomorskiab39ffb2018-10-02 11:19:32 -070014
15## Overview
16
17`CROSSTOOL` is a text file containing a
18[protocol buffer](https://developers.google.com/protocol-buffers/docs/overview)
19that provides the necessary level of granularity for configuring the behavior of
20Bazel's C++ rules. By default, Bazel automatically configures `CROSSTOOL` for
21your build, but you have the option to configure it manually. You reference the
22`CROSSTOOL` file in your `BUILD` file(s) using a `cc_toolchain` target and check
23it into source control alongside your project. You can share a single
24`CROSSTOOL` file across multiple projects or create separate per-project files.
25
26When a C++ target enters the analysis phase, Bazel selects the appropriate
27`cc_toolchain` target based on the BUILD file, then reads the corresponding
spomorski20ca4e12018-10-03 07:44:47 -070028toolchain definition from the `CROSSTOOL` file. The `cc_toolchain` target
29passes information from the `CROSSTOOL` proto to the C++ target through a
spomorskiab39ffb2018-10-02 11:19:32 -070030`CcToolchainProvider`.
31
32For example, a compile or link action, instantiated by a rule such as
33`cc_binary` or `cc_library`, needs the following information:
34
35* The compiler or linker to use
36* Command-line flags for the compiler/linker
37* Configuration flags passed through the `--copt/--linkopt` options
38* Environment variables
39* Artifacts needed in the sandbox in which the action executes
40
spomorski20ca4e12018-10-03 07:44:47 -070041All of the above information except the artifacts required in the sandbox is
42specified in the `CROSSTOOL` proto.
spomorskiab39ffb2018-10-02 11:19:32 -070043
44The artifacts to be shipped to the sandbox are declared in the `cc_toolchain`
45target. For example, with the `cc_toolchain.linker_files` attribute you can
46specify the linker binary and toolchain libraries to ship into the sandbox.
47
spomorski20ca4e12018-10-03 07:44:47 -070048## `CROSSTOOL` proto structure
spomorskiab39ffb2018-10-02 11:19:32 -070049
spomorski20ca4e12018-10-03 07:44:47 -070050The `CROSSTOOL` proto has the following structure:
spomorskiab39ffb2018-10-02 11:19:32 -070051
52* Map from `--cpu` to toolchain (to be used when `--compiler` is not specified
53 or when `cc_toolchain_suite.toolchains` omits the `cpu` entry)
54
55* Toolchain for a particular `--cpu` and `--compiler` combination (1)
56 * Static toolchain:
57 * `compiler_flags`
58 * `linker_flags`
59 * `compilation_mode_flags`
60 * `linking_mode_flags`
61 * Dynamic toolchain:
62 * `features`
63
64* Toolchain for a particular `--cpu` and `--compiler` combination (2)
65
66* Toolchain for a particular `--cpu` and `--compiler` combination (3)
67
68* ...
69
70
71## Toolchain selection
72
73The toolchain selection logic operates as follows:
74
751. User specifies a `cc_toolchain_suite` target in the `BUILD` file and points
76 Bazel to the target using the
spomorski20ca4e12018-10-03 07:44:47 -070077 [`--crosstool_top` option](https://docs.bazel.build/versions/master/user-manual.html#flag--crosstool_top).
spomorskiab39ffb2018-10-02 11:19:32 -070078 The `CROSSTOOL` file must reside in the same directory as the
79 `BUILD` file containing the `cc_toolchain_suite` target.
80
812. The `cc_toolchain_suite` target and the `CROSSTOOL`
82 file reference multiple toolchains. The values of the `--cpu` and
83 `--compiler `flags determine which of those toolchains is selected,
84 either based only on the `--cpu` flag value, or based on a joint
85 `--cpu | --compiler` value. The selection process is as follows:
86
87 * If the `--compiler` option is specified, Bazel selects the
88 corresponding entry from the `cc_toolchain_suite.toolchains`
89 attribute with `--cpu | --compiler`. If Bazel does not find
90 a corresponding entry, it throws an error.
91
92 * If the `--compiler` option is not specified, Bazel selects
93 the corresponding entry from the `cc_toolchain_suite.toolchains`
94 attribute with just `--cpu`.
95
96 However, if Bazel does not find a corresponding entry and the
97 `--incompatible_disable_cc_toolchain_label_from_crosstool_proto`
98 option is disabled, Bazel iterates through `default_toolchains`
99 in the `CROSSTOOL` file until it finds an entry where the
100 `default_toolchain.cpu` value matches the specified `--cpu`
101 option value. Bazel then reads the `toolchain_identifier`
102 value to identify the corresponding toolchain, and selects the appropriate
103 entry in the `cc_toolchain_suite.toolchains` attribute using
104 `toolchain.target_cpu | toolchain.compiler`.
105
106 * If no flags are specified, Bazel inspects the host system and selects a
107 `--cpu` value based on its findings. See the
108 [inspection mechanism code](https://source.bazel.build/bazel/+/1b73bc37e184e71651eb631223dcce321ba16211:src/main/java/com/google/devtools/build/lib/analysis/config/AutoCpuConverter.java).
109
110Once a toolchain has been selected, corresponding `feature` and `action_config`
spomorski863bc872018-10-02 12:20:05 -0700111messages in the `CROSSTOOL` file govern the configuration of the build (that is,
spomorskiab39ffb2018-10-02 11:19:32 -0700112items described earlier in this document). These messages allow the
113implementation of fully fledged C++ features in Bazel without modifying the
114Bazel binary. C++ rules support multiple unique actions documented in detail
115[in the Bazel source code](https://source.bazel.build/bazel/+/4f547a7ea86df80e4c76145ffdbb0c8b75ba3afa:tools/build_defs/cc/action_names.bzl).
116
spomorski20ca4e12018-10-03 07:44:47 -0700117## `CROSSTOOL` features
spomorskiab39ffb2018-10-02 11:19:32 -0700118
119A feature is an entity that requires non-default command-line flags, actions,
120constraints on the execution environment, or dependency alterations. A feature
121can be something as simple as allowing BUILD files to select configurations of
122flags, such as `treat_warnings_as_errors`, or interact with the C++ rules and
123include new compile actions and inputs to the compilation, such as
124`header_modules` or `thin_lto`.
125
126Ideally, a toolchain definition consists of a set of features, where each
127feature consists of multiple flag groups, each defining a list of flags that
128apply to specific Bazel actions.
129
spomorski20ca4e12018-10-03 07:44:47 -0700130A feature is specified by name, which allows full decoupling of the `CROSSTOOL`
spomorskiab39ffb2018-10-02 11:19:32 -0700131configuration from Bazel releases. In other words, a Bazel release does not
spomorski20ca4e12018-10-03 07:44:47 -0700132affect the behavior of `CROSSTOOL` configurations as long as those
133configurations do not require the use of new features.
spomorskiab39ffb2018-10-02 11:19:32 -0700134
135A feature is enabled only when both Bazel and the CROSSTOOL configuration
136support it.
137
138Features can have interdependencies, depend on command line flags, `BUILD` file
139settings, and other variables.
140
141### Feature relationships
142
143Dependencies are typically managed directly with Bazel, which simply enforces
144the requirements and manages conflicts intrinsic to the nature of the features
145defined in the build. The toolchain specification allows for more granular
spomorski863bc872018-10-02 12:20:05 -0700146constraints for use directly within the `CROSSTOOL` file that govern feature
spomorskiab39ffb2018-10-02 11:19:32 -0700147support and expansion. These are:
148
149<table>
150 <col width="300">
151 <col width="600">
152 <tr>
153 <td><strong>Constraint</strong>
154 </td>
155 <td><strong>Description</strong>
156 </td>
157 </tr>
158 <tr>
159 <td><code>requires: ['feature1', 'feature2']</code>
160 </td>
161 <td>Feature-level. The feature is supported only if the specified required
162 features are enabled. For example, when a feature is only supported in
163 certain build modes (features <code>opt</code>, <code>dbg</code>, or
164 <code>fastbuild</code>). Multiple `requires` statements are
165 satisfied all at once if any one of them is satisfied.
166 </td>
167 </tr>
168 <tr>
169 <td><code>implies: 'feature'</code>
170 </td>
171 <td>Feature-level. This feature implies the specified feature. For example, a
172 module compile implies the need for module maps, which can be implemented
173 by a repeated <code>implies</code> string in the feature where each of
174 the strings names a specific feature. Enabling a feature also implicitly
175 enables all features implied by it (that is, it functions recursively).
176 <p>
177 Also provides the ability to factor common subsets of functionality out of
178 a set of features, such as the common parts of sanitizers. Implied
179 features cannot be disabled.
180 </td>
181 </tr>
182 <tr>
183 <td><code>provides: 'feature'</code>
184 </td>
185 <td>Feature-level. Indicates that this feature is one of several mutually
186 exclusive alternate features. For example, all of the sanitizers could
187 specify <code>provides: "sanitizer"</code>.
188 <p>
189 This improves error handling by listing the alternatives if the user asks
190 for two or more mutually exclusive features at once.
191 </td>
192 </tr>
193 <tr>
194 <td><code>with_feature: {feature: 'feature1', not_feature: 'feature2']</code>
195 </td>
196 <td>Flag set-level. A feature can specify multiple flag sets with multiple
197 <code>with_feature</code> statements. When <code>with_feature</code> is
198 specified, the flag set will only expand to the build command if all of the
199 feature in the specified <code>feature:</code> set are enabled, and all the
200 features specified in <code>not_feature:</code> set are disabled.
201 </td>
202 </tr>
203</table>
204
spomorski20ca4e12018-10-03 07:44:47 -0700205## `CROSSTOOL` actions
spomorskiab39ffb2018-10-02 11:19:32 -0700206
spomorski20ca4e12018-10-03 07:44:47 -0700207`CROSSTOOL` actions provide the flexibility to modify the circumstances under
spomorskiab39ffb2018-10-02 11:19:32 -0700208which an action executes without assuming how the action will be run. An
spomorski20ca4e12018-10-03 07:44:47 -0700209`action_config` specifies the tool binary that an action invokes, while a
210`feature` specifies the configuration (flags) that determine how that tool
211behaves when the action is invoked.
spomorskiab39ffb2018-10-02 11:19:32 -0700212
spomorski20ca4e12018-10-03 07:44:47 -0700213[Features](#crosstool-features) reference `CROSSTOOL` actions to signal which
214Bazel actions they affect since `CROSSTOOL` actions can modify the Bazel action
spomorski863bc872018-10-02 12:20:05 -0700215graph. The `CROSSTOOL` file includes actions that have flags and tools
216associated with them, such as `c++-compile`. Flags are assigned to each action
217by associating them with a feature.
spomorskiab39ffb2018-10-02 11:19:32 -0700218
spomorski20ca4e12018-10-03 07:44:47 -0700219Each `CROSSTOOL` action name represents a single type of action performed by
spomorskiab39ffb2018-10-02 11:19:32 -0700220Bazel, such as compiling or linking. There is, however, a many-to-one
spomorski20ca4e12018-10-03 07:44:47 -0700221relationship between `CROSSTOOL` actions and Bazel action types, where a Bazel
spomorskiab39ffb2018-10-02 11:19:32 -0700222action type refers to a Java class that implements an action (such as
223`CppCompileAction`). In particular, the "assembler actions" and "compiler
224actions" in the table below are `CppCompileAction`, while the link actions are
225`CppLinkAction`.
226
227### Assembler actions
228
229<table>
230 <col width="300">
231 <col width="600">
232 <tr>
233 <td><strong>Action</strong>
234 </td>
235 <td><strong>Description</strong>
236 </td>
237 </tr>
238 <tr>
239 <td><code>preprocess-assemble</code>
240 </td>
241 <td>Assemble with preprocessing. Typically for <code>.S</code> files.
242 </td>
243 </tr>
244 <tr>
245 <td><code>assemble</code>
246 </td>
247 <td>Assemble without preprocessing. Typically for <code>.s</code> files.
248 </td>
249 </tr>
250</table>
251
252### Compiler actions
253
254<table>
255 <col width="300">
256 <col width="600">
257 <tr>
258 <td><strong>Action</strong>
259 </td>
260 <td><strong>Description</strong>
261 </td>
262 </tr>
263 <tr>
264 <td><code>cc-flags-make-variable</code>
265 </td>
266 <td>Propagates <code>CC_FLAGS</code> to genrules.
267 </td>
268 </tr>
269 <tr>
270 <td><code>c-compile</code>
271 </td>
272 <td>Compile as C.
273 </td>
274 </tr>
275 <tr>
276 <td><code>c++-compile</code>
277 </td>
278 <td>Compile as C++.
279 </td>
280 </tr>
281 <tr>
282 <td><code>c++-header-parsing</code>
283 </td>
284 <td>Run the compiler's parser on a header file to ensure that the header is
285 self-contained, as it will otherwise produce compilation errors. Applies
286 only to toolchains that support modules.
287 </td>
288 </tr>
289</table>
290
291### Link actions
292
293<table>
294 <col width="300">
295 <col width="600">
296 <tr>
297 <td><strong>Action</strong>
298 </td>
299 <td><strong>Description</strong>
300 </td>
301 </tr>
302 <tr>
303 <td><code>c++-link-dynamic-library</code>
304 </td>
305 <td>Link a shared library containing all of its dependencies.
306 </td>
307 </tr>
308 <tr>
309 <td><code>c++-link-nodeps-dynamic-library</code>
310 </td>
311 <td>Link a shared library only containing <code>cc_library</code> sources.
312 </td>
313 </tr>
314 <tr>
315 <td><code>c++-link-executable</code>
316 </td>
317 <td>Link a final ready-to-run library.
318 </td>
319 </tr>
320</table>
321
322### AR actions
323
324AR actions assemble object files into archive libraries (`.a` files) via `ar`
325and encode some semantics into the name.
326
327<table>
328 <col width="300">
329 <col width="600">
330 <tr>
331 <td><strong>Action</strong>
332 </td>
333 <td><strong>Description</strong>
334 </td>
335 </tr>
336 <tr>
337 <td><code>c++-link-static-library</code>
338 </td>
339 <td>Create a static library (archive).
340 </td>
341 </tr>
342</table>
343
344### LTO actions
345
346<table>
347 <col width="300">
348 <col width="600">
349 <tr>
350 <td><strong>Action</strong>
351 </td>
352 <td><strong>Description</strong>
353 </td>
354 </tr>
355 <tr>
356 <td><code>lto-backend</code>
357 </td>
358 <td>ThinLTO action compiling bitcodes into native objects.
359 </td>
360 </tr>
361 <tr>
362 <td><code>lto-index</code>
363 </td>
364 <td>ThinLTO action generating global index.
365 </td>
366 </tr>
367</table>
368
spomorski20ca4e12018-10-03 07:44:47 -0700369## `CROSSTOOL` `action_config`
spomorskiab39ffb2018-10-02 11:19:32 -0700370
spomorski20ca4e12018-10-03 07:44:47 -0700371A `CROSSTOOL` `action_config` is a proto message that describes a Bazel action
372by specifying the tool (binary) to invoke during the action and sets of flags,
spomorskiab39ffb2018-10-02 11:19:32 -0700373defined by features, that apply constraints to the action's execution. A
spomorski20ca4e12018-10-03 07:44:47 -0700374`CROSSTOOL` action takes the following attributes:
spomorskiab39ffb2018-10-02 11:19:32 -0700375
376<table>
377 <col width="300">
378 <col width="600">
379 <tr>
380 <td><strong>Attribute</strong>
381 </td>
382 <td><strong>Description</strong>
383 </td>
384 </tr>
385 <tr>
386 <td><code>action_name</code>
387 </td>
spomorski20ca4e12018-10-03 07:44:47 -0700388 <td>The Bazel action to which this <code>CROSSTOOL</code> action corresponds.
389 Bazel uses this attribute to discover per-action tool and execution
390 requirements.
spomorskiab39ffb2018-10-02 11:19:32 -0700391 </td>
392 </tr>
393 <tr>
394 <td><code>tool</code>
395 </td>
396 <td>The executable to invoke. This can depend on a feature. A default must be
397 provided.
398 </td>
399 </tr>
400 <tr>
401 <td><code>flag_set</code>
402 </td>
403 <td>A set of flags that applies to a group of actions. Same as for a feature.
404 </td>
405 </tr>
406 <tr>
407 <td><code>env_set</code>
408 </td>
409 <td>A set of environment constraints that applies to a group of actions. Same
410 as for a feature.
411 </td>
412 </tr>
413</table>
414
spomorski20ca4e12018-10-03 07:44:47 -0700415A `CROSSTOOL` `action_config` can require and imply other features and
spomorskiab39ffb2018-10-02 11:19:32 -0700416<code>action_config</code>s as dictated by the
417[feature relationships](#feature-relationships) described earlier. This behavior
418is similar to that of a feature.
419
420The last two attributes are redundant against the corresponding attributes on
421features and are included because some Bazel actions require certain flags or
spomorski20ca4e12018-10-03 07:44:47 -0700422environment variables and we want to avoid unnecessary `action_config`+`feature`
spomorskiab39ffb2018-10-02 11:19:32 -0700423pairs. Typically, sharing a single feature across multiple `action_config`s is
424preferred.
425
spomorski20ca4e12018-10-03 07:44:47 -0700426You can not define more than one `CROSSTOOL` `action_config` with the same
spomorskiab39ffb2018-10-02 11:19:32 -0700427`action_name` within the same toolchain. This prevents ambiguity in tool paths
428and enforces the intention behind `action_config` - that an action's properties
429are clearly described in a single place in the toolchain.
430
431### `tool` messages
432
spomorski20ca4e12018-10-03 07:44:47 -0700433A `CROSSTOOL` `action_config` can specify a set of tools via `tool` messages.
spomorskiab39ffb2018-10-02 11:19:32 -0700434A `tool` message consists of the following fields:
435
436
437<table>
438 <col width="300">
439 <col width="600">
440 <tr>
441 <td><strong>Field</strong>
442 </td>
443 <td><strong>Description</strong>
444 </td>
445 </tr>
446 <tr>
447 <td><code>tool_path</code>
448 </td>
449 <td>Path to the tool in question (relative to the <code>CROSSTOOL</code>
450 file).
451 </td>
452 </tr>
453 <tr>
454 <td><code>with_feature</code>
455 </td>
456 <td>A set of features that must be enabled for this tool to apply.
457 </td>
458 </tr>
459</table>
460
spomorski20ca4e12018-10-03 07:44:47 -0700461For a given `CROSSTOOL` `action_config`, only a single `tool` message applies
462its tool path and execution requirements to the Bazel action. A tool is selected
463by sequentially parsing `tool` messages on an `action_config` until a tool with
464a `with_feature` set matching the feature configuration is found
spomorskiab39ffb2018-10-02 11:19:32 -0700465(see [Feature relationships](#feature-relationships) earlier in this document
466for more information). We recommend that you end your tool lists with a default
467tool that corresponds to an empty feature configuration.
468
spomorskiab39ffb2018-10-02 11:19:32 -0700469### Example usage
470
spomorski20ca4e12018-10-03 07:44:47 -0700471Features and `CROSSTOOL` actions can be used together to implement Bazel actions
spomorskiab39ffb2018-10-02 11:19:32 -0700472with diverse cross-platform semantics. For example, debug symbol generation on
473macOS requires generating symbols in the compile action, then invoking a
474specialized tool during the link action to create compressed dsym archive, and
475then decompressing that archive to produce the application bundle and `.plist`
476files consumable by Xcode.
477
478With Bazel, this process can instead be implemented as follows, with
479`unbundle-debuginfo` being a Bazel action:
480
481```
482toolchain {
483 action_config {
484 config_name: "c++-link-executable"
485 action_name: "c++-link-executable"
486 tool {
487 with_feature { feature: "generate-debug-symbols" }
488 tool_path: "toolchain/mac/ld-with-dsym-packaging"
489 }
490 tool {
491 tool_path: "toolchain/mac/ld"
492 }
493 }
494
495 feature {
496 name: "generate-debug-symbols"
497 flag_set {
498 action: "c-compile"
499 action: "c++-compile"
500 flag_group {
501 flag: "-g"
502 }
503 }
504 implies: { feature: "unbundle-debuginfo" }
505 }
506}
507```
508
509This same feature can be implemented entirely differently for Linux, which uses
510`fission`, or for Windows, which produces `.pdb` files. For example, the
511implementation for `fission`-based debug symbol generation might look as
512follows:
513
514```
515toolchain {
516 action_config {
517 name: "c++-compile"
518
519 tool {
520 tool_path: "toolchain/bin/gcc"
521 }
522 }
523
524 feature {
525 name: "generate-debug-symbols"
526 requires { feature: "dbg" }
527 flag_set {
528 action: "c++-compile"
529 flag_group {
530 flag: "-gsplit-dwarf"
531 }
532 }
533 flag_set {
534 action: "c++-link-executable"
535 flag_group {
536 flag: "-Wl"
537 flag: "--gdb-index"
538 }
539 }
540 }
541 }
542}
543```
544
545### Flag groups
546
spomorski20ca4e12018-10-03 07:44:47 -0700547`CROSSTOOL` allows you to bundle flags into groups that serve a specific purpose.
spomorski863bc872018-10-02 12:20:05 -0700548You can specify a flag within the `CROSSTOOL` file using pre-defined variables
spomorskiab39ffb2018-10-02 11:19:32 -0700549within the flag value, which the compiler expands when adding the flag to the
550build command. For example:
551
552```
553 flag_group {
554 flag: "%{output_file_path}
555 }
556```
557
558In this case, the contents of the flag will be replaced by the output file path
559of the action.
560
561Flag groups are expanded to the build command in the order in which they appear
562in the `CROSSTOOL` file, top-to-bottom, left-to-right.
563
564For flags that need to repeat with different values when added to the build
565command, the flag group can iterate variables of type `list`. For example, the
566variable `include_path` of type `list`:
567
568```
569 flag_group {
570 iterate_over: "include_paths"
571 flag: "-I%{include_paths}"
572 }
573```
574
575expands to `-I<path>` for each path element in the `include_paths` list. All
576flags (or `flag_group`s) in the body of a flag group declaration are expanded as
577a unit. For example:
578
579```
580 flag_group {
581 iterate_over: "include_paths"
582 flag: "-I"
583 flag: "%{include_paths}"
584 }
585```
586
587expands to `-I <path>` for each path element in the `include_paths` list.
588
589A variable can repeat multiple times. For example:
590
591```
592 flag_group {
593 iterate_over: "include_paths"
594 flag: "-iprefix=%{include_paths}"
595 flag: "-isystem=%{include_paths}"
596 }
597```
598
599expands to:
600
601```
602 -iprefix=<inc0> -isystem=<inc0> -iprefix=<inc1> -isystem=<inc1>
603```
604
605Variables can correspond to structures accessible using dot-notation. For
606example:
607
608```
609 flag_group {
610 flag: "-l%{libraries_to_link.name}"
611 }
612```
613
614Structures can be nested and may also contain sequences. To prevent name clashes
615and to be explicit, you must specify the full path through the fields. For
616example:
617
618```
619 flag_group {
620 iterate_over: "libraries_to_link"
621 flag_group {
622 iterate_over: "libraries_to_link.shared_libraries"
623 flag: "-l%{libraries_to_link.shared_libraries.name}"
624 }
625 }
626```
627
628### Conditional expansion
629
630Flag groups support conditional expansion based on the presence of a particular
631variable or its field using the `expand_if_all_available`, `expand_if_none_available`,
632`expand_if_true`, `expand_if_false`, or `expand_if_equal` messages. For example:
633
634```
635 flag_group {
636 iterate_over: "libraries_to_link"
637 flag_group {
638 iterate_over: "libraries_to_link.shared_libraries"
639 flag_group {
640 expand_if_all_available: "libraries_to_link.shared_libraries.is_whole_archive"
641 flag: "--whole_archive"
642 }
643 flag_group {
644 flag: "-l%{libraries_to_link.shared_libraries.name}"
645 }
646 flag_group {
647 expand_if_all_available: "libraries_to_link.shared_libraries.is_whole_archive"
648 flag: "--no_whole_archive"
649 }
650 }
651 }
652```
653
654**Note:** The `--whole_archive` and `--no_whole_archive` options are added to
655the build command only when a currently iterated library has an
656`is_whole_archive` field.
657
spomorski20ca4e12018-10-03 07:44:47 -0700658## `CROSSTOOL` reference
spomorskiab39ffb2018-10-02 11:19:32 -0700659
660This section provides a reference of build variables, features, and other
spomorski20ca4e12018-10-03 07:44:47 -0700661information required to successfully configure `CROSSTOOL`.
spomorskiab39ffb2018-10-02 11:19:32 -0700662
spomorski20ca4e12018-10-03 07:44:47 -0700663### `CROSSTOOL` build variables
spomorskiab39ffb2018-10-02 11:19:32 -0700664
spomorski20ca4e12018-10-03 07:44:47 -0700665The following is a reference of `CROSSTOOL` build variables.
spomorskiab39ffb2018-10-02 11:19:32 -0700666
667**Note:** `[action]` indicates the relevant action type.
668
669<table>
670 <col width="300">
671 <col width="600">
672 <tr>
673 <td><strong>Variable</strong>
674 </td>
675 <td><strong>Description</strong>
676 </td>
677 </tr>
678 <tr>
679 <td><strong><code>source_file</code></strong>
680 </td>
681 <td><code>[compile]</code> Source file to compile.
682 </td>
683 </tr>
684 <tr>
685 <td><strong><code>input_file</code></strong>
686 </td>
687 <td><code>[strip]</code> Artifact to strip.
688 </td>
689 </tr>
690 <tr>
691 <td><strong><code>output_file</code></strong>
692 </td>
693 <td><code>[compile]</code> Compilation output.
694 </td>
695 </tr>
696 <tr>
697 <td><strong><code>output_assembly_file</code></strong>
698 </td>
699 <td><code>[compile]</code> Emitted assembly file. Applies only when the
700 <code>compile</code> action emits assembly text, typically when using the
701 <code>--save_temps</code> flag. The contents are the same as for
702 <code>output_file</code>.
703 </td>
704 </tr>
705 <tr>
706 <td><strong><code>output_preprocess_file</code></strong>
707 </td>
708 <td><code>[compile]</code> Preprocessed output. Applies only to compile
709 actions that only preprocess the source files, typically when using the
710 <code>--save_temps</code> flag. The contents are the same as for
711 <code>output_file</code>.
712 </td>
713 </tr>
714 <tr>
715 <td><strong><code>includes</code></strong>
716 </td>
717 <td><code>[compile]</code> Sequence of files the compiler must
718 unconditionally include in the compiled source.
719 </td>
720 </tr>
721 <tr>
722 <td><strong><code>include_paths</code></strong>
723 </td>
724 <td><code>[compile]</code> Sequence directories in which the compiler
725 searches for headers included using <code>#include&lt;foo.h&gt;</code>
726 and <code>#include "foo.h"</code>.
727 </td>
728 </tr>
729 <tr>
730 <td><strong><code>quote_include_paths</code></strong>
731 </td>
732 <td><code>[compile]</code> Sequence of <code>-iquote</code> includes -
733 directories in which the compiler searches for headers included using
734 <code>#include&lt;foo.h&gt;</code>.
735 </td>
736 </tr>
737 <tr>
738 <td><strong><code>system_include_paths</code></strong>
739 </td>
740 <td><code>[compile]</code> Sequence of <code>-isystem</code> includes -
741 directories in which the compiler searches for headers included using
742 <code>#include "foo.h"</code>.
743 </td>
744 </tr>
745 <tr>
746 <td><strong><code>dependency_file</code></strong>
747 </td>
748 <td><code>[compile]</code> The <code>.d</code> dependency file generated by
749 the compiler.
750 </td>
751 </tr>
752 <tr>
753 <td><strong><code>preprocessor_defines</code></strong>
754 </td>
755 <td><code>[compile]</code> Sequence of <code>defines</code>, such as
756 <code>--DDEBUG</code>.
757 </td>
758 </tr>
759 <tr>
760 <td><strong><code>pic</code></strong>
761 </td>
762 <td><code>[compile]</code> Compiles the output as position-independent code.
763 </td>
764 </tr>
765 <tr>
766 <td><strong><code>gcov_gcno_file</code></strong>
767 </td>
768 <td><code>[compile]</code> The <code>gcov</code> coverage file.
769 </td>
770 </tr>
771 <tr>
772 <td><strong><code>per_object_debug_info_file</code></strong>
773 </td>
774 <td><code>[compile]</code> The per-object debug info (<code>.dwp</code>)
775 file.
776 </td>
777 </tr>
778 <tr>
779 <td><strong><code>stripotps</code></strong>
780 </td>
781 <td><code>[strip]</code> Sequence of <code>stripopts</code>.
782 </td>
783 </tr>
784 <tr>
785 <td><strong><code>legacy_compile_flags</code></strong>
786 </td>
spomorski20ca4e12018-10-03 07:44:47 -0700787 <td><code>[compile]</code> Sequence of flags from legacy
788 <code>CROSSTOOL</code> fields such as <code>compiler_flag</code>,
789 <code>optional_compiler_flag</code>, <code>cxx_flag</code>, and
790 <code>optional_cxx_flag</code>.
spomorskiab39ffb2018-10-02 11:19:32 -0700791 </td>
792 </tr>
793 <tr>
794 <td><strong><code>user_compile_flags</code></strong>
795 </td>
796 <td><code>[compile]</code> Sequence of flags from either the
797 <code>copt</code> rule attribute or the <code>--copt</code>,
798 <code>--cxxopt</code>, and <code>--conlyopt</code> flags.
799 </td>
800 </tr>
801 <tr>
802 <td><strong><code>unfiltered_compile_flags</code></strong>
803 </td>
804 <td><code>[compile]</code> Sequence of flags from the
spomorski20ca4e12018-10-03 07:44:47 -0700805 <code>unfiltered_cxx_flag</code> legacy <code>CROSSTOOL</code> field or the
spomorskiab39ffb2018-10-02 11:19:32 -0700806 <code>unfiltered _compile_flags</code> feature. These are not filtered by
807 the <code>nocopts</code> rule attribute.
808 </td>
809 </tr>
810 <tr>
811 <td><strong><code>sysroot</code></strong>
812 </td>
813 <td>The <code>sysroot</code>.
814 </td>
815 </tr>
816 <tr>
817 <td><strong><code>runtime_library_search_directories</code></strong>
818 </td>
819 <td><code>[link]</code> Entries in the linker runtime search path (usually
820 set with the <code>-rpath</code> flag).
821 </td>
822 </tr>
823 <tr>
824 <td><strong><code>library_search_directories</code></strong>
825 </td>
826 <td><code>[link]</code> Entries in the linker search path (usually set with
827 the <code>-L</code> flag).
828 </td>
829 </tr>
830 <tr>
831 <td><strong><code>libraries_to_link</code></strong>
832 </td>
833 <td><code>[link]</code> Flags providing files to link as inputs in the linker
834 invocation.
835 </td>
836 </tr>
837 <tr>
838 <td><strong><code>def_file_path</code></strong>
839 </td>
840 <td><code>[link]</code> Location of def file used on Windows with MSVC.
841 </td>
842 </tr>
843 <tr>
844 <td><strong><code>linker_param_file</code></strong>
845 </td>
846 <td><code>[link]</code> Location of linker param file created by bazel to
847 overcome command line length limit.
848 </td>
849 </tr>
850 <tr>
851 <td><strong><code>output_execpath</code></strong>
852 </td>
853 <td><code>[link]</code> execpath of the output of the linker.
854 </td>
855 </tr>
856 <tr>
857 <td><strong><code>generate_interface_library</code></strong>
858 </td>
859 <td><code>[link]</code> "yes"|"no" depending on whether interface library
860 should be generated.
861 </td>
862 </tr>
863 <tr>
864 <td><strong><code>interface_library_builder_path</code></strong>
865 </td>
866 <td><code>[link]</code> Path to the interface library builder tool.
867 </td>
868 </tr>
869 <tr>
870 <td><strong><code>interface_library_input_path</code></strong>
871 </td>
spomorski20ca4e12018-10-03 07:44:47 -0700872 <td><code>[link]</code> Input for the interface library <code>ifso</code>
873 builder tool.
spomorskiab39ffb2018-10-02 11:19:32 -0700874 </td>
875 </tr>
876 <tr>
877 <td><strong><code>interface_library_output_path</code></strong>
878 </td>
879 <td><code>[link]</code> Path where to generate interface library using the
880 <code>ifso</code> builder tool.
881 </td>
882 </tr>
883 <tr>
884 <td><strong><code>legacy_link_flags</code></strong>
885 </td>
spomorski20ca4e12018-10-03 07:44:47 -0700886 <td><code>[link]</code> Linker flags coming from the legacy
887 <code>CROSSTOOL</code>.
spomorskiab39ffb2018-10-02 11:19:32 -0700888 </td>
889 </tr>
890 <tr>
891 <td><strong><code>user_link_flags</code></strong>
892 </td>
893 <td><code>[link]</code> Linker flags coming from the <code>--linkopt</code>
894 or <code>linkopts</code> attribute.
895 </td>
896 </tr>
897 <tr>
898 <td><strong><code>symbol_counts_output</code></strong>
899 </td>
900 <td><code>[link]</code> Path to which to write symbol counts.
901 </td>
902 </tr>
903 <tr>
904 <td><strong><code>linkstamp_paths</code></strong>
905 </td>
906 <td><code>[link]</code> A build variable giving linkstamp paths.
907 </td>
908 </tr>
909 <tr>
910 <td><strong><code>force_pic</code></strong>
911 </td>
912 <td><code>[link]</code> Presence of this variable indicates that PIC code
913 should be generated.
914 </td>
915 </tr>
916 <tr>
917 <td><strong><code>strip_debug_symbols</code></strong>
918 </td>
919 <td><code>[link]</code> Presence of this variable indicates that the debug
920 symbols should be stripped.
921 </td>
922 </tr>
923 <tr>
924 <td><strong><code>is_cc_test</code></strong>
925 </td>
926 <td><code>[link]</code> Truthy when current action is a <code>cc_test</code>
927 linking action, false otherwise.
928 </td>
929 </tr>
930 <tr>
931 <td><strong><code>is_using_fission</code></strong>
932 </td>
933 <td><code>[link]</code> Presence of this variable indicates that files were
934 compiled with fission. Debug info is in <code>.dwo</code> files instead
935 of <code>.o</code> files and the linker needs to know this.
936 </td>
937 </tr>
938</table>
939
940
941
942### CROSSTOOL features
943
spomorski20ca4e12018-10-03 07:44:47 -0700944The following is a reference of `CROSSTOOL` features and their activation
spomorskiab39ffb2018-10-02 11:19:32 -0700945conditions.
946
947<table>
948 <col width="300">
949 <col width="600">
950 <tr>
951 <td><strong>Feature</strong>
952 </td>
953 <td><strong>Activation Condition</strong>
954 </td>
955 </tr>
956 <tr>
957 <td><strong><code>opt | dbg | fastbuild</code></strong>
958 </td>
959 <td>Enabled by default based on compilation mode.
960 </td>
961 </tr>
962 <tr>
963 <td><strong><code>static_linking_mode | dynamic_linking_mode</code></strong>
964 </td>
965 <td>Enabled by default based on linking mode.
966 </td>
967 </tr>
968 <tr>
969 <td><strong><code>random_seed</code></strong>
970 </td>
971 <td>Enabled by default.
972 </td>
973 </tr>
974 <tr>
975 <td><strong><code>dependency_file</code></strong>
976 </td>
977 <td>Enabled by default.
978 </td>
979 </tr>
980 <tr>
981 <td><strong><code>per_object_debug_info</code></strong>
982 </td>
spomorski20ca4e12018-10-03 07:44:47 -0700983 <td>Enabled if the <code>supports_fission</code> attribute is set in the
984 `CROSSTOOL` file and the current compilation mode is specified in the
985 <code>--fission</code> flag.
spomorskiab39ffb2018-10-02 11:19:32 -0700986 </td>
987 </tr>
988 <tr>
989 <td><strong><code>pic</code></strong>
990 </td>
spomorski20ca4e12018-10-03 07:44:47 -0700991 <td>Required if the target needs PIC objects for dynamic libraries. Enabled
992 by default - the `pic` variable is present whenever PIC compilation is
993 requested.
spomorskiab39ffb2018-10-02 11:19:32 -0700994 </td>
995 </tr>
996</table>