From patchwork Mon Nov 16 23:12:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Murray X-Patchwork-Id: 104574 Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.6319.1794870789446552737 for ; Mon, 16 Nov 2026 15:13:09 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@konsulko.com header.s=google header.b=O0gbWQ6j; spf=pass (domain: konsulko.com, ip: 209.85.221.177, mailfrom: scott.murray@konsulko.com) Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-5ec20398b05so4061284e0c.1 for ; Mon, 16 Nov 2026 15:13:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; t=1794870788; x=1795475588; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=7Hd2WjwCeNMWBIxKd0vP44ABcuATK0QxPbUhq32VZM8=; b=O0gbWQ6joiIG1cig/e9XhRnXGuL0V3t/bW5iICv7F7ASam9hC33JDEEohbVxHNRj5H 3qhIalxcLDsYIaNd/7DlKpDxqW/BMhedbTI3Vt+5kUMZQInDTdWAGE1lFh/1w4NJSKEF vnt7+/xrCJ9wz18gn8DuLMigJ/odjr26XkIZ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794870788; x=1795475588; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=7Hd2WjwCeNMWBIxKd0vP44ABcuATK0QxPbUhq32VZM8=; b=miQEFaJ5SHQnPO//NKvgs8UJbi25HnqnREqIRDICSESTVfLzPNHbvuXC9uuW6TX8sy 9o+zdry0ga8LEfrmw+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pSw2xNydC3QfErId3FPI/gKtev fxDaApI1Paw7kCVXJPlLUCxDRTPN/z8Aa3vuagfMXCGduBSISRlVQMw/0wmL2B4GzzQ== X-Received: by 2002:a05:6122:2094:b0:5ea:e18b:32e3 with SMTP id 71dfb90a1353d-5ee34aa1142mr4672940e0c.15.1794870788159; Mon, 16 Nov 2026 15:13:08 -0800 (PST) Return-Path: Received: from ghidorah.spiteful.org (107-179-213-3.cpe.teksavvy.com. [107.179.213.3]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5ee34e9516dsm7575235e0c.12.2026.11.16.15.13.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2026 15:13:07 -0800 (PST) From: Scott Murray To: yocto-patches@lists.yoctoproject.org Subject: [meta-lts-mixins][wrynose/rust][PATCH 19/19] ptest-cargo: align test and application build environments Date: Mon, 16 Nov 2026 18:12:40 -0500 Message-ID: <016354f64984a6de91edc792fe77d77ff3c2ac04.1794870526.git.scott.murray@konsulko.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Mon, 16 Nov 2026 23:13:13 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/5458 From: Vasileios Anagnostopoulos do_compile runs oe_cargo_fix_env before invoking cargo. That function points cargo and the crate build scripts at the cross toolchain correctly. do_compile_ptest_cargo spawned cargo from python with only RUSTFLAGS set, so every build script that still had to run for the test build (e.g. dev-dependencies, test-only features, etc) saw the plain task environment. The test binaries were therefore built in a different, and for cross builds wrong, environment than the application. Run the test build through oe_cargo_fix_env as well so both builds share one environment. Co-authored-by: Patrick Wicki Signed-off-by: Vasileios Anagnostopoulos Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Richard Purdie (adapted from oe-core commit 81ace97afd065c8c6b9753451f6b62b2400f008d) Signed-off-by: Scott Murray --- classes-recipe/ptest-cargo.bbclass | 35 ++++++++++-------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/classes-recipe/ptest-cargo.bbclass b/classes-recipe/ptest-cargo.bbclass index 62444e9..5cdd1c4 100644 --- a/classes-recipe/ptest-cargo.bbclass +++ b/classes-recipe/ptest-cargo.bbclass @@ -5,39 +5,28 @@ RUST_TEST_ARGS[doc] = "Arguments to give to the test binaries (e.g. --shuffle)" # I didn't find a cleaner way to share data between compile and install tasks CARGO_TEST_BINARIES_FILES ?= "${B}/test_binaries_list" +CARGO_TEST_BUILD_JSON ?= "${B}/cargo_test_build.json" + +# Build the tests with the same environment as do_compile (oe_cargo_fix_env). +cargo_ptest_build () { + oe_cargo_fix_env + export RUSTFLAGS="${RUSTFLAGS}" + bbnote "Building tests with cargo" + "${CARGO}" build --tests --message-format json-render-diagnostics ${CARGO_BUILD_FLAGS} ${PACKAGECONFIG_CONFARGS} > "${CARGO_TEST_BUILD_JSON}" +} # Sadly, generated test binaries have no deterministic names (https://github.com/rust-lang/cargo/issues/1924) # This forces us to parse the cargo output in json format to find those test binaries. python do_compile_ptest_cargo() { - import subprocess import json - cargo = bb.utils.which(d.getVar("PATH"), d.getVar("CARGO")) - cargo_build_flags = d.getVar("CARGO_BUILD_FLAGS") - packageconfig_confargs = d.getVar("PACKAGECONFIG_CONFARGS") - rust_flags = d.getVar("RUSTFLAGS") manifest_path = d.getVar("CARGO_MANIFEST_PATH") project_manifest_path = os.path.normpath(manifest_path) manifest_dir = os.path.dirname(manifest_path) - env = os.environ.copy() - env['RUSTFLAGS'] = rust_flags - cmd = f"{cargo} build --tests --message-format json {cargo_build_flags} {packageconfig_confargs}" - bb.note(f"Building tests with cargo ({cmd})") - - try: - proc = subprocess.Popen(cmd, shell=True, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) - except subprocess.CalledProcessError as e: - bb.fatal(f"Cannot build test with cargo: {e}") - - lines = [] - for line in proc.stdout: - data = line.strip('\n') - lines.append(data) - bb.note(data) - proc.communicate() - if proc.returncode != 0: - bb.fatal(f"Unable to compile test with cargo, '{cmd}' failed") + bb.build.exec_func("cargo_ptest_build", d) + with open(d.getVar("CARGO_TEST_BUILD_JSON")) as f: + lines = f.read().splitlines() # Definition of the format: https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages test_bins = []