1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//! Designed to help create good build scripts, with a focus on ease of use for you,
//! valuable output in cargo build -vv & no annoying surprises for anyone downstream.
//!
//! # Usage
//!
//! ```rust, no_run
//! # use indexmap::IndexSet;
//! use build_safely::prelude::*;
//!
//! // Result uses BuildError to give meaningful messages
//! fn main() -> Result<()> {
//!
//! // get an environment variable and re-run build script if it changes.
//! let my_var: String = get_var("MY_VAR")?;
//!
//! // get values from an environment variable, separated by the
//! // OS path separator and re-run build script if it changes.
//! let my_vals: IndexSet<String> = split_var("MY_VALUES")?;
//! if my_vals.contains("some_value") {
//! unimplemented!("do something")
//! }
//!
//! // get a new AutoCfg or provide a valuable error
//! // rather than panicking.
//! let ac = AutoCfg::new()?;
//!
//! // check to see if the downstream crate has defined
//! // `unstable.allow-features` in `.cargo/config.toml`.
//! // It is mandatory to perform this check and pass the
//! // result to any calls to `emit_unstable_feature`
//! let allowed_features = cargo_allowed_features()?;
//!
//! // We want to make use of `assert_matches` if it is available
//! ac.emit_unstable_feature(assert_matches, &allowed_features);
//! // ^^^^^^^^^^^^^^ - enum variant to avoid typos
//!
//! Ok(())
//! }
//! ```
//!
//! # Prelude
//!
//! ```rust
//! use build_safely::prelude::*;
//! ```
//!
//! provides:
//!
//! - A [`Result`] alias & [`BuildError`] type that gives meaningful output from `main() -> Result<()>`.
//! - [`get_var()`] & [`split_var()`] which automatically register `cargo::rerun-if-env-changed`
//! and include the variable name in any errors.
//! - [`emit_unstable_feature()`](nightly::Nightly::emit_unstable_feature),
//! [`cargo_allowed_features`](nightly::cargo_allowed_features) &
//! enum [`UnstableFeature`](nightly::UnstableFeature) to provide a safe way to identify the
//! availability of nightly features & handle the future stabilisation process without additional
//! effort on your part. All while respecting any `allow-features` whitelists.
//!
use ;
use IndexSet;
/// Recommended prelude: `use build_safely::prelude::*`
///
/// - A [`Result`] alias & [`BuildError`] type that gives meaningful output from `main() -> Result<()>`.
/// - [`get_var()`] & [`split_var()`] which automatically register `cargo::rerun-if-env-changed`
/// and include the variable name in any errors.
/// - [`emit_unstable_feature()`](nightly::Nightly::emit_unstable_feature),
/// [`cargo_allowed_features`](nightly::cargo_allowed_features) &
/// enum [`UnstableFeature`](nightly::UnstableFeature) to provide a safe way to identify the
/// availability of nightly features & handle the future stabilisation process without additional
/// effort on your part. All while respecting any `allow-features` whitelists.
/// Attempt to get an environment variable, re-run build if it changes or provide a meaningful
/// error if missing.
///
/// - Emits `cargo::rerun-if-env-changed=key` to ensure changes trigger a rebuild.
/// - If not found the error returned will include the key name in the debug representation.
/// Attempt to get an environment variable and split the values using the OS path separator,
/// re-run build if it changes or provide a meaningful error if missing.
///
/// - Emits `cargo::rerun-if-env-changed=key` to ensure changes trigger a rebuild.
/// - If not found the error returned will include the key name in the debug representation.
/// - Returns an [IndexSet] which implements `.contains()` AND retains ordering
/// Result type wrapping [BuildError]. Using `main() -> Result<()>` in `build.rs` will
/// provide useful information in the debug representation sent to stderr on failure.
pub type Result<T> = Result;
/// An error designed to have nice debug representations for common errors encountered
/// in build.rs
/// Generate your own with `Err("some text")`
/// Generate your own with `Err(String)`