cc_common
Utilities for C++ compilation, linking, and command line generation.Methods
- CcToolchainInfo
- configure_features
- create_compilation_context
- create_compile_variables
- create_library_to_link
- create_link_variables
- create_linking_context
- do_not_use_tools_cpp_compiler_present
- get_environment_variables
- get_memory_inefficient_command_line
- get_tool_for_action
- is_enabled
- merge_cc_infos
CcToolchainInfo
Provider cc_common.CcToolchainInfoThe key used to retrieve the provider that contains information about the C++ toolchain being used
configure_features
feature_configuration cc_common.configure_features(cc_toolchain, requested_features=[], unsupported_features=[])Creates a feature_configuration instance.
Parameters
Parameter | Description |
---|---|
cc_toolchain
|
cc_toolchain for which we configure features. |
requested_features
|
List of features to be enabled. |
unsupported_features
|
List of features that are unsupported by the current rule. |
create_compilation_context
CompilationContext cc_common.create_compilation_context(headers=unbound, system_includes=unbound, includes=unbound, quote_includes=unbound, defines=unbound)Creates a
CompilationContext
.
Parameters
Parameter | Description |
---|---|
headers
|
Set of headers needed to compile this target |
system_includes
|
Set of search paths for header files referenced by angle brackets, i.e. #include |
includes
|
Set of search paths for header files referenced both by angle bracket and quotes.Usually passed with -I |
quote_includes
|
Set of search paths for header files referenced by quotes, i.e. #include "foo/bar/header.h". They can be either relative to the exec root or absolute. Usually passed with -iquote |
defines
|
Set of defines needed to compile this target. Each define is a string |
create_compile_variables
variables cc_common.create_compile_variables(cc_toolchain, feature_configuration, source_file=None, output_file=None, user_compile_flags=None, include_directories=None, quote_include_directories=None, system_include_directories=None, preprocessor_defines=None, use_pic=False, add_legacy_cxx_options=False)Returns variables used for compilation actions.
Parameters
Parameter | Description |
---|---|
cc_toolchain
|
cc_toolchain for which we are creating build variables. |
feature_configuration
|
Feature configuration to be queried. |
source_file
|
Optional source file for the compilation. Please prefer passing source_file here over appending it to the end of the command line generated from cc_common.get_memory_inefficient_command_line, as then it's in the power of the toolchain author to properly specify and position compiler flags. |
output_file
|
Optional output file of the compilation. Please prefer passing output_file here over appending it to the end of the command line generated from cc_common.get_memory_inefficient_command_line, as then it's in the power of the toolchain author to properly specify and position compiler flags. |
user_compile_flags
|
List of additional compilation flags (copts). Passing depset is deprecated and will be removed by --incompatible_disable_depset_in_cc_user_flags flag. |
include_directories
|
Depset of include directories. |
quote_include_directories
|
Depset of quote include directories. |
system_include_directories
|
Depset of system include directories. |
preprocessor_defines
|
Depset of preprocessor defines. |
use_pic
|
When true the compilation will generate position independent code. |
add_legacy_cxx_options
|
When true the flags will contain options coming from legacy cxx_flag crosstool fields. |
create_library_to_link
unknown cc_common.create_library_to_link(actions, feature_configuration, cc_toolchain, static_library=None, pic_static_library=None, dynamic_library=None, interface_library=None, alwayslink=False)Creates
LibraryToLink
Parameters
Parameter | Description |
---|---|
actions
|
|
feature_configuration
|
|
cc_toolchain
|
|
static_library
|
|
pic_static_library
|
|
dynamic_library
|
|
interface_library
|
|
alwayslink
|
Whether to link the static library/objects in the --whole_archive block. |
create_link_variables
variables cc_common.create_link_variables(cc_toolchain, feature_configuration, library_search_directories=None, runtime_library_search_directories=None, user_link_flags=None, output_file=None, param_file=None, def_file=None, is_using_linker=True, is_linking_dynamic_library=False, must_keep_debug=True, use_test_only_flags=False, is_static_linking_mode=True)Returns link variables used for linking actions.
Parameters
Parameter | Description |
---|---|
cc_toolchain
|
cc_toolchain for which we are creating build variables. |
feature_configuration
|
Feature configuration to be queried. |
library_search_directories
|
Depset of directories where linker will look for libraries at link time. |
runtime_library_search_directories
|
Depset of directories where loader will look for libraries at runtime. |
user_link_flags
|
List of additional link flags (linkopts). Passing depset is deprecated and will be removed by --incompatible_disable_depset_in_cc_user_flags flag. |
output_file
|
Optional output file path. |
param_file
|
Optional param file path. |
def_file
|
Optional .def file path. |
is_using_linker
|
True when using linker, False when archiver. Caller is responsible for keeping this in sync with action name used (is_using_linker = True for linking executable or dynamic library, is_using_linker = False for archiving static library). |
is_linking_dynamic_library
|
True when creating dynamic library, False when executable or static library. Caller is responsible for keeping this in sync with action name used. This field will be removed once b/65151735 is fixed. |
must_keep_debug
|
When set to True, bazel will expose 'strip_debug_symbols' variable, which is usually used to use the linker to strip debug symbols from the output file. |
use_test_only_flags
|
When set to True flags coming from test_only_linker_flag crosstool fields will be included.This field will be removed once b/65151735 is fixed. |
is_static_linking_mode
|
True when using static_linking_mode, False when using dynamic_linking_mode. Caller is responsible for keeping this in sync with 'static_linking_mode' and 'dynamic_linking_mode' features enabled on the feature configuration. This field will be removed once b/65151735 is fixed. |
create_linking_context
unknown cc_common.create_linking_context(libraries_to_link=None, user_link_flags=None)Creates a
LinkingContext
.
Parameters
Parameter | Description |
---|---|
libraries_to_link
|
List of |
user_link_flags
|
List of user link flags passed as strings. |
do_not_use_tools_cpp_compiler_present
None cc_common.do_not_use_tools_cpp_compiler_presentDo not use this field, its only puprose is to help with migration from config_setting.values{'compiler') to config_settings.flag_values{'@bazel_tools//tools/cpp:compiler'}
get_environment_variables
dict cc_common.get_environment_variables(feature_configuration, action_name, variables)Returns environment variables to be set for given action.
Parameters
Parameter | Description |
---|---|
feature_configuration
|
Feature configuration to be queried. |
action_name
|
Name of the action. Has to be one of the names in @bazel_tools//tools/build_defs/cc:action_names.bzl. |
variables
|
Build variables to be used for template expansion. |
get_memory_inefficient_command_line
sequence cc_common.get_memory_inefficient_command_line(feature_configuration, action_name, variables)Returns flattened command line flags for given action, using given variables for expansion. Flattens nested sets and ideally should not be used, or at least should not outlive analysis. Work on memory efficient function returning Args is ongoing.
Parameters
Parameter | Description |
---|---|
feature_configuration
|
Feature configuration to be queried. |
action_name
|
Name of the action. Has to be one of the names in @bazel_tools//tools/build_defs/cc:action_names.bzl. |
variables
|
Build variables to be used for template expansions. |
get_tool_for_action
string cc_common.get_tool_for_action(feature_configuration, action_name)Returns tool path for given action.
Parameters
Parameter | Description |
---|---|
feature_configuration
|
Feature configuration to be queried. |
action_name
|
Name of the action. Has to be one of the names in @bazel_tools//tools/build_defs/cc:action_names.bzl. |
is_enabled
bool cc_common.is_enabled(feature_configuration, feature_name)Returns True if given feature is enabled in the feature configuration.
Parameters
Parameter | Description |
---|---|
feature_configuration
|
Feature configuration to be queried. |
feature_name
|
Name of the feature. |
merge_cc_infos
cc_info cc_common.merge_cc_infos(cc_infos=[])Merges a list of
CcInfo
s into one.
Parameters
Parameter | Description |
---|---|
cc_infos
|
List of |