Buck: cgo_library()

cgo_library()

This is liable to change in the future.

A cgo_library() rule builds an object from the supplied set of Go/C source files and dependencies. The outputs are linked into go executable in the last step (compile). This rule borrows from cxx_binary since C/C++ sources are being compiled.

Arguments

  • name (required) #

    The name of the rule.

  • package_name (defaults to go.prefix + path relative to the buck root) #

    Sets the full name of the package being compiled. This defaults to the path from the buck root. (e.g. given a ./.buckconfig, a rule in ./a/b/BUCK defaults to package "a/b")

  • srcs (defaults to []) #

    The set of C, C++, Objective-C, Objective-C++, or assembly source files to be preprocessed, compiled, and assembled by this rule. We determine which stages to run on each input source based on its file extension. See the GCC documentation for more detail on how file extensions are interpreted. Each element can be either a string specifying a source file (e.g. 'foo/bar.c') or a tuple of a string specifying a source file and a list of compilation flags (e.g. ('foo/bar.c', ['-Wall', '-Werror'])). In the latter case the specified flags will be used in addition to the rule's other flags when preprocessing and compiling that file (if applicable).

  • headers (defaults to []) #

    The set of header files that are made available for inclusion to the source files in this target. These should be specified as either a list of header files or a dictionary of header names to header files. The header name can contain forward slashes (/). The headers can be included with #include "$HEADER_NAMESPACE/$HEADER_NAME" or #include <$HEADER_NAMESPACE/$HEADER_NAME>, where $HEADER_NAMESPACE is the value of the target's header_namespace attribute, and $HEADER_NAME is the header name if specified, and the filename of the header file otherwise. See header_namespace for more information.

  • preprocessor_flags (defaults to []) #

    Flags to use when preprocessing any of the above sources (which require preprocessing).

  • platform_preprocessor_flags (defaults to []) #

    Platform specific preprocessor flags. These should be specified as a list of pairs where the first element is an un-anchored regex (in java.util.regex.Pattern syntax) against which the platform name is matched, and the second element is a list of flags to use when preprocessing the target's sources. See preprocessor_flags for more information.

  • cgo_compiler_flags_arg (defaults to []) #

    The set of additional compiler flags to pass to go tool cgo.

  • compiler_flags (defaults to []) #

    Flags to use when compiling any of the above sources (which require compilation).

  • platform_compiler_flags (defaults to []) #

    Platform specific compiler flags. These should be specified as a list of pairs where the first element is an un-anchored regex (in java.util.regex.Pattern syntax) against which the platform name is matched, and the second element is a list of flags to use when compiling the target's sources. See compiler_flags for more information.

  • linker_extra_outputs (defaults to []) #

    Declares extra outputs that the linker emits. These identifiers can be used in $(output ...) macros in linker_flags to interpolate the output path into the linker command line. Useful for custom linkers that emit extra output files.

  • linker_flags (defaults to []) #

    Flags to use whenever this rule is involved in a link operation (e.g linked into an executable or shared library).

  • platform_linker_flags (defaults to []) #

    Platform specific linker flags. These should be specified as a list of pairs where the first element is an un-anchored regex (in java.util.regex.Pattern syntax) against which the platform name is matched, and the second element is a list of flags to use when this target is involved in a link operation. See linker_flags for more information.

  • raw_headers (defaults to []) #

    Status: experimental/unstable. The set of header files that can be used for inclusion to the source files in the target and all targets that transitively depend on it. Buck doesn't add raw headers to the search path of a compiler/preprocessor automatically. preprocessor_flags or exported_preprocessor_flags can be used to add such raw headers to the search path. raw_headers are considered to be experimental for now and cannot be used together with headers or exported_headers in the same target. See CxxRawHeadersIntegrationTest for examples.

  • visibility (defaults to []) #

    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 deps or exported_deps attributes. For more information, see visibility.

  • licenses (defaults to []) #

    Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query.

  • labels (defaults to []) #

    Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using buck query attrfilter.

Examples

# A rule that builds a Go native executable with linked cgo library based on
# C/C++ util library.
go_binary(
    name = "bin",
    srcs = ["main.go"],
    cgo_deps = [":lib"],
)

cgo_library(
    name = "lib",
    srcs = ["cgo_source.go"],
    headers = ["util.h"],
    deps = [":util"],
)

cxx_library(
    name = "util",
    srcs = ["util.c"],
    headers = ["util.h"],
)