Skip to content

rustflags in config.toml not being passed to linker in Linux but work fine in windows. #141566

Closed
@ajundi

Description

@ajundi

linker is not using rustflags defined in the config.toml file in LINUX only (it is working fine in windows with same code and rustc version).
I ran the same project in linux and windows and displayed the linker arguments using cargo rustc -- --print=link-args my config.toml inside project's .cargo folder contains the following.

[target.'cfg(all(target_arch = "arm", target_os = "none"))']
rustflags = ["-C", "link-arg=-Tlink.x"]

[build]
target = "thumbv7em-none-eabihf"

In windows I got the following linker args at the end of the linker command
... target\\thumbv7em-none-eabihf\\debug\\deps\\i2c-4754388f49bb4437" "--gc-sections" "-Tlink.x"

In linux this is what I get at the end of my linker args

... target/thumbv7em-none-eabihf/debug/deps/i2c-ce1445d509cca9ef" "--gc-sections"

WORKAROUND:
Manually assigning RUSTFLAGS before running the build command works correctly
RUSTFLAGS="-C link-arg=-Tlink.x" cargo rustc -- --print=link-args

This displayed the correct linker arguments in linux and probe-rs worked great.
......target/thumbv7em-none-eabihf/debug/deps/i2c-9061183c020b57e6" "--gc-sections" "-Tlink.x"

rustc --version --verbose:

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1

I also tried the nightly version same issue.

rustc 1.89.0-nightly (5e16c6620 2025-05-24)
binary: rustc
commit-hash: 5e16c662062fd6dee91f0fe2a1580483488d80cf
commit-date: 2025-05-24
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions