cxx_genrule() enables you to run shell commands as part of the Buck build process. A
cxx_genrule() exposes—through a set of string parameter macros and variables—information about the tools and configuration options used by the Buck environment, specifically those related to the C/C++ toolchain.
The information exposed through these tools and configuration options is a reflection of: Buck's built-in settings, the settings in
.buckconfig.local, and the result of various command-line overrides specified through the
--config command-line option.
This information is available only to the shell commands specified in the
cxx_genrule. The information is not available to other arguments of the rule.
cxx_genrule() can be an input to another
Note that if you specify the
cxx_genrule as a command-line target to
buck build, you must include a platform flavor. For example:
buck build :cxx_gr_name#iphonesimulator-x86_64
You could also just specify the default platform flavor explicitly:
buck build :cxx_gr_name#default
The name of the rule.
Either a list or a map of the source files which Buck makes available to the shell command at the path in the
SRCDIRenvironment variable. If you specify a list, the source files are the names in the list. If you specify a map, the source files are made available as the names in the keys of the map, where the values of the map are the original source file names.
The shell command to run to generate the output file. It is the fallback of
cmd_exe. The shell command can access information about the buck build environment through a set of macros, parameterized macros, and variables.
The following macros are available to the shell command and are accessed using the following syntax.
- Path to the C compiler.
- Path to the C++ compiler.
- Flags passed to the C compiler.
- Flags passed to the C preprocessor.
- Flags passed to the C++ compiler.
- Path to the linker.
- Flags passed to the linker for binaries that use position-independent code (PIC).
- Flags passed to the linker for binaries that use position-independent code (PIC). Use the pattern parameter to specify a regular expression that matches the build targets that use these flags.
- Flags passed to the linker for shared libraries, such as dynamic-link libraries (DLLs).
- Flags passed to the linker for shared libraries, such as dynamic-link libraries (DLLs). Use the pattern parameter to specify a regular expression that matches the build targets that use these flags.
- Flags passed to the linker for statically-linked libraries.
- Flags passed to the linker for statically-linked libraries. Use the pattern parameter to specify a regular expression that matches the build targets that use these flags.
- The platform flavor with which this
It is also possible to expand references to other rules within the shell command, using a subset of the builtin string parameter macros. Note that all build rules expanded in the command are automatically considered to be dependencies of the
- Expands to the commands necessary to run the executable generated by the specified build rule. For a C++ executable, this will typically just be the name of the output executable itself, such as
main. If the specified build rule does not generate an executable output, an exception will be thrown and the build will fail.
- Expands to the path of the output of the build rule. This means that you can refer to these without needing to be aware of how Buck is storing data on the disk mid-build.
Finally, Buck adds the following variables to the environment in which the shell command runs. They are accessed using the following syntax. Note the use of braces rather than parentheses.
- A string expansion of the
srcsargument delimited by the
environment_expansion_separatorargument where each element of
srcswill be translated into an absolute path.
- The absolute path to the to which sources are copied prior to running the command.
- The output file for the
genrule(). The file specified by this variable must always be written by this command. If not, the execution of this rule will be considered a failure, halting the build process.
- A temporary directory which can be used for intermediate results and will not be bundled into the output.
A platform-specific version of the shell command parameter
cmd. It runs on Linux and UNIX systems—including OSX—on which
bashis installed. It has a higher priority than
bashargument is run with
/bin/bash -c. It has access to the same set of macros and variables as the
A platform-specific version of the shell command parameter
cmd. It runs on Windows and has a higher priority than
cmd_exeargument is run with
cmd.exe /c. It has access to the same set of macros and variables as the
Specifies the type of this genrule. This is used for logging and is particularly useful for grouping genrules that share an underlying logical "type".
For example, if you have the following
cxx_genruledefined in the root directory of your Buck project
cxx_genrule( name = 'cxx_gen', type = 'epilog', cmd = 'touch finish.txt; cp finish.txt $OUT', out = 'finish.txt' )
then the following
buck query "attrfilter( type, 'epilog', '//...' )"
The name of the output file or directory. The complete path to this argument is provided to the shell command through the
" ") #
The delimiter between paths in environment variables, such as SRCS, that can contain multiple paths. It can be useful to specify this parameter if the paths could contain spaces.
Whether this target should be executed in a sandbox or not.
Whether the output of the genrule is itself executable. Marking an output as executable makes
$(exe ...)macro expansion work with this target.
List of build targets that identify tests that exercise this target.
List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their
exported_depsattributes. For more information, see visibility.