1# Copyright (C) 2023 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 15load("@rules_rust//bindgen:defs.bzl", "rust_bindgen") 16load("@rules_rust//rust:defs.bzl", "rust_library") 17 18package( 19 default_visibility = ["//visibility:public"], 20) 21 22# Newer version of `rust_bindgen` requires a `cc_library` target that actually produces a static 23# library and instead of only headers. Thus we generate a placeholder source file to meet the 24# requirement. 25genrule( 26 name = "bindgen_noop_cc", 27 outs = ["bindgen_noop_cc.cc"], 28 cmd = "touch $(OUTS)", 29) 30 31cc_library( 32 name = "bindgen_cc_lib", 33 srcs = [":bindgen_noop_cc"], 34 deps = ["@linux_x86_64_sysroot//:linux_x86_64_sysroot_include"], 35) 36 37CUSTOM_DERIVES = "AsBytes,FromBytes,FromZeroes" 38 39rust_bindgen( 40 name = "x86_bootparam_bindgen", 41 bindgen_flags = [ 42 "--ctypes-prefix", 43 "core::ffi", 44 "--use-core", 45 "--allowlist-type", 46 "boot_params", 47 "--with-derive-default", 48 "--with-derive-custom-struct=.*={}".format(CUSTOM_DERIVES), 49 "--with-derive-custom-union=.*={}".format(CUSTOM_DERIVES), 50 "--raw-line", 51 """ 52#![allow(non_camel_case_types)] 53#![allow(non_snake_case)] 54#![cfg_attr(not(test), no_std)] 55use zerocopy::{AsBytes, FromBytes, FromZeroes};""", 56 ], 57 cc_lib = ":bindgen_cc_lib", 58 header = "@linux_x86_64_sysroot//:sysroot/usr/include/x86_64-linux-gnu/asm/bootparam.h", 59) 60 61rust_library( 62 name = "x86_bootparam_defs", 63 srcs = [":x86_bootparam_bindgen"], 64 crate_root = ":x86_bootparam_bindgen", 65 data = [":x86_bootparam_bindgen"], 66 deps = ["@zerocopy"], 67) 68 69rust_library( 70 name = "libboot", 71 srcs = glob(["**/*.rs"]), 72 crate_name = "boot", 73 edition = "2021", 74 deps = [ 75 ":x86_bootparam_defs", 76 "@zerocopy", 77 ] + select({ 78 "@gbl//toolchain:gbl_rust_uefi_aarch64": [ 79 "@gbl//libboot/aarch64_cache_helper:aarch64_cache_helper_staticlib", 80 ], 81 "//conditions:default": [], 82 }), 83) 84