xref: /aosp_15_r20/external/bazelbuild-rules_rust/crate_universe/private/selects.bzl (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1*d4726bddSHONG Yifan"""Function for preserving `select` entries for Cargo cfg expressions which did
2*d4726bddSHONG Yifannot match any enabled target triple / Bazel platform.
3*d4726bddSHONG Yifan
4*d4726bddSHONG YifanFor example we might generate:
5*d4726bddSHONG Yifan
6*d4726bddSHONG Yifan    rust_library(
7*d4726bddSHONG Yifan        ...
8*d4726bddSHONG Yifan        deps = [
9*d4726bddSHONG Yifan            "//common:unconditional_dep",
10*d4726bddSHONG Yifan        ] + selects.with_unmapped({
11*d4726bddSHONG Yifan            "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [
12*d4726bddSHONG Yifan                "//third-party/rust:windows-sys",  # cfg(windows)
13*d4726bddSHONG Yifan            ],
14*d4726bddSHONG Yifan            "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [
15*d4726bddSHONG Yifan                "//third-party/rust:libc",  # cfg(any(unix, target_os = "wasi"))
16*d4726bddSHONG Yifan            ],
17*d4726bddSHONG Yifan            "//conditions:default": [],
18*d4726bddSHONG Yifan            selects.NO_MATCHING_PLATFORM_TRIPLES: [
19*d4726bddSHONG Yifan                "//third-party/rust:hermit-abi",  # cfg(target_os = "hermit")
20*d4726bddSHONG Yifan            ],
21*d4726bddSHONG Yifan        })
22*d4726bddSHONG Yifan    )
23*d4726bddSHONG Yifan"""
24*d4726bddSHONG Yifan
25*d4726bddSHONG Yifan_SENTINEL = struct()
26*d4726bddSHONG Yifan
27*d4726bddSHONG Yifandef _with_unmapped(configurations):
28*d4726bddSHONG Yifan    configurations.pop(_SENTINEL)
29*d4726bddSHONG Yifan    return select(configurations)
30*d4726bddSHONG Yifan
31*d4726bddSHONG Yifanselects = struct(
32*d4726bddSHONG Yifan    with_unmapped = _with_unmapped,
33*d4726bddSHONG Yifan    NO_MATCHING_PLATFORM_TRIPLES = _SENTINEL,
34*d4726bddSHONG Yifan)
35