about summary refs log tree commit diff
path: root/src/tools/miri/test-cargo-miri/build.rs
blob: 6c1f4d80d3392c26c13b3f4bd48bf6b5f18b9de0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::env;

#[cfg(miri)]
compile_error!("`miri` cfg should not be set in build script");

fn not_in_miri() -> i32 {
    // Inline assembly definitely does not work in Miri.
    let mut dummy = 42;
    unsafe {
        std::arch::asm!("/* {} */", in(reg) &mut dummy);
    }
    return dummy;
}

fn main() {
    not_in_miri();
    // Cargo calls `miri --print=cfg` to populate the `CARGO_CFG_*` env vars.
    // Make sure that the "miri" flag is set.
    assert!(env::var_os("CARGO_CFG_MIRI").is_some(), "cargo failed to tell us about `--cfg miri`");
    println!("cargo:rerun-if-changed=build.rs");
    println!("cargo:rerun-if-env-changed=MIRITESTVAR");
    println!("cargo:rustc-env=MIRITESTVAR=testval");

    // Test that autocfg works. This invokes RUSTC.
    let a = autocfg::new();
    assert!(a.probe_sysroot_crate("std"));
    assert!(!a.probe_sysroot_crate("doesnotexist"));
    assert!(a.probe_rustc_version(1, 0));
    assert!(!a.probe_rustc_version(2, 0));
    assert!(a.probe_type("i128"));
    assert!(!a.probe_type("doesnotexist"));
    assert!(a.probe_trait("Send"));
    assert!(!a.probe_trait("doesnotexist"));
    assert!(a.probe_path("std::num"));
    assert!(!a.probe_path("doesnotexist"));
    assert!(a.probe_constant("i32::MAX"));
    assert!(!a.probe_constant("doesnotexist"));
    assert!(a.probe_expression("Box::new(0)"));
    assert!(!a.probe_expression("doesnotexist"));
}