Buck: prebuilt_cxx_library()

prebuilt_cxx_library()

This is liable to change in the future.

A prebuilt_cxx_library() rule represents a set of native libraries and C/C++ header files and provides various flags to control how they are linked and exported.

Arguments

  • name (required) #

    The name of the rule.

  • header_only (defaults to False) #

    Indicates if this library only consists of headers or not. If this is set to True, Buck will not link this library into any library that depends on it.

  • lib_name (defaults to {name}) #

    The name of the library. If your library file was named libmylib.a, this should be mylib. This defaults to the name of the rule.

  • lib_dir (defaults to lib) #

    The directory the library lib_name can be found. This can use the$(platform) macro to specify platform-dependent versions of the library.

  • supported_platforms_regex (defaults to None) #

    If present, an un-anchored regex (in java.util.regex.Pattern syntax) that matches all platforms that this library supports. It will not be built for other platforms.

  • exported_headers (defaults to []) #

    The set of header files that are made available for inclusion to the source files in the target and all targets that transitively depend on it. These should be specified as either a list of header files or a dictionary of header names to header files. 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. Note that the header name can contain forward slashes (/). See header_namespace for more information.

  • exported_platform_headers (defaults to []) #

    Platform specific header files. 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 either a list of header files or a dictionary of header names to header files that will be made available for inclusion to the source files in the target and all targets that transitively depend on it if the platform matches the regex. See headers for more information.

  • header_namespace (defaults to name) #

    A path prefix when including headers of this target. Defaults to the path from the root of the repository to the directory where this target is defined. Can contain forward slashes (/), but cannot start with one. See headers for more information.

  • exported_preprocessor_flags (defaults to []) #

    Just as preprocessor_flags, flags to use when preprocessing any of the above sources (which require preprocessing). However, unlike preprocessor_flags, these preprocessor flags are also used by rules that transitively depend on this rule when preprocessing their own sources.

  • exported_platform_preprocessor_flags (defaults to []) #

    Platform specific exported 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 source files in the target and all targets that transitively depend on it if the platform matches the regex. See exported_preprocessor_flags for more information.

  • exported_linker_flags (defaults to []) #

    Linker flags to add to this library and to libraries that depend on this library.

  • force_static (defaults to False) #

    DEPRECATED: See preferred_linkage. If true, the library will always be linked statically, even if the target that depends on it specifies link_style to be something other than static. Note that this may still cause the library to be linked into its own shared library, if it happens to be the root of the linkable dependency tree (e.g. if a Python library directly depends on the library with force_static=True). Also note this will cause duplicate symbols if multiple targets that depend on the library are linked together.

  • preferred_linkage (defaults to any) #

    Controls how a library should be linked.

    any
    The library will be linked based on its dependents link_style.
    shared
    The library will be always be linked as a shared library.
    static
    The library will be linked as a static library.
    Note: since shared libraries re-export its dependencies, depending on multiple shared libraries which themselves have overlapping static dependencies will cause duplicate symbols.

  • exported_deps (defaults to []) #

    Dependencies that will also appear to belong to any rules that depend on this one. Currently, this only affects linking: exported dependencies will also be included in the link line of dependents of this rules, but normal dependencies will not.

  • include_dirs (defaults to None) #

    A directory that headers can be included from. This can use the $(platform)macro to specify platform-dependent versions of the directory.

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule in its deps.

  • 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 prebuilt library containing only headers that other libraries may need.

prebuilt_cxx_library(
  name = 'stdutil',
  exported_headers = glob(['*.h']),
)

A prebuilt library for multiple platforms. The directory tree for an Android and iOS build is laid out below it.

prebuilt_cxx_library(
  name = 'mylib',
  lib_dir = 'lib/$(platform)',
  exported_headers = [
    'mylib.h',
  ],
)
lib/
  android-arm/
    libmylib.a
  android-armv7/
    libmylib.a
  android-x86/
    libmylib.a
  iphonesimulator-x86_64/
    libmylib.a
  iphoneos-i386/
    libmylib.a
  iphoneos-arm64/
    libmylib.a