diff --git a/build.rs b/build.rs index 02457f9..9890349 100644 --- a/build.rs +++ b/build.rs @@ -3,12 +3,12 @@ // Allow dead code in triple.rs and targets.rs for our purposes here. #![allow(dead_code)] +use serde_json::Value; use std::env; use std::fs::File; use std::io::{self, prelude::*, Write}; use std::path::PathBuf; use std::str::FromStr; -use serde_json::Value; extern crate serde_json; @@ -37,12 +37,11 @@ mod parse_error { use triple::Triple; fn main() { - let out_dir = PathBuf::from(env::var("OUT_DIR").expect( - "The OUT_DIR environment variable must be set", - )); + let out_dir = + PathBuf::from(env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set")); let target = env::var("TARGET").expect("The TARGET environment variable must be set"); - + let triple = match Triple::from_str(&target) { Ok(triple) => { assert_eq!(target, triple.to_string(), "host is unrecognized"); @@ -51,14 +50,18 @@ fn main() { Err(_) => { let mut file = File::open(&target).expect("error opening target file"); let mut json = String::new(); - file.read_to_string(&mut json).expect("error reading target file"); + file.read_to_string(&mut json) + .expect("error reading target file"); let v: Value = serde_json::from_str(&json).expect("error parsing target file as json"); let target = v["llvm-target"] - .as_str() - .expect("error parsing \"llvm-target\" as a string"); + .as_str() + .expect("error parsing \"llvm-target\" as a string"); let triple = Triple::from_str(target).expect("error parsing host target"); - assert_eq!(target, triple.to_string(), - "host is unrecognized (as defined in target json file)"); + assert_eq!( + target, + triple.to_string(), + "host is unrecognized (as defined in target json file)" + ); triple } }; diff --git a/examples/misc.rs b/examples/misc.rs index 4503e0b..ff5057d 100644 --- a/examples/misc.rs +++ b/examples/misc.rs @@ -1,7 +1,7 @@ extern crate target_lexicon; -use target_lexicon::{Triple, HOST}; use std::str::FromStr; +use target_lexicon::{Triple, HOST}; fn main() { println!("The host triple is {}.", HOST); diff --git a/src/host.rs b/src/host.rs index 27f7e23..1e83d93 100644 --- a/src/host.rs +++ b/src/host.rs @@ -1,4 +1,4 @@ -use {Architecture, Vendor, OperatingSystem, Environment, BinaryFormat, Triple}; +use {Architecture, BinaryFormat, Environment, OperatingSystem, Triple, Vendor}; // Include the implementations of the `HOST` object containing information // about the current host. diff --git a/src/lib.rs b/src/lib.rs index d2634bd..5b06f4e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,17 +2,13 @@ #![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)] #![warn(unused_import_braces)] -#![cfg_attr(feature="cargo-clippy", warn( - float_arithmetic, - mut_mut, - nonminimal_bool, - option_map_unwrap_or, - option_map_unwrap_or_else, - print_stdout, - unicode_not_nfc, - use_self, - ))] - +#![cfg_attr( + feature = "cargo-clippy", + warn( + float_arithmetic, mut_mut, nonminimal_bool, option_map_unwrap_or, option_map_unwrap_or_else, + print_stdout, unicode_not_nfc, use_self + ) +)] #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), feature(alloc))] @@ -25,8 +21,8 @@ extern crate failure_derive; #[cfg(not(feature = "std"))] mod std { - pub use core::*; pub use alloc::{borrow, string}; + pub use core::*; } mod host; @@ -37,5 +33,5 @@ mod triple; pub use host::HOST; pub use parse_error::ParseError; -pub use targets::{Architecture, Vendor, OperatingSystem, Environment, BinaryFormat}; -pub use triple::{Triple, PointerWidth, Endianness}; +pub use targets::{Architecture, BinaryFormat, Environment, OperatingSystem, Vendor}; +pub use triple::{Endianness, PointerWidth, Triple}; diff --git a/src/targets.rs b/src/targets.rs index bafda31..7dd328b 100644 --- a/src/targets.rs +++ b/src/targets.rs @@ -1,8 +1,8 @@ // This file defines all the identifier enums and target-aware logic. -use std::str::FromStr; use std::fmt; -use triple::{Triple, PointerWidth, Endianness}; +use std::str::FromStr; +use triple::{Endianness, PointerWidth, Triple}; /// The "architecture" field, which in some cases also specifies a specific /// subarchitecture. @@ -120,35 +120,35 @@ impl Architecture { pub fn endianness(&self) -> Result { match *self { Architecture::Unknown => Err(()), - Architecture::Aarch64 | - Architecture::Arm | - Architecture::Armv4t | - Architecture::Armv5te | - Architecture::Armv7 | - Architecture::Armv7s | - Architecture::Asmjs | - Architecture::I386 | - Architecture::I586 | - Architecture::I686 | - Architecture::Mips64el | - Architecture::Mipsel | - Architecture::Msp430 | - Architecture::Powerpc64le | - Architecture::Riscv32 | - Architecture::Riscv64 | - Architecture::Thumbv6m | - Architecture::Thumbv7em | - Architecture::Thumbv7m | - Architecture::Wasm32 | - Architecture::X86_64 => Ok(Endianness::Little), - Architecture::Mips | - Architecture::Mips64 | - Architecture::Powerpc | - Architecture::Powerpc64 | - Architecture::S390x | - Architecture::Sparc | - Architecture::Sparc64 | - Architecture::Sparcv9 => Ok(Endianness::Big), + Architecture::Aarch64 + | Architecture::Arm + | Architecture::Armv4t + | Architecture::Armv5te + | Architecture::Armv7 + | Architecture::Armv7s + | Architecture::Asmjs + | Architecture::I386 + | Architecture::I586 + | Architecture::I686 + | Architecture::Mips64el + | Architecture::Mipsel + | Architecture::Msp430 + | Architecture::Powerpc64le + | Architecture::Riscv32 + | Architecture::Riscv64 + | Architecture::Thumbv6m + | Architecture::Thumbv7em + | Architecture::Thumbv7m + | Architecture::Wasm32 + | Architecture::X86_64 => Ok(Endianness::Little), + Architecture::Mips + | Architecture::Mips64 + | Architecture::Powerpc + | Architecture::Powerpc64 + | Architecture::S390x + | Architecture::Sparc + | Architecture::Sparc64 + | Architecture::Sparcv9 => Ok(Endianness::Big), } } @@ -157,34 +157,34 @@ impl Architecture { match *self { Architecture::Unknown => Err(()), Architecture::Msp430 => Ok(PointerWidth::U16), - Architecture::Arm | - Architecture::Armv4t | - Architecture::Armv5te | - Architecture::Armv7 | - Architecture::Armv7s | - Architecture::Asmjs | - Architecture::I386 | - Architecture::I586 | - Architecture::I686 | - Architecture::Mipsel | - Architecture::Riscv32 | - Architecture::Sparc | - Architecture::Thumbv6m | - Architecture::Thumbv7em | - Architecture::Thumbv7m | - Architecture::Wasm32 | - Architecture::Mips | - Architecture::Powerpc => Ok(PointerWidth::U32), - Architecture::Aarch64 | - Architecture::Mips64el | - Architecture::Powerpc64le | - Architecture::Riscv64 | - Architecture::X86_64 | - Architecture::Mips64 | - Architecture::Powerpc64 | - Architecture::S390x | - Architecture::Sparc64 | - Architecture::Sparcv9 => Ok(PointerWidth::U64), + Architecture::Arm + | Architecture::Armv4t + | Architecture::Armv5te + | Architecture::Armv7 + | Architecture::Armv7s + | Architecture::Asmjs + | Architecture::I386 + | Architecture::I586 + | Architecture::I686 + | Architecture::Mipsel + | Architecture::Riscv32 + | Architecture::Sparc + | Architecture::Thumbv6m + | Architecture::Thumbv7em + | Architecture::Thumbv7m + | Architecture::Wasm32 + | Architecture::Mips + | Architecture::Powerpc => Ok(PointerWidth::U32), + Architecture::Aarch64 + | Architecture::Mips64el + | Architecture::Powerpc64le + | Architecture::Riscv64 + | Architecture::X86_64 + | Architecture::Mips64 + | Architecture::Powerpc64 + | Architecture::S390x + | Architecture::Sparc64 + | Architecture::Sparcv9 => Ok(PointerWidth::U64), } } } @@ -195,9 +195,7 @@ pub fn default_binary_format(triple: &Triple) -> BinaryFormat { match triple.operating_system { OperatingSystem::Darwin | OperatingSystem::Ios => BinaryFormat::Macho, OperatingSystem::Windows => BinaryFormat::Coff, - OperatingSystem::Nebulet | - OperatingSystem::Emscripten | - OperatingSystem::Unknown => { + OperatingSystem::Nebulet | OperatingSystem::Emscripten | OperatingSystem::Unknown => { match triple.architecture { Architecture::Wasm32 => BinaryFormat::Wasm, _ => BinaryFormat::Unknown, diff --git a/src/triple.rs b/src/triple.rs index 393d8d6..4e71140 100644 --- a/src/triple.rs +++ b/src/triple.rs @@ -1,11 +1,11 @@ // This file defines the `Triple` type and support code shared by all targets. +use parse_error::ParseError; use std::borrow::ToOwned; -use std::str::FromStr; use std::fmt; -use parse_error::ParseError; -use targets::{Architecture, Vendor, OperatingSystem, Environment, BinaryFormat, - default_binary_format}; +use std::str::FromStr; +use targets::{default_binary_format, Architecture, BinaryFormat, Environment, OperatingSystem, + Vendor}; /// The target memory endianness. #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] @@ -121,15 +121,15 @@ impl fmt::Display for Triple { let implied_binary_format = default_binary_format(&self); write!(f, "{}", self.architecture)?; - if self.vendor == Vendor::Unknown && self.operating_system == OperatingSystem::Unknown && - (self.environment != Environment::Unknown || - self.binary_format != implied_binary_format) + if self.vendor == Vendor::Unknown && self.operating_system == OperatingSystem::Unknown + && (self.environment != Environment::Unknown + || self.binary_format != implied_binary_format) { // "none" is special-case shorthand for unknown vendor and unknown operating system. f.write_str("-none")?; - } else if self.operating_system == OperatingSystem::Linux && - (self.environment == Environment::Android || - self.environment == Environment::Androideabi) + } else if self.operating_system == OperatingSystem::Linux + && (self.environment == Environment::Android + || self.environment == Environment::Androideabi) { // As a special case, omit the vendor for Android targets. write!(f, "-{}", self.operating_system)?; @@ -244,9 +244,9 @@ impl FromStr for Triple { /// or so to report errors at compile time instead. #[macro_export] macro_rules! triple { - ($str: tt) => ( + ($str:tt) => { target_lexicon::Triple::from_str($str).expect("invalid triple literal") - ); + }; } #[cfg(test)]