#cargo #config

cargo-config2

Load and resolve Cargo configuration

5 releases

Uses new Rust 2021

new 0.1.4 Jan 28, 2023
0.1.3 Jan 24, 2023
0.1.2 Jan 10, 2023
0.1.1 Jan 9, 2023
0.1.0 Jan 9, 2023

#83 in Configuration

Download history 7060/week @ 2023-01-07 7146/week @ 2023-01-14 6396/week @ 2023-01-21

20,602 downloads per month
Used in 3 crates (2 directly)

Apache-2.0 OR MIT

165KB
3K SLoC

cargo-config2

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.

Usage

Add this to your Cargo.toml:

[dependencies]
cargo-config2 = "0.1"

Compiler support: requires rustc 1.60+

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>.)

Examples

// 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)?;
println!("{rustflags:?}");

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

License

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.

Dependencies

~2.5–3.5MB
~69K SLoC