xref: /aosp_15_r20/bootable/libbootloader/gbl/libboot/BUILD (revision 5225e6b173e52d2efc6bcf950c27374fd72adabc)
1*5225e6b1SAndroid Build Coastguard Worker# Copyright (C) 2023 The Android Open Source Project
2*5225e6b1SAndroid Build Coastguard Worker#
3*5225e6b1SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
4*5225e6b1SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
5*5225e6b1SAndroid Build Coastguard Worker# You may obtain a copy of the License at
6*5225e6b1SAndroid Build Coastguard Worker#
7*5225e6b1SAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
8*5225e6b1SAndroid Build Coastguard Worker#
9*5225e6b1SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*5225e6b1SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
11*5225e6b1SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*5225e6b1SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
13*5225e6b1SAndroid Build Coastguard Worker# limitations under the License.
14*5225e6b1SAndroid Build Coastguard Worker
15*5225e6b1SAndroid Build Coastguard Workerload("@gbl//toolchain:gbl_workspace_util.bzl", "ANDROID_RUST_LINTS")
16*5225e6b1SAndroid Build Coastguard Workerload("@rules_rust//bindgen:defs.bzl", "rust_bindgen")
17*5225e6b1SAndroid Build Coastguard Workerload("@rules_rust//rust:defs.bzl", "rust_library")
18*5225e6b1SAndroid Build Coastguard Worker
19*5225e6b1SAndroid Build Coastguard Workerpackage(
20*5225e6b1SAndroid Build Coastguard Worker    default_visibility = ["//visibility:public"],
21*5225e6b1SAndroid Build Coastguard Worker)
22*5225e6b1SAndroid Build Coastguard Worker
23*5225e6b1SAndroid Build Coastguard Worker# Newer version of `rust_bindgen` requires a `cc_library` target that actually produces a static
24*5225e6b1SAndroid Build Coastguard Worker# library and instead of only headers. Thus we generate a placeholder source file to meet the
25*5225e6b1SAndroid Build Coastguard Worker# requirement.
26*5225e6b1SAndroid Build Coastguard Workergenrule(
27*5225e6b1SAndroid Build Coastguard Worker    name = "bindgen_noop_cc",
28*5225e6b1SAndroid Build Coastguard Worker    outs = ["bindgen_noop_cc.cc"],
29*5225e6b1SAndroid Build Coastguard Worker    cmd = "touch $(OUTS)",
30*5225e6b1SAndroid Build Coastguard Worker)
31*5225e6b1SAndroid Build Coastguard Worker
32*5225e6b1SAndroid Build Coastguard Workercc_library(
33*5225e6b1SAndroid Build Coastguard Worker    name = "bindgen_cc_lib",
34*5225e6b1SAndroid Build Coastguard Worker    srcs = [":bindgen_noop_cc"],
35*5225e6b1SAndroid Build Coastguard Worker    deps = ["@linux_x86_64_sysroot//:linux_x86_64_sysroot_include"],
36*5225e6b1SAndroid Build Coastguard Worker)
37*5225e6b1SAndroid Build Coastguard Worker
38*5225e6b1SAndroid Build Coastguard WorkerCUSTOM_DERIVES = "AsBytes,FromBytes,FromZeroes"
39*5225e6b1SAndroid Build Coastguard Worker
40*5225e6b1SAndroid Build Coastguard Workerrust_bindgen(
41*5225e6b1SAndroid Build Coastguard Worker    name = "x86_bootparam_bindgen",
42*5225e6b1SAndroid Build Coastguard Worker    bindgen_flags = [
43*5225e6b1SAndroid Build Coastguard Worker        "--ctypes-prefix",
44*5225e6b1SAndroid Build Coastguard Worker        "core::ffi",
45*5225e6b1SAndroid Build Coastguard Worker        "--use-core",
46*5225e6b1SAndroid Build Coastguard Worker        "--allowlist-type",
47*5225e6b1SAndroid Build Coastguard Worker        "boot_params",
48*5225e6b1SAndroid Build Coastguard Worker        "--with-derive-default",
49*5225e6b1SAndroid Build Coastguard Worker        "--with-derive-custom-struct=.*={}".format(CUSTOM_DERIVES),
50*5225e6b1SAndroid Build Coastguard Worker        "--with-derive-custom-union=.*={}".format(CUSTOM_DERIVES),
51*5225e6b1SAndroid Build Coastguard Worker        "--raw-line",
52*5225e6b1SAndroid Build Coastguard Worker        """
53*5225e6b1SAndroid Build Coastguard Worker#![allow(non_camel_case_types)]
54*5225e6b1SAndroid Build Coastguard Worker#![allow(non_snake_case)]
55*5225e6b1SAndroid Build Coastguard Worker#![cfg_attr(not(test), no_std)]
56*5225e6b1SAndroid Build Coastguard Workeruse zerocopy::{AsBytes, FromBytes, FromZeroes};""",
57*5225e6b1SAndroid Build Coastguard Worker    ],
58*5225e6b1SAndroid Build Coastguard Worker    cc_lib = ":bindgen_cc_lib",
59*5225e6b1SAndroid Build Coastguard Worker    header = "@linux_x86_64_sysroot//:sysroot/usr/include/x86_64-linux-gnu/asm/bootparam.h",
60*5225e6b1SAndroid Build Coastguard Worker)
61*5225e6b1SAndroid Build Coastguard Worker
62*5225e6b1SAndroid Build Coastguard Workerrust_library(
63*5225e6b1SAndroid Build Coastguard Worker    name = "x86_bootparam_defs",
64*5225e6b1SAndroid Build Coastguard Worker    srcs = [":x86_bootparam_bindgen"],
65*5225e6b1SAndroid Build Coastguard Worker    crate_root = ":x86_bootparam_bindgen",
66*5225e6b1SAndroid Build Coastguard Worker    data = [":x86_bootparam_bindgen"],
67*5225e6b1SAndroid Build Coastguard Worker    deps = ["@zerocopy"],
68*5225e6b1SAndroid Build Coastguard Worker)
69*5225e6b1SAndroid Build Coastguard Worker
70*5225e6b1SAndroid Build Coastguard Workerrust_library(
71*5225e6b1SAndroid Build Coastguard Worker    name = "libboot",
72*5225e6b1SAndroid Build Coastguard Worker    srcs = glob(["**/*.rs"]),
73*5225e6b1SAndroid Build Coastguard Worker    crate_name = "boot",
74*5225e6b1SAndroid Build Coastguard Worker    edition = "2021",
75*5225e6b1SAndroid Build Coastguard Worker    rustc_flags = ANDROID_RUST_LINTS,
76*5225e6b1SAndroid Build Coastguard Worker    deps = [
77*5225e6b1SAndroid Build Coastguard Worker        ":x86_bootparam_defs",
78*5225e6b1SAndroid Build Coastguard Worker        "@gbl//liberror",
79*5225e6b1SAndroid Build Coastguard Worker        "@gbl//libsafemath",
80*5225e6b1SAndroid Build Coastguard Worker        "@zbi",
81*5225e6b1SAndroid Build Coastguard Worker        "@zerocopy",
82*5225e6b1SAndroid Build Coastguard Worker    ] + select({
83*5225e6b1SAndroid Build Coastguard Worker        "@gbl//toolchain:gbl_rust_uefi_aarch64": [
84*5225e6b1SAndroid Build Coastguard Worker            "@gbl//libboot/aarch64_cache_helper:aarch64_cache_helper_staticlib",
85*5225e6b1SAndroid Build Coastguard Worker        ],
86*5225e6b1SAndroid Build Coastguard Worker        "//conditions:default": [],
87*5225e6b1SAndroid Build Coastguard Worker    }),
88*5225e6b1SAndroid Build Coastguard Worker)
89