Sha256: 9b2b610956f9a012024360335f044a8ef5d9aa5fbc20d71ca24f8127ec721c3b

Contents?: true

Size: 1.21 KB

Versions: 25

Compression:

Stored size: 1.21 KB

Contents

use std::env::var;
use std::io::Write;

fn main() {
    use_feature_or_nothing("windows_by_handle"); // https://github.com/rust-lang/rust/issues/63010

    // Don't rerun this on changes other than build.rs, as we only depend on
    // the rustc version.
    println!("cargo:rerun-if-changed=build.rs");
}

fn use_feature_or_nothing(feature: &str) {
    if has_feature(feature) {
        use_feature(feature);
    }
}

fn use_feature(feature: &str) {
    println!("cargo:rustc-cfg={}", feature);
}

/// Test whether the rustc at `var("RUSTC")` supports the given feature.
fn has_feature(feature: &str) -> bool {
    let out_dir = var("OUT_DIR").unwrap();
    let rustc = var("RUSTC").unwrap();

    let mut child = std::process::Command::new(rustc)
        .arg("--crate-type=rlib") // Don't require `main`.
        .arg("--emit=metadata") // Do as little as possible but still parse.
        .arg("--out-dir")
        .arg(out_dir) // Put the output somewhere inconsequential.
        .arg("-") // Read from stdin.
        .stdin(std::process::Stdio::piped()) // Stdin is a pipe.
        .spawn()
        .unwrap();

    writeln!(child.stdin.take().unwrap(), "#![feature({})]", feature).unwrap();

    child.wait().unwrap().success()
}

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
wasmtime-18.0.3 ./ext/cargo-vendor/cap-fs-ext-2.0.1/build.rs
wasmtime-17.0.1 ./ext/cargo-vendor/cap-fs-ext-2.0.1/build.rs
wasmtime-17.0.0 ./ext/cargo-vendor/cap-fs-ext-2.0.1/build.rs
wasmtime-16.0.0 ./ext/cargo-vendor/cap-fs-ext-2.0.1/build.rs
wasmtime-15.0.1 ./ext/cargo-vendor/cap-fs-ext-2.0.1/build.rs
wasmtime-15.0.0 ./ext/cargo-vendor/cap-fs-ext-2.0.1/build.rs
wasmtime-14.0.4 ./ext/cargo-vendor/cap-fs-ext-2.0.0/build.rs
wasmtime-14.0.3 ./ext/cargo-vendor/cap-fs-ext-2.0.0/build.rs
wasmtime-14.0.1 ./ext/cargo-vendor/cap-fs-ext-2.0.0/build.rs
wasmtime-14.0.0 ./ext/cargo-vendor/cap-fs-ext-2.0.0/build.rs
wasmtime-13.0.0 ./ext/cargo-vendor/cap-fs-ext-2.0.0/build.rs
wasmtime-12.0.1 ./ext/cargo-vendor/cap-fs-ext-2.0.0/build.rs
wasmtime-12.0.0 ./ext/cargo-vendor/cap-fs-ext-2.0.0/build.rs
wasmtime-11.0.0 ./ext/cargo-vendor/cap-fs-ext-1.0.15/build.rs
wasmtime-10.0.1 ./ext/cargo-vendor/cap-fs-ext-1.0.15/build.rs
wasmtime-10.0.0 ./ext/cargo-vendor/cap-fs-ext-1.0.15/build.rs
wasmtime-9.0.4 ./ext/cargo-vendor/cap-fs-ext-1.0.15/build.rs
wasmtime-9.0.1 ./ext/cargo-vendor/cap-fs-ext-1.0.15/build.rs
wasmtime-8.0.0 ./ext/cargo-vendor/cap-fs-ext-1.0.14/build.rs
wasmtime-7.0.0 ./ext/cargo-vendor/cap-fs-ext-1.0.9/build.rs