This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 965cddfa365f261c3c8ace3dbe35a0a1cca70c4e Author: Tiago Medicci <[email protected]> AuthorDate: Thu May 21 14:29:22 2026 +0200 system/libffi: Add libffi package integration Add Kconfig, build rules, and ignore entries required to build and package libffi as a standalone system component. Signed-off-by: Tiago Medicci <[email protected]> --- system/libffi/.gitignore | 4 ++ system/libffi/Kconfig | 24 +++++++++ system/libffi/Make.defs | 28 ++++++++++ system/libffi/Makefile | 135 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+) diff --git a/system/libffi/.gitignore b/system/libffi/.gitignore new file mode 100644 index 000000000..26d13e2cd --- /dev/null +++ b/system/libffi/.gitignore @@ -0,0 +1,4 @@ +/*.zip +/build/ +/install/ +/libffi/ diff --git a/system/libffi/Kconfig b/system/libffi/Kconfig new file mode 100644 index 000000000..0b11516ef --- /dev/null +++ b/system/libffi/Kconfig @@ -0,0 +1,24 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config LIB_LIBFFI + bool "libffi" + default n + ---help--- + Enable the libffi Foreign Function Interface library. libffi + provides a portable way to call C functions with arguments + determined at runtime. It is required by CPython's _ctypes module. + +if LIB_LIBFFI + +config LIB_LIBFFI_VERSION + string "libffi commit hash" + default "9760868682cc9a33008761f158d86481d56738aa" + ---help--- + Git commit hash of the libffi repository to download and build. + The source is fetched from https://github.com/libffi/libffi at + the specified commit. + +endif # LIB_LIBFFI diff --git a/system/libffi/Make.defs b/system/libffi/Make.defs new file mode 100644 index 000000000..5949ff04f --- /dev/null +++ b/system/libffi/Make.defs @@ -0,0 +1,28 @@ +############################################################################ +# apps/system/libffi/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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. +# +############################################################################ + +ifneq ($(CONFIG_LIB_LIBFFI),) +CONFIGURED_APPS += $(APPDIR)/system/libffi + +EXTRA_LIBPATHS += -L$(APPDIR)/system/libffi/install/lib +EXTRA_LIBS += -lffi +endif diff --git a/system/libffi/Makefile b/system/libffi/Makefile new file mode 100644 index 000000000..c2b4810ed --- /dev/null +++ b/system/libffi/Makefile @@ -0,0 +1,135 @@ +############################################################################ +# apps/system/libffi/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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. +# +############################################################################ + +include $(APPDIR)/Make.defs + +LIBFFI_URL = https://github.com/libffi/libffi/archive +LIBFFI_COMMIT = $(patsubst "%",%,$(strip $(CONFIG_LIB_LIBFFI_VERSION))) +LIBFFI_ZIP = libffi-$(LIBFFI_COMMIT).zip +LIBFFI_SRC = libffi +LIBFFI_BUILDDIR = $(CURDIR)/build +LIBFFI_INSTALLDIR = $(CURDIR)/install +APPS_INCDIR = $(APPDIR)$(DELIM)include + +UNPACK ?= unzip -q -o + +# --------------------------------------------------------------------------- +# Derive the autotools --host triplet from the NuttX configuration. +# +# libffi's configure.host matches on patterns such as: +# riscv*-*-* arm*-*-* aarch64*-*-* xtensa*-*-* +# mips*-*-* i?86-*-* x86_64-*-* +# +# We map CONFIG_ARCH (and, for RISC-V, the word-size selectors) to the +# CPU part that libffi expects, then append "-nuttx-elf" as vendor-os. +# --------------------------------------------------------------------------- + +ifeq ($(CONFIG_ARCH),risc-v) + ifeq ($(CONFIG_ARCH_RV64),y) + LIBFFI_CPU = riscv64 + else + LIBFFI_CPU = riscv32 + endif +else ifeq ($(CONFIG_ARCH),arm64) + LIBFFI_CPU = aarch64 +else ifeq ($(CONFIG_ARCH),arm) + LIBFFI_CPU = arm +else ifeq ($(CONFIG_ARCH),xtensa) + LIBFFI_CPU = xtensa +else ifeq ($(CONFIG_ARCH),mips) + LIBFFI_CPU = mips +else ifeq ($(CONFIG_ARCH),x86_64) + LIBFFI_CPU = x86_64 +else ifeq ($(CONFIG_ARCH),x86) + LIBFFI_CPU = i686 +else + LIBFFI_CPU = $(subst -,,$(CONFIG_ARCH)) +endif + +LIBFFI_HOST = $(LIBFFI_CPU)-nuttx-elf + +# --------------------------------------------------------------------------- +# CFLAGS for the libffi build itself. +# +# We start from the NuttX-provided CFLAGS (which already carry -march, +# -mabi, -isystem paths, -D__NuttX__, etc.) and add a few flags that the +# library needs. We deliberately strip -nostdlib because autoconf link +# checks need the default startfiles/libs to succeed. +# --------------------------------------------------------------------------- + +LIBFFI_CFLAGS = $(filter-out -nostdlib -Werror -Werror=% -Wno-cpp,$(CFLAGS)) +LIBFFI_CFLAGS += -ffunction-sections -fdata-sections -O2 + +# --------------------------------------------------------------------------- +# Download, autoreconf, configure, build, install +# --------------------------------------------------------------------------- + +ifeq ($(wildcard $(LIBFFI_SRC)/.git),) + +$(LIBFFI_ZIP): + @echo "Downloading: $(LIBFFI_URL)/$(LIBFFI_COMMIT).zip" + $(Q) curl -L $(LIBFFI_URL)/$(LIBFFI_COMMIT).zip -o $(LIBFFI_ZIP) + +$(LIBFFI_SRC): $(LIBFFI_ZIP) + @echo "Unpacking: $(LIBFFI_ZIP) -> $(LIBFFI_SRC)" + $(Q) $(UNPACK) $(LIBFFI_ZIP) + $(Q) mv libffi-$(LIBFFI_COMMIT) $(LIBFFI_SRC) + +endif + +$(LIBFFI_SRC)/configure: $(LIBFFI_SRC) + @echo "Generating libffi configure script (autoreconf)" + $(Q) (cd $(LIBFFI_SRC) && autoreconf -v -i) + +$(LIBFFI_INSTALLDIR)/lib/libffi.a: $(LIBFFI_SRC)/configure + $(Q) mkdir -p $(LIBFFI_BUILDDIR) + $(Q) ( \ + cd $(LIBFFI_BUILDDIR) && \ + $(CURDIR)/$(LIBFFI_SRC)/configure \ + --host=$(LIBFFI_HOST) \ + --prefix=$(LIBFFI_INSTALLDIR) \ + --disable-shared \ + --enable-static \ + --disable-docs \ + --disable-exec-static-tramp \ + --disable-multi-os-directory \ + CC="$(CC)" \ + CFLAGS="$(LIBFFI_CFLAGS)" \ + AR="$(CROSSDEV)ar" \ + RANLIB="$(CROSSDEV)ranlib" \ + ) + $(MAKE) -C $(LIBFFI_BUILDDIR) -j$(shell nproc) + $(MAKE) -C $(LIBFFI_BUILDDIR) install + +context:: $(LIBFFI_INSTALLDIR)/lib/libffi.a + $(Q) mkdir -p $(APPS_INCDIR) + $(Q) cp $(LIBFFI_INSTALLDIR)/include/*.h $(APPS_INCDIR) + +distclean:: + $(call DELDIR, $(LIBFFI_BUILDDIR)) + $(call DELDIR, $(LIBFFI_INSTALLDIR)) + $(call DELDIR, $(LIBFFI_SRC)) + $(call DELFILE, $(LIBFFI_ZIP)) + $(call DELFILE, $(APPS_INCDIR)/ffi.h) + $(call DELFILE, $(APPS_INCDIR)/ffitarget.h) + +include $(APPDIR)/Application.mk
