//python/private:py_cc_toolchain_rule.bzl

Implementation of py_cc_toolchain rule.

NOTE: This is a beta-quality feature. APIs subject to change until #824 issue is considered done.

rule py_cc_toolchain(name, headers, python_version, abi_flags='<AUTO>', headers_abi3='@rules_python//python:none', libc='', libs=None, platform_machine='', soabi='', sys_platform='')

A toolchain for a Python runtime’s C/C++ information (e.g. headers)

This rule carries information about the C/C++ side of a Python runtime, e.g. headers, shared libraries, etc.

This provides ToolchainInfo with the following attributes:

  • py_cc_toolchain: PyCcToolchainInfo

  • toolchain_label: Label only present when --visibile_for_testing=True for internal testing. The rule’s label; this allows identifying what toolchain implmentation was selected for testing purposes.

Attributes:
  • name(Name)

    A unique name for this target.

    mandatory

  • headers(label)

    Target that provides the Python headers. Typically this is a cc_library target.

    mandatory

    Required providers: CcInfo

  • python_version(str)

    The Major.minor Python version, e.g. 3.11

    mandatory

  • abi_flags(str) (default “<AUTO>”)

    The runtime’s ABI flags, i.e. sys.abiflags.

    If not set, or set to <AUTO>, the ABI flags are automatically derived from --//python/config_settings:py_freethreaded (e.g., 't' when free-threaded is enabled, or '' otherwise).

    Added in version 2.3.0.

    optional

  • headers_abi3(label) (default “@rules_python//python:none”)

    Target that provides the Python ABI3 (stable abi) headers.

    Typically this is a cc_library target.

    Added in version 1.7.0: The features.headers_abi3 attribute can be used to detect if this attribute is available or not.

    optional

    Required providers: SentinelInfo | CcInfo

  • libc(str) (default “”)

    Target C library variant, e.g. ‘glibc’, ‘musl’.

    Added in version 2.3.0.

    optional

  • libs(label) (default None)

    Target that provides the Python runtime libraries for linking. Typically this is a cc_library target of .so files.

    optional

    Required providers: CcInfo

  • platform_machine(str) (default “”)

    Target architecture as a PEP 508 platform_machine marker, e.g. ‘x86_64’, ‘aarch64’, ‘x86_32’.

    Added in version 2.3.0.

    optional

  • soabi(str) (default “”)

    The SOABI tag for extension modules (see PEP 3149), e.g. ‘cpython-311-x86_64-linux-gnu’ or ‘cp311’.

    Added in version 2.3.0.

    optional

  • sys_platform(str) (default “”)

    Target OS as a PEP 508 sys_platform marker, e.g. ‘linux’, ‘darwin’, ‘win32’.

    Added in version 2.2.0.

    optional