# Copyright (C) 2022 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #
# Generate Rust bindings for C headers # # Bindgen reads C headers and generates compatible Rust declarations of types # and APIs. This allows us to keep Rust code in sync with C code that it depends # on. # # Input variables: # MODULE_BINDGEN_ALLOW_FILES # MODULE_BINDGEN_ALLOW_FUNCTIONS # MODULE_BINDGEN_ALLOW_TYPES # MODULE_BINDGEN_ALLOW_VARS # MODULE_BINDGEN_BLOCK_TYPES # MODULE_BINDGEN_CTYPES_PREFIX # MODULE_BINDGEN_FLAGS # MODULE_BINDGEN_OUTPUT_ENV_VAR # MODULE_BINDGEN_SRC_HEADER # MODULE_BINDGEN_OUTPUT_FILE_NAME # MODULE_BINDGEN_WRAP_STATIC_FNS
ifeq ($(strip $(MODULE_BINDGEN_SRC_HEADER)),)
$(error $(MODULE): MODULE_BINDGEN_SRC_HEADER is required to use bindgen.mk) endif
# Add some extra user space definitions that are needed for the musl headers
$(BINDGEN_STATIC_FNS_OBJ): GLOBAL_COMPILEFLAGS += -DTRUSTY_USERSPACE=1 -U_ALL_SOURCE -D_XOPEN_SOURCE=700 endif
-include $(BINDGEN_STATIC_FNS_DEP)
# Save the variables read or written by compile.mk
BINDGEN_SAVED_MODULE_INCLUDES := $(MODULE_INCLUDES)
BINDGEN_SAVED_MODULE_OBJS := $(MODULE_OBJS)
BINDGEN_SAVED_MODULE_SRCS := $(MODULE_SRCS)
BINDGEN_SAVED_MODULE_SRCS_FIRST := $(MODULE_SRCS_FIRST)
MODULE_SRCS := $(BINDGEN_STATIC_FNS_SRC)
MODULE_SRCS_FIRST :=
# Explicitly prepend the -I prefix to MODULE_INCLUDES just like make/module.mk
MODULE_INCLUDES := $(addprefix -I,$(MODULE_INCLUDES)) # We add $TRUSTY_TOP to the include directories because the .static_fns.c file # includes $MODULE_BINDGEN_SRC_HEADER as is (which could be a relative path)
MODULE_INCLUDES += -I$(TRUSTY_TOP)
includemake/compile.mk ifneq ($(realpath $(MODULE_OBJS)),$(realpath $(BINDGEN_STATIC_FNS_OBJ)))
$(error Internal bindgen build error: mismatch between MODULE_OBJS="$(MODULE_OBJS)" and "$(BINDGEN_STATIC_FNS_OBJ)") endif
MODULE_BINDGEN_FLAGS += $(addprefix --allowlist-var ,$(MODULE_BINDGEN_ALLOW_VARS))
MODULE_BINDGEN_FLAGS += $(addprefix --allowlist-type ,$(MODULE_BINDGEN_ALLOW_TYPES))
MODULE_BINDGEN_FLAGS += $(addprefix --blocklist-type ,$(MODULE_BINDGEN_BLOCK_TYPES))
MODULE_BINDGEN_FLAGS += $(addprefix --allowlist-function ,$(MODULE_BINDGEN_ALLOW_FUNCTIONS))
MODULE_BINDGEN_FLAGS += $(addprefix --allowlist-file ,$(MODULE_BINDGEN_ALLOW_FILES)) # other sanitizer flags if present will cause bindgen to fail unless we pass # -fno-sanitize-ignorelist, see https://issues.chromium.org/issues/40265121
BINDGEN_MODULE_COMPILEFLAGS := $(MODULE_COMPILEFLAGS) -fvisibility=default -fno-sanitize-ignorelist
ifeq ($(call TOBOOL,$(TRUSTY_USERSPACE)),true) # library.mk overrides GLOBAL_COMPILEFLAGS and GLOBAL_INCLUDES for the .o, so we # must do the same here for bindgen
$(MODULE_BINDGEN_OUTPUT_FILE): GLOBAL_COMPILEFLAGS := $(GLOBAL_SHARED_COMPILEFLAGS) $(GLOBAL_USER_COMPILEFLAGS) $(GLOBAL_USER_IN_TREE_COMPILEFLAGS) $(GLOBAL_USER_IN_TREE_CPPFLAGS)
$(MODULE_BINDGEN_OUTPUT_FILE): GLOBAL_INCLUDES := $(addprefix -I,$(GLOBAL_UAPI_INCLUDES) $(GLOBAL_SHARED_INCLUDES) $(GLOBAL_USER_INCLUDES)) endif
# MODULE_BINDGEN_OUTPUT_ENV_VAR is not compatible with Soong as Soong does not allow # custom `envflags`. bindgen modules should resort to using `MODULE_BINDGEN_OUTPUT_FILE` # and `include!(concat!(env!("OUT_DIR"), "/{MODULE_BINDGEN_OUTPUT_FILE}"))` to include # the generated bindgen file.
MODULE_RUST_ENV := $(MODULE_RUST_ENV) $(MODULE_BINDGEN_OUTPUT_ENV_VAR)=$(MODULE_BINDGEN_OUTPUT_FILE) OUT_DIR=$(dir $(MODULE_BINDGEN_OUTPUT_FILE))
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.