[meta-lts-mixins][scarthgap/rust][PATCH 35/35] classes/cargo: remove BUILD_MODE, replace with CARGO_PROFILE
Scott Murray <[email protected]> Fri, 31 Jul 2026 07:33:05 -0400
| Newsgroups | org.yoctoproject.lists.yocto-patches |
|---|---|
| Message-ID | <9987a76095ee751864e55e418539f42b9c3b8a6b.1785496469.git.scott.murray@konsulko.com> |
From: Ross Burton <[email protected]> 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 <[email protected]> Signed-off-by: Mathieu Dubois-Briand <[email protected]> Signed-off-by: Richard Purdie <[email protected]> (adapted from oe-core commit d4de7d0256aca47cdb1df48640c37221deaa09d4) Signed-off-by: Scott Murray <[email protected]> --- classes-recipe/cargo.bbclass | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/classes-recipe/cargo.bbclass b/classes-recipe/cargo.bbclass index 8e05a82..b34f3ce 100644 --- a/classes-recipe/cargo.bbclass +++ b/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}" -- 2.55.0