#cargo #config


Load and resolve Cargo configuration

17 releases

0.1.16 Nov 17, 2023
0.1.12 Sep 14, 2023
0.1.8 Jul 3, 2023
0.1.6 Mar 7, 2023

#47 in Filesystem

Download history 9796/week @ 2023-08-15 12136/week @ 2023-08-22 10809/week @ 2023-08-29 11302/week @ 2023-09-05 12127/week @ 2023-09-12 11212/week @ 2023-09-19 12681/week @ 2023-09-26 12728/week @ 2023-10-03 12040/week @ 2023-10-10 19098/week @ 2023-10-17 16887/week @ 2023-10-24 16820/week @ 2023-10-31 16504/week @ 2023-11-07 19855/week @ 2023-11-14 15680/week @ 2023-11-21 15303/week @ 2023-11-28

70,412 downloads per month
Used in 11 crates (6 directly)

Apache-2.0 OR MIT



crates.io docs.rs license rustc build status

Load and resolve Cargo configuration.

This library is intended to accurately emulate the actual behavior of Cargo configuration, for example, this supports the following behaviors:

Supported tables and fields are mainly based on cargo-llvm-cov's use cases, but feel free to submit an issue if you see something missing in your use case.


Add this to your Cargo.toml:

cargo-config2 = "0.1"

Compiler support: requires rustc 1.67+

cargo-config2 is usually runnable with Cargo versions older than the Rust version required for build. (e.g., a cargo subcommand using cargo-config2 could work with older versions such as cargo +1.59 <subcommand>.)


// Read config files hierarchically from the current directory, merge them,
// apply environment variables, and resolve relative paths.
let config = cargo_config2::Config::load()?;
let target = "x86_64-unknown-linux-gnu";
// Resolve target-specific configuration (`target.<triple>` and `target.<cfg>`),
// and returns the resolved rustflags for `target`.
let rustflags = config.rustflags(target)?;

See also the get example that partial re-implementation of cargo config get using cargo-config2.


Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Third party software

This product includes copies and modifications of software developed by third parties:

See the license files included in these directories for more details.


~103K SLoC