-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Allow build.rs scripts to provide a set of cfg flags to be used when compiling the lib #1478
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
Comments
It's already possible for people to expose environment variables that end users can use to control this kind of behavior, but that's strictly worse than using |
Just ran into this as well while writing libudev bindings. Older versions of libudev are missing |
This commit enables the build script for a crate to provide feedback to the crate itself about how it should be built. This is done through the `--cfg` flags of the compiler, and each build script is now allowed to print `rustc-cfg` directives to inform Cargo about what `--cfg` flags it should pass. All `--cfg` flags are local to the current crate and are not propagated outwards to transitive dependencies. The primary use-case that this feature is targeting is compile-time feature detection for applications like C bindings or C libraries where the version being targeted may change over time. Closes rust-lang#1478
This commit enables the build script for a crate to provide feedback to the crate itself about how it should be built. This is done through the `--cfg` flags of the compiler, and each build script is now allowed to print `rustc-cfg` directives to inform Cargo about what `--cfg` flags it should pass. All `--cfg` flags are local to the current crate and are not propagated outwards to transitive dependencies. The primary use-case that this feature is targeting is compile-time feature detection for applications like C bindings or C libraries where the version being targeted may change over time. Closes rust-lang#1478
This commit enables the build script for a crate to provide feedback to the crate itself about how it should be built. This is done through the `--cfg` flags of the compiler, and each build script is now allowed to print `rustc-cfg` directives to inform Cargo about what `--cfg` flags it should pass. All `--cfg` flags are local to the current crate and are not propagated outwards to transitive dependencies. The primary use-case that this feature is targeting is compile-time feature detection for applications like C bindings or C libraries where the version being targeted may change over time. Closes #1478
Nix needs to be able to be able to detect what the current version of libc provides in order to figure out how to provide bindings. For example, figuring out if eventfd is available, figuring out what flags are supported for various fns, etc...
This detection can be done in the
build.rs
script, however there is no way for this script to provide the results to the compilation stage. Ideally,build.rs
could specify a set of CFG flags that get passed torustc
in order to perform the conditional compilation as required.cc @alexcrichton
The text was updated successfully, but these errors were encountered: