Debian Codegraph @

README.md

raw
1 # cargo-config2
2
3 [![crates.io](https://img.shields.io/crates/v/cargo-config2?style=flat-square&logo=rust)](https://crates.io/crates/cargo-config2)
4 [![docs.rs](https://img.shields.io/badge/docs.rs-cargo--config2-blue?style=flat-square&logo=docs.rs)](https://docs.rs/cargo-config2)
5 [![license](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue?style=flat-square)](#license)
6 [![msrv](https://img.shields.io/badge/msrv-1.85-blue?style=flat-square&logo=rust)](https://www.rust-lang.org)
7 [![github actions](https://img.shields.io/github/actions/workflow/status/taiki-e/cargo-config2/ci.yml?branch=main&style=flat-square&logo=github)](https://github.com/taiki-e/cargo-config2/actions)
8
9 <!-- tidy:sync-markdown-to-rustdoc:start:src/lib.rs -->
10
11 Load and resolve [Cargo configuration](https://doc.rust-lang.org/nightly/cargo/reference/config.html).
12
13 This library is intended to accurately emulate the actual behavior of Cargo configuration, for example, this supports the following behaviors:
14
15 - [Hierarchical structure and merge](https://doc.rust-lang.org/nightly/cargo/reference/config.html#hierarchical-structure)
16 - [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.
17 - `target.<triple>` and `target.<cfg>` resolution.
18
19 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.
20
21 ## Usage
22
23 Add this to your `Cargo.toml`:
24
25 ```toml
26 [dependencies]
27 cargo-config2 = "0.1"
28 ```
29
30 `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>`.)
31
32 ## Examples
33
34 ```rust
35 // Read config files hierarchically from the current directory, merge them,
36 // apply environment variables, and resolve relative paths.
37 let config = cargo_config2::Config::load().unwrap();
38 let target = "x86_64-unknown-linux-gnu";
39 // Resolve target-specific configuration (`target.<triple>` and `target.<cfg>`),
40 // and returns the resolved rustflags for `target`.
41 let rustflags = config.rustflags(target).unwrap();
42 println!("{rustflags:?}");
43 ```
44
45 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.
46
47 <!-- tidy:sync-markdown-to-rustdoc:end -->
48
49 ## License
50
51 Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or
52 [MIT license](LICENSE-MIT) at your option.
53
54 Unless you explicitly state otherwise, any contribution intentionally submitted
55 for inclusion in the work by you, as defined in the Apache-2.0 license, shall
56 be dual licensed as above, without any additional terms or conditions.
57
58 ### Third party software
59
60 This product includes copies and modifications of software developed by third parties:
61
62 - [`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".
63
64 See the license files included in these directories for more details.