From: Ross Burton Date: Mon, 20 Jul 2026 19:45:10 +0000 (+0100) Subject: classes/cargo: remove BUILD_MODE, replace with CARGO_PROFILE X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=d4de7d0256aca47cdb1df48640c37221deaa09d4;p=thirdparty%2Fopenembedded%2Fopenembedded-core.git classes/cargo: remove BUILD_MODE, replace with CARGO_PROFILE The BUILD_MODE variable appears to be a way to select the Cargo build profile that is used, but it can't be assigned because it and other pieces of code base their logic on the value of DEBUG_BUILD. Instead of a BUILD_MODE variable that is "--release" or "" depending on the value of DEBUG_BUILD, replace it with a clear CARGO_PROFILE variable that selects the profile to use. The default has the same behaviour as before: either "release" or "dev" based on DEBUG_BUILD. This profile is then passed to cargo, and used to construct paths in the build tree (with the caveat that the "dev" profile puts files in "debug"). [1] https://doc.rust-lang.org/cargo/reference/profiles.html Signed-off-by: Ross Burton Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Richard Purdie --- diff --git a/meta/classes-recipe/cargo.bbclass b/meta/classes-recipe/cargo.bbclass index 8e05a820af..b34f3ce0cd 100644 --- a/meta/classes-recipe/cargo.bbclass +++ b/meta/classes-recipe/cargo.bbclass @@ -31,18 +31,28 @@ B = "${WORKDIR}/build" export RUST_BACKTRACE = "1" RUSTFLAGS ??= "" -BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}" + +# The cargo profile to use. Defaults to release or dev based on DEBUG_BUILD, but +# can be set to any valid profile. +# https://doc.rust-lang.org/cargo/reference/profiles.html +CARGO_PROFILE ?= "${@oe.utils.vartrue('DEBUG_BUILD', 'dev', 'release', d)}" + # --frozen flag will prevent network access (which is required since only # the do_fetch step is authorized to access network) # and will require an up to date Cargo.lock file. # This force the package being built to already ship a Cargo.lock, in the end # this is what we want, at least, for reproducibility of the build. -CARGO_BUILD_FLAGS = "-v --frozen --target ${RUST_HOST_SYS} ${BUILD_MODE} --manifest-path=${CARGO_MANIFEST_PATH}" +CARGO_BUILD_FLAGS = "-v --frozen --target ${RUST_HOST_SYS} --profile=${CARGO_PROFILE} --manifest-path=${CARGO_MANIFEST_PATH}" + +# The build directory is named after the profile, apart from the dev profile +# which uses 'debug'. +def cargo_build_directory(d): + profile = d.getVar("CARGO_PROFILE") + return "debug" if profile == "dev" else profile +BUILD_DIR = "${@cargo_build_directory(d)}" -# This is based on the content of CARGO_BUILD_FLAGS and generally will need to -# change if CARGO_BUILD_FLAGS changes. -BUILD_DIR = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}" CARGO_TARGET_SUBDIR = "${RUST_HOST_SYS}/${BUILD_DIR}" + oe_cargo_build () { export RUSTFLAGS="${RUSTFLAGS}" bbnote "Using rust targets from ${RUST_TARGET_PATH}"