1*5225e6b1SAndroid Build Coastguard Worker# Copyright (C) 2024 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_toolchain.bzl", "link_static_cc_library") 16*5225e6b1SAndroid Build Coastguard Workerload("@gbl_llvm_prebuilts//:info.bzl", "LLVM_PREBUILTS_C_INCLUDE") 17*5225e6b1SAndroid Build Coastguard Workerload("@rules_rust//bindgen:defs.bzl", "rust_bindgen") 18*5225e6b1SAndroid Build Coastguard Workerload("@rules_rust//rust:defs.bzl", "rust_library") 19*5225e6b1SAndroid Build Coastguard Worker 20*5225e6b1SAndroid Build Coastguard Workerpackage( 21*5225e6b1SAndroid Build Coastguard Worker default_visibility = ["//visibility:public"], 22*5225e6b1SAndroid Build Coastguard Worker) 23*5225e6b1SAndroid Build Coastguard Worker 24*5225e6b1SAndroid Build Coastguard Workerexports_files(glob(["**/*"])) 25*5225e6b1SAndroid Build Coastguard Worker 26*5225e6b1SAndroid Build Coastguard Worker# Newer version of `rust_bindgen` requires a `cc_library` target that actually produces a static 27*5225e6b1SAndroid Build Coastguard Worker# library and instead of only headers. Thus we generate a placeholder source file to meet the 28*5225e6b1SAndroid Build Coastguard Worker# requirement. 29*5225e6b1SAndroid Build Coastguard Workergenrule( 30*5225e6b1SAndroid Build Coastguard Worker name = "bindgen_noop_cc", 31*5225e6b1SAndroid Build Coastguard Worker outs = ["bindgen_noop_cc.cc"], 32*5225e6b1SAndroid Build Coastguard Worker cmd = "touch $(OUTS)", 33*5225e6b1SAndroid Build Coastguard Worker) 34*5225e6b1SAndroid Build Coastguard Worker 35*5225e6b1SAndroid Build Coastguard Workercc_library( 36*5225e6b1SAndroid Build Coastguard Worker name = "headers", 37*5225e6b1SAndroid Build Coastguard Worker srcs = [":bindgen_noop_cc"], 38*5225e6b1SAndroid Build Coastguard Worker hdrs = [ 39*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_chain_partition_descriptor.h", 40*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_cmdline.h", 41*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_crypto.h", 42*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_descriptor.h", 43*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_footer.h", 44*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_hash_descriptor.h", 45*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_hashtree_descriptor.h", 46*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_kernel_cmdline_descriptor.h", 47*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_ops.h", 48*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_property_descriptor.h", 49*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_rsa.h", 50*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_sha.h", 51*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_slot_verify.h", 52*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_sysdeps.h", 53*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_util.h", 54*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_vbmeta_image.h", 55*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_version.h", 56*5225e6b1SAndroid Build Coastguard Worker "libavb/libavb.h", 57*5225e6b1SAndroid Build Coastguard Worker "libavb/sha/avb_crypto_ops_impl.h", 58*5225e6b1SAndroid Build Coastguard Worker "libavb_cert/avb_cert_ops.h", 59*5225e6b1SAndroid Build Coastguard Worker "libavb_cert/avb_cert_types.h", 60*5225e6b1SAndroid Build Coastguard Worker "libavb_cert/avb_cert_validate.h", 61*5225e6b1SAndroid Build Coastguard Worker "libavb_cert/libavb_cert.h", 62*5225e6b1SAndroid Build Coastguard Worker ], 63*5225e6b1SAndroid Build Coastguard Worker includes = [ 64*5225e6b1SAndroid Build Coastguard Worker ".", 65*5225e6b1SAndroid Build Coastguard Worker "libavb/sha/", 66*5225e6b1SAndroid Build Coastguard Worker ], 67*5225e6b1SAndroid Build Coastguard Worker deps = ["@gbl//libc:headers"], 68*5225e6b1SAndroid Build Coastguard Worker) 69*5225e6b1SAndroid Build Coastguard Worker 70*5225e6b1SAndroid Build Coastguard Workercc_library( 71*5225e6b1SAndroid Build Coastguard Worker name = "libavb_c", 72*5225e6b1SAndroid Build Coastguard Worker srcs = [ 73*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_chain_partition_descriptor.c", 74*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_cmdline.c", 75*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_crc32.c", 76*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_crypto.c", 77*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_descriptor.c", 78*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_footer.c", 79*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_hash_descriptor.c", 80*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_hashtree_descriptor.c", 81*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_kernel_cmdline_descriptor.c", 82*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_property_descriptor.c", 83*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_rsa.c", 84*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_slot_verify.c", 85*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_util.c", 86*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_vbmeta_image.c", 87*5225e6b1SAndroid Build Coastguard Worker "libavb/avb_version.c", 88*5225e6b1SAndroid Build Coastguard Worker "libavb_cert/avb_cert_validate.c", 89*5225e6b1SAndroid Build Coastguard Worker 90*5225e6b1SAndroid Build Coastguard Worker # Contains noop placeholder for avb_printv/avb_printf 91*5225e6b1SAndroid Build Coastguard Worker "@gbl//libavb:print.c", 92*5225e6b1SAndroid Build Coastguard Worker ], 93*5225e6b1SAndroid Build Coastguard Worker copts = [ 94*5225e6b1SAndroid Build Coastguard Worker "-D_FILE_OFFSET_BITS=64", 95*5225e6b1SAndroid Build Coastguard Worker "-D_POSIX_C_SOURCE=199309L", 96*5225e6b1SAndroid Build Coastguard Worker "-Wa,--noexecstack", 97*5225e6b1SAndroid Build Coastguard Worker "-Werror", 98*5225e6b1SAndroid Build Coastguard Worker "-Wall", 99*5225e6b1SAndroid Build Coastguard Worker "-Wextra", 100*5225e6b1SAndroid Build Coastguard Worker "-Wformat=2", 101*5225e6b1SAndroid Build Coastguard Worker "-Wmissing-prototypes", 102*5225e6b1SAndroid Build Coastguard Worker "-Wno-unused-parameter", 103*5225e6b1SAndroid Build Coastguard Worker "-ffunction-sections", 104*5225e6b1SAndroid Build Coastguard Worker "-g", 105*5225e6b1SAndroid Build Coastguard Worker "-DAVB_ENABLE_DEBUG", 106*5225e6b1SAndroid Build Coastguard Worker "-DAVB_COMPILATION", 107*5225e6b1SAndroid Build Coastguard Worker # libavb uses more than 4K of stack space. This prevents the compiler from inserting 108*5225e6b1SAndroid Build Coastguard Worker # _chkstk(). 109*5225e6b1SAndroid Build Coastguard Worker "-mstack-probe-size=8192", 110*5225e6b1SAndroid Build Coastguard Worker ], 111*5225e6b1SAndroid Build Coastguard Worker deps = [ 112*5225e6b1SAndroid Build Coastguard Worker ":headers", 113*5225e6b1SAndroid Build Coastguard Worker ], 114*5225e6b1SAndroid Build Coastguard Worker) 115*5225e6b1SAndroid Build Coastguard Worker 116*5225e6b1SAndroid Build Coastguard Workerlink_static_cc_library( 117*5225e6b1SAndroid Build Coastguard Worker name = "libavb_c_staticlib", 118*5225e6b1SAndroid Build Coastguard Worker cc_library = ":libavb_c", 119*5225e6b1SAndroid Build Coastguard Worker) 120*5225e6b1SAndroid Build Coastguard Worker 121*5225e6b1SAndroid Build Coastguard Workercc_library( 122*5225e6b1SAndroid Build Coastguard Worker name = "avb_crypto_ops_sha_impl", 123*5225e6b1SAndroid Build Coastguard Worker srcs = [ 124*5225e6b1SAndroid Build Coastguard Worker "libavb/sha/sha256_impl.c", 125*5225e6b1SAndroid Build Coastguard Worker "libavb/sha/sha512_impl.c", 126*5225e6b1SAndroid Build Coastguard Worker ], 127*5225e6b1SAndroid Build Coastguard Worker copts = ["-DAVB_COMPILATION"], 128*5225e6b1SAndroid Build Coastguard Worker deps = [ 129*5225e6b1SAndroid Build Coastguard Worker ":headers", 130*5225e6b1SAndroid Build Coastguard Worker ], 131*5225e6b1SAndroid Build Coastguard Worker) 132*5225e6b1SAndroid Build Coastguard Worker 133*5225e6b1SAndroid Build Coastguard Workerlink_static_cc_library( 134*5225e6b1SAndroid Build Coastguard Worker name = "avb_crypto_ops_sha_impl_staticlib", 135*5225e6b1SAndroid Build Coastguard Worker cc_library = ":avb_crypto_ops_sha_impl", 136*5225e6b1SAndroid Build Coastguard Worker) 137*5225e6b1SAndroid Build Coastguard Worker 138*5225e6b1SAndroid Build Coastguard Workerrust_bindgen( 139*5225e6b1SAndroid Build Coastguard Worker name = "libavb_c_bindgen", 140*5225e6b1SAndroid Build Coastguard Worker # Flags should match Soong definition in external/avb/rust/Android.bp. 141*5225e6b1SAndroid Build Coastguard Worker bindgen_flags = [ 142*5225e6b1SAndroid Build Coastguard Worker "--constified-enum-module=AvbDescriptorTag", 143*5225e6b1SAndroid Build Coastguard Worker "--bitfield-enum=Avb.*Flags", 144*5225e6b1SAndroid Build Coastguard Worker "--default-enum-style=rust", 145*5225e6b1SAndroid Build Coastguard Worker "--with-derive-default", 146*5225e6b1SAndroid Build Coastguard Worker "--with-derive-custom=Avb.*Descriptor=FromZeroes,FromBytes", 147*5225e6b1SAndroid Build Coastguard Worker "--with-derive-custom=AvbCertPermanentAttributes=FromZeroes,FromBytes,AsBytes", 148*5225e6b1SAndroid Build Coastguard Worker "--with-derive-custom=AvbCertCertificate.*=FromZeroes,FromBytes,AsBytes", 149*5225e6b1SAndroid Build Coastguard Worker "--with-derive-custom=AvbCertUnlock.*=FromZeroes,FromBytes,AsBytes", 150*5225e6b1SAndroid Build Coastguard Worker "--allowlist-type=AvbDescriptorTag", 151*5225e6b1SAndroid Build Coastguard Worker "--allowlist-type=Avb.*Flags", 152*5225e6b1SAndroid Build Coastguard Worker "--allowlist-function=.*", 153*5225e6b1SAndroid Build Coastguard Worker "--allowlist-var=AVB.*", 154*5225e6b1SAndroid Build Coastguard Worker "--use-core", 155*5225e6b1SAndroid Build Coastguard Worker "--raw-line=#![no_std]", 156*5225e6b1SAndroid Build Coastguard Worker "--raw-line=use zerocopy::{AsBytes, FromBytes, FromZeroes};", 157*5225e6b1SAndroid Build Coastguard Worker "--ctypes-prefix=core::ffi", 158*5225e6b1SAndroid Build Coastguard Worker ], 159*5225e6b1SAndroid Build Coastguard Worker cc_lib = "headers", 160*5225e6b1SAndroid Build Coastguard Worker # For x86_32, we need to explicitly specify 32bit architecture. 161*5225e6b1SAndroid Build Coastguard Worker clang_flags = select({ 162*5225e6b1SAndroid Build Coastguard Worker "@gbl//toolchain:gbl_rust_uefi_x86_32": ["-m32"], 163*5225e6b1SAndroid Build Coastguard Worker "//conditions:default": ["-m64"], 164*5225e6b1SAndroid Build Coastguard Worker }) + [ 165*5225e6b1SAndroid Build Coastguard Worker "-I{}".format(LLVM_PREBUILTS_C_INCLUDE), 166*5225e6b1SAndroid Build Coastguard Worker "-nostdinc", 167*5225e6b1SAndroid Build Coastguard Worker ], 168*5225e6b1SAndroid Build Coastguard Worker header = "libavb_cert/libavb_cert.h", 169*5225e6b1SAndroid Build Coastguard Worker) 170*5225e6b1SAndroid Build Coastguard Worker 171*5225e6b1SAndroid Build Coastguard Workerrust_library( 172*5225e6b1SAndroid Build Coastguard Worker name = "avb_bindgen", 173*5225e6b1SAndroid Build Coastguard Worker srcs = [":libavb_c_bindgen"], 174*5225e6b1SAndroid Build Coastguard Worker rustc_flags = [ 175*5225e6b1SAndroid Build Coastguard Worker "--allow=non_snake_case", 176*5225e6b1SAndroid Build Coastguard Worker "--allow=non_camel_case_types", 177*5225e6b1SAndroid Build Coastguard Worker ], 178*5225e6b1SAndroid Build Coastguard Worker deps = ["@zerocopy"], 179*5225e6b1SAndroid Build Coastguard Worker) 180*5225e6b1SAndroid Build Coastguard Worker 181*5225e6b1SAndroid Build Coastguard Workerrust_library( 182*5225e6b1SAndroid Build Coastguard Worker name = "avb", 183*5225e6b1SAndroid Build Coastguard Worker srcs = glob(["rust/src/**/*.rs"]), 184*5225e6b1SAndroid Build Coastguard Worker crate_features = ["uuid"], 185*5225e6b1SAndroid Build Coastguard Worker edition = "2021", 186*5225e6b1SAndroid Build Coastguard Worker deps = [ 187*5225e6b1SAndroid Build Coastguard Worker ":avb_bindgen", 188*5225e6b1SAndroid Build Coastguard Worker ":libavb_c_staticlib", 189*5225e6b1SAndroid Build Coastguard Worker "@uuid", 190*5225e6b1SAndroid Build Coastguard Worker "@zerocopy", 191*5225e6b1SAndroid Build Coastguard Worker ], 192*5225e6b1SAndroid Build Coastguard Worker) 193*5225e6b1SAndroid Build Coastguard Worker 194*5225e6b1SAndroid Build Coastguard Workerrust_library( 195*5225e6b1SAndroid Build Coastguard Worker name = "avb_test", 196*5225e6b1SAndroid Build Coastguard Worker srcs = ["rust/tests/test_ops.rs"], 197*5225e6b1SAndroid Build Coastguard Worker crate_features = ["uuid"], 198*5225e6b1SAndroid Build Coastguard Worker edition = "2021", 199*5225e6b1SAndroid Build Coastguard Worker deps = [ 200*5225e6b1SAndroid Build Coastguard Worker ":avb", 201*5225e6b1SAndroid Build Coastguard Worker "@uuid", 202*5225e6b1SAndroid Build Coastguard Worker ], 203*5225e6b1SAndroid Build Coastguard Worker) 204