@@ -418,8 +418,8 @@ The two settings to change are
418418{obj}` local_runtime_toolchains_repo.target_compatible_with ` and
419419{obj}` local_runtime_toolchains_repo.target_settings ` , which control how Bazel
420420decides if a toolchain should match. By default, they point to targets * within*
421- the local runtime repository. We have to override them to * not * reference the
422- local runtime repository at all.
421+ the local runtime repository (trigger repo initialization) . We have to override
422+ them to * not * reference the local runtime repository at all.
423423
424424In the example below, we reconfigure the local toolchains so they are only
425425activated if the custom flag ` --//:py=local ` is set and the target platform
@@ -438,35 +438,27 @@ local_runtime_toolchains_repo(
438438 "local_python3": ["HOST_CONSTRAINTS"],
439439 },
440440 target_settings = {
441- "local_python3": ["@//:is_local_py_enabled "]
441+ "local_python3": ["@//:is_py_local "]
442442 }
443443)
444444
445445# File: BUILD.bazel
446446load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
447447
448- alias(
449- name = "is_local_py_enabled",
450- actual = select({
451- ":_is_py_local_set": "@local_python3//:is_matching_python_version",
452- "//conditions:default": ":_does_not_match",
453- }),
454- )
455-
456448config_setting(
457- name = "_is_py_local_set ",
449+ name = "is_py_local ",
458450 flag_values = {":py": "local"},
459451)
460452
461- config_setting (
462- name = "_does_not_match ",
463- flag_values = {":py": "<DOES NOT MATCH>"} ,
453+ string_flag (
454+ name = "py ",
455+ build_setting_default = "" ,
464456)
465-
466457```
467458
468459:::{tip}
469- With some minor changes, different values for the ` --//:py ` flag can be used
460+ Easily switching between * multiple* local toolchains can be accomplished by
461+ adding additional ` :is_py_X ` targets and setting ` --//:py ` to match.
470462to easily switch between different local toolchains.
471463:::
472464
@@ -498,7 +490,7 @@ locally installed Python.
498490### Autodetecting toolchain
499491
500492The autodetecting toolchain is a deprecated toolchain that is built into Bazel.
501- It's name is a bit misleading: it doesn't autodetect anything. All it does is
493+ ** It's name is a bit misleading: it doesn't autodetect anything** . All it does is
502494use ` python3 ` from the environment a binary runs within. This provides extremely
503495limited functionality to the rules (at build time, nothing is knowable about
504496the Python runtime).
0 commit comments