@@ -243,6 +243,73 @@ existing attributes:
243243* Adding additional Python versions via {bzl: obj }` python.single_version_override ` or
244244 {bzl: obj }` python.single_version_platform_override ` .
245245
246+ ### Registering custom runtimes
247+
248+ Because the python-build-standalone project has _ thousands_ of prebuilt runtimes
249+ available, rules_python only includes popular runtimes in its built in
250+ configurations. If you want to use a runtime that isn't already known to
251+ rules_python then {obj}` single_version_platform_override() ` can be used to do
252+ so. In short, it allows specifying an arbitrary URL and using custom flags
253+ to control when a runtime is used.
254+
255+ In the example below, we register a particular python-build-standalone runtime
256+ that is activated for Linux x86 builds when the custom flag
257+ ` --//:runtime=my-custom-runtime ` is set.
258+
259+ ```
260+ # File: MODULE.bazel
261+ bazel_dep(name = "bazel_skylib", version = "1.7.1.")
262+ bazel_dep(name = "rules_python", version = "1.5.0")
263+ python = use_extension("@rules_python//python/extensions:python.bzl", "python")
264+ python.single_version_platform_override(
265+ platform = "my-platform",
266+ python_version = "3.13.3",
267+ sha256 = "01d08b9bc8a96698b9d64c2fc26da4ecc4fa9e708ce0a34fb88f11ab7e552cbd",
268+ os_name = "linux",
269+ arch = "x86_64",
270+ target_settings = [
271+ "@@//:runtime=my-custom-runtime",
272+ ],
273+ urls = ["https://github.com/astral-sh/python-build-standalone/releases/download/20250409/cpython-3.13.3+20250409-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz"],
274+ )
275+ # File: //:BUILD.bazel
276+ load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
277+ string_flag(
278+ name = "custom_runtime",
279+ build_setting_default = "",
280+ )
281+ config_setting(
282+ name = "is_custom_runtime_linux-x86-install-only-stripped",
283+ flag_values = {
284+ ":custom_runtime": "linux-x86-install-only-stripped",
285+ },
286+ )
287+ ```
288+
289+ Notes:
290+ - While any URL and archive can be used, it's assumed their content looks how
291+ a python-build-standalone archive looks.
292+ - A "version aware" toolchain is registered, which means the Python version flag
293+ must also match (e.g. ` --@rules_python//python/config_settings:python_version=3.13.3 `
294+ must be set -- see ` minor_mapping ` and ` is_default ` for controls and docs
295+ about version matching and selection).
296+ - The ` target_compatible_with ` attribute can be used to entirely specify the
297+ arg of the same name the toolchain uses.
298+ - The labels in ` target_settings ` must be absolute; ` @@ ` refers to the main repo.
299+ - The ` target_settings ` are ` config_setting ` targets, which means you can
300+ customize how matching occurs.
301+
302+ :::{seealso}
303+ See {obj}` //python/config_settings ` for flags rules_python already defines
304+ that can be used with ` target_settings ` . Some particular ones of note are:
305+ {flag}` --py_linux_libc ` and {flag}` --py_freethreaded ` , among others.
306+ :::
307+
308+ :::{versionadded} VERSION_NEXT_FEATURE
309+ Added support for custom platform names, ` target_compatible_with ` , and
310+ ` target_settings ` with ` single_version_platform_override ` .
311+ :::
312+
246313### Using defined toolchains from WORKSPACE
247314
248315It is possible to use toolchains defined in ` MODULE.bazel ` in ` WORKSPACE ` . For example
0 commit comments