-
Notifications
You must be signed in to change notification settings - Fork 344
esp-config #2156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+731
−179
Merged
esp-config #2156
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
cfc972e
Initial esp-config poc, replacing the place-spi-driver-in-ram feature
MabezDev 9a0bdd4
Allow documentation generation for configuration options
MabezDev 0ba6677
add `Value::Number` and a macro to parse
MabezDev aa3f19d
Add Value::String and replace esp-wifi's config
MabezDev b28e291
repo maint
MabezDev fc9dc71
make bool parsing stricter and number parsing more flexible
MabezDev 915e542
use hand rolled const str to int
MabezDev bea819a
Collect unknown config options
MabezDev c48f26f
friendly errors
MabezDev ad30276
also batch invalid values
MabezDev 50b2485
dump msrv to 1.79
MabezDev 82bb385
Mention perf boost from disabling logging
MabezDev 864c9ce
review suggestions
MabezDev 3153f89
output selected config
MabezDev aa01e9c
changelogs and migration guides
MabezDev 22231a7
review feedback
MabezDev 27152b0
avoid multiple case conversions where possible
MabezDev 71a8aa1
refactor generate, fix bug, add full test
MabezDev 07de843
run host tests in CI
MabezDev 03a5cf1
add more esp-config tests
MabezDev 413b67b
review comments
MabezDev 239c379
add cargo env workaround
MabezDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "esp-config" | ||
version = "0.1.0" | ||
edition = "2021" | ||
rust-version = "1.79.0" | ||
|
||
[dependencies] | ||
document-features = "0.2.10" | ||
|
||
[dev-dependencies] | ||
temp-env = "0.3.6" | ||
|
||
[features] | ||
## Enable the generation and parsing of a config | ||
build = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# esp-config | ||
|
||
[](https://crates.io/crates/esp-config) | ||
[](https://docs.rs/esp-config) | ||
 | ||
 | ||
[](https://matrix.to/#/#esp-rs:matrix.org) | ||
|
||
## [Documentation](https://docs.rs/crate/esp-config) | ||
|
||
## Usage | ||
|
||
`esp-config` takes a prefix (usually the crate name) and a set of configuration keys and default values to produce a configuration system that supports: | ||
|
||
- Emitting rustc cfg's for boolean keys | ||
- Emitting environment variables for numbers | ||
- Along with decimal parsing, it supports Hex, Octal and Binary with the respective `0x`, `0o` and `0b` prefixes. | ||
- Emitting environment variables string values | ||
|
||
### Viewing the configuration | ||
|
||
The possible configuration values are output as a markdown table in the crates `OUT_DIR` with the format `{prefix}_config_table.md`, this can then be included into the crates top level documentation. Here is an example of the output: | ||
|
||
|
||
| Name | Description | Default value | | ||
|------|-------------|---------------| | ||
|**ESP_HAL_PLACE_SPI_DRIVER_IN_RAM**|Places the SPI driver in RAM for better performance|false| | ||
|
||
### Setting configuration options | ||
|
||
For any available configuration option, the environment variable or cfg is _always_ set based on the default value specified in the table. Users can override this by setting environment variables locally in their shell _or_ the preferred option is to utilize cargo's [`env` section](https://doc.rust-lang.org/cargo/reference/config.html#env). | ||
|
||
It's important to note that due to a [bug in cargo](https://github.com/rust-lang/cargo/issues/10358), any modifications to the environment, local or otherwise will only get picked up on a full clean build of the project. | ||
MabezDev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
To see the final selected configuration another table is output to the `OUT_DIR` with the format `{prefix}_selected_config.md`. | ||
|
||
### Capturing configuration values in the downstream crate | ||
|
||
For all supported data types, there are helper macros that emit `const` code for parsing the configuration values. | ||
|
||
- Numbers - `esp_config_int!(integer_type, "ENV")` | ||
- Strings - `esp_config_str!("ENV")` | ||
- Bool - `esp_config_bool!("ENV")` | ||
|
||
In addition to environment variables, for boolean types rust `cfg`'s are emitted in snake case _without_ the prefix. | ||
|
||
## Minimum Supported Rust Version (MSRV) | ||
|
||
This crate is guaranteed to compile on stable Rust 1.79 and up. It _might_ | ||
compile with older versions but that may change in any new patch release. | ||
|
||
## License | ||
|
||
Licensed under either of: | ||
|
||
- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) | ||
- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) | ||
|
||
at your option. | ||
|
||
### Contribution | ||
|
||
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. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.