]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/test-cargo-miri/build.rs
Rollup merge of #103521 - chenyukang:yukang/fix-103451-avoid-hang, r=jackh726,wesleywiser
[rust.git] / src / tools / miri / test-cargo-miri / build.rs
1 use std::env;
2
3 #[cfg(miri)]
4 compile_error!("`miri` cfg should not be set in build script");
5
6 fn not_in_miri() -> i32 {
7     // Inline assembly definitely does not work in Miri.
8     let mut dummy = 42;
9     unsafe {
10         std::arch::asm!("/* {} */", in(reg) &mut dummy);
11     }
12     return dummy;
13 }
14
15 fn main() {
16     not_in_miri();
17     // Cargo calls `miri --print=cfg` to populate the `CARGO_CFG_*` env vars.
18     // Make sure that the "miri" flag is set.
19     assert!(env::var_os("CARGO_CFG_MIRI").is_some(), "cargo failed to tell us about `--cfg miri`");
20     println!("cargo:rerun-if-changed=build.rs");
21     println!("cargo:rerun-if-env-changed=MIRITESTVAR");
22     println!("cargo:rustc-env=MIRITESTVAR=testval");
23
24     // Test that autocfg works. This invokes RUSTC.
25     let a = autocfg::new();
26     assert!(a.probe_sysroot_crate("std"));
27     assert!(!a.probe_sysroot_crate("doesnotexist"));
28     assert!(a.probe_rustc_version(1, 0));
29     assert!(!a.probe_rustc_version(2, 0));
30     assert!(a.probe_type("i128"));
31     assert!(!a.probe_type("doesnotexist"));
32     assert!(a.probe_trait("Send"));
33     assert!(!a.probe_trait("doesnotexist"));
34     assert!(a.probe_path("std::num"));
35     assert!(!a.probe_path("doesnotexist"));
36     assert!(a.probe_constant("i32::MAX"));
37     assert!(!a.probe_constant("doesnotexist"));
38     assert!(a.probe_expression("Box::new(0)"));
39     assert!(!a.probe_expression("doesnotexist"));
40 }