cython_library
A rule that compiles Cython (.pyx) sources into Python C extensions.
Details
This rule handles the full pipeline: Cython transpilation to C/C++, compilation to shared libraries, and assembly into a Python library.
Function Signature
def cython_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_hacks: str = "prelude//cxx/tools:cxx_hacks",
_cxx_toolchain: str = select({"prelude//:none": "gh_facebook_buck2_shims_meta//:cxx_no_default_deps", "DEFAULT": "gh_facebook_buck2_shims_meta//:cxx"}),
_cython_toolchain: str = "gh_facebook_buck2_shims_meta//:cython",
_exec_os_type: str = "prelude//os_lookup/targets:os_lookup",
_is_building_android_binary: bool = select({"prelude//os:building_android_binary": True, "DEFAULT": False}),
_meta_apple_library_validation_enabled: bool = False,
_python_toolchain: str = "gh_facebook_buck2_shims_meta//:python",
_target_os_type: str = "prelude//os_lookup/targets:os_lookup",
allow_cache_upload: None | bool = None,
allow_embedding: None | bool = None,
api: list[str] = [],
archive_allow_cache_upload: bool = False,
attrs_validators: None | list[str] = None,
auto_link_groups: bool = False,
base_module: None | str = None,
bridging_header: None | str = None,
can_be_asset: None | bool = None,
code_comments: bool = False,
compiler_flags: list[str] = [],
contacts: list[str] = [],
coverage_instrumentation_compiler_flags: list[str] = [],
cpp_compiler_flags: list[str] = [],
cpp_deps: list[str] = [],
cpp_external_deps: list[str] = [],
cpp_preprocessor_flags: list[str] = [],
cpp_python_extension_srcs: list[str] = [],
cuda_compile_style: str = "mono",
cxx_runtime_type: None | str = None,
cython_annotate: None | str = None,
cython_binding: bool = False,
cython_compiler: None | str = None,
cython_so_package: None | str = None,
default_deps: str = "exported_deps",
default_host_platform: None | str = None,
default_platform: None | str = None,
defaults: dict[str, str] = {},
deffile: None | str = None,
deps: list[str] = [],
deps_query: None | str = None,
devirt_enabled: bool = False,
diagnostics: dict[str, str] = {},
executable_name: None | str = None,
expect_eligible_for_dedupe: bool = False,
export_header_unit: None | str = None,
export_header_unit_filter: list[str] = [],
exported_deps: list[str] = [],
exported_header_style: str = "local",
exported_headers: list[str] | dict[str, str] = [],
exported_lang_preprocessor_flags: dict[str, list[str]] = {},
exported_linker_flags: list[str] = [],
exported_needs_coverage_instrumentation: bool = False,
exported_post_linker_flags: list[str] = [],
exported_preprocessor_flags: list[str] = [],
extra_dwp_flags: list[str] = [],
extra_xcode_files: list[str] = [],
extra_xcode_sources: list[str] = [],
fat_lto: bool = False,
flags: list[str] = [],
focused_list_target: None | str = None,
force_static: None | bool = None,
frameworks: list[str] = [],
generate_cpp: bool = True,
header_mode: None | str = None,
header_namespace: None | str = None,
headers: list[str] | dict[str, str] = [],
headers_as_raw_headers_mode: None | str = None,
include_directories: list[str] = [],
include_in_android_merge_map_output: bool = True,
includes: list[str] | dict[str, str] = [],
labels: list[str] = [],
lang_compiler_flags: dict[str, list[str]] = {},
lang_preprocessor_flags: dict[str, list[str]] = {},
legacy_noexcept: bool = True,
libraries: list[str] = [],
licenses: list[str] = [],
link_deps_query_whole: bool = False,
link_execution_preference: None | str = None,
link_group: None | str = None,
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])] = None,
link_ordering: None | str = None,
link_style: None | str = None,
link_whole: None | bool = None,
linker_extra_outputs: list[str] = [],
linker_flags: list[str] = [],
local_linker_flags: list[str] = [],
module_name: None | str = None,
need_static_lib: bool = False,
post_linker_flags: list[str] = [],
precompiled_header: None | str = None,
prefer_stripped_objects: bool = False,
preferred_linkage: str = "any",
prefix_header: None | str = None,
preprocessor_flags: list[str] = [],
public_declarations: list[str] = [],
public_include_directories: list[str] = [],
public_system_include_directories: list[str] = [],
python_deps: list[str] = [],
python_external_deps: list[str] = [],
raw_headers: list[str] = [],
raw_headers_as_headers_mode: None | str = None,
reexport_all_header_dependencies: None | bool = None,
resources: list[str] | dict[str, str] = [],
sdk_modules: list[str] = [],
separate_debug_info: bool = False,
soname: None | str = None,
srcs: list[str] | dict[str, str] = [],
static_library_basename: None | str = None,
stub: bool = False,
suffix_all: None | bool = None,
supported_platforms_regex: None | str = None,
supports_header_symlink_subtarget: bool = False,
supports_merged_linking: None | bool = None,
supports_python_dlopen: None | bool = None,
supports_shlib_interfaces: bool = True,
supports_stripping: bool = True,
thin_lto: bool = False,
third_party_project: None | str = None,
types: list[str] = [],
typing: bool = False,
use_archive: None | bool = None,
use_content_based_paths: bool = True,
use_fbcc_rust_wrapper: bool = False,
use_header_units: bool | str = False,
used_by_wrap_script: bool = False,
uses_cxx_explicit_modules: bool = False,
uses_explicit_modules: bool = False,
version: None | str = None,
version_universe: None | str = None,
weak_framework_names: list[str] = [],
) -> 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_embedding: (defaults to:None)Whether to allow embedding this extension into the main binary.
-
api: (defaults to:[])List of module names that should generate public API headers (_api.h files) for C++ interop.
-
base_module: (defaults to:None)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.
-
code_comments: (defaults to:False)Whether to include source code comments in the generated output.
-
cpp_compiler_flags: (defaults to:[])Additional flags to pass to the C++ compiler.
-
cpp_deps: (defaults to:[])C++ library dependencies for linking.
-
cpp_external_deps: (defaults to:[])External C++ dependencies specified by name.
-
cpp_preprocessor_flags: (defaults to:[])Additional C++ preprocessor flags.
-
cpp_python_extension_srcs: (defaults to:[])Additional C++ source files to compile into the Python extensions.
-
cython_annotate: (defaults to:None)Level of Cython annotation to generate.
-
cython_binding: (defaults to:False)Whether this is a Cython binding module.
-
cython_compiler: (defaults to:None)Override the default Cython compiler.
-
cython_so_package: (defaults to:None)Override the package path for the generated .so file.
-
deps: (defaults to:[])Dependencies of this rule, including other cython_library and python_library targets.
-
extra_xcode_sources: (defaults to:[])When the project is generated, this is the list of files that will added to the build phase "Compile Sources" of the given target.
-
flags: (defaults to:[])Additional flags to pass to the Cython compiler.
-
generate_cpp: (defaults to:True)Whether to generate C++ (.cpp) or C (.c) output from Cython.
-
header_namespace: (defaults to:None)A namespace for the exported headers. If set, headers will be available under this namespace for dependent rules.
-
headers: (defaults to:[])Cython header files (.pxd) to expose to dependent Cython rules.
-
includes: (defaults to:[])Additional Cython include files (.pxd, .pxi) for this library.
-
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(). -
legacy_noexcept: (defaults to:True)Whether to use legacy implicit noexcept behavior.
-
link_execution_preference: (defaults to:None)The execution preference for linking. Options are:
- any : No preference is set, and the link action will be performed based on buck2's executor configuration.
- full_hybrid : The link action will execute both locally and remotely, regardless of buck2's executor configuration (if the executor is capable of hybrid execution). The use_limited_hybrid setting of the hybrid executor is ignored.
- local : The link action will execute locally if compatible on current host platform.
- local_only : The link action will execute locally, and error if the current platform is not compatible.
- remote : The link action will execute remotely if a compatible remote platform exists, otherwise locally.
The default is None, expressing that no preference has been set on the target itself.
-
need_static_lib: (defaults to:False)Whether to also produce a static C++ library.
-
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_styleinstead. -
public_declarations: (defaults to:[])List of public declaration module names.
-
python_deps: (defaults to:[])Python-only dependencies.
-
python_external_deps: (defaults to:[])External Python dependencies specified by name.
-
srcs: (defaults to:[])The Cython source files (.pyx) and header files (.pxd, .pxi) to include in this library.
-
suffix_all: (defaults to:None)Whether to suffix all symbols for static linking.
-
types: (defaults to:[])Type stub files (.pyi) for the generated modules.
-
typing: (defaults to:False)Whether to enable type checking support.