1// Copyright 2014 The Bazel Authors. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14// 15// File format for Blaze to configure Crosstool releases. 16 17syntax = "proto2"; 18 19package com.google.devtools.build.lib.view.config.crosstool; 20 21// option java_api_version = 2; // copybara-comment-this-out-please 22option java_package = "com.google.devtools.build.lib.view.config.crosstool"; 23 24// A description of a toolchain, which includes all the tools generally expected 25// to be available for building C/C++ targets, based on the GNU C compiler. 26// 27// System and cpu names are two overlapping concepts, which need to be both 28// supported at this time. The cpu name is the blaze command-line name for the 29// target system. The most common values are 'k8' and 'piii'. The system name is 30// a more generic identification of the executable system, based on the names 31// used by the GNU C compiler. 32// 33// Typically, the system name contains an identifier for the cpu (e.g. x86_64 or 34// alpha), an identifier for the machine (e.g. pc, or unknown), and an 35// identifier for the operating system (e.g. cygwin or linux-gnu). Typical 36// examples are 'x86_64-unknown-linux-gnu' and 'i686-unknown-cygwin'. 37// 38// The system name is used to determine if a given machine can execute a given 39// executable. In particular, it is used to check if the compilation products of 40// a toolchain can run on the host machine. 41message CToolchain { 42 // A group of correlated flags. Supports parametrization via variable 43 // expansion. 44 // 45 // To expand a variable of list type, flag_group has to be annotated with 46 // `iterate_over` message. Then all nested flags or flag_groups will be 47 // expanded repeatedly for each element of the list. 48 // 49 // For example: 50 // flag_group { 51 // iterate_over: 'include_path' 52 // flag: '-I' 53 // flag: '%{include_path}' 54 // } 55 // ... will get expanded to -I /to/path1 -I /to/path2 ... for each 56 // include_path /to/pathN. 57 // 58 // To expand a variable of structure type, use dot-notation, e.g.: 59 // flag_group { 60 // iterate_over: "libraries_to_link" 61 // flag_group { 62 // iterate_over: "libraries_to_link.libraries" 63 // flag: "-L%{libraries_to_link.libraries.directory}" 64 // } 65 // } 66 // 67 // Flag groups can be nested; if they are, the flag group must only contain 68 // other flag groups (no flags) so the order is unambiguously specified. 69 // In order to expand a variable of nested lists, 'iterate_over' can be used. 70 // 71 // For example: 72 // flag_group { 73 // iterate_over: 'object_files' 74 // flag_group { flag: '--start-lib' } 75 // flag_group { 76 // iterate_over: 'object_files' 77 // flag: '%{object_files}' 78 // } 79 // flag_group { flag: '--end-lib' } 80 // } 81 // ... will get expanded to 82 // --start-lib a1.o a2.o ... --end-lib --start-lib b1.o b2.o .. --end-lib 83 // with %{object_files} being a variable of nested list type 84 // [['a1.o', 'a2.o', ...], ['b1.o', 'b2.o', ...], ...]. 85 // 86 // TODO(bazel-team): Write more elaborate documentation and add a link to it. 87 message FlagGroup { 88 repeated string flag = 1; 89 90 repeated FlagGroup flag_group = 2; 91 92 optional string iterate_over = 3; 93 94 repeated string expand_if_all_available = 4; 95 96 repeated string expand_if_none_available = 5; 97 98 optional string expand_if_true = 6; 99 100 optional string expand_if_false = 7; 101 102 optional VariableWithValue expand_if_equal = 8; 103 } 104 105 message VariableWithValue { 106 required string variable = 1; 107 108 required string value = 2; 109 } 110 111 // A key/value pair to be added as an environment variable. The value of 112 // this pair is expanded in the same way as is described in FlagGroup. 113 // The key remains an unexpanded string literal. 114 message EnvEntry { 115 required string key = 1; 116 required string value = 2; 117 repeated string expand_if_all_available = 3; 118 } 119 120 // A set of features; used to support logical 'and' when specifying feature 121 // requirements in Feature. 122 message FeatureSet { 123 repeated string feature = 1; 124 } 125 126 // A set of positive and negative features. This stanza will 127 // evaluate to true when every 'feature' is enabled, and every 128 // 'not_feature' is not enabled. 129 message WithFeatureSet { 130 repeated string feature = 1; 131 repeated string not_feature = 2; 132 } 133 134 // A set of flags that are expanded in the command line for specific actions. 135 message FlagSet { 136 // The actions this flag set applies to; each flag set must specify at 137 // least one action. 138 repeated string action = 1; 139 140 // The flags applied via this flag set. 141 repeated FlagGroup flag_group = 2; 142 143 // A list of feature sets defining when this flag set gets applied. The 144 // flag set will be applied when any one of the feature sets evaluate to 145 // true. (That is, when when every 'feature' is enabled, and every 146 // 'not_feature' is not enabled.) 147 // 148 // If 'with_feature' is omitted, the flag set will be applied 149 // unconditionally for every action specified. 150 repeated WithFeatureSet with_feature = 3; 151 152 // Deprecated (https://github.com/bazelbuild/bazel/issues/7008) - use 153 // expand_if_all_available in flag_group 154 // 155 // A list of build variables that this feature set needs, but which are 156 // allowed to not be set. If any of the build variables listed is not 157 // set, the feature set will not be expanded. 158 // 159 // NOTE: Consider alternatives before using this; usually tools should 160 // consistently create the same set of files, even if empty; use this 161 // only for backwards compatibility with already existing behavior in tools 162 // that are currently not worth changing. 163 repeated string expand_if_all_available = 4; 164 } 165 166 // A set of environment variables that are expanded in the command line for 167 // specific actions. 168 message EnvSet { 169 // The actions this env set applies to; each env set must specify at 170 // least one action. 171 repeated string action = 1; 172 173 // The environment variables applied via this env set. 174 repeated EnvEntry env_entry = 2; 175 176 // A list of feature sets defining when this env set gets applied. The 177 // env set will be applied when any one of the feature sets evaluate to 178 // true. (That is, when when every 'feature' is enabled, and every 179 // 'not_feature' is not enabled.) 180 // 181 // If 'with_feature' is omitted, the env set will be applied 182 // unconditionally for every action specified. 183 repeated WithFeatureSet with_feature = 3; 184 } 185 186 // Contains all flag specifications for one feature. 187 // Next ID: 8 188 message Feature { 189 // The feature's name. Feature names are generally defined by Bazel; it is 190 // possible to introduce a feature without a change to Bazel by adding a 191 // 'feature' section to the toolchain and adding the corresponding string as 192 // feature in the BUILD file. 193 optional string name = 1; 194 195 // If 'true', this feature is enabled unless a rule type explicitly marks it 196 // as unsupported. Such features cannot be turned off from within a BUILD 197 // file or the command line. 198 optional bool enabled = 7; 199 200 // If the given feature is enabled, the flag sets will be applied for the 201 // actions in the modes that they are specified for. 202 repeated FlagSet flag_set = 2; 203 204 // If the given feature is enabled, the env sets will be applied for the 205 // actions in the modes that they are specified for. 206 repeated EnvSet env_set = 6; 207 208 // A list of feature sets defining when this feature is supported by the 209 // toolchain. The feature is supported if any of the feature sets fully 210 // apply, that is, when all features of a feature set are enabled. 211 // 212 // If 'requires' is omitted, the feature is supported independently of which 213 // other features are enabled. 214 // 215 // Use this for example to filter flags depending on the build mode 216 // enabled (opt / fastbuild / dbg). 217 repeated FeatureSet requires = 3; 218 219 // A list of features or action configs that are automatically enabled when 220 // this feature is enabled. If any of the implied features or action configs 221 // cannot be enabled, this feature will (silently) not be enabled either. 222 repeated string implies = 4; 223 224 // A list of names this feature conflicts with. 225 // A feature cannot be enabled if: 226 // - 'provides' contains the name of a different feature or action config 227 // that we want to enable. 228 // - 'provides' contains the same value as a 'provides' in a different 229 // feature or action config that we want to enable. 230 // 231 // Use this in order to ensure that incompatible features cannot be 232 // accidentally activated at the same time, leading to hard to diagnose 233 // compiler errors. 234 repeated string provides = 5; 235 } 236 237 // Describes a tool associated with a crosstool action config. 238 message Tool { 239 // Describes the origin of a path. 240 enum PathOrigin { 241 // Indicates that `tool_path` is relative to the location of the 242 // crosstool. For legacy reasons, absolute paths are als0 allowed here. 243 CROSSTOOL_PACKAGE = 0; 244 245 // Indicates that `tool_path` is an absolute path. 246 // This is enforced by Bazel. 247 FILESYSTEM_ROOT = 1; 248 249 // Indicates that `tool_path` is relative to the current workspace's 250 // exec root. 251 WORKSPACE_ROOT = 2; 252 } 253 254 // Path to the tool, relative to the location of the crosstool. 255 required string tool_path = 1; 256 257 // Origin of `tool_path`. 258 // Optional only for legacy reasons. New crosstools should set this value! 259 optional PathOrigin tool_path_origin = 4 [default = CROSSTOOL_PACKAGE]; 260 261 // A list of feature sets defining when this tool is applicable. The tool 262 // will used when any one of the feature sets evaluate to true. (That is, 263 // when when every 'feature' is enabled, and every 'not_feature' is not 264 // enabled.) 265 // 266 // If 'with_feature' is omitted, the tool will apply for any feature 267 // configuration. 268 repeated WithFeatureSet with_feature = 2; 269 270 // Requirements on the execution environment for the execution of this tool, 271 // to be passed as out-of-band "hints" to the execution backend. 272 // Ex. "requires-darwin" 273 repeated string execution_requirement = 3; 274 } 275 276 // The name for an artifact of a given category of input or output artifacts 277 // to an action. 278 message ArtifactNamePattern { 279 // The category of artifacts that this selection applies to. This field 280 // is compared against a list of categories defined in bazel. Example 281 // categories include "linked_output" or "debug_symbols". An error is thrown 282 // if no category is matched. 283 required string category_name = 1; 284 // The prefix and extension for creating the artifact for this selection. 285 // They are used to create an artifact name based on the target name. 286 required string prefix = 2; 287 required string extension = 3; 288 } 289 290 // An action config corresponds to a blaze action, and allows selection of 291 // a tool based on activated features. Action configs come in two varieties: 292 // automatic (the blaze action will exist whether or not the action config 293 // is activated) and attachable (the blaze action will be added to the 294 // action graph only if the action config is activated). 295 // 296 // Action config activation occurs by the same semantics as features: a 297 // feature can 'require' or 'imply' an action config in the same way that it 298 // would another feature. 299 // Next ID: 9 300 message ActionConfig { 301 // The name other features will use to activate this action config. Can 302 // be the same as action_name. 303 required string config_name = 1; 304 305 // The name of the blaze action that this config applies to, ex. 'c-compile' 306 // or 'c-module-compile'. 307 required string action_name = 2; 308 309 // If 'true', this feature is enabled unless a rule type explicitly marks it 310 // as unsupported. Such action_configs cannot be turned off from within a 311 // BUILD file or the command line. 312 optional bool enabled = 8; 313 314 // The tool applied to the action will be the first Tool with a feature 315 // set that matches the feature configuration. An error will be thrown 316 // if no tool matches a provided feature configuration - for that reason, 317 // it's a good idea to provide a default tool with an empty feature set. 318 repeated Tool tool = 3; 319 320 // If the given action config is enabled, the flag sets will be applied 321 // to the corresponding action. 322 repeated FlagSet flag_set = 4; 323 324 // If the given action config is enabled, the env sets will be applied 325 // to the corresponding action. 326 repeated EnvSet env_set = 5; 327 328 // A list of feature sets defining when this action config 329 // is supported by the toolchain. The action config is supported if any of 330 // the feature sets fully apply, that is, when all features of a 331 // feature set are enabled. 332 // 333 // If 'requires' is omitted, the action config is supported independently 334 // of which other features are enabled. 335 // 336 // Use this for example to filter actions depending on the build 337 // mode enabled (opt / fastbuild / dbg). 338 repeated FeatureSet requires = 6; 339 340 // A list of features or action configs that are automatically enabled when 341 // this action config is enabled. If any of the implied features or action 342 // configs cannot be enabled, this action config will (silently) 343 // not be enabled either. 344 repeated string implies = 7; 345 } 346 347 repeated Feature feature = 50; 348 repeated ActionConfig action_config = 53; 349 repeated ArtifactNamePattern artifact_name_pattern = 54; 350 351 // The unique identifier of the toolchain within the crosstool release. It 352 // must be possible to use this as a directory name in a path. 353 // It has to match the following regex: [a-zA-Z_][\.\- \w]* 354 required string toolchain_identifier = 1; 355 356 // A basic toolchain description. 357 required string host_system_name = 2; 358 required string target_system_name = 3; 359 required string target_cpu = 4; 360 required string target_libc = 5; 361 required string compiler = 6; 362 363 required string abi_version = 7; 364 required string abi_libc_version = 8; 365 366 // Tool locations. Relative paths are resolved relative to the configuration 367 // file directory. 368 // NOTE: DEPRECATED. Prefer specifying an ActionConfig for the action that 369 // needs the tool. 370 // TODO(b/27903698) migrate to ActionConfig. 371 repeated ToolPath tool_path = 9; 372 373 // Feature flags. 374 // TODO(bazel-team): Sink those into 'Feature' instances. 375 // Legacy field, ignored by Bazel. 376 optional bool supports_gold_linker = 10 [default = false]; 377 // Legacy field, ignored by Bazel. 378 optional bool supports_thin_archives = 11 [default = false]; 379 // Legacy field, use 'supports_start_end_lib' feature instead. 380 optional bool supports_start_end_lib = 28 [default = false]; 381 // Legacy field, use 'supports_interface_shared_libraries' instead. 382 optional bool supports_interface_shared_objects = 32 [default = false]; 383 // Legacy field, use 'static_link_cpp_runtimes' feature instead. 384 optional bool supports_embedded_runtimes = 40 [default = false]; 385 // If specified, Blaze finds statically linked / dynamically linked runtime 386 // libraries in the declared crosstool filegroup. Otherwise, Blaze 387 // looks in "[static|dynamic]-runtime-libs-$TARGET_CPU". 388 // Deprecated, see https://github.com/bazelbuild/bazel/issues/6942 389 optional string static_runtimes_filegroup = 45; 390 // Deprecated, see https://github.com/bazelbuild/bazel/issues/6942 391 optional string dynamic_runtimes_filegroup = 46; 392 // Legacy field, ignored by Bazel. 393 optional bool supports_incremental_linker = 41 [default = false]; 394 // Legacy field, ignored by Bazel. 395 optional bool supports_normalizing_ar = 26 [default = false]; 396 // Legacy field, use 'per_object_debug_info' feature instead. 397 optional bool supports_fission = 43 [default = false]; 398 // Legacy field, ignored by Bazel. 399 optional bool supports_dsym = 51 [default = false]; 400 // Legacy field, use 'supports_pic' feature instead 401 optional bool needsPic = 12 [default = false]; 402 403 // Compiler flags for C/C++/Asm compilation. 404 repeated string compiler_flag = 13; 405 // Additional compiler flags for C++ compilation. 406 repeated string cxx_flag = 14; 407 // Additional unfiltered compiler flags for C/C++/Asm compilation. 408 // These are not subject to nocopt filtering in cc_* rules. 409 // Note: These flags are *not* applied to objc/objc++ compiles. 410 repeated string unfiltered_cxx_flag = 25; 411 // Linker flags. 412 repeated string linker_flag = 15; 413 // Additional linker flags when linking dynamic libraries. 414 repeated string dynamic_library_linker_flag = 27; 415 // Additional test-only linker flags. 416 repeated string test_only_linker_flag = 49; 417 // Objcopy flags for embedding files into binaries. 418 repeated string objcopy_embed_flag = 16; 419 // Ld flags for embedding files into binaries. This is used by filewrapper 420 // since it calls ld directly and needs to know what -m flag to pass. 421 repeated string ld_embed_flag = 23; 422 // Ar flags for combining object files into archives. If this is not set, it 423 // defaults to "rcsD". 424 // TODO(b/37271982): Remove after blaze with ar action_config release 425 repeated string ar_flag = 47; 426 // Legacy field, ignored by Bazel. 427 repeated string ar_thin_archives_flag = 48; 428 // Legacy field, ignored by Bazel. 429 repeated string gcc_plugin_compiler_flag = 34; 430 431 // Additional compiler and linker flags depending on the compilation mode. 432 repeated CompilationModeFlags compilation_mode_flags = 17; 433 434 // Additional linker flags depending on the linking mode. 435 repeated LinkingModeFlags linking_mode_flags = 18; 436 437 // Legacy field, ignored by Bazel. 438 repeated string gcc_plugin_header_directory = 19; 439 // Legacy field, ignored by Bazel. 440 repeated string mao_plugin_header_directory = 20; 441 442 // Make variables that are made accessible to rules. 443 repeated MakeVariable make_variable = 21; 444 445 // Built-in include directories for C++ compilation. These should be the exact 446 // paths used by the compiler, and are generally relative to the exec root. 447 // The paths used by the compiler can be determined by 'gcc -Wp,-v some.c'. 448 // We currently use the C++ paths also for C compilation, which is safe as 449 // long as there are no name clashes between C++ and C header files. 450 // 451 // Relative paths are resolved relative to the configuration file directory. 452 // 453 // If the compiler has --sysroot support, then these paths should use 454 // %sysroot% rather than the include path, and specify the sysroot attribute 455 // in order to give blaze the information necessary to make the correct 456 // replacements. 457 repeated string cxx_builtin_include_directory = 22; 458 459 // The built-in sysroot. If this attribute is not present, blaze does not 460 // allow using a different sysroot, i.e. through the --grte_top option. Also 461 // see the documentation above. 462 optional string builtin_sysroot = 24; 463 464 // Legacy field, ignored by Bazel. 465 optional string default_python_top = 29; 466 // Legacy field, ignored by Bazel. 467 optional string default_python_version = 30; 468 // Legacy field, ignored by Bazel. 469 optional bool python_preload_swigdeps = 42; 470 471 // The default GRTE to use. This should be a label, and gets the same 472 // treatment from Blaze as the --grte_top option. This setting is only used in 473 // the absence of an explicit --grte_top option. If unset, Blaze will not pass 474 // -sysroot by default. The local part must be 'everything', i.e., 475 // '//some/label:everything'. There can only be one GRTE library per package, 476 // because the compiler expects the directory as a parameter of the -sysroot 477 // option. 478 // This may only be set to a non-empty value if builtin_sysroot is also set! 479 optional string default_grte_top = 31; 480 481 // Legacy field, ignored by Bazel. 482 repeated string debian_extra_requires = 33; 483 484 // Legacy field, ignored by Bazel. Only there for compatibility with 485 // things internal to Google. 486 optional string cc_target_os = 55; 487 488 // Next free id: 56 489} 490 491message ToolPath { 492 required string name = 1; 493 required string path = 2; 494} 495 496enum CompilationMode { 497 FASTBUILD = 1; 498 DBG = 2; 499 OPT = 3; 500 // This value is ignored and should not be used in new files. 501 COVERAGE = 4; 502} 503 504message CompilationModeFlags { 505 required CompilationMode mode = 1; 506 repeated string compiler_flag = 2; 507 repeated string cxx_flag = 3; 508 // Linker flags that are added when compiling in a certain mode. 509 repeated string linker_flag = 4; 510} 511 512enum LinkingMode { 513 FULLY_STATIC = 1; 514 MOSTLY_STATIC = 2; 515 DYNAMIC = 3; 516 MOSTLY_STATIC_LIBRARIES = 4; 517} 518 519message LinkingModeFlags { 520 required LinkingMode mode = 1; 521 repeated string linker_flag = 2; 522} 523 524message MakeVariable { 525 required string name = 1; 526 required string value = 2; 527} 528 529message DefaultCpuToolchain { 530 required string cpu = 1; 531 required string toolchain_identifier = 2; 532} 533 534// An entire crosstool release, containing the version number, and a set of 535// toolchains. 536message CrosstoolRelease { 537 // The major and minor version of the crosstool release. 538 required string major_version = 1; 539 required string minor_version = 2; 540 541 // Legacy field, ignored by Bazel. 542 optional string default_target_cpu = 3; 543 // Legacy field, ignored by Bazel. 544 repeated DefaultCpuToolchain default_toolchain = 4; 545 546 // All the toolchains in this release. 547 repeated CToolchain toolchain = 5; 548} 549