|
| 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}})) |
0 commit comments