https://github.com/taiki-e/cargo-config2
Load and resolve Cargo configuration.
https://github.com/taiki-e/cargo-config2
cargo rust
Last synced: about 1 year ago
JSON representation
Load and resolve Cargo configuration.
- Host: GitHub
- URL: https://github.com/taiki-e/cargo-config2
- Owner: taiki-e
- License: apache-2.0
- Created: 2023-01-09T06:48:55.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-20T17:52:35.000Z (about 1 year ago)
- Last Synced: 2025-04-13T08:19:14.929Z (about 1 year ago)
- Topics: cargo, rust
- Language: Rust
- Homepage: https://docs.rs/cargo-config2
- Size: 598 KB
- Stars: 13
- Watchers: 2
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# cargo-config2
[](https://crates.io/crates/cargo-config2)
[](https://docs.rs/cargo-config2)
[](#license)
[](https://www.rust-lang.org)
[](https://github.com/taiki-e/cargo-config2/actions)
Load and resolve [Cargo configuration](https://doc.rust-lang.org/nightly/cargo/reference/config.html).
This library is intended to accurately emulate the actual behavior of Cargo configuration, for example, this supports the following behaviors:
- [Hierarchical structure and merge](https://doc.rust-lang.org/nightly/cargo/reference/config.html#hierarchical-structure)
- [Environment variables](https://doc.rust-lang.org/nightly/cargo/reference/config.html#environment-variables) and [relative paths](https://doc.rust-lang.org/nightly/cargo/reference/config.html#config-relative-paths) resolution.
- `target.` and `target.` resolution.
Supported tables and fields are mainly based on [cargo-llvm-cov](https://github.com/taiki-e/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`:
```toml
[dependencies]
cargo-config2 = "0.1"
```
`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 `.)
## Examples
```rust
// Read config files hierarchically from the current directory, merge them,
// apply environment variables, and resolve relative paths.
let config = cargo_config2::Config::load().unwrap();
let target = "x86_64-unknown-linux-gnu";
// Resolve target-specific configuration (`target.` and `target.`),
// and returns the resolved rustflags for `target`.
let rustflags = config.rustflags(target).unwrap();
println!("{rustflags:?}");
```
See also the [`get` example](https://github.com/taiki-e/cargo-config2/blob/HEAD/examples/get.rs) that partial re-implementation of `cargo config get` using cargo-config2.
## License
Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or
[MIT license](LICENSE-MIT) 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:
- [`src/cfg_expr`](https://github.com/taiki-e/cargo-config2/tree/HEAD/src/cfg_expr) includes copies and modifications of [`cfg-expr` crate](https://github.com/EmbarkStudios/cfg-expr) by Embark Studios, licensed under "Apache-2.0 OR MIT".
See the license files included in these directories for more details.