xref: /aosp_15_r20/external/bazelbuild-rules_python/python/private/pypi/flags.bzl (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
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"""Values and helpers for pip_repository related flags.
16
17NOTE: The transitive loads of this should be kept minimal. This avoids loading
18unnecessary files when all that are needed are flag definitions.
19"""
20
21load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
22load("//python/private:enum.bzl", "enum")
23
24# Determines if we should use whls for third party
25#
26# buildifier: disable=name-conventions
27UseWhlFlag = enum(
28    # Automatically decide the effective value based on environment, target
29    # platform and the presence of distributions for a particular package.
30    AUTO = "auto",
31    # Do not use `sdist` and fail if there are no available whls suitable for the target platform.
32    ONLY = "only",
33    # Do not use whl distributions and instead build the whls from `sdist`.
34    NO = "no",
35)
36
37# Determines whether universal wheels should be preferred over arch platform specific ones.
38#
39# buildifier: disable=name-conventions
40UniversalWhlFlag = enum(
41    # Prefer platform-specific wheels over universal wheels.
42    ARCH = "arch",
43    # Prefer universal wheels over platform-specific wheels.
44    UNIVERSAL = "universal",
45)
46
47# Determines which libc flavor is preferred when selecting the linux whl distributions.
48#
49# buildifier: disable=name-conventions
50WhlLibcFlag = enum(
51    # Prefer glibc wheels (e.g. manylinux_2_17_x86_64 or linux_x86_64)
52    GLIBC = "glibc",
53    # Prefer musl wheels (e.g. musllinux_2_17_x86_64)
54    MUSL = "musl",
55)
56
57INTERNAL_FLAGS = [
58    "dist",
59    "whl_plat",
60    "whl_plat_py3",
61    "whl_plat_py3_abi3",
62    "whl_plat_pycp3x",
63    "whl_plat_pycp3x_abi3",
64    "whl_plat_pycp3x_abicp",
65    "whl_py2_py3",
66    "whl_py3",
67    "whl_py3_abi3",
68    "whl_pycp3x",
69    "whl_pycp3x_abi3",
70    "whl_pycp3x_abicp",
71]
72
73def define_pypi_internal_flags(name):
74    for flag in INTERNAL_FLAGS:
75        string_flag(
76            name = "_internal_pip_" + flag,
77            build_setting_default = "",
78            values = [""],
79            visibility = ["//visibility:public"],
80        )
81