xref: /aosp_15_r20/prebuilts/build-tools/prebuilt_tool.bzl (revision cda5da8d549138a6648c5ee6d7a49cf8f4a657be)
1# Copyright (C) 2024 The Android Open Source Project
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"""Declares a tool that fits multiple platforms/config settings."""
16
17load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
18
19visibility("private")
20
21def prebuilt_tool(
22        name,
23        actual = None,
24        **kwargs):
25    """Declares a tool that fits multiple platforms/config settings.
26
27    Args:
28        name: name of the target
29        actual: Non-configurable. Name of the binary below `<platform>/bin`. Defaults to name.
30        **kwargs: additional arguments to the internal target.
31    """
32
33    if actual == None:
34        actual = name
35
36    native_binary(
37        name = name,
38        src = select({
39            Label("//build/kernel/kleaf/platforms/libc:glibc"): "linux-x86/bin/" + actual,
40            Label("//build/kernel/kleaf/platforms/libc:musl"): "linux_musl-x86/bin/" + actual,
41        }),
42        out = name,
43        data = [Label(":libs")],
44        target_compatible_with = select({
45            Label("//build/kernel/kleaf/platforms/libc:glibc"): [],
46            Label("//build/kernel/kleaf/platforms/libc:musl"): [],
47            "//conditions:default": ["@platforms//:incompatible"],
48        }),
49        **kwargs
50    )
51