# Cargo --config KEY=VALUE is not effective

**URL:** <https://users.rust-lang.org/t/cargo-config-key-value-is-not-effective/103889>\
**Category:** help\
**Created:** [December 13, 2023, 2:35pm UTC](https://users.rust-lang.org/t/cargo-config-key-value-is-not-effective/103889 "2023-12-13T14:35:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![UmeshKalappa0](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/umeshkalappa0/32/37732_2.png) [@UmeshKalappa0](https://users.rust-lang.org/u/UmeshKalappa0)\
**Post date:** [December 13, 2023, 2:35pm UTC](https://users.rust-lang.org/t/cargo-config-key-value-is-not-effective/103889/1 "2023-12-13T14:35:10Z")

</div>

We have the hello world sample and added dependency rand like

```rust
cargo add rand 

```

then Cargo.toml looks like

$cat Cargo.toml

```rust
[package]
name = "hello"
version = "0.1.0"
edition = "2021"

[dependencies]
rand = "0.8.5"

```

and we are trying to pass the linker option for rustc through the cargo like

```rust
$cargo --config 'build.rustflags = ["-L /<path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/bin/../lib/rustlib/aarch64-wrs-vxworks/lib/ -L <path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/"]' build --verbose

```

rand has the dependency like libc and cargo try to build and fails like

```rust
Some errors have detailed explanations: E0408, E0412, E0425, E0463, E0531.
For more information about an error, try `rustc --explain E0408`.
error: could not compile `libc` (build script) due to 50 previous errors

rustc --crate-name build_script_build CARGO_HOME/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.151/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=138 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=97b99bae06b5ff0f -C extra-filename=-97b99bae06b5ff0f --out-dir /<path>/rust/hello/target/debug/build/libc-97b99bae06b5ff0f -L dependency=/<path>/rust/hello/target/debug/deps --cap-lints allow

```

note that from 1.70.0 rustc or cargo needs to pass the "-L/rustlib/" target libs path manually and before pervious version are working fine without ,hence we tried to pass through cargo like --config or RUSTFLAGS ,which is not effective and cargo is not passing to rustc like mentioned above ...

any suggestions here to avoid these errors or how we make cargo search the target libs by default without manually intervention from command-line /RUSTFLAGS/ etc ?

like

> export RUSTFLAGS="-L \<path\>/rust-1.70.0.0/x86\_64-unknown-linux-gnu/bin/../lib/rustlib/aarch64-wrs-vxworks/lib/ -L \<path\>rust-1.70.0.0/x86\_64-unknown-linux-gnu/lib/rustlib/x86\_64-unknown-linux-gnu/lib/"

```rust
   Compiling libc v0.2.151
   Compiling cfg-if v1.0.0
   Compiling ppv-lite86 v0.2.17
     
  Running `rustc --crate-name cfg_if --edition=2018 <path>/rust/../../usr/rust/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cfg-if-1.0.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=138 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=1f5677bb9cb2f9d9 -C extra-filename=-1f5677bb9cb2f9d9 --out-dir <path>/rust/hello/target/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -L dependency=<path>/rust/hello/target/x86_64-unknown-linux-gnu/debug/deps -L dependency=/<path>/rust/hello/target/debug/deps --cap-lints allow -L <path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/bin/../lib/rustlib/aarch64-wrs-vxworks/lib/ -L<path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/`
  Running `rustc --crate-name ppv_lite86 --edition=2018 <path>/rust/../../usr/rust/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ppv-lite86-0.2.17/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=138 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="simd"' --cfg 'feature="std"' -C metadata=3911f71223ba48c3 -C extra-filename=-3911f71223ba48c3 --out-dir <path>/hello/target/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -L dependency=<path>/rust/hello/target/x86_64-unknown-linux-gnu/debug/deps -L dependency=/<path>/rust/hello/target/debug/deps --cap-lints allow -L /<path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/bin/../lib/rustlib/aarch64-wrs-vxworks/lib/ -L /<path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/`
  Running `rustc --crate-name build_script_build <path>/rust/../../usr/rust/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.151/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=138 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=97b99bae06b5ff0f -C extra-filename=-97b99bae06b5ff0f --out-dir /<path>/rust/hello/target/debug/build/libc-97b99bae06b5ff0f -L dependency=/<path>/rust/hello/target/debug/deps --cap-lints allow`
     

```

no luck also with

```rust
cargo rustc -- "-L /<path>/rust-1.70.0.0/x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/ "

```

from above cargo verbose ,you see that the library search was appended to CFG-IF and PPV-lite86 compilation ,but "-L " was not passed to LIBC compilation.

any inputs from experts will helps us to debug the issue further ,thanks in advance

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/bjorn3/32/5255_2.png) [@bjorn3](https://users.rust-lang.org/u/bjorn3)\
**Post date:** [December 13, 2023, 4:56pm UTC](https://users.rust-lang.org/t/cargo-config-key-value-is-not-effective/103889/2 "2023-12-13T16:56:25Z")

</div>

Why are you trying to pass this rustc argument in the first place? Rustc will find the standard library on it's own and cargo will pass it for all dependencies you explicitly declare. You should never need to add an rlib dependency behind cargo's back.

> [@UmeshKalappa0](#):
>
> rand has the dependency like libc and cargo try to build and fails like

You are missing the part with the actual error. Can you post that?

---

<div class="post-metadata">

**Author:** ![UmeshKalappa0](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/umeshkalappa0/32/37732_2.png) [@UmeshKalappa0](https://users.rust-lang.org/u/UmeshKalappa0)\
**Post date:** [December 13, 2023, 5:17pm UTC](https://users.rust-lang.org/t/cargo-config-key-value-is-not-effective/103889/3 "2023-12-13T17:17:32Z")

</div>

@bjorn3 ,thank you for coming back and yes rustc version like 1.64 was finding the std lib on its own ,but not with rustc 1.70.0 and issue we seen like

```rust
cargo build --target aarch64-wrs-vxworks --verbose
   Compiling libc v0.2.151
   Compiling cfg-if v1.0.0
   Compiling ppv-lite86 v0.2.17
     Running `rustc --crate-name cfg_if --edition=2018 /folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/../../usr/rust/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cfg-if-1.0.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=138 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=94c41ef99b5090bf -C extra-filename=-94c41ef99b5090bf --out-dir /folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/hello/target/aarch64-wrs-vxworks/debug/deps --target aarch64-wrs-vxworks -L dependency=/folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/hello/target/aarch64-wrs-vxworks/debug/deps -L dependency=/folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/hello/target/debug/deps --cap-lints allow -L /folk/prj-rust-dev/umesh/vxworks/vx7-2309-features/compilers/rust-1.70.0.0/x86_64-unknown-linux-gnu/bin/../lib/rustlib/aarch64-wrs-vxworks/lib/`
     Running `rustc --crate-name ppv_lite86 --edition=2018 /folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/../../usr/rust/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ppv-lite86-0.2.17/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=138 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="simd"' --cfg 'feature="std"' -C metadata=9c465ec463cac700 -C extra-filename=-9c465ec463cac700 --out-dir /folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/hello/target/aarch64-wrs-vxworks/debug/deps --target aarch64-wrs-vxworks -L dependency=/folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/hello/target/aarch64-wrs-vxworks/debug/deps -L dependency=/folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/hello/target/debug/deps --cap-lints allow -L /folk/prj-rust-dev/umesh/vxworks/vx7-2309-features/compilers/rust-1.70.0.0/x86_64-unknown-linux-gnu/bin/../lib/rustlib/aarch64-wrs-vxworks/lib/`

Running `rustc --crate-name build_script_build /folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/../../usr/rust/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.151/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=138 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=97b99bae06b5ff0f -C extra-filename=-97b99bae06b5ff0f --out-dir /folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/hello/target/debug/build/libc-97b99bae06b5ff0f -L dependency=/folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/hello/target/debug/deps --cap-lints allow`
error[E0463]: can't find crate for `std`

error: cannot find macro `panic` in this scope
   --> /folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/../../usr/rust/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.151/build.rs:192:25
    |
192 | None => panic!("Failed to get rustc version"),
    | ^^^^^
...
197 | let rustc = otry!(env::var_os("RUSTC"));
    | --------------------------- in this macro invocation
    |
    = note: this error originates in the macro `otry` (in Nightly builds, run with -Z macro-backtrace for more info)

error: cannot find macro `panic` in this scope
   --> /folk/prj-rust-dev/umesh/vxworks/vsb/usr/rust/../../usr/rust/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.151/build.rs:192:25
    |
192 | None => panic!("Failed to get rustc version"),
    | ^^^^^
...
210 | let version = otry!(str::from_utf8(&output.stdout).ok());

```

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/bjorn3/32/5255_2.png) [@bjorn3](https://users.rust-lang.org/u/bjorn3)\
**Post date:** [December 13, 2023, 5:48pm UTC](https://users.rust-lang.org/t/cargo-config-key-value-is-not-effective/103889/4 "2023-12-13T17:48:11Z")

</div>

> [@UmeshKalappa0](#):
>
> and yes rustc version like 1.64 was finding the std lib on its own ,but not with rustc 1.70.0

What does `rustc --print sysroot` show?

> [@UmeshKalappa0](#):
>
> and issue we seen like

The rustflags probably don't get applied to build scripts. This is normal behavior when cross-compiling.

---

<div class="post-metadata">

**Author:** ![UmeshKalappa0](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/umeshkalappa0/32/37732_2.png) [@UmeshKalappa0](https://users.rust-lang.org/u/UmeshKalappa0)\
**Post date:** [December 14, 2023, 2:55am UTC](https://users.rust-lang.org/t/cargo-config-key-value-is-not-effective/103889/5 "2023-12-14T02:55:58Z")

</div>

> [@bjorn3](#):
>
> `rustc --print sysroot`

@bjorn3 ,

> > What does `rustc --print sysroot` show?

/folk/prj-rust-dev/umesh/vxworks/vx7-2309-features

and it was expected like

/folk/prj-rust-dev/umesh/vxworks/vx7-2309-features/compilers/rust-1.70.0.0/x86\_64-unknown-linux-gnu

does we can over-ride sysroot from cargo ,that has effect on build.rs file too ?

> > The rustflags probably don't get applied to build scripts.

ok ,but manual says other way like ever rustc or compiler invocation from cargo these flags are passed .

and by looking at code like [cargo/src/cargo/core/compiler/build\_context/target\_info.rs at 69aea5b6f69add7c51cca939a79644080c0b0ba0 · rust-lang/cargo · GitHub](https://github.com/rust-lang/cargo/blob/69aea5b6f69add7c51cca939a79644080c0b0ba0/src/cargo/core/compiler/build_context/target_info.rs#L396) ,you are right the RUSTFLAGS are not passed to build scripts and plugins .

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/bjorn3/32/5255_2.png) [@bjorn3](https://users.rust-lang.org/u/bjorn3)\
**Post date:** [December 14, 2023, 10:35am UTC](https://users.rust-lang.org/t/cargo-config-key-value-is-not-effective/103889/6 "2023-12-14T10:35:42Z")

</div>

> [@UmeshKalappa0](#):
>
> does we can over-ride sysroot from cargo ,that has effect on build.rs file too ?

You can pass `--sysroot /path/to/sysroot` to rustc to set the sysroot, but that doesn't help if you can't pass flags to rustc for build scripts. Something which I know of the top of my head that should work is to write a shell script which wraps rustc and passes `--sysroot` and then set the `RUSTC` env var to the path to this shell script. `RUSTC` is not ignored for build scripts when cross-compiling unlike `RUSTFLAGS`.

> [@UmeshKalappa0](#):
>
> /folk/prj-rust-dev/umesh/vxworks/vx7-2309-features
> 
> and it was expected like
> 
> /folk/prj-rust-dev/umesh/vxworks/vx7-2309-features/compilers/rust-1.70.0.0/x86\_64-unknown-linux-gnu

Did you set any flags in config.toml when compiling the toolchain? A while ago there was a change to how the sysroot is found. I don't remember if that change was already in 1.64 though, but if not it could be that this change breaks on a flag you set in config.toml.

---

<div class="post-metadata">

**Author:** ![UmeshKalappa0](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/umeshkalappa0/32/37732_2.png) [@UmeshKalappa0](https://users.rust-lang.org/u/UmeshKalappa0)\
**Post date:** [December 14, 2023, 3:06pm UTC](https://users.rust-lang.org/t/cargo-config-key-value-is-not-effective/103889/7 "2023-12-14T15:06:46Z")

</div>

> [@bjorn3](#):
>
> Did you set any flags in config.toml when compiling the toolchain? A while ago there was a change to how the sysroot is found. I don't remember if that change was already in 1.64 though, but if not it could be that this change breaks on a flag you set in config.toml.

Not exaclty not remembering making any changes to config.toml ,please let me know if you come across the sysroot changes like stated ,till then will using the wrapper script for rustc .

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [March 13, 2024, 3:07pm UTC](https://users.rust-lang.org/t/cargo-config-key-value-is-not-effective/103889/8 "2024-03-13T15:07:31Z")

</div>

Closed on March 13, 2024, 3:07pm UTC

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
