You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I build the project I do not see the link argument -fsome-artisanal-option passed to the linker. I have confirmed using strace that cargo never opens those config files.
If I run cargo build within one of the crates in the workspace, cargo does parse the .cargo/config.toml. e.g.:
~/cargo-bug$ cd testbin/
~/cargo-bug/testbin$ cargo build
Compiling testbin v0.1.0 (/home/ian/cargo-bug/testbin)
error: linking with `cc` failed: exit status: 1
....
= note: cc: error: unrecognized command line option '-fsome-artisanal-option'
In this example the link error is expected because the -fsome-artisanal-option is not a real linker flag but an example pulled from some rust documentation. The point is that we can see that it is being passed to the linker when we run cargo build from within testbin.
Possible Solution(s)
When building each sub-crate in a workspace, Cargo should check for a .cargo/config.toml within the crate root, and parse and load it when building that specific crate. Options within one sub-crate's .cargo/config.toml should not be passed to another sub-crate.
$ rustup --version
rustup 1.24.2 (755e2b07e 2021-05-12)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.54.0-nightly (cc77ba46f 2021-06-03)`
$ rustc --version
rustc 1.54.0-nightly (cc77ba46f 2021-06-03)
$ cat /etc/issue
Ubuntu 20.04.2 LTS \n \l
The text was updated successfully, but these errors were encountered:
Thanks for the report! Yea, this can be confusing, since cargo always uses the current working directory to find configuration files. This is mostly the same as issue #2930, so I'm going to close in favor of that. Unfortunately it is not so simple to change the behavior since it could break existing workflows, so the path forward is not exactly clear.
Problem
Thanks for creating cargo, it's such a useful build tool.
Unfortunately, I've run into an issue with Cargo workspaces and
.cargo/config.toml
files.In a workspace, Cargo does not respect any per-crate .cargo/config.tomls
Steps
Given a workspace like this, with two default crates generated by cargo:
I created a per-crate .cargo/config.toml like so:
When I build the project I do not see the link argument
-fsome-artisanal-option
passed to the linker. I have confirmed using strace that cargo never opens those config files.If I run cargo build within one of the crates in the workspace, cargo does parse the
.cargo/config.toml
. e.g.:In this example the link error is expected because the
-fsome-artisanal-option
is not a real linker flag but an example pulled from some rust documentation. The point is that we can see that it is being passed to the linker when we runcargo build
from withintestbin
.Possible Solution(s)
When building each sub-crate in a workspace, Cargo should check for a .cargo/config.toml within the crate root, and parse and load it when building that specific crate. Options within one sub-crate's .cargo/config.toml should not be passed to another sub-crate.
Notes
Output of
cargo version
:The text was updated successfully, but these errors were encountered: