xref: /aosp_15_r20/external/bazelbuild-rules_python/python/private/pypi/flags.bzl (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1*60517a1eSAndroid Build Coastguard Worker# Copyright 2024 The Bazel Authors. All rights reserved.
2*60517a1eSAndroid Build Coastguard Worker#
3*60517a1eSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
4*60517a1eSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
5*60517a1eSAndroid Build Coastguard Worker# You may obtain a copy of the License at
6*60517a1eSAndroid Build Coastguard Worker#
7*60517a1eSAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
8*60517a1eSAndroid Build Coastguard Worker#
9*60517a1eSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*60517a1eSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
11*60517a1eSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*60517a1eSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
13*60517a1eSAndroid Build Coastguard Worker# limitations under the License.
14*60517a1eSAndroid Build Coastguard Worker
15*60517a1eSAndroid Build Coastguard Worker"""Values and helpers for pip_repository related flags.
16*60517a1eSAndroid Build Coastguard Worker
17*60517a1eSAndroid Build Coastguard WorkerNOTE: The transitive loads of this should be kept minimal. This avoids loading
18*60517a1eSAndroid Build Coastguard Workerunnecessary files when all that are needed are flag definitions.
19*60517a1eSAndroid Build Coastguard Worker"""
20*60517a1eSAndroid Build Coastguard Worker
21*60517a1eSAndroid Build Coastguard Workerload("@bazel_skylib//rules:common_settings.bzl", "string_flag")
22*60517a1eSAndroid Build Coastguard Workerload("//python/private:enum.bzl", "enum")
23*60517a1eSAndroid Build Coastguard Worker
24*60517a1eSAndroid Build Coastguard Worker# Determines if we should use whls for third party
25*60517a1eSAndroid Build Coastguard Worker#
26*60517a1eSAndroid Build Coastguard Worker# buildifier: disable=name-conventions
27*60517a1eSAndroid Build Coastguard WorkerUseWhlFlag = enum(
28*60517a1eSAndroid Build Coastguard Worker    # Automatically decide the effective value based on environment, target
29*60517a1eSAndroid Build Coastguard Worker    # platform and the presence of distributions for a particular package.
30*60517a1eSAndroid Build Coastguard Worker    AUTO = "auto",
31*60517a1eSAndroid Build Coastguard Worker    # Do not use `sdist` and fail if there are no available whls suitable for the target platform.
32*60517a1eSAndroid Build Coastguard Worker    ONLY = "only",
33*60517a1eSAndroid Build Coastguard Worker    # Do not use whl distributions and instead build the whls from `sdist`.
34*60517a1eSAndroid Build Coastguard Worker    NO = "no",
35*60517a1eSAndroid Build Coastguard Worker)
36*60517a1eSAndroid Build Coastguard Worker
37*60517a1eSAndroid Build Coastguard Worker# Determines whether universal wheels should be preferred over arch platform specific ones.
38*60517a1eSAndroid Build Coastguard Worker#
39*60517a1eSAndroid Build Coastguard Worker# buildifier: disable=name-conventions
40*60517a1eSAndroid Build Coastguard WorkerUniversalWhlFlag = enum(
41*60517a1eSAndroid Build Coastguard Worker    # Prefer platform-specific wheels over universal wheels.
42*60517a1eSAndroid Build Coastguard Worker    ARCH = "arch",
43*60517a1eSAndroid Build Coastguard Worker    # Prefer universal wheels over platform-specific wheels.
44*60517a1eSAndroid Build Coastguard Worker    UNIVERSAL = "universal",
45*60517a1eSAndroid Build Coastguard Worker)
46*60517a1eSAndroid Build Coastguard Worker
47*60517a1eSAndroid Build Coastguard Worker# Determines which libc flavor is preferred when selecting the linux whl distributions.
48*60517a1eSAndroid Build Coastguard Worker#
49*60517a1eSAndroid Build Coastguard Worker# buildifier: disable=name-conventions
50*60517a1eSAndroid Build Coastguard WorkerWhlLibcFlag = enum(
51*60517a1eSAndroid Build Coastguard Worker    # Prefer glibc wheels (e.g. manylinux_2_17_x86_64 or linux_x86_64)
52*60517a1eSAndroid Build Coastguard Worker    GLIBC = "glibc",
53*60517a1eSAndroid Build Coastguard Worker    # Prefer musl wheels (e.g. musllinux_2_17_x86_64)
54*60517a1eSAndroid Build Coastguard Worker    MUSL = "musl",
55*60517a1eSAndroid Build Coastguard Worker)
56*60517a1eSAndroid Build Coastguard Worker
57*60517a1eSAndroid Build Coastguard WorkerINTERNAL_FLAGS = [
58*60517a1eSAndroid Build Coastguard Worker    "dist",
59*60517a1eSAndroid Build Coastguard Worker    "whl_plat",
60*60517a1eSAndroid Build Coastguard Worker    "whl_plat_py3",
61*60517a1eSAndroid Build Coastguard Worker    "whl_plat_py3_abi3",
62*60517a1eSAndroid Build Coastguard Worker    "whl_plat_pycp3x",
63*60517a1eSAndroid Build Coastguard Worker    "whl_plat_pycp3x_abi3",
64*60517a1eSAndroid Build Coastguard Worker    "whl_plat_pycp3x_abicp",
65*60517a1eSAndroid Build Coastguard Worker    "whl_py2_py3",
66*60517a1eSAndroid Build Coastguard Worker    "whl_py3",
67*60517a1eSAndroid Build Coastguard Worker    "whl_py3_abi3",
68*60517a1eSAndroid Build Coastguard Worker    "whl_pycp3x",
69*60517a1eSAndroid Build Coastguard Worker    "whl_pycp3x_abi3",
70*60517a1eSAndroid Build Coastguard Worker    "whl_pycp3x_abicp",
71*60517a1eSAndroid Build Coastguard Worker]
72*60517a1eSAndroid Build Coastguard Worker
73*60517a1eSAndroid Build Coastguard Workerdef define_pypi_internal_flags(name):
74*60517a1eSAndroid Build Coastguard Worker    for flag in INTERNAL_FLAGS:
75*60517a1eSAndroid Build Coastguard Worker        string_flag(
76*60517a1eSAndroid Build Coastguard Worker            name = "_internal_pip_" + flag,
77*60517a1eSAndroid Build Coastguard Worker            build_setting_default = "",
78*60517a1eSAndroid Build Coastguard Worker            values = [""],
79*60517a1eSAndroid Build Coastguard Worker            visibility = ["//visibility:public"],
80*60517a1eSAndroid Build Coastguard Worker        )
81