Bug 15976

Summary: Rust cc crate mixes host flags with target flags
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Gyorgy Sarvari <skandigraun>
Component: devtools / tool chainAssignee: Deepesh Varatharajan <deepesh.varatharajan>
Status: NEW --- QA Contact:
Severity: normal    
Priority: Medium CC: ccasciato, meta.mr.watcher, meta.watcher, randy.macleod, ross.burton, sundeep.kokkonda
Version: unspecified   
Target Milestone: 6.1 M2   
Hardware: All   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Don't know
Attachments:
Description Flags
cc-rs-test.tar.gz none

Description Gyorgy Sarvari 2025-09-18 05:55:09 UTC
A recent update in the cc crate has changed the way C/C++ compiler flags are gathered, it now reads more environment variables than it used to: https://github.com/rust-lang/cc-rs/pull/1401

This now sometimes leads to incorrect results. I have noticed this during a recent Firefox update, which also brought the update of the cc crate: in case the recipe is compiled for the target, but a crate has a build-only dependency on another crate, then the used compiler flags look wrong. Build-only dependencies are compiled for the build-host (which is correct), but the crate reads both the CFLAGS/CXXFLAGS and HOST_CFLAGS/HOST_CXXFLAGS variables (the latter ones are defined by cargo_common.bbclass).

However the former variables contain flags for the target, and the latter flags contain flags for the build host - and after mixing them, the result can be surprising.

Upstream has a bug tracking this also: https://github.com/rust-lang/cc-rs/issues/1469
Comment 1 Randy MacLeod 2025-09-18 14:37:05 UTC
Certain environment variables are passed through to the bitbake system.
We need more info on what happened here and then to decide if we can prevent it.
Comment 2 Randy MacLeod 2026-01-07 19:37:43 UTC
Move to 6.0.

Gyorgy, do you happen to have a simple reproducer or
a suggestion about how we could produce one?
Comment 3 Gyorgy Sarvari 2026-01-07 20:32:39 UTC
Created attachment 5168 [details]
cc-rs-test.tar.gz

The easiest reproduction is to have a Cargo.toml that marks a crate as a build-only dependency - that crate will be compiled with wrong flags (when cross-compiling).

This happens with Firefox and Rust also. (But I gotta admit, both are pretty big for testing this).

I have attached a simple repro. This is a hello world, with a build-dependency that uses cc-rs - the dependency itself is irrelevant.

To see the problem, before compiling set two environment variables:
export HOST_CFLAGS=THIS_SHOULD_NOT_APPEAR_ALONG_WITH_CFLAGS
export CFLAGS=THIS_SHOULD_NOT_APPEAR_WHEN_COMPILING_RING
CC_ENABLE_DEBUG_OUTPUT=1 cargo build -vv

Of course both variables are bogus, but they shouldn't be used together in the same compilation command - and the error you will get will show however that they are used in the same compilation command, when compiling ring crate for the host.