Skip to main content

cxx_python_extension

name

def name(
*,
name: str,
default_target_platform: None | str = ...,
target_compatible_with: list[str] = ...,
compatible_with: list[str] = ...,
exec_compatible_with: list[str] = ...,
visibility: list[str] = ...,
within_view: list[str] = ...,
metadata: OpaqueMetadata = ...,
tests: list[str] = ...,
modifiers: OpaqueMetadata = ...,
_apple_platforms: dict[str, str] = ...,
_cxx_hacks: str = ...,
_cxx_toolchain: str = ...,
_meta_apple_library_validation_enabled: bool = ...,
_python_toolchain: str = ...,
_target_os_type: str = ...,
allow_cache_upload: None | bool = ...,
allow_embedding: bool = ...,
allow_suffixing: bool = ...,
archive_allow_cache_upload: bool = ...,
auto_link_groups: bool = ...,
base_module: None | str = ...,
bridging_header: None | str = ...,
can_be_asset: None | bool = ...,
compiler_flags: list[str] = ...,
contacts: list[str] = ...,
coverage_instrumentation_compiler_flags: list[str] = ...,
cuda_compile_style: str = ...,
cxx_runtime_type: None | str = ...,
default_host_platform: None | str = ...,
default_platform: None | str = ...,
defaults: dict[str, str] = ...,
deffile: None | str = ...,
deps: list[str] = ...,
devirt_enabled: bool = ...,
diagnostics: dict[str, str] = ...,
executable_name: None | str = ...,
export_header_unit: None | str = ...,
export_header_unit_filter: list[str] = ...,
exported_deps: list[str] = ...,
exported_header_style: str = ...,
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_needs_coverage_instrumentation: bool = ...,
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] = ...,
extra_xcode_files: list[str] = ...,
extra_xcode_sources: list[str] = ...,
fat_lto: bool = ...,
focused_list_target: None | str = ...,
force_static: None | bool = ...,
frameworks: list[str] = ...,
header_namespace: None | str = ...,
headers: list[str] | dict[str, str] = ...,
headers_as_raw_headers_mode: None | str = ...,
include_directories: list[str] = ...,
include_in_android_merge_map_output: bool = ...,
labels: list[str] = ...,
lang_compiler_flags: dict[str, list[str]] = ...,
lang_platform_compiler_flags: dict[str, list[(str, list[str])]] = ...,
lang_platform_preprocessor_flags: dict[str, list[(str, list[str])]] = ...,
lang_preprocessor_flags: dict[str, list[str]] = ...,
libraries: list[str] = ...,
licenses: list[str] = ...,
link_group: None | str = ...,
link_group_map: None | str | list[(str, list[(None | str | list[None | str], str, None | str | list[str], None | str)], None | dict[str, typing.Any])] = ...,
link_ordering: None | str = ...,
link_style: None | str = ...,
link_whole: bool = ...,
linker_extra_outputs: list[str] = ...,
linker_flags: list[str] = ...,
local_linker_flags: list[str] = ...,
module_name: None | str = ...,
platform_compiler_flags: list[(str, list[str])] = ...,
platform_deps: list[(str, list[str])] = ...,
platform_headers: list[(str, list[str] | dict[str, str])] = ...,
platform_linker_flags: list[(str, list[str])] = ...,
platform_preprocessor_flags: list[(str, list[str])] = ...,
platform_srcs: list[(str, list[str | (str, list[str])])] = ...,
post_linker_flags: list[str] = ...,
post_platform_linker_flags: list[(str, list[str])] = ...,
precompiled_header: None | str = ...,
preferred_linkage: str = ...,
prefix_header: None | str = ...,
preprocessor_flags: list[str] = ...,
public_include_directories: list[str] = ...,
public_system_include_directories: list[str] = ...,
raw_headers: list[str] = ...,
raw_headers_as_headers_mode: None | str = ...,
reexport_all_header_dependencies: None | bool = ...,
resources: list[str] | dict[str, str] = ...,
sdk_modules: list[str] = ...,
separate_debug_info: bool = ...,
soname: None | str = ...,
srcs: list[str | (str, list[str])] = ...,
static_library_basename: None | str = ...,
suffix_all: bool = ...,
support_shlib_interfaces: bool = ...,
supported_platforms_regex: None | str = ...,
supports_merged_linking: None | bool = ...,
thin_lto: bool = ...,
type_stub: None | str = ...,
use_archive: None | bool = ...,
use_header_units: bool = ...,
used_by_wrap_script: bool = ...,
uses_cxx_explicit_modules: bool = ...,
uses_explicit_modules: bool = ...,
version: None | str = ...,
version_universe: None | str = ...,
weak_framework_names: list[str] = ...,
) -> None

A cxx_python_extension() rule is a variant of a C/C++ library which is built as a Python module. As such, it has a module name formed by the base_module parameter and the rule name.

Parameters

  • name: name of the target
  • default_target_platform: specifies the default target platform, used when no platforms are specified on the command line
  • target_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration
  • compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration
  • exec_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with an execution platform
  • visibility: a list of visibility patterns restricting what targets can depend on this one
  • within_view: a list of visibility patterns restricting what this target can depend on
  • metadata: a key-value map of metadata associated with this target
  • tests: a list of targets that provide tests for this one
  • modifiers: an array of modifiers associated with this target
  • base_module: The package in which the specified source files and resources should reside in their final location in the top-level binary. If unset, Buck uses the project-relative directory that contains the BUCK file.
  • compiler_flags: Flags to use when compiling any of the above sources (which require compilation).
  • deps: Other rules that list srcs from which this rule imports.
  • header_namespace: 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.
  • headers: 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.
  • labels: 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() .
  • link_style: Determines whether to build and link this rule's dependencies statically or dynamically. Can be either static, static_pic or shared. Note: since shared libraries re-export its dependencies, depending on multiple shared libraries which themselves have overlapping static dependencies may cause problems if they init using global state.
  • linker_extra_outputs: 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: Flags to add to the linker command line whenever the output from this rule is used in a link operation, such as linked into an executable or a shared library.
  • local_linker_flags: 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).
  • platform_compiler_flags: 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.
  • platform_headers: 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 if the platform matches the regex. See headers for more information.
  • platform_linker_flags: Platform-specific linker flags. This argument is specified as a list of pairs where the first element in each pair is an un-anchored regex against which the platform name is matched. The regex should use java.util.regex.Pattern syntax. The second element in each pair is a list of linker flags. If the regex matches the platform, these flags are added to the linker command line when the output from this rule is used in a link operation.
  • platform_preprocessor_flags: 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.
  • platform_srcs: Platform specific source 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 source files or a list of tuples of source files and a list of compilation flags to be preprocessed, compiled and assembled if the platform matches the regex. See srcs for more information.
  • preprocessor_flags: Flags to use when preprocessing any of the above sources (which require preprocessing).
  • srcs: 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. '') or a tuple of a string specifying a source file and a list of compilation flags (e.g. ('', ['-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).

Details

Examples:


# A rule that builds a Python extension from a single .cpp file.
cxx_python_extension(
name = 'mymodule',
base_module = 'foo.bar',
srcs = [
'mymodule.cpp',
],
)

# A library rule which has a single source importing the above extension.
python_library(
name = 'utils',
srcs = [
'utils.py',
],
deps = [
':mymodule',
],
)


## The `utils.py` source, wrapped by the `utils` rule above.

## Import the C/C++ extension build above.
from foo.bar import mymodule

...