#probe #rustc #features #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

#1088 in Development tools

Download history 28506/week @ 2023-11-30 34559/week @ 2023-12-07 29307/week @ 2023-12-14 20907/week @ 2023-12-21 20182/week @ 2023-12-28 33297/week @ 2024-01-04 26824/week @ 2024-01-11 33870/week @ 2024-01-18 30044/week @ 2024-01-25 31795/week @ 2024-02-01 26447/week @ 2024-02-08 25870/week @ 2024-02-15 33593/week @ 2024-02-22 30681/week @ 2024-02-29 33681/week @ 2024-03-07 28139/week @ 2024-03-14

130,603 downloads per month
Used in 1,350 crates (via bv)

MIT/Apache

9KB

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