diff --git a/makefiles/cargo-settings.inc.mk b/makefiles/cargo-settings.inc.mk index 983c2c1909..25ed2b4bb5 100644 --- a/makefiles/cargo-settings.inc.mk +++ b/makefiles/cargo-settings.inc.mk @@ -1,5 +1,7 @@ -# Setting anything other than "debug" or "release" will necessitate additional -# -Z unstable-options as of 2021-03 nightlies. +# The profile with which to build Rust usually `release` or `dev`. +# +# This needs to be known to the build scripts because the path of the produced +# binary is derived from this. CARGO_PROFILE ?= release # Value for CARGO_CHANNEL when using nightly @@ -42,4 +44,10 @@ CARGO_CHANNEL ?= CARGO_TARGET_DIR = $(BINDIR)/target # The single Rust library to be built. -CARGO_LIB = $(CARGO_TARGET_DIR)/$(RUST_TARGET)/${CARGO_PROFILE}/lib$(APPLICATION_RUST_MODULE).a +# +# The dev->debug and bench->release substitutions represent a historical +# peculiarity in cargo: "For historical reasons, the `dev` and `test` profiles +# are stored in the `debug` directory, and the `release` and `bench` profiles +# are stored in the `release` directory. User-defined profiles are stored in a +# directory with the same name as the profile". +CARGO_LIB = $(CARGO_TARGET_DIR)/$(RUST_TARGET)/$(patsubst test,debug,$(patsubst dev,debug,$(patsubst bench,release,${CARGO_PROFILE})))/lib$(APPLICATION_RUST_MODULE).a diff --git a/makefiles/cargo-targets.inc.mk b/makefiles/cargo-targets.inc.mk index 118cb83f7a..e253784a0f 100644 --- a/makefiles/cargo-targets.inc.mk +++ b/makefiles/cargo-targets.inc.mk @@ -66,7 +66,7 @@ $(CARGO_LIB): $(RIOTBUILD_CONFIG_HEADER_C) $(BUILDDEPS) $(CARGO_COMPILE_COMMANDS cargo $(patsubst +,,+${CARGO_CHANNEL}) \ build \ --target $(RUST_TARGET) \ - `if [ x$(CARGO_PROFILE) = xrelease ]; then echo --release; else if [ x$(CARGO_PROFILE) '!=' xdebug ]; then echo "--profile $(CARGO_PROFILE)"; fi; fi` \ + --profile $(CARGO_PROFILE) \ $(CARGO_OPTIONS) $(APPLICATION_RUST_MODULE).module: $(CARGO_LIB) FORCE