#rustc #features #probe #autoconf

build feature-probe

Probe for rustc features from build.rs

2 releases

Uses old Rust 2015

0.1.1 Jun 7, 2018
0.1.0 Jun 7, 2018

#519 in Development tools

Download history 12511/week @ 2022-06-03 11984/week @ 2022-06-10 11460/week @ 2022-06-17 12757/week @ 2022-06-24 12109/week @ 2022-07-01 10743/week @ 2022-07-08 11293/week @ 2022-07-15 11435/week @ 2022-07-22 11873/week @ 2022-07-29 13000/week @ 2022-08-05 12271/week @ 2022-08-12 11191/week @ 2022-08-19 9572/week @ 2022-08-26 11285/week @ 2022-09-02 11252/week @ 2022-09-09 8783/week @ 2022-09-16

42,843 downloads per month
Used in 663 crates (via bv)

MIT/Apache

8KB

feature-probe-rs: probe for rustc features from build.rs

Build Status Crates.io License: MIT License: Apache 2.0

To support multiple versions of Rust, it's often necessary to conditionally compile parts of our libraries or programs. It's possible to allow users to specify what features to enable, but detection is better, because users get all the features that their version of Rust supports. And while we could check the rustc version, it's better to probe for individual features. That way, code will work both on nightly, and on stable releases after particular features stabilize, without changes.

Usage

It’s on crates.io, so you can add

[build-dependencies]
feature-probe = "0.1.1"

Then add to your build.rs:

extern crate feature_probe;

use feature_probe::Probe;

Then you can probe for features such as types or expressions. For example:

fn main () {
    let probe = Probe::new();
    
    if probe.probe_type("i128") {
        println!("cargo:rustc-cfg=int_128");
    }
    
    if probe.probe_type("::std::ops::RangeInclusive<u64>") {
        println!("cargo:rustc-cfg=inclusive_range");
    }
}

This crate supports Rust version 1.16.0 and later.

No runtime deps