#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

#315 in Development tools

Download history 1641/week @ 2021-02-16 2206/week @ 2021-02-23 1364/week @ 2021-03-02 1913/week @ 2021-03-09 1560/week @ 2021-03-16 1676/week @ 2021-03-23 1734/week @ 2021-03-30 2324/week @ 2021-04-06 2321/week @ 2021-04-13 2479/week @ 2021-04-20 2799/week @ 2021-04-27 2659/week @ 2021-05-04 2496/week @ 2021-05-11 3000/week @ 2021-05-18 3533/week @ 2021-05-25 2512/week @ 2021-06-01

8,887 downloads per month
Used in 135 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