-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
91 lines (84 loc) · 2.81 KB
/
build.rs
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use rustc_version::{version_meta, Channel};
fn has_cfg(name: &str) -> bool {
std::env::var_os(format!("CARGO_CFG_{}", name.to_uppercase())).is_some()
}
fn cfg(name: &str) -> String {
std::env::var(format!("CARGO_CFG_{}", name.to_uppercase())).unwrap_or_default()
}
fn main() {
println!("cargo::rerun-if-env-changed=MIRIFLAGS");
let is_miri = has_cfg("miri");
let is_tree_borrows =
std::env::var("MIRIFLAGS").is_ok_and(|flags| flags.contains("-Zmiri-tree-borrows"));
if is_miri && !is_tree_borrows {
println!("cargo::rustc-cfg=feature=\"sound-under-stacked-borrows\"");
}
let ac = autocfg::new();
let is_nightly = version_meta().unwrap().channel == Channel::Nightly;
println!("cargo::rerun-if-env-changed=LITHIUM_THREAD_LOCAL");
if let Ok(thread_local) = std::env::var("LITHIUM_THREAD_LOCAL") {
println!("cargo::rustc-cfg=thread_local=\"{thread_local}\"");
} else if is_nightly && has_cfg("target_thread_local") {
println!("cargo::rustc-cfg=thread_local=\"attribute\"");
} else if ac
.probe_raw(
r"
#![no_std]
extern crate std;
std::thread_local! {
static FOO: () = ();
}
",
)
.is_ok()
{
println!("cargo::rustc-cfg=thread_local=\"std\"");
} else {
println!("cargo::rustc-cfg=thread_local=\"unimplemented\"");
}
println!("cargo::rerun-if-env-changed=LITHIUM_BACKEND");
if let Ok(backend) = std::env::var("LITHIUM_BACKEND") {
println!("cargo::rustc-cfg=backend=\"{backend}\"");
} else if is_nightly && cfg("target_os") == "emscripten" && !has_cfg("emscripten_wasm_eh") {
println!("cargo::rustc-cfg=backend=\"emscripten\"");
} else if is_nightly
&& (has_cfg("unix")
|| (has_cfg("windows") && cfg("target_env") == "gnu")
|| cfg("target_arch") == "wasm32")
{
println!("cargo::rustc-cfg=backend=\"itanium\"");
} else if is_nightly && (has_cfg("windows") && cfg("target_env") == "msvc") && !is_miri {
println!("cargo::rustc-cfg=backend=\"seh\"");
} else if ac
.probe_raw(
r"
#![no_std]
extern crate std;
use std::panic::{catch_unwind, resume_unwind};
",
)
.is_ok()
{
println!("cargo::rustc-cfg=backend=\"panic\"");
} else {
println!("cargo::rustc-cfg=backend=\"unimplemented\"");
}
if ac
.probe_raw(
r#"
#![no_std]
extern crate std;
use std::io::Write;
fn main() {
let _ = std::io::stderr().write_all(b"hello");
std::process::abort();
}
"#,
)
.is_ok()
{
println!("cargo::rustc-cfg=abort=\"std\"");
} else {
println!("cargo::rustc-cfg=abort=\"core\"");
}
}