Skip to content

Latest commit

 

History

History
executable file
·
52 lines (39 loc) · 6.56 KB

cc_bin_docs.md

File metadata and controls

executable file
·
52 lines (39 loc) · 6.56 KB

Module providing means of compiling executables with usage of mapping metadata.

cc_bin

cc_bin(name, additional_linker_inputs, copts, defines, deps, hdrs_map, includes, linkopts,
       linkstatic, local_defines, private_hdrs, public_hdrs, srcs, stamp)

This rule allows for compiling code into executables.

Example:

cc_bin(
    name = "foo",
    hdrs_map = {
        "**/*.hpp": ["bar/{filename}"],
    },
    srcs = [
        "foo.cpp",
        "foo.hpp",
    ],
)

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
additional_linker_inputs Pass these files to the C++ linker command.

For example, compiled Windows .res files can be provided here to be embedded in the binary target.
List of labels optional []
copts Add these options to the C++ compilation command. Subject to "Make variable" substitution and Bourne shell tokenization. Each string in this attribute is added in the given order to COPTS before compiling the binary target. The flags take effect only for compiling this target, not its dependencies, so be careful about header files included elsewhere. All paths should be relative to the workspace, not to the current package.

If the package declares the feature no_copts_tokenization, Bourne shell tokenization applies only to strings that consist of a single "Make" variable.
List of strings optional []
defines List of defines to add to the compile line. Subject to "Make" variable substitution and Bourne shell tokenization. Each string, which must consist of a single Bourne shell token, is prepended with -D and added to the compile command line to this target, as well as to every rule that depends on it. Be very careful, since this may have far-reaching effects. When in doubt, add define values to local_defines instead. List of strings optional []
deps The list of dependencies of current target List of labels optional []
hdrs_map Dictionary describing paths under which header files should be avaiable as.

Keys are simple glob pathnames, used to match agains all header files avaiable in the rule. Values are list of paths to which matching header files should be mapped.

'{filename}' is special token used to signify to matching file name.

For example: '"**/*o.hpp": ["a/{filename}"]' - will ensure all hpp files with names ending with '0' will be also avaible as if they were placed in a subdirectory.
Dictionary: String -> List of strings optional {}
includes List of include dirs to be added to the compile line. Subject to "Make variable" substitution. Each string is prepended with -isystem and added to COPTS. Unlike COPTS, these flags are added for this rule and every rule that depends on it. (Note: not the rules it depends upon!) Be very careful, since this may have far-reaching effects. When in doubt, add "-I" flags to COPTS instead.

Headers must be added to srcs or hdrs, otherwise they will not be available to dependent rules when compilation is sandboxed (the default).
List of strings optional []
linkopts Add these flags to the C++ linker command. Subject to "Make" variable substitution, Bourne shell tokenization and label expansion. Each string in this attribute is added to LINKOPTS before linking the binary target. Each element of this list that does not start with $ or - is assumed to be the label of a target in deps. The list of files generated by that target is appended to the linker options. An error is reported if the label is invalid, or is not declared in deps. List of strings optional []
linkstatic Link the binary in static mode. Boolean optional True
local_defines List of defines to add to the compile line. Subject to "Make" variable substitution and Bourne shell tokenization. Each string, which must consist of a single Bourne shell token, is prepended with -D and added to the compile command line for this target, but not to its dependents. List of strings optional []
private_hdrs List of headers that CANNOT be included by dependent rules. Notice: the cutoff happens during compilation. List of labels optional []
public_hdrs List of headers that may be included by dependent rules transitively. Notice: the cutoff happens during compilation. List of labels optional []
srcs The list of source files. List of labels required
stamp Whether to encode build information into the binary. Possible values:

* stamp = 1: Always stamp the build information into the binary, even in --nostamp builds. This setting should be avoided, since it potentially kills remote caching for the binary and any downstream actions that depend on it.

* stamp = 0: Always replace build information by constant values. This gives good build result caching.

* stamp = -1: Embedding of build information is controlled by the --[no]stamp flag.

Stamped binaries are not rebuilt unless their dependencies change.
Integer optional -1