33// FIXME: Once the portability lint RFC is implemented (see tracking issue #41619),
44// switch to use those structures instead.
55
6+ use std:: str:: FromStr ;
67use std:: sync:: Arc ;
78use std:: { fmt, mem, ops} ;
89
@@ -15,6 +16,7 @@ use rustc_hir::attrs::{self, AttributeKind, CfgEntry, CfgHideShow, HideOrShow};
1516use rustc_middle:: ty:: TyCtxt ;
1617use rustc_span:: symbol:: { Symbol , sym} ;
1718use rustc_span:: { DUMMY_SP , Span } ;
19+ use rustc_target:: spec:: { self , Env , Os } ;
1820
1921use crate :: display:: { Joined as _, MaybeDisplay , Wrapped } ;
2022use crate :: html:: escape:: Escape ;
@@ -421,70 +423,20 @@ impl fmt::Display for Display<'_> {
421423 ( sym:: unix, None ) => "Unix" ,
422424 ( sym:: windows, None ) => "Windows" ,
423425 ( sym:: debug_assertions, None ) => "debug-assertions enabled" ,
424- ( sym:: target_os, Some ( os) ) => match os. as_str ( ) {
425- "android" => "Android" ,
426- "cygwin" => "Cygwin" ,
427- "dragonfly" => "DragonFly BSD" ,
428- "emscripten" => "Emscripten" ,
429- "freebsd" => "FreeBSD" ,
430- "fuchsia" => "Fuchsia" ,
431- "haiku" => "Haiku" ,
432- "hermit" => "Hermit" ,
433- "illumos" => "illumos" ,
434- "ios" => "iOS" ,
435- "l4re" => "L4Re" ,
436- "linux" => "Linux" ,
437- "macos" => "macOS" ,
438- "netbsd" => "NetBSD" ,
439- "openbsd" => "OpenBSD" ,
440- "redox" => "Redox" ,
441- "solaris" => "Solaris" ,
442- "tvos" => "tvOS" ,
443- "wasi" => "WASI" ,
444- "watchos" => "watchOS" ,
445- "windows" => "Windows" ,
446- "visionos" => "visionOS" ,
447- _ => "" ,
448- } ,
449- ( sym:: target_arch, Some ( arch) ) => match arch. as_str ( ) {
450- "aarch64" => "AArch64" ,
451- "arm" => "ARM" ,
452- "loongarch32" => "LoongArch LA32" ,
453- "loongarch64" => "LoongArch LA64" ,
454- "m68k" => "M68k" ,
455- "csky" => "CSKY" ,
456- "mips" => "MIPS" ,
457- "mips32r6" => "MIPS Release 6" ,
458- "mips64" => "MIPS-64" ,
459- "mips64r6" => "MIPS-64 Release 6" ,
460- "msp430" => "MSP430" ,
461- "powerpc" => "PowerPC" ,
462- "powerpc64" => "PowerPC-64" ,
463- "riscv32" => "RISC-V RV32" ,
464- "riscv64" => "RISC-V RV64" ,
465- "s390x" => "s390x" ,
466- "sparc64" => "SPARC64" ,
467- "wasm32" | "wasm64" => "WebAssembly" ,
468- "x86" => "x86" ,
469- "x86_64" => "x86-64" ,
470- _ => "" ,
471- } ,
426+ ( sym:: target_os, Some ( os) ) => human_readable_target_os ( * os) . unwrap_or_default ( ) ,
427+ ( sym:: target_arch, Some ( arch) ) => {
428+ human_readable_target_arch ( * arch) . unwrap_or_default ( )
429+ }
472430 ( sym:: target_vendor, Some ( vendor) ) => match vendor. as_str ( ) {
473431 "apple" => "Apple" ,
474432 "pc" => "PC" ,
475433 "sun" => "Sun" ,
476434 "fortanix" => "Fortanix" ,
477435 _ => "" ,
478436 } ,
479- ( sym:: target_env, Some ( env) ) => match env. as_str ( ) {
480- "gnu" => "GNU" ,
481- "msvc" => "MSVC" ,
482- "musl" => "musl" ,
483- "newlib" => "Newlib" ,
484- "uclibc" => "uClibc" ,
485- "sgx" => "SGX" ,
486- _ => "" ,
487- } ,
437+ ( sym:: target_env, Some ( env) ) => {
438+ human_readable_target_env ( * env) . unwrap_or_default ( )
439+ }
488440 ( sym:: target_endian, Some ( endian) ) => {
489441 return write ! ( fmt, "{endian}-endian" ) ;
490442 }
@@ -527,6 +479,135 @@ impl fmt::Display for Display<'_> {
527479 }
528480}
529481
482+ fn human_readable_target_os ( os : Symbol ) -> Option < & ' static str > {
483+ let os = Os :: from_str ( os. as_str ( ) ) . ok ( ) ?;
484+
485+ use Os :: * ;
486+ Some ( match os {
487+ // tidy-alphabetical-start
488+ Aix => "AIX" ,
489+ AmdHsa => "AMD HSA" ,
490+ Android => "Android" ,
491+ Cuda => "CUDA" ,
492+ Cygwin => "Cygwin" ,
493+ Dragonfly => "DragonFly BSD" ,
494+ Emscripten => "Emscripten" ,
495+ EspIdf => "ESP-IDF" ,
496+ FreeBsd => "FreeBSD" ,
497+ Fuchsia => "Fuchsia" ,
498+ Haiku => "Haiku" ,
499+ HelenOs => "HelenOS" ,
500+ Hermit => "Hermit" ,
501+ Horizon => "Horizon" ,
502+ Hurd => "GNU/Hurd" ,
503+ IOs => "iOS" ,
504+ Illumos => "illumos" ,
505+ L4Re => "L4Re" ,
506+ Linux => "Linux" ,
507+ LynxOs178 => "LynxOS-178" ,
508+ MacOs => "macOS" ,
509+ Managarm => "Managarm" ,
510+ Motor => "Motor OS" ,
511+ NetBsd => "NetBSD" ,
512+ None => "bare-metal" , // FIXME(scrabsha): is this appropriate?
513+ Nto => "QNX Neutrino" ,
514+ NuttX => "NuttX" ,
515+ OpenBsd => "OpenBSD" ,
516+ Psp => "Play Station Portable" ,
517+ Psx => "Play Station 1" ,
518+ Qurt => "QuRT" ,
519+ Redox => "Redox OS" ,
520+ Rtems => "RTEMS OS" ,
521+ Solaris => "Solaris" ,
522+ SolidAsp3 => "SOLID ASP3" ,
523+ TeeOs => "TEEOS" ,
524+ Trusty => "Trusty" ,
525+ TvOs => "tvOS" ,
526+ Uefi => "UEFI" ,
527+ VexOs => "VEXos" ,
528+ VisionOs => "visionOS" ,
529+ Vita => "Play Station Vita" ,
530+ VxWorks => "VxWorks" ,
531+ Wasi => "WASI" ,
532+ WatchOs => "watchOS" ,
533+ Windows => "Windows" ,
534+ Xous => "Xous" ,
535+ Zkvm => "zero knowledge Virtual Machine" ,
536+ // tidy-alphabetical-end
537+ Unknown | Other ( _) => return Option :: None ,
538+ } )
539+ }
540+
541+ fn human_readable_target_arch ( os : Symbol ) -> Option < & ' static str > {
542+ let arch = spec:: Arch :: from_str ( os. as_str ( ) ) . ok ( ) ?;
543+
544+ use spec:: Arch :: * ;
545+ Some ( match arch {
546+ // tidy-alphabetical-start
547+ AArch64 => "AArch64" ,
548+ AmdGpu => "AMG GPU" ,
549+ Arm => "ARM" ,
550+ Arm64EC => "ARM64EC" ,
551+ Avr => "AVR" ,
552+ Bpf => "BPF" ,
553+ CSky => "C-SKY" ,
554+ Hexagon => "Hexagon" ,
555+ LoongArch32 => "LoongArch64" ,
556+ LoongArch64 => "LoongArch32" ,
557+ M68k => "Motorola 680x0" ,
558+ Mips => "MIPS" ,
559+ Mips32r6 => "MIPS release 6" ,
560+ Mips64 => "MIPS-64" ,
561+ Mips64r6 => "MIPS-64 release 6" ,
562+ Msp430 => "MSP430" ,
563+ Nvptx64 => "NVidia GPU" ,
564+ PowerPC => "PowerPC" ,
565+ PowerPC64 => "PowerPC64" ,
566+ RiscV32 => "RISC-V RV32" ,
567+ RiscV64 => "RISC-V RV64" ,
568+ S390x => "s390x" ,
569+ Sparc => "SPARC" ,
570+ Sparc64 => "SPARC-64" ,
571+ SpirV => "SPIR-V" ,
572+ Wasm32 | Wasm64 => "WebAssembly" ,
573+ X86 => "x86" ,
574+ X86_64 => "x86-64" ,
575+ Xtensa => "Xtensa" ,
576+ // tidy-alphabetical-end
577+ Other ( _) => return None ,
578+ } )
579+ }
580+
581+ fn human_readable_target_env ( env : Symbol ) -> Option < & ' static str > {
582+ let env = Env :: from_str ( env. as_str ( ) ) . ok ( ) ?;
583+
584+ use Env :: * ;
585+ Some ( match env {
586+ // tidy-alphabetical-start
587+ Gnu => "GNU" ,
588+ MacAbi => "Catalyst" ,
589+ Mlibc => "mac ABI" ,
590+ Msvc => "MSVC" ,
591+ Musl => "musl" ,
592+ Newlib => "Newlib" ,
593+ Nto70 => "Neutrino 7.0" ,
594+ Nto71 => "Neutrino 7.1" ,
595+ Nto71IoSock => "Neutrino 7.1 with io-sock" ,
596+ Nto80 => "Neutrino 8.0" ,
597+ Ohos => "OpenHarmony" ,
598+ P1 => "WASIp1" ,
599+ P2 => "WASIp2" ,
600+ P3 => "WASIp3" ,
601+ Relibc => "relibc" ,
602+ Sgx => "SGX" ,
603+ Sim => "Simulator" ,
604+ Uclibc => "uClibc" ,
605+ V5 => "V5" ,
606+ // tidy-alphabetical-end
607+ Unspecified | Other ( _) => return None ,
608+ } )
609+ }
610+
530611#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
531612struct NameValueCfg {
532613 name : Symbol ,
0 commit comments