You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The FEATURES_LOWERCASE static variable is created by searching for env variables with prefix CARGO_FEATURE_, and parsing the suffixes to extract features names.
Its correct that every feature has such env variable, but not each such env variable is a real enabled feature.
For example, when I compile my executable I get these additional features that are not part of my crate:
"libc","numpy","pyo3"
I can't say why these environment variables were on, but its not due to exports in bashrc or something like that, probably env variables manipulations by my dependencies build scripts.
Anyway, I think a better approach is to parse Cargo.toml and extract all of the possible features of the current built crate, and than check if there is an env variable called format!(CARGO_FEATURE_{}", feature.to_uppercase().replace("-", "_")).
This is how I do it in my build.rs:
fnenabled_features() -> Vec<String>{let cargo_toml = Path::new(&env!("CARGO_MANIFEST_DIR")).join("Cargo.toml");
fs::read_to_string(cargo_toml).expect("Failed to read Cargo.toml").parse::<toml::Table>().expect("Failed to parse Cargo.toml").into_iter().flat_map(|features| {
features
.as_table().expect("features must be a table").keys().filter(|k| *k != "default").cloned()}).filter(|f| {
env::var(format!("CARGO_FEATURE_{}",
f.to_uppercase().replace("-", "_"))).is_ok()}).collect()}
The text was updated successfully, but these errors were encountered:
The
FEATURES_LOWERCASE
static variable is created by searching for env variables with prefixCARGO_FEATURE_
, and parsing the suffixes to extract features names.Its correct that every feature has such env variable, but not each such env variable is a real enabled feature.
For example, when I compile my executable I get these additional features that are not part of my crate:
I can't say why these environment variables were on, but its not due to exports in
bashrc
or something like that, probably env variables manipulations by my dependencies build scripts.Anyway, I think a better approach is to parse
Cargo.toml
and extract all of the possible features of the current built crate, and than check if there is an env variable calledformat!(CARGO_FEATURE_{}", feature.to_uppercase().replace("-", "_"))
.This is how I do it in my
build.rs
:The text was updated successfully, but these errors were encountered: