Skip to content

Commit f373be6

Browse files
committed
chore: stop exposing config settings in the toolchain aliases repo
1 parent ba6fc87 commit f373be6

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Create toolchain alias targets."""
16+
17+
load("@rules_python//python:versions.bzl", "PLATFORMS")
18+
19+
def toolchain_aliases(*, name, platforms, native = native):
20+
"""Cretae toolchain aliases for the python toolchains.
21+
22+
Args:
23+
name: {type}`str` The name of the current repository.
24+
platforms: {type}`platforms` The list of platforms that are supported
25+
for the current toolchain repository.
26+
native: The native struct used in the macro, useful for testing.
27+
"""
28+
for platform in PLATFORMS.keys():
29+
if platform not in platforms:
30+
continue
31+
32+
native.config_setting(
33+
name = platform,
34+
flag_values = PLATFORMS[platform].flag_values,
35+
constraint_values = PLATFORMS[platform].compatible_with,
36+
visibility = ["//visibility:private"],
37+
)
38+
39+
native.alias(name = "files", actual = select({{":" + item: "@" + name + "_" + item + "//:files" for item in platforms}}))
40+
native.alias(name = "includes", actual = select({{":" + item: "@" + name + "_" + item + "//:includes" for item in platforms}}))
41+
native.alias(name = "libpython", actual = select({{":" + item: "@" + name + "_" + item + "//:libpython" for item in platforms}}))
42+
native.alias(name = "py3_runtime", actual = select({{":" + item: "@" + name + "_" + item + "//:py3_runtime" for item in platforms}}))
43+
native.alias(name = "python_headers", actual = select({{":" + item: "@" + name + "_" + item + "//:python_headers" for item in platforms}}))
44+
native.alias(name = "python_runtimes", actual = select({{":" + item: "@" + name + "_" + item + "//:python_runtimes" for item in platforms}}))
45+
native.alias(name = "python3", actual = select({{":" + item: "@" + name + "_" + item + "//:" + ("python.exe" if "windows" in item else "bin/python3") for item in platforms}}))

python/private/toolchains_repo.bzl

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,16 @@ def _toolchain_aliases_impl(rctx):
135135
build_contents = """\
136136
# Generated by python/private/toolchains_repo.bzl
137137
package(default_visibility = ["//visibility:public"])
138-
load("@rules_python//python:versions.bzl", "gen_python_config_settings")
139-
gen_python_config_settings()
138+
load("@rules_python//python/private:toolchain_aliases.bzl", "toolchain_aliases")
140139
exports_files(["defs.bzl"])
141140
142141
PLATFORMS = [
143142
{loaded_platforms}
144143
]
145-
alias(name = "files", actual = select({{":" + item: "@{py_repository}_" + item + "//:files" for item in PLATFORMS}}))
146-
alias(name = "includes", actual = select({{":" + item: "@{py_repository}_" + item + "//:includes" for item in PLATFORMS}}))
147-
alias(name = "libpython", actual = select({{":" + item: "@{py_repository}_" + item + "//:libpython" for item in PLATFORMS}}))
148-
alias(name = "py3_runtime", actual = select({{":" + item: "@{py_repository}_" + item + "//:py3_runtime" for item in PLATFORMS}}))
149-
alias(name = "python_headers", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_headers" for item in PLATFORMS}}))
150-
alias(name = "python_runtimes", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_runtimes" for item in PLATFORMS}}))
151-
alias(name = "python3", actual = select({{":" + item: "@{py_repository}_" + item + "//:" + ("python.exe" if "windows" in item else "bin/python3") for item in PLATFORMS}}))
144+
toolchain_aliases(
145+
name = "{py_repository}",
146+
platforms = PLATFORMS,
147+
)
152148
""".format(
153149
py_repository = rctx.attr.user_repository_name,
154150
loaded_platforms = "\n".join([" \"{}\",".format(p) for p in rctx.attr.platforms]),

0 commit comments

Comments
 (0)