diff --git a/examples/rust/hello/Makefile b/examples/rust/hello/Makefile index 2c638eb3c44..c5af986713a 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 34b444e9d80..747f8960b86 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 90f3615a201..80abe29704c 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