Skip to content

Commit d1c33c3

Browse files
committed
rustc_target: introduce Os
Improve type safety by using an enum rather than strings.
1 parent 46f2759 commit d1c33c3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
4949
use rustc_session::Session;
5050
use rustc_session::config::OutputFilenames;
5151
use rustc_span::{Symbol, sym};
52-
use rustc_target::spec::{Abi, Arch, Env};
52+
use rustc_target::spec::{Abi, Arch, Env, Os};
5353

5454
pub use crate::config::*;
5555
use crate::prelude::*;
@@ -163,15 +163,15 @@ impl CodegenBackend for CraneliftCodegenBackend {
163163
fn target_config(&self, sess: &Session) -> TargetConfig {
164164
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
165165
let target_features = match sess.target.arch {
166-
Arch::X86_64 if sess.target.os != "none" => {
166+
Arch::X86_64 if sess.target.os != Os::None => {
167167
// x86_64 mandates SSE2 support and rustc requires the x87 feature to be enabled
168168
vec![sym::fxsr, sym::sse, sym::sse2, Symbol::intern("x87")]
169169
}
170-
Arch::AArch64 => match &*sess.target.os {
171-
"none" => vec![],
170+
Arch::AArch64 => match &sess.target.os {
171+
Os::None => vec![],
172172
// On macOS the aes, sha2 and sha3 features are enabled by default and ring
173173
// fails to compile on macOS when they are not present.
174-
"macos" => vec![sym::neon, sym::aes, sym::sha2, sym::sha3],
174+
Os::MacOs => vec![sym::neon, sym::aes, sym::sha2, sym::sha3],
175175
// AArch64 mandates Neon support
176176
_ => vec![sym::neon],
177177
},
@@ -184,7 +184,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
184184
// targets due to GCC using a different ABI than LLVM. Therefore `f16` and `f128`
185185
// won't be available when using a LLVM-built sysroot.
186186
let has_reliable_f16_f128 = !(sess.target.arch == Arch::X86_64
187-
&& sess.target.os == "windows"
187+
&& sess.target.os == Os::Windows
188188
&& sess.target.env == Env::Gnu
189189
&& sess.target.abi != Abi::Llvm);
190190

0 commit comments

Comments
 (0)