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 15load("@gbl//toolchain:gbl_toolchain.bzl", "link_static_cc_library") 16load("@gbl//toolchain:gbl_workspace_util.bzl", "ANDROID_RUST_LINTS") 17load("@gbl_llvm_prebuilts//:info.bzl", "LLVM_PREBUILTS_C_INCLUDE") 18load("@rules_rust//bindgen:defs.bzl", "rust_bindgen") 19load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 20 21package( 22 default_visibility = ["//visibility:public"], 23) 24 25link_static_cc_library( 26 name = "libdttable_c_static", 27 cc_library = "@libdttable_c", 28) 29 30rust_bindgen( 31 name = "libdttable_c_bindgen", 32 bindgen_flags = [ 33 "--use-core", 34 "--with-derive-custom-struct=dt_table.*=AsBytes,FromBytes,FromZeroes,PartialEq", 35 "--allowlist-type", 36 "(dt_table.*)", 37 "--allowlist-var", 38 "(DT_TABLE.*)", 39 "--raw-line", 40 """ 41# ![cfg_attr(not(test), no_std)] 42 43use zerocopy::{AsBytes, FromBytes, FromZeroes}; 44""", 45 ], 46 cc_lib = "@libdttable_c", 47 # For x86_32, we need to explicitly specify 32bit architecture. 48 clang_flags = select({ 49 "@gbl//toolchain:gbl_rust_uefi_x86_32": ["-m32"], 50 "//conditions:default": ["-m64"], 51 }) + [ 52 "-I{}".format(LLVM_PREBUILTS_C_INCLUDE), 53 "-nostdinc", 54 ], 55 header = "@libdttable_c//:dt_table.h", 56) 57 58rust_library( 59 name = "libdttable_bindgen", 60 srcs = [":libdttable_c_bindgen"], 61 deps = ["@zerocopy"], 62) 63 64rust_library( 65 name = "libdttable", 66 srcs = ["src/lib.rs"], 67 crate_name = "dttable", 68 edition = "2021", 69 rustc_flags = ANDROID_RUST_LINTS, 70 deps = [ 71 ":libdttable_bindgen", 72 ":libdttable_c_static", 73 "@gbl//liberror", 74 "@gbl//libsafemath", 75 "@zerocopy", 76 ], 77) 78 79rust_test( 80 name = "libdttable_test", 81 compile_data = [ 82 "@gbl//libdttable/test/data:all", 83 ], 84 crate = ":libdttable", 85 rustc_flags = ANDROID_RUST_LINTS, 86 deps = [ 87 "@gbl//libfdt", 88 ], 89) 90