1# Copyright (C) 2022 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
16LOCAL_DIR := $(GET_LOCAL_DIR)
17
18MODULE := $(LOCAL_DIR)
19
20BSSL_SRC_DIR := external/boringssl/src
21BSSL_RUST_DIR := $(BSSL_SRC_DIR)/rust/bssl-sys
22
23MODULE_SRCS := $(BSSL_RUST_DIR)/src/lib.rs
24
25MODULE_CRATE_NAME := bssl_sys
26
27MODULE_LIBRARY_DEPS += \
28	external/boringssl \
29	trusty/user/base/lib/bssl-rust-support \
30	trusty/user/base/lib/trusty-sys \
31
32MODULE_BINDGEN_SRC_HEADER := $(BSSL_RUST_DIR)/wrapper.h
33
34MODULE_BINDGEN_FLAGS += \
35	--no-derive-default \
36	--enable-function-attribute-detection \
37	--default-macro-constant-type="signed" \
38	--rustified-enum="point_conversion_form_t" \
39
40MODULE_RUSTFLAGS += --cfg 'unsupported_inline_wrappers'
41
42# These regexes use [[:punct:]] instead of / to handle Windows file paths.
43# Ideally we would write [/\\], but escaping rules are complex, and often
44# ill-defined, in some build systems, so align on [[:punct:]].
45MODULE_BINDGEN_ALLOW_FILES += \
46	".*[[:punct:]]include[[:punct:]]openssl[[:punct:]].*\\.h" \
47	".*[[:punct:]]rust_wrapper\\.h" \
48
49# Specifying the correct clang target results in __builtin_va_list being
50# declared as a 4 item array of u64 for aarch64 targets. This is not FFI-safe,
51# so we can't declare va_list functions for aarch64 until bindgen supports
52# mapping va_list to its Rust equivalent
53# (https://github.com/rust-lang/rust/issues/44930)
54MODULE_BINDGEN_FLAGS += \
55	--blocklist-function="BIO_vsnprintf" \
56	--blocklist-function="OPENSSL_vasprintf" \
57
58# bssl-sys expects the bindgen output to be placed in BINDGEN_RS_FILE.
59MODULE_BINDGEN_OUTPUT_ENV_VAR := BINDGEN_RS_FILE
60
61MODULE_INCLUDES += \
62	$(BSSL_SRC_DIR)/include \
63
64include make/library.mk
65