From 840c2f30db650d23a53f75c46a49b74d06f699f2 Mon Sep 17 00:00:00 2001 From: Shoji Tokunaga Date: Sat, 30 May 2026 02:03:08 +0900 Subject: [PATCH] apps/rust: Add dependencies for Rust cargo in make builds Add a Rust make helper that collects crate input files, and use it for the Rust hello and slint examples. This makes the generated Rust static libraries depend on the crate sources, manifests, build scripts. Hook the libraries into both context and all, so re-running make after editing Rust inputs rebuilds the crate. Signed-off-by: Shoji Tokunaga --- examples/rust/hello/Makefile | 9 ++++++++- examples/rust/slint/Makefile | 9 ++++++++- tools/Rust.mk | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/examples/rust/hello/Makefile b/examples/rust/hello/Makefile index 2c638eb3c..c5af98671 100644 --- a/examples/rust/hello/Makefile +++ b/examples/rust/hello/Makefile @@ -27,9 +27,16 @@ PRIORITY = $(CONFIG_EXAMPLES_HELLO_RUST_CARGO_PRIORITY) STACKSIZE = $(CONFIG_EXAMPLES_HELLO_RUST_CARGO_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_HELLO_RUST_CARGO) -context:: +RUST_LIB := $(call RUST_GET_BINDIR,hello,$(APPDIR)/examples/rust) +RUST_SRCS := $(call RUST_CARGO_SRCS,hello,$(APPDIR)/examples/rust) + +$(RUST_LIB): $(RUST_SRCS) $(call RUST_CARGO_BUILD,hello,$(APPDIR)/examples/rust) +context:: $(RUST_LIB) + +all:: $(RUST_LIB) + clean:: $(call RUST_CARGO_CLEAN,hello,$(APPDIR)/examples/rust) diff --git a/examples/rust/slint/Makefile b/examples/rust/slint/Makefile index 34b444e9d..747f8960b 100644 --- a/examples/rust/slint/Makefile +++ b/examples/rust/slint/Makefile @@ -25,9 +25,16 @@ PRIORITY = $(CONFIG_EXAMPLES_RUST_SLINT_PRIORITY) STACKSIZE = $(CONFIG_EXAMPLES_RUST_SLINT_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_RUST_SLINT) -context:: +RUST_LIB := $(call RUST_GET_BINDIR,slint,$(APPDIR)/examples/rust) +RUST_SRCS := $(call RUST_CARGO_SRCS,slint,$(APPDIR)/examples/rust) + +$(RUST_LIB): $(RUST_SRCS) $(call RUST_CARGO_BUILD,slint,$(APPDIR)/examples/rust) +context:: $(RUST_LIB) + +all:: $(RUST_LIB) + clean:: $(call RUST_CARGO_CLEAN,slint,$(APPDIR)/examples/rust) diff --git a/tools/Rust.mk b/tools/Rust.mk index 90f3615a2..80abe2970 100644 --- a/tools/Rust.mk +++ b/tools/Rust.mk @@ -144,3 +144,18 @@ $(2)/$(1)/target/$(strip $(if $(findstring .json,$(call RUST_TARGET_TRIPLE)), \ $(basename $(notdir $(call RUST_TARGET_TRIPLE))), \ $(call RUST_TARGET_TRIPLE)))/$(if $(CONFIG_DEBUG_FULLOPT),release,debug)/lib$(1).a endef + +# Collect crate input files for a crate +# +# Usage: $(call RUST_CARGO_SRCS,cratename,prefix) +# +# Inputs: +# cratename - Name of the Rust crate (e.g. hello) +# prefix - Path prefix to the crate (e.g. path/to/project) +# +# Output: +# List of crate input files (excluding the cargo target directory) + +define RUST_CARGO_SRCS +$(shell find $(2)/$(1) -type f -not -path '$(2)/$(1)/target/*' 2>/dev/null) +endef