prebuilt_cxx_library()
This is liable to change in the future.
Aprebuilt_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 short name for this build target.
header_only
(defaults toFalse
) #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.header_dirs
(defaults to[]
) #A directory that headers can be included from. These directories are added to the include path using
-isystem
.platform_header_dirs
(defaults to[]
) #Platform specific header directories. 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 directories. See
header_dirs
for more information.static_lib
(defaults to[]
) #The path to the library to use when performing static linking.
platform_static_lib
(defaults to[]
) #Platform specific static library. 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 the path to the library. See
static_lib
for more information.static_pic_lib
(defaults to[]
) #The path to the library to use when performing static PIC linking.
platform_static_pic_lib
(defaults to[]
) #Platform specific static PIC library. 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 the path to the library. See
static_pic_lib
for more information.supported_platforms_regex
(defaults toNone
) #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'sheader_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 (/
). Seeheader_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 toname
) #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. Seeheaders
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, unlikepreprocessor_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[]
) #Flags to add to the linker command line when the output from this rule, or the output from any rule that transitively depends on this rule, is used in a link operation.
force_static
(defaults toFalse
) #DEPRECATED:
See preferred_linkage
. Iftrue
, the library will always be linked statically, even if the target that depends on it specifieslink_style
to be something other thanstatic
. 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 withforce_static=True
). Also note this will cause duplicate symbols if multiple targets that depend on the library are linked together.preferred_linkage
(defaults toany
) #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.
exported_deps
(defaults to[]
) #Dependencies that will also appear to belong to any rules that depend on this one. This has two effects:
- Exported dependencies will also be included in the link line of dependents of this rules, but normal dependencies will not.
- When
reexport_all_header_dependencies = False
, only exported headers of the rules specified here are re-exported.
exported_platform_deps
(defaults to[]
) #Platform specific dependencies that will also appear to belong to any rules that depend on this one. 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 external dependencies (same format as
exported_deps
) that are exported if the platform matches the regex. Seeexported_deps
for more information.supports_merged_linking
(defaults toTrue
) #Whether this rule supports building with the merged linking strategy when building for non-native binaries (e.g. when using
[python].native_link_strategy
smerged
setting).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
orexported_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 prebuilt library containing only headers that other libraries may need.
prebuilt_cxx_library( name = 'stdutil', header_only = True, header_dirs = [ 'include', ], )
A prebuilt library with static and shared libs.
prebuilt_cxx_library( name = 'mylib', soname = 'libmylib.so', static_lib = 'libmylib.a', static_pic_lib = 'libmylib_pic.a', shared_lib = 'libmylib.so', exported_headers = [ 'mylib.h', ], )
A prebuilt library with multiple builds for multiple platforms.
prebuilt_cxx_library( name = 'mylib', soname = 'libmylib.so', platform_shared_lib = [ ('android-arm', 'android-arm/libmylib.so'), ('android-x86', 'android-x86/libmylib.so'), ('iphonesimulator-x86_64', 'iphonesimulator-x86_64/libmylib.so'), ], platform_static_lib = [ ('android-arm', 'android-arm/libmylib.a'), ('android-x86', 'android-x86/libmylib.a'), ('iphonesimulator-x86_64', 'iphonesimulator-x86_64/libmylib.a'), ], exported_headers = [ 'mylib.h', ], )