diff mbox series

[meta-lts-mixins,scarthgap/rust,09/11] classes/cargo_common: ensure B is clean

Message ID 201f2082b4da39801247a4e44ed5df98265fc257.1762633051.git.scott.murray@konsulko.com
State New
Headers show
Series Update to Rust 1.90.0 | expand

Commit Message

Scott Murray Nov. 8, 2025, 8:19 p.m. UTC
From: Ross Burton <ross.burton@arm.com>

The cargo class defaults to out-of-tree builds in WORKDIR/build, but
at no point was that directory cleaned.  This causes problems with the
rust standard library recipe (libstd-rs) which installs manually with cp,
so rebuilds can be contaminated with the contents of previous builds.

I believe that post-release we should switch cargo.bbclass to mandating
out-of-tree builds to reduce the complexity, but for now in out-of-tree
builds we can just delete the ${B}/target directory.

Note that we use ${B}/target because there at least were reasons to use
that name[1], it is unclear if these limitations still hold. We can't
simply clean ${B} because that will break recipes that use cargo and
something else to build, for example librsvg.

[1] https://github.com/rust-lang/cargo/pull/1657

(From OE-Core rev: 1452ac7a44196454a52f3f6d883290ddcccfd3f8)

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(adapted from oe-core commit 9d9ce457630ea7403ffe7028e3370647db0b83fa)
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
---
 classes-recipe/cargo_common.bbclass | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/classes-recipe/cargo_common.bbclass b/classes-recipe/cargo_common.bbclass
index c0f6544..db050ca 100644
--- a/classes-recipe/cargo_common.bbclass
+++ b/classes-recipe/cargo_common.bbclass
@@ -110,6 +110,10 @@  cargo_common_do_configure () {
 	# Put build output in build directory preferred by bitbake instead of
 	# inside source directory unless they are the same
 	if [ "${B}" != "${S}" ]; then
+		# We should consider mandating out-of-tree builds and just using [cleandirs]
+		rm -rf ${B}/target
+		mkdir -p ${B}
+
 		cat <<- EOF >> ${CARGO_HOME}/config.toml
 
 		[build]