-
Notifications
You must be signed in to change notification settings - Fork 32
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
FEATURES_LOWERCASE
contains features that do not exists
#74
Comments
I'm not convinced that what you describe is the behavior we want in the general case: The additional features you are referring to ( |
It depends on what API do you want to expose. I expect the If you want to keep the behaviour as is, we can consider a new independent field of an accurate list of enabled features of only the compiled crate. |
Is there a public repo for which the behavior you observe is reproducible? |
No, but here is a toy example: # Cargo.toml
[package]
name = "temp"
version = "0.1.0"
edition = "2021"
[dependencies]
pyo3 = { version = "0.23", features = ["auto-initialize"], optional = true }
numpy = { version = "0.23", optional = true }
[build-dependencies]
built = "0.7"
[features]
python = ["pyo3", "numpy"] // build.rs
fn main() {
built::write_built_file().expect("Failed to acquire build-time information");
} // main.rs
mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}
fn main() {
println!("{:?}", built_info::FEATURES_LOWERCASE);
} This is the output with the > cargo run -q --features python
["numpy", "pyo3", "python"] I would expect it to be > cargo run -q --features python
["python"] This example is slightly different than my original description of the issue, but I can't reproduce it exactly in this toy example and im not sure what causes it in my real application, which is not open source. |
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: