Skip to content

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

Closed
carllerche opened this issue Apr 3, 2015 · 2 comments · Fixed by #1505
Closed
Labels
A-configuration Area: cargo config files and env vars P-high Priority: High

Comments

@carllerche
Copy link
Member

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 to rustc in order to perform the conditional compilation as required.

cc @alexcrichton

@wycats
Copy link
Contributor

wycats commented Apr 4, 2015

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 cfg and abstracting common cfgs via the build script.

@alexcrichton alexcrichton added P-high Priority: High A-configuration Area: cargo config files and env vars labels Apr 4, 2015
@dcuddeback
Copy link

Just ran into this as well while writing libudev bindings. Older versions of libudev are missing udev_hwdb_* functions, which I'd like to detect in the build script and enable with a #[cfg(...)] attribute, similar to using Autoconf's AC_CHECK_FUNCS macro.

alexcrichton added a commit to alexcrichton/cargo that referenced this issue Apr 10, 2015
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
alexcrichton added a commit to alexcrichton/cargo that referenced this issue Apr 14, 2015
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
bors added a commit that referenced this issue Apr 29, 2015
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-configuration Area: cargo config files and env vars P-high Priority: High
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants