You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(toolchains): create toolchains from locally installed python (#2742)
This adds docs and public APIs for using a locally installed python for
a toolchain.
Work towards #2070
---------
Co-authored-by: Ignas Anikevicius <[email protected]>
Copy file name to clipboardExpand all lines: docs/toolchains.md
+93-4
Original file line number
Diff line number
Diff line change
@@ -199,10 +199,10 @@ Remember to call `use_repo()` to make repos visible to your module:
199
199
200
200
201
201
:::{deprecated} 1.1.0
202
-
The toolchain specific `py_binary` and `py_test` symbols are aliases to the regular rules.
202
+
The toolchain specific `py_binary` and `py_test` symbols are aliases to the regular rules.
203
203
i.e. Deprecated `load("@python_versions//3.11:defs.bzl", "py_binary")` & `load("@python_versions//3.11:defs.bzl", "py_test")`
204
204
205
-
Usages of them should be changed to load the regular rules directly;
205
+
Usages of them should be changed to load the regular rules directly;
206
206
i.e. Use `load("@rules_python//python:py_binary.bzl", "py_binary")` & `load("@rules_python//python:py_test.bzl", "py_test")` and then specify the `python_version` when using the rules corresponding to the python version you defined in your toolchain. {ref}`Library modules with version constraints`
207
207
:::
208
208
@@ -327,7 +327,97 @@ After registration, your Python targets will use the toolchain's interpreter dur
327
327
is still used to 'bootstrap' Python targets (see https://github.com/bazel-contrib/rules_python/issues/691).
328
328
You may also find some quirks while using this toolchain. Please refer to [python-build-standalone documentation's _Quirks_ section](https://gregoryszorc.com/docs/python-build-standalone/main/quirks.html).
329
329
330
-
## Autodetecting toolchain
330
+
## Local toolchain
331
+
332
+
It's possible to use a locally installed Python runtime instead of the regular
333
+
prebuilt, remotely downloaded ones. A local toolchain contains the Python
334
+
runtime metadata (Python version, headers, ABI flags, etc) that the regular
335
+
remotely downloaded runtimes contain, which makes it possible to build e.g. C
336
+
extensions (unlike the autodetecting and runtime environment toolchains).
337
+
338
+
For simple cases, some rules are provided that will introspect
339
+
a Python installation and create an appropriate Bazel definition from
340
+
it. To do this, three pieces need to be wired together:
341
+
342
+
1. Specify a path or command to a Python interpreter (multiple can be defined).
343
+
2. Create toolchains for the runtimes in (1)
344
+
3. Register the toolchains created by (2)
345
+
346
+
The below is an example that will use `python3` from PATH to find the
347
+
interpreter, then introspect its installation to generate a full toolchain.
0 commit comments