Skip to content

Commit 0eb293d

Browse files
committed
Use an allow-list of platforms that support std.
Use a fall-through for no_std targets.
1 parent cee9f05 commit 0eb293d

File tree

3 files changed

+62
-20
lines changed

3 files changed

+62
-20
lines changed

src/libpanic_unwind/lib.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,33 @@ cfg_if::cfg_if! {
4141
if #[cfg(target_os = "emscripten")] {
4242
#[path = "emcc.rs"]
4343
mod real_imp;
44-
} else if #[cfg(any(target_arch = "wasm32", target_os = "none"))] {
45-
#[path = "dummy.rs"]
46-
mod real_imp;
4744
} else if #[cfg(target_os = "hermit")] {
4845
#[path = "hermit.rs"]
4946
mod real_imp;
5047
} else if #[cfg(target_env = "msvc")] {
5148
#[path = "seh.rs"]
5249
mod real_imp;
53-
} else {
50+
} else if #[cfg(any(
51+
all(target_family = "windows", target_env = "gnu"),
52+
target_os = "cloudabi",
53+
target_family = "unix",
54+
all(target_vendor = "fortanix", target_env = "sgx"),
55+
))] {
5456
// Rust runtime's startup objects depend on these symbols, so make them public.
5557
#[cfg(all(target_os="windows", target_arch = "x86", target_env="gnu"))]
5658
pub use real_imp::eh_frame_registry::*;
5759
#[path = "gcc.rs"]
5860
mod real_imp;
61+
} else {
62+
// Targets that don't support unwinding.
63+
// - arch=wasm32
64+
// - os=none ("bare metal" targets)
65+
// - os=uefi
66+
// - nvptx64-nvidia-cuda
67+
// - avr-unknown-unknown
68+
// - mipsel-sony-psp
69+
#[path = "dummy.rs"]
70+
mod real_imp;
5971
}
6072
}
6173

src/libstd/build.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,29 @@ fn main() {
6262
}
6363
println!("cargo:rustc-link-lib=c");
6464
println!("cargo:rustc-link-lib=compiler_rt");
65-
}
66-
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
67-
if target.contains("-none") || target.contains("nvptx") {
65+
} else if (target.contains("sgx") && target.contains("fortanix"))
66+
|| target.contains("hermit")
67+
|| target.contains("l4re")
68+
|| target.contains("redox")
69+
|| target.contains("haiku")
70+
|| target.contains("vxworks")
71+
|| target.contains("wasm32")
72+
|| target.contains("asmjs")
73+
{
74+
// These platforms don't have any special requirements.
75+
} else {
76+
// This is for Cargo's build-std support, to mark std as unstable for
77+
// typically no_std platforms.
78+
// This covers:
79+
// - os=none ("bare metal" targets)
80+
// - mipsel-sony-psp
81+
// - nvptx64-nvidia-cuda
82+
// - avr-unknown-unknown
83+
// - tvos (aarch64-apple-tvos, x86_64-apple-tvos)
84+
// - uefi (x86_64-unknown-uefi, i686-unknown-uefi)
85+
// - JSON targets
86+
// - Any new targets that have not been explicitly added above.
6887
println!("cargo:rustc-cfg=feature=\"restricted-std\"");
6988
}
89+
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
7090
}

src/libunwind/lib.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,31 @@
99

1010
cfg_if::cfg_if! {
1111
if #[cfg(target_env = "msvc")] {
12-
// no extra unwinder support needed
13-
} else if #[cfg(
14-
any(
15-
all(target_arch = "wasm32", not(target_os = "emscripten")),
16-
target_os = "none",
17-
target_os = "hermit",
18-
target_os = "uefi",
19-
target_os = "cuda",
20-
target_os = "l4re",
21-
))]
22-
{
23-
// no unwinder on the system!
24-
} else {
12+
// Windows MSVC no extra unwinder support needed
13+
} else if #[cfg(any(
14+
target_os = "l4re",
15+
target_os = "none",
16+
))] {
17+
// These "unix" family members do not have unwinder.
18+
// Note this also matches x86_64-linux-kernel.
19+
} else if #[cfg(any(
20+
unix,
21+
windows,
22+
target_os = "cloudabi",
23+
all(target_vendor = "fortanix", target_env = "sgx"),
24+
))] {
2525
mod libunwind;
2626
pub use libunwind::*;
27+
} else {
28+
// no unwinder on the system!
29+
// - wasm32 (not emscripten, which is "unix" family)
30+
// - os=none ("bare metal" targets)
31+
// - os=hermit
32+
// - os=uefi
33+
// - os=cuda
34+
// - nvptx64-nvidia-cuda
35+
// - mipsel-sony-psp
36+
// - Any new targets not listed above.
2737
}
2838
}
2939

0 commit comments

Comments
 (0)