From d260ec88a67b71766b34e207af224da6659e38c8 Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 21 Aug 2024 21:47:34 +0200 Subject: [PATCH] makefiles: Add "cargo-command" target for executing cargo Examples of executed commands are `cargo check`, `cargo fix` or `cargo doc`. --- makefiles/cargo-targets.inc.mk | 9 +++++++++ makefiles/info.inc.mk | 1 + 2 files changed, 10 insertions(+) diff --git a/makefiles/cargo-targets.inc.mk b/makefiles/cargo-targets.inc.mk index b327aca47a..d0924fe88c 100644 --- a/makefiles/cargo-targets.inc.mk +++ b/makefiles/cargo-targets.inc.mk @@ -68,6 +68,15 @@ $(CARGO_LIB): cargo-preflight $(RIOTBUILD_CONFIG_HEADER_C) $(BUILDDEPS) $(CARGO_ --profile $(CARGO_PROFILE) \ $(CARGO_OPTIONS) +cargo-command: cargo-preflight $(RIOTBUILD_CONFIG_HEADER_C) $(CARGO_COMPILE_COMMANDS) FORCE + @[ x"$(CARGO_COMMAND)" != x"" ] || ($(COLOR_ECHO) "$(COLOR_RED)Error: Running cargo-command requires a CARGO_COMMAND to be set.$(COLOR_RESET) Set CARGO_COMMAND=\"cargo clippy --release --fix\" or any other cargo command to run with the right RIOT environment."; exit 1) + @# mind the "+" to pass down make's jobserver. + $(Q)+ CC= CFLAGS= CPPFLAGS= CXXFLAGS= \ + RIOT_COMPILE_COMMANDS_JSON="$(CARGO_COMPILE_COMMANDS)" \ + CARGO_BUILD_TARGET="$(RUST_TARGET)" \ + PROFILE="$(CARGO_PROFILE)" \ + $(CARGO_COMMAND) + $(APPLICATION_RUST_MODULE).module: $(CARGO_LIB) FORCE $(Q)# Ensure no old object files persist. These would lead to duplicate $(Q)# symbols, or worse, lingering behaivor of XFA entries. diff --git a/makefiles/info.inc.mk b/makefiles/info.inc.mk index a7b19dc405..d9a09a4ef8 100644 --- a/makefiles/info.inc.mk +++ b/makefiles/info.inc.mk @@ -254,3 +254,4 @@ info-rust: @echo "and export these environment variables:" @echo " RIOT_COMPILE_COMMANDS_JSON=\"$(CARGO_COMPILE_COMMANDS)\"" @echo " RIOTBUILD_CONFIG_HEADER_C=\"$(RIOTBUILD_CONFIG_HEADER_C)\"" + @echo "You can also call cargo related commands with \`make cargo-command CARGO_COMMAND="cargo check"\`; beware that the way the profile is passed in is not consistent across cargo commands, and adding \`--profile $(CARGO_PROFILE)\` as part of CARGO_COMMAND may be necessary."