-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[build] Use py_cc_toolchain for configuring pybind11
The py_cc_toolchain is a rules_python concept that bridges the Python and C++ toolchains by providing cc_library targets for the headers and libraries that allow compiling C code against the Python interpreter selected by the Python toolchain. This commit changes our MODULE and WORKSPACE to add that new kind of toolchain and our pydrake bindings to use it. Therefore, it's no longer necessary for our prior approach (the '@python' repository) to be public, so that repository is now deprecated for removal. To simplify this transition, we also revise how pydrake module shared libraries are named in our binary packages. The importlib.machinery package defines many possible values for EXTENSION_SUFFIXES (i.e., the filename extension used for native code), e.g., for example on Ubuntu 22.04 the possible values are ['.cpython-310-x86_64-linux-gnu.so', '.abi3.so', '.so']. Previously we used the first choice (with the python version baked in) but this is awkward, so now we use the last option (plain '.so'). The distinction only matters in case we package multiple python versions into the same release artifact at once, which we never do. It will also be moot once we switch to using ABI 3 in the future (in which case we'll use the middle choice). Ditto for lcm-python's shared library. Details: We now call our python_repository rule twice: once to create "python" (which is deprecated and no longer unused by Drake) and once to create "python_internal". The internal flavor provides fewer constants since many are no longer needed with the py_cc_toolchain. We provide new labels in //tools/workspace/python as a single point of control for depending on Python. The comments in python/repository.bzl provide an overview of how the pieces all fit together. The PYTHON_SITE_PACKAGES is no longer used as an opaque constant; its correct value is trivially derivable from the Python version number so we'll just use the longhand anywhere we need such a path.
- Loading branch information
1 parent
e37610a
commit 7d91e3e
Showing
18 changed files
with
287 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,32 @@ | ||
# This file exists to make our directory into a Bazel package, so that our | ||
# neighboring *.bzl file can be loaded elsewhere. | ||
|
||
load("//tools/lint:lint.bzl", "add_lint_tests") | ||
load(":internal.bzl", "current_py_cc_libpython", "python_version_txt") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
# Provides a text file containing the major.minor version number of the current | ||
# Python toolchain, without any newlines. | ||
python_version_txt( | ||
name = "python_version.txt", | ||
) | ||
|
||
# Provides a single point of control within Drake for how to compile a native | ||
# C/C++ Python module (e.g., for pybind11). | ||
alias( | ||
name = "cc_headers", | ||
actual = "@rules_python//python/cc:current_py_cc_headers", | ||
) | ||
|
||
# Provides a single point of control within Drake for how to link a native | ||
# C/C++ Python module (e.g., for pybind11). | ||
alias( | ||
name = "cc_libs", | ||
actual = "@rules_python//python/cc:current_py_cc_libs", | ||
) | ||
|
||
# Provides a single point of control within Drake for how to link a C/C++ | ||
# exectuable that embeds a Python interpreter (e.g., for unit testing). | ||
current_py_cc_libpython( | ||
name = "cc_libpython", | ||
) | ||
|
||
add_lint_tests() |
Oops, something went wrong.