# # Copyright (c) 2020, Google, Inc. All rights reserved # # 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. #
# Build a userspace library for Trusty # # args: # MODULE : module name (required) # MODULE_SRCS : list of source files, local path (not required for header-only # libraries) # MODULE_LIBRARY_DEPS : libraries that this module depends on. These libraries # must be built using the new library.mk system (i.e. include # make/library.mk at the end of the library's rules) # MODULE_DEPS : legacy dependencies that do not use the new library.mk system. # These dependencies will be built exclusively for this module and not # shared with other modules). Do not use this for library dependencies # compatible with library.mk, instead use MODULE_LIBRARY_DEPS. # MODULE_ADD_IMPLICIT_DEPS : Add basic libraries to MODULE_LIBRARY_DEPS. # Defaults to true. (currently adds libc-trusty) # MODULE_USE_WHOLE_ARCHIVE : use --whole-archive when linking this module # MODULE_DEFINES : #defines local to this module # MODULE_CONSTANTS : JSON files with constants used for both the manifest and C # headers (optional) (CONSTANTS is a deprecated equivalent to # MODULE_CONSTANTS) # MODULE_COMPILEFLAGS : COMPILEFLAGS local to this module # MODULE_CFLAGS : CFLAGS local to this module # MODULE_CPPFLAGS : CPPFLAGS local to this module # MODULE_ASMFLAGS : ASMFLAGS local to this module # MODULE_INCLUDES : include directories local to this module # MODULE_SRCDEPS : extra dependencies that all of this module's files depend on # MODULE_EXTRA_OBJECTS : extra .o files that should be linked with the module # MODULE_WHOLE_ARCHIVES : extra .a libraries that need --whole-archive, e.g., # prebuilt archive dependencies # MODULE_ARM_OVERRIDE_SRCS : list of source files, local path that should be # force compiled with ARM (if applicable) # MODULE_RUST_EDITION : Rust edition to compile this crate for (optional) # MODULE_RUST_TESTS : If true, this module will be built as both a crate library # and a Rust test service (optional, default is false) # MODULE_RUST_USE_CLIPPY: whether to require clippy be run for this library. # Compilation will fail if any clippy error is found. # MODULE_SKIP_DOCS : If true, no documentation will be generated for # this module (optional, default is false) # MODULE_SDK_LIB_NAME : Name of library in SDK (if applicable). Default is # libMODULE_NAME where MODULE_NAME is the final path component of MODULE. # MODULE_SDK_HEADERS : Headers to copy into the SDK. Any headers in # MODULE_EXPORT_INCLUDES will be included as well, but generated headers # must be listed explicitly. # MODULE_SDK_HEADER_INSTALL_DIR : Path under include prefix to install SDK # headers into. # MODULE_LICENSES : Any additional license files for the library other than # $(MODULE)/LICENSE and $(MODULE)/NOTICE # MODULE_RUST_STEM: The stem of the output .rlib file for this library. # Defaults to $(MODULE_CRATE_NAME) if left empty. # MANIFEST : App manifest JSON file, only applicable if this module is an app # MANIFEST_OVERLAY : Additional manifest overlay JSON files(s) # # Exported flags: # The following args are the same as their corresponding variables above, but # will be exported to all users of this library. These flags are also prepended # to this module's local flags. To override an exported flag, add the # corresponding override to e.g. MODULE_COMPILEFLAGS. # # MODULE_EXPORT_COMPILEFLAGS # MODULE_EXPORT_CONSTANTS # MODULE_EXPORT_CFLAGS # MODULE_EXPORT_CPPFLAGS # MODULE_EXPORT_ASMFLAGS # MODULE_EXPORT_LDFLAGS # MODULE_EXPORT_INCLUDES # MODULE_EXPORT_SRCDEPS
# the minimum library rules.mk file is as follows: # # LOCAL_DIR := $(GET_LOCAL_DIR) # MODULE := $(LOCAL_DIR) # # MODULE_SRCS := $(LOCAL_DIR)/source_file.c # # include make/library.mk
# if QUERY_MODULE is set, the rules.mk that included us was itself included not # to define a module's make targets but to query the variables it sets for the # rest of the build. in this case, skip all further processing ifeq ($(QUERY_MODULE),)
ifneq ($(MODULE_EXPORT_CONSTANTS),)
$(error MODULE_EXPORT_CONSTANTS is not supported by library.mk for use in the kernel) endif ifneq ($(MODULE_EXPORT_CFLAGS),)
$(error MODULE_EXPORT_CFLAGS is not supported by library.mk for use in the kernel) endif ifneq ($(MODULE_EXPORT_CPPFLAGS),)
$(error MODULE_EXPORT_CPPFLAGS is not supported by library.mk for use in the kernel) endif ifneq ($(MODULE_EXPORT_ASMFLAGS),)
$(error MODULE_EXPORT_ASMFLAGS is not supported by library.mk for use in the kernel) endif ifneq ($(MODULE_EXPORT_LDFLAGS),)
$(error MODULE_EXPORT_LDFLAGS is not supported by library.mk for use in the kernel) endif
# Building for the kernel, turn off independent library build and fall back to # lk module system. includemake/module.mk
ifeq ($(call TOBOOL,$(BUILD_AS_RUST_TEST_MODULE)),true) # Disable Rust tests on architectures that do not support Rust ifeq ($(call TOBOOL,$(ARCH_$(ARCH)_SUPPORTS_RUST)),true) # Allow a project to disable rust tests ifeq ($(call TOBOOL,$(TRUSTY_DISABLE_RUST_TESTS)),false)
MODULE_RUST_LOG_NAME := $(MODULE)
$(call INFO,$(MODULE_RUST_LOG_NAME),processing,as a rust test service)
# Build with the new module system. Currently, the Trusty userspace libraries # and apps use the new module system, as does the bootloader/test-runner binary.
$(call INFO,$(MODULE),processing,library or app)
# Reset new module system marker. This will be set again in dependencies by # userspace_recurse.mk
TRUSTY_NEW_MODULE_SYSTEM :=
# proc macros must be host libraries, and all their dependencies are as well. # This will be reset after we recursively include all dependencies.
MODULE_RUST_HOST_LIB := true
ifneq ($(strip $(filter-out proc-macro,$(MODULE_RUST_CRATE_TYPES))),)
$(error $(MODULE) cannot be built as both a proc-macro and a target crate) endif endif
includemake/set_library_builddir.mk
# Skip docs for apps because dependencies for apps are setup differently than # for rlibs (apps do use $MODULE_RSOBJS which is the variable we use as an input # to the rustdoc target to ensure that dependencies are built before generating # docs) and currently that breaks the rustdoc builds. We don't currently need # generated docs for apps, but if that changes it should be possible to fix # this. ifeq ($(call TOBOOL,$(TRUSTY_APP)),true)
MODULE_SKIP_DOCS := true endif
ifeq ($(call TOBOOL,$(MODULE_RUST_HOST_LIB)),false) # Add any common flags to the module includemake/common_flags.mk endif
ifneq ($(INCMODULES),)
$(error $(MODULE) should only be included from other userspace modules that use library.mk. One of the following modules needs to be updated to use the new library system: $(LIB_SAVED_MODULE) $(ALLMODULES)) endif ifneq ($(GLOBAL_OPTFLAGS),)
$(error $(MODULE) has modified GLOBAL_OPTFLAGS, this variable is deprecated) endif ifneq ($(GLOBAL_COMPILEFLAGS),)
$(error $(MODULE) has modified GLOBAL_COMPILEFLAGS, this variable is deprecated, please use MODULE_EXPORT_COMPILEFLAGS) endif ifneq ($(GLOBAL_CFLAGS),)
$(error $(MODULE) has modified GLOBAL_CFLAGS, this variable is deprecated, please use MODULE_EXPORT_CFLAGS) endif ifneq ($(GLOBAL_CPPFLAGS),)
$(error $(MODULE) has modified GLOBAL_CPPFLAGS, this variable is deprecated, please use MODULE_EXPORT_CPPFLAGS) endif ifneq ($(GLOBAL_ASMFLAGS),)
$(error $(MODULE) has modified GLOBAL_ASMFLAGS, this variable is deprecated, please use MODULE_EXPORT_ASMFLAGS) endif ifneq ($(GLOBAL_DEFINES),)
$(error $(MODULE) has modified GLOBAL_DEFINES, this variable is deprecated) endif ifneq ($(GLOBAL_INCLUDES),)
$(error $(MODULE) has modified GLOBAL_INCLUDES, this variable is deprecated, please use MODULE_EXPORT_INCLUDES) endif ifneq ($(MODULE_OPTFLAGS),)
$(error $(MODULE) sets MODULE_OPTFLAGS, which is deprecated. Please move these flags to another variable.) endif
ifneq ($(MODULE_EXPORT_RUSTFLAGS),)
$(error $(MODULE) sets MODULE_EXPORT_RUSTFLAGS, which is not supported) endif
ifneq ($(strip $(MODULE_DEPS)),)
$(warning $(MODULE) is a userspace library module but has deprecated MODULE_DEPS: $(MODULE_DEPS).) endif
# ALLMODULES is only used for the legacy dependency system, so if a library is # included in it, something must have gone wrong. ifneq ($(filter $(MODULE),$(ALLMODULES)),) ifeq ($(LIB_SAVED_MODULE),) # We don't know who our parent was because it was a legacy module, so we can't # give a very good error message here.
$(error Please move $(MODULE) from MODULE_DEPS into MODULE_LIBRARY_DEPS) else
$(error MODULE $(LIB_SAVED_MODULE) depends on $(MODULE) via MODULE_DEPS, but $(MODULE) is only compatible with MODULE_LIBRARY_DEPS) endif endif
ifneq ($(CONSTANTS),)
$(warning $(MODULE) has set CONSTANTS, this variable is deprecated, please use MODULE_CONSTANTS or MODULE_EXPORT_CONSTANTS) endif
MODULE_CONSTANTS += $(CONSTANTS)
ifneq ($(MODULE_SRCS)$(MODULE_SRCS_FIRST),) # Add this module to the SDK LDFLAGS and objects lists. This needs to be done # before including our dependencies in case of recursive deps. ifneq ($(filter $(MODULE),$(TRUSTY_SDK_MODULES)),) ifeq ($(strip $(MODULE_SDK_LIB_NAME)),)
MODULE_SDK_LIB_NAME := $(call TOSDKLIBNAME,$(MODULE)) endif
ifeq ($(call TOBOOL,$(MODULE_IS_RUST)),false) # If this module isn't rust, we can link against it from the sdk using -lmodule
MODULE_SDK_LIBS += $(TRUSTY_SDK_LIB_DIR)/lib$(MODULE_SDK_LIB_NAME).a
MODULE_EXPORT_LDFLAGS += $(filter-out $(MODULE_EXPORT_LDFLAGS),-l$(MODULE_SDK_LIB_NAME)) endif
endif# SDK module endif# not header only
# Add this library's headers to the SDK. ifneq ($(filter $(MODULE),$(TRUSTY_SDK_MODULES)),)
MODULE_EXPORT_SDK_HEADERS :=
definecopy-headers-rule # Some libraries include symlinked headers. For now, follow # those symlinks and copy their targets instead so SDK users # can still include the symlink sources.
HEADERS := $$(shell cd "$(1)"2>/dev/null && find -L . -type f)
OUTPUT_HEADERS := $$(filter-out $$(MODULE_EXPORT_SDK_HEADERS),$$(addprefix $(TRUSTY_SDK_INCLUDE_DIR)/$(MODULE_SDK_HEADER_INSTALL_DIR)/,$$(HEADERS)))
MODULE_EXPORT_SDK_HEADERS += $$(OUTPUT_HEADERS) # Create a fake dependency on configheader to trigger coping the file again # in case the copy source file path changes due to configuration change. # E.g. for headers copied from prebuilts/build-tools/sysroots/*
$$(OUTPUT_HEADERS): $(CONFIGHEADER)
$$(OUTPUT_HEADERS): $(TRUSTY_SDK_INCLUDE_DIR)/$(MODULE_SDK_HEADER_INSTALL_DIR)/% : $(1)/% $(MODULE_SRCDEPS)
@$$(MKDIR)
$$(NOECHO)cp -L $$< $$@ endef
# Make sure we copy all SDK headers even if they are not needed by the build
ALL_SDK_INCLUDES += $(MODULE_EXPORT_SDK_HEADERS)
endif# SDK MODULE
# Stem defaults to the crate name ifeq ($(MODULE_RUST_STEM),)
MODULE_RUST_STEM := $(MODULE_CRATE_NAME) endif
# Register the module in a global registry. This is used to avoid repeatedly # generating rules for this module from modules that depend on it.
_MODULES_$(MODULE) := T
# Cache exported flags for use in modules that depend on this library.
_MODULES_$(MODULE)_COMPILEFLAGS := $(MODULE_EXPORT_COMPILEFLAGS)
_MODULES_$(MODULE)_CONSTANTS := $(MODULE_EXPORT_CONSTANTS)
_MODULES_$(MODULE)_CFLAGS := $(MODULE_EXPORT_CFLAGS)
_MODULES_$(MODULE)_CPPFLAGS := $(MODULE_EXPORT_CPPFLAGS)
_MODULES_$(MODULE)_ASMFLAGS := $(MODULE_EXPORT_ASMFLAGS)
_MODULES_$(MODULE)_INCLUDES := $(MODULE_EXPORT_INCLUDES)
_MODULES_$(MODULE)_LDFLAGS := $(MODULE_EXPORT_LDFLAGS)
_MODULES_$(MODULE)_SRCDEPS := $(MODULE_EXPORT_SRCDEPS)
_MODULES_$(MODULE)_RUST_STEM := $(MODULE_RUST_STEM) ifeq ($(filter $(MODULE),$(TRUSTY_SDK_MODULES)),) ifeq ($(call TOBOOL,$(MODULE_IS_RUST)),true)
_MODULES_$(MODULE)_CRATE_NAME := $(MODULE_CRATE_NAME)
# Memorize the output headers for this module so that we can add them as srcdeps # to dependencies
_MODULES_$(MODULE)_SDK_HEADERS := $(MODULE_EXPORT_SDK_HEADERS)
# We need to populate rlibs here, before recursing, in case we have a circular # dependency. This is analogous to _INCLUDES above. ifneq ($(filter rlib,$(MODULE_RUST_CRATE_TYPES)),)
_MODULES_$(MODULE)_LIBRARIES := $(call TOBUILDDIR,lib$(MODULE_RUST_STEM)).rlib
_MODULES_$(MODULE)_RLIBS := $(MODULE_CRATE_NAME)=$(call TOBUILDDIR,lib$(MODULE_RUST_STEM).rlib) endif
else
_MODULES_$(MODULE)_LIBRARIES := $(call TOBUILDDIR,$(MODULE)).mod.a endif endif# not SDK module
# Will contain a list of SDK libraries that this library depends on. Used for # dependency resolution, not for including the libraries directly in the link.
_MODULES_$(MODULE)_SDK_LIBS := $(MODULE_SDK_LIBS)
DEPENDENCY_MODULE :=
DEPENDENCY_MODULE_PATH :=
# Recurse into dependencies that this module re-exports flags from. This needs # to happen before we recurse into regular dependencies in the case of recursive # dependencies, which need to pick up this module's re-exported flags.
$(foreach dep,$(sort $(MODULE_LIBRARY_EXPORTED_DEPS)),\
$(eval EXPORT_DEPENDENCY_MODULE := $(dep))\
$(evalincludemake/userspace_recurse.mk))
# We need to process each dependent module only once. # Therefore we get the realpath to avoid different relative-path references to the same module, # then sort to remove any duplicates. # Module dependencies are then make relative to to top of the build environment.
MODULE_REAL_LIBRARY_DEPS := $(realpath $(MODULE_LIBRARY_DEPS)) ifneq ($(words MODULE_REAL_LIBRARY_DEPS), $(words MODULE_LIBRARY_DEPS))
$(error some modules path do not exist) endif
ifeq ($(filter $(MODULE),$(TRUSTY_SDK_MODULES)),) # Only add in tree header paths to this module's include path if this module # isn't part of the SDK
MODULE_INCLUDES := $(MODULE_EXPORT_INCLUDES) $(MODULE_INCLUDES) endif
# Make sure the headers this module requires are copied before the module is # compiled
MODULE_SRCDEPS += $(MODULE_SDK_HEADERS)
MODULE_EXPORT_SRCDEPS += $(MODULE_SDK_HEADERS)
# Generate constant headers and manifest, if needed. includemake/gen_manifest.mk
# Generate Rust bindings with bindgen if requested ifneq ($(strip $(MODULE_BINDGEN_SRC_HEADER)),) includemake/bindgen.mk endif
ifneq ($(MODULE_SRCS)$(MODULE_SRCS_FIRST),) # Not a header-only library, so we need to build the source files
define CRATE_CONFIG :=
{ "display_name": "$(MODULE_RUST_STEM)", "root_module": "$(filter %.rs,$(MODULE_SRCS))", "edition": "$(MODULE_RUST_EDITION)", "deps": [
$(call STRIP_TRAILING_COMMA,$(foreach dep,$(sort $(MODULE_LIBRARY_DEPS) $(MODULE_LIBRARY_EXPORTED_DEPS)),\
$(if $(_MODULES_$(dep)_RUST_STEM),{"name": "$(_MODULES_$(dep)_RUST_STEM)"$(COMMA) "crate": $(_MODULES_$(dep)_CRATE_INDEX)}$(COMMA))))
], "cfg": [
$(call STRIP_TRAILING_COMMA,\
$(foreach cfg, \
$(filter --cfg=%, \ # Look for any cfg flags that are separated by a space and coerce to '='
$(shell echo"$(MODULE_RUSTFLAGS) $(GLOBAL_SHARED_RUSTFLAGS)" \
| sed -e 's/--cfg /--cfg=/g'\
)\ # Now that we only have cfgs, remove the --cfg and setup escaped quotations around cfgs that have values
),"$(shell echo $(cfg) \
| sed -e 's/--cfg=//g' \
| sed -E 's/=(.*)/=\\\\\x22\1\\\\\x22/g'\
)"$(COMMA)))
]
},
# Save our current module because module.mk clears it.
LIB_SAVED_MODULE := $(MODULE)
LIB_SAVED_MODULE_LIBRARY_DEPS := $(MODULE_LIBRARY_DEPS)
LIB_SAVED_MODULE_SRCDEPS := $(MODULE_SRCDEPS)
LIB_SAVED_MODULE_LIBRARIES := $(MODULE_LIBRARIES)
# Save the rust flags for use in trusted_app.mk. userspace_recurse.mk will clean # up after us.
LIB_SAVED_MODULE_RUSTFLAGS := $(MODULE_RUSTFLAGS)
LIB_SAVED_MODULE_RUSTDOCFLAGS := $(MODULE_RUSTDOCFLAGS)
LIB_SAVED_MODULE_RUSTDOC_OBJECT := $(MODULE_RUSTDOC_OBJECT)
LIB_SAVED_MODULE_IS_RUST := $(MODULE_IS_RUST)
LIB_SAVED_MODULE_RUST_USE_CLIPPY := $(MODULE_RUST_USE_CLIPPY)
LIB_SAVED_MODULE_RUST_ENV := $(MODULE_RUST_ENV)
ifneq ($(filter $(MODULE),$(TRUSTY_SDK_MODULES)),) # Install the library into the SDK
ifeq ($(call TOBOOL,$(MODULE_IS_RUST)),true) # Rust modules aren't added to the SDK sysroot yet. We need to keep track of the # library archive here so that we can ensure it is built before its dependencies. # # TODO: Add proper support for SDK rlibs
MODULE_EXPORT_LIBRARIES += $(LIBRARY_ARCHIVE) endif
ifeq ($(call TOBOOL,$(MODULE_USE_WHOLE_ARCHIVE)),true)
MODULE_EXPORT_WHOLE_ARCHIVES += $(LIBRARY_ARCHIVE) # Include the current module explicitly in MODULE_WHOLE_ARCHIVES # in case we were included from trusted_app.mk
MODULE_WHOLE_ARCHIVES += $(LIBRARY_ARCHIVE) endif
# Append dependency libraries into ALLMODULE_OBJS. This needs to happen after we # set up the SDK library copies, if necessary, because we need ALLMODULE_OBJS # without dependencies there.
ALLMODULE_OBJS := $(ALLMODULE_OBJS) $(filter-out $(ALLMODULE_OBJS),$(MODULE_LIBRARIES))
ifeq ($(call TOBOOL,$(MODULE_RUST_TESTS)),true) # Rebuild this module as a test service as well
BUILD_AS_RUST_TEST_MODULE := true
DEPENDENCY_MODULE := $(MODULE)-test
DEPENDENCY_MODULE_PATH := $(MODULE) includemake/userspace_recurse.mk endif endif# module is not disabled endif# not building rust test app
$(call INFO_DONE_SILENT,$(MODULE),processing,library or app)
endif# building userspace module
# Reset all variables for the next module
MODULE :=
MODULE_CRATE_NAME :=
MODULE_RUST_STEM :=
MODULE_SRCDEPS :=
MODULE_LIBRARY_DEPS :=
MODULE_LIBRARY_EXPORTED_DEPS :=
MODULE_USE_WHOLE_ARCHIVE :=
MODULE_LIBRARIES :=
MODULE_LICENSES :=
MODULE_RLIBS :=
MODULE_RSOBJS :=
MODULE_RUSTDOC_OBJECT :=
MODULE_RUSTDOCFLAGS :=
MODULE_RUST_USE_CLIPPY :=
MODULE_SKIP_DOCS :=
MODULE_DISABLED :=
MODULE_SDK_LIB_NAME :=
MODULE_SDK_HEADER_INSTALL_DIR :=
MODULE_SDK_HEADERS := # MODULE_WHOLE_ARCHIVES is used by trusted_app.mk # so we intentionally do not reset it here
LIB_SAVED_MODULE :=
LIB_SAVED_ALLMODULE_OBJS :=
ifneq ($(filter proc-macro,$(MODULE_RUST_CRATE_TYPES)),) # Reset host build state only once we finish building the proc-macro and its deps
MODULE_RUST_HOST_LIB := endif
MODULE_RUST_CRATE_TYPES :=
MODULE_RUST_TESTS :=
OTHER_SDK_OBJS :=
SDK_LIB :=
OTHER_OBJS :=
OTHER_SDK_OBJS :=
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.