Skip to content

Commit

Permalink
add new Rust 1.57 targets
Browse files Browse the repository at this point in the history
There are some idiosyncratic targets in here -- include special code to
handle them.
  • Loading branch information
sunshowers committed Dec 5, 2021
1 parent eb35ed6 commit 255417c
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 9 deletions.
32 changes: 32 additions & 0 deletions src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum Architecture {
Bpfel,
Hexagon,
X86_32(X86_32Architecture),
M68k,
Mips32(Mips32Architecture),
Mips64(Mips64Architecture),
Msp430,
Expand Down Expand Up @@ -396,8 +397,11 @@ pub enum Vendor {
Unknown,
Amd,
Apple,
Espressif,
Experimental,
Fortanix,
Kmc,
Nintendo,
Nvidia,
Pc,
Rumprun,
Expand Down Expand Up @@ -434,6 +438,7 @@ pub enum OperatingSystem {
Fuchsia,
Haiku,
Hermit,
Horizon,
Illumos,
Ios,
L4re,
Expand All @@ -446,6 +451,7 @@ pub enum OperatingSystem {
Psp,
Redox,
Solaris,
SolidAsp3,
Tvos,
Uefi,
VxWorks,
Expand Down Expand Up @@ -481,9 +487,11 @@ pub enum Environment {
Musleabihf,
Muslabi64,
Msvc,
Newlib,
Kernel,
Uclibc,
Uclibceabi,
Uclibceabihf,
Sgx,
Sim,
Softfloat,
Expand Down Expand Up @@ -533,6 +541,7 @@ impl Architecture {
| X86_64
| XTensa => Ok(Endianness::Little),
Bpfeb
| M68k
| Mips32(Mips32Architecture::Mips)
| Mips64(Mips64Architecture::Mips64)
| Mips32(Mips32Architecture::Mipsisa32r6)
Expand Down Expand Up @@ -562,6 +571,7 @@ impl Architecture {
| Riscv32(_)
| Sparc
| Wasm32
| M68k
| Mips32(_)
| Powerpc
| XTensa => Ok(PointerWidth::U32),
Expand Down Expand Up @@ -747,6 +757,7 @@ impl fmt::Display for Architecture {
Bpfel => f.write_str("bpfel"),
Hexagon => f.write_str("hexagon"),
X86_32(x86_32) => x86_32.fmt(f),
M68k => f.write_str("m68k"),
Mips32(mips32) => mips32.fmt(f),
Mips64(mips64) => mips64.fmt(f),
Msp430 => f.write_str("msp430"),
Expand Down Expand Up @@ -928,6 +939,7 @@ impl FromStr for Architecture {
"bpfeb" => Bpfeb,
"bpfel" => Bpfel,
"hexagon" => Hexagon,
"m68k" => M68k,
"msp430" => Msp430,
"nvptx64" => Nvptx64,
"powerpc" => Powerpc,
Expand Down Expand Up @@ -972,8 +984,11 @@ impl fmt::Display for Vendor {
Unknown => "unknown",
Amd => "amd",
Apple => "apple",
Espressif => "espressif",
Experimental => "experimental",
Fortanix => "fortanix",
Kmc => "kmc",
Nintendo => "nintendo",
Nvidia => "nvidia",
Pc => "pc",
Rumprun => "rumprun",
Expand All @@ -996,8 +1011,11 @@ impl FromStr for Vendor {
"unknown" => Unknown,
"amd" => Amd,
"apple" => Apple,
"espressif" => Espressif,
"experimental" => Experimental,
"fortanix" => Fortanix,
"kmc" => Kmc,
"nintendo" => Nintendo,
"nvidia" => Nvidia,
"pc" => Pc,
"rumprun" => Rumprun,
Expand Down Expand Up @@ -1066,6 +1084,7 @@ impl fmt::Display for OperatingSystem {
Fuchsia => "fuchsia",
Haiku => "haiku",
Hermit => "hermit",
Horizon => "horizon",
Illumos => "illumos",
Ios => "ios",
L4re => "l4re",
Expand All @@ -1084,6 +1103,7 @@ impl fmt::Display for OperatingSystem {
Psp => "psp",
Redox => "redox",
Solaris => "solaris",
SolidAsp3 => "solid_asp3",
Tvos => "tvos",
Uefi => "uefi",
VxWorks => "vxworks",
Expand Down Expand Up @@ -1144,6 +1164,7 @@ impl FromStr for OperatingSystem {
"fuchsia" => Fuchsia,
"haiku" => Haiku,
"hermit" => Hermit,
"horizon" => Horizon,
"illumos" => Illumos,
"ios" => Ios,
"l4re" => L4re,
Expand All @@ -1155,6 +1176,7 @@ impl FromStr for OperatingSystem {
"psp" => Psp,
"redox" => Redox,
"solaris" => Solaris,
"solid_asp3" => SolidAsp3,
"tvos" => Tvos,
"uefi" => Uefi,
"vxworks" => VxWorks,
Expand Down Expand Up @@ -1192,9 +1214,11 @@ impl fmt::Display for Environment {
Musleabihf => "musleabihf",
Muslabi64 => "muslabi64",
Msvc => "msvc",
Newlib => "newlib",
Kernel => "kernel",
Uclibc => "uclibc",
Uclibceabi => "uclibceabi",
Uclibceabihf => "uclibceabihf",
Sgx => "sgx",
Sim => "sim",
Softfloat => "softfloat",
Expand Down Expand Up @@ -1232,9 +1256,11 @@ impl FromStr for Environment {
"musleabihf" => Musleabihf,
"muslabi64" => Muslabi64,
"msvc" => Msvc,
"newlib" => Newlib,
"kernel" => Kernel,
"uclibc" => Uclibc,
"uclibceabi" => Uclibceabi,
"uclibceabihf" => Uclibceabihf,
"sgx" => Sgx,
"sim" => Sim,
"softfloat" => Softfloat,
Expand Down Expand Up @@ -1296,6 +1322,7 @@ mod tests {
"aarch64_be-unknown-linux-gnu",
"aarch64_be-unknown-linux-gnu_ilp32",
"aarch64-fuchsia",
"aarch64-kmc-solid_asp3",
"aarch64-linux-android",
"aarch64-pc-windows-msvc",
"aarch64-unknown-cloudabi",
Expand Down Expand Up @@ -1328,6 +1355,9 @@ mod tests {
"armv5te-unknown-linux-uclibceabi",
"armv6-unknown-freebsd",
"armv6-unknown-netbsd-eabihf",
"armv6k-nintendo-3ds",
"armv7a-kmc-solid_asp3-eabi",
"armv7a-kmc-solid_asp3-eabihf",
"armv7a-none-eabi",
"armv7a-none-eabihf",
"armv7-apple-ios",
Expand All @@ -1341,6 +1371,7 @@ mod tests {
"armv7-unknown-linux-gnueabihf",
"armv7-unknown-linux-musleabi",
"armv7-unknown-linux-musleabihf",
"armv7-unknown-linux-uclibceabihf",
"armv7-unknown-netbsd-eabihf",
"armv7-wrs-vxworks-eabihf",
"armv7a-none-eabi",
Expand Down Expand Up @@ -1374,6 +1405,7 @@ mod tests {
"i686-uwp-windows-gnu",
"i686-uwp-windows-msvc",
"i686-wrs-vxworks",
"m68k-unknown-linux-gnu",
"mips-unknown-linux-gnu",
"mips-unknown-linux-musl",
"mips-unknown-linux-uclibc",
Expand Down
92 changes: 83 additions & 9 deletions src/triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,25 @@ impl fmt::Display for Triple {
// triples.
write!(f, "-{}", self.operating_system)?;
} else {
write!(f, "-{}-{}", self.vendor, self.operating_system)?;
write!(
f,
"-{}-{}",
TripleField(&self.vendor),
TripleField(self.operating_system),
)?;
}
if self.environment != Environment::Unknown {
write!(f, "-{}", self.environment)?;

match (&self.vendor, self.operating_system, self.environment) {
(Vendor::Nintendo, OperatingSystem::Horizon, Environment::Newlib)
| (Vendor::Espressif, OperatingSystem::Espidf, Environment::Newlib) => {
// The triple representations of these platforms don't have an environment field.
}
(_, _, Environment::Unknown) => {
// Don't print out the environment if it is unknown.
}
_ => {
write!(f, "-{}", self.environment)?;
}
}

if self.binary_format != implied_binary_format {
Expand Down Expand Up @@ -257,7 +272,7 @@ impl FromStr for Triple {
let mut has_vendor = false;
let mut has_operating_system = false;
if let Some(s) = current_part {
if let Ok(vendor) = Vendor::from_str(s) {
if let Ok(TripleField(vendor)) = TripleField::<Vendor>::from_str(s) {
has_vendor = true;
result.vendor = vendor;
current_part = parts.next();
Expand All @@ -266,7 +281,9 @@ impl FromStr for Triple {

if !has_operating_system {
if let Some(s) = current_part {
if let Ok(operating_system) = OperatingSystem::from_str(s) {
if let Ok(TripleField(operating_system)) =
TripleField::<OperatingSystem>::from_str(s)
{
has_operating_system = true;
result.operating_system = operating_system;
current_part = parts.next();
Expand All @@ -275,11 +292,24 @@ impl FromStr for Triple {
}

let mut has_environment = false;
if let Some(s) = current_part {
if let Ok(environment) = Environment::from_str(s) {

match (&result.vendor, result.operating_system) {
(Vendor::Nintendo, OperatingSystem::Horizon)
| (Vendor::Espressif, OperatingSystem::Espidf) => {
// These platform use the newlib environment.
has_environment = true;
result.environment = environment;
current_part = parts.next();
result.environment = Environment::Newlib;
}
_ => {}
}

if !has_environment {
if let Some(s) = current_part {
if let Ok(environment) = Environment::from_str(s) {
has_environment = true;
result.environment = environment;
current_part = parts.next();
}
}
}

Expand Down Expand Up @@ -318,6 +348,50 @@ impl FromStr for Triple {
}
}

// Some fields are represented differently in triple strings -- this wrapper aids in handling that.
#[derive(Copy, Clone, Debug)]
struct TripleField<Field>(Field);

impl FromStr for TripleField<Vendor> {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"esp" => TripleField(Vendor::Espressif),
s => TripleField(s.parse()?),
})
}
}

impl<'a> fmt::Display for TripleField<&'a Vendor> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self.0 {
Vendor::Espressif => f.write_str("esp"),
vendor => write!(f, "{}", vendor),
}
}
}

impl FromStr for TripleField<OperatingSystem> {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"3ds" => TripleField(OperatingSystem::Horizon),
s => TripleField(s.parse()?),
})
}
}

impl fmt::Display for TripleField<OperatingSystem> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.0 {
OperatingSystem::Horizon => f.write_str("3ds"),
os => write!(f, "{}", os),
}
}
}

/// A convenient syntax for triple literals.
///
/// This currently expands to code that just calls `Triple::from_str` and does
Expand Down

0 comments on commit 255417c

Please sign in to comment.