Skip to main content

prebuilt_cxx_library

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.

Function Signature

def prebuilt_cxx_library(
*,
name: str,
default_target_platform: None | str = None,
target_compatible_with: list[str] = [],
compatible_with: list[str] = [],
exec_compatible_with: list[str] = [],
visibility: list[str] = [],
within_view: list[str] = ["PUBLIC"],
metadata: OpaqueMetadata = {},
tests: list[str] = [],
modifiers: OpaqueMetadata = [],
_apple_platforms: dict[str, str] = {},
_create_third_party_build_root: str = "prelude//third-party/tools:create_build",
_cxx_toolchain: str = "gh_facebook_buck2_shims_meta//:cxx",
_target_os_type: str = "prelude//os_lookup/targets:os_lookup",
allow_cache_upload: None | bool = None,
can_be_asset: bool = False,
contacts: list[str] = [],
default_host_platform: None | str = None,
deffile: None | str = None,
deps: list[str] = [],
exported_deps: list[str] = [],
exported_header_style: str = "system",
exported_headers: list[str] | dict[str, str] = [],
exported_lang_platform_preprocessor_flags: dict[str, list[(str, list[str])]] = {},
exported_lang_preprocessor_flags: dict[str, list[str]] = {},
exported_linker_flags: list[str] = [],
exported_platform_deps: list[(str, list[str])] = [],
exported_platform_headers: list[(str, list[str] | dict[str, str])] = [],
exported_platform_linker_flags: list[(str, list[str])] = [],
exported_platform_preprocessor_flags: list[(str, list[str])] = [],
exported_post_linker_flags: list[str] = [],
exported_post_platform_linker_flags: list[(str, list[str])] = [],
exported_preprocessor_flags: list[str] = [],
extract_soname: bool = False,
force_static: bool = False,
frameworks: list[str] = [],
header_dirs: None | list[str] = None,
header_namespace: None | str = None,
header_only: bool = False,
import_lib: None | str = None,
include_in_android_merge_map_output: bool = True,
labels: list[str] = [],
libraries: list[str] = [],
licenses: list[str] = [],
link_whole: bool = False,
link_without_soname: bool = False,
linker_flags: list[str] = [],
local_linker_flags: list[str] = [],
local_linker_script_flags: list[str] = [],
platform_header_dirs: None | list[(str, list[str])] = None,
platform_import_lib: None | list[(str, str)] = None,
platform_shared_lib: None | list[(str, str)] = None,
platform_static_lib: None | list[(str, str)] = None,
platform_static_pic_lib: None | list[(str, str)] = None,
post_linker_flags: list[str] = [],
preferred_linkage: str = "any",
prestripped: bool = False,
provided: bool = False,
public_include_directories: list[str] = [],
public_system_include_directories: list[str] = [],
raw_headers: list[str] = [],
shared_lib: None | str = None,
soname: None | str = None,
static_lib: None | str = None,
static_pic_lib: None | str = None,
stub: bool = False,
supported_platforms_regex: None | str = None,
supports_lto: bool = False,
supports_merged_linking: None | bool = None,
supports_python_dlopen: bool = True,
supports_shared_library_interface: bool = True,
third_party_build: None | str = None,
version: None | str = None,
versioned_exported_lang_platform_preprocessor_flags: list[(dict[str, str], dict[str, list[(str, list[str])]])] = [],
versioned_exported_lang_preprocessor_flags: list[(dict[str, str], dict[str, list[str]])] = [],
versioned_exported_platform_preprocessor_flags: list[(dict[str, str], list[(str, list[str])])] = [],
versioned_exported_preprocessor_flags: list[(dict[str, str], list[str])] = [],
versioned_header_dirs: None | list[(dict[str, str], list[str])] = None,
versioned_import_lib: None | list[(dict[str, str], str)] = None,
versioned_shared_lib: None | list[(dict[str, str], str)] = None,
versioned_soname: None | list[(dict[str, str], str)] = None,
versioned_static_lib: None | list[(dict[str, str], str)] = None,
versioned_static_pic_lib: None | list[(dict[str, str], str)] = None,
) -> None

Parameters

  • name: (required)

    name of the target

  • default_target_platform: (defaults to: None)

    specifies the default target platform, used when no platforms are specified on the command line

  • target_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • exec_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with an execution platform

  • visibility: (defaults to: [])

    a list of visibility patterns restricting what targets can depend on this one

  • within_view: (defaults to: ["PUBLIC"])

    a list of visibility patterns restricting what this target can depend on

  • metadata: (defaults to: {})

    a key-value map of metadata associated with this target

  • tests: (defaults to: [])

    a list of targets that provide tests for this one

  • modifiers: (defaults to: [])

    an array of modifiers associated with this target

  • allow_cache_upload: (defaults to: None)

    Whether to allow uploading the output of this rule to be uploaded to cache when the action is executed locally if the configuration allows (i.e. there is a cache configured and the client has permission to write to it).

  • deffile: (defaults to: None)

    Specifies the *.def file used on windows to modify a dll's exports in place of explicit __declspec(dllexport) declarations. The default is to not use a defile.

  • 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_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_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.

  • 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. See exported_deps 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.

  • 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.

  • header_namespace: (defaults to: None)

    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.

  • 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.

  • local_linker_flags: (defaults to: [])

    Flags to add to the linker command line whenever the output from this rule is used in a link operation driven by this rule (e.g. when this rule links a shared library, but not when the output is linked into a shared library by another rule's link group links).

  • local_linker_script_flags: (defaults to: [])

    Linker script lags to add to the linker command line whenever the output from this rule is used in a link operation driven by this rule. Used by rules that need to treat linker script flags different from normal linker flags.

  • platform_shared_lib: (defaults to: None)

    Platform specific shared 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 shared_lib for more information.

  • platform_static_lib: (defaults to: None)

    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.

  • platform_static_pic_lib: (defaults to: None)

    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.

  • preferred_linkage: (defaults to: "any")

    Determines what linkage is used when the library is depended on by another target. To control how the dependencies of this library are linked, use link_style instead.

  • prestripped: (defaults to: False)

    When set, skips running strip commands when building this library.

  • shared_lib: (defaults to: None)

    The path to the library to use when performing shared linking.

  • static_lib: (defaults to: None)

    The path to the library to use when performing static linking.

  • static_pic_lib: (defaults to: None)

    The path to the library to use when performing static PIC linking.

  • 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.

  • supports_merged_linking: (defaults to: None)

    Whether this rule supports building with the merged linking strategy when building for non-native binaries (e.g. when using .buckconfig s merged setting).

  • version: (defaults to: None)

    A string denoting a meaningful version of this rule that is optionally passed to the linker as extra metadata.

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',
],
)