diff --git a/Cargo.lock b/Cargo.lock index 26572d4449..72b0b738fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -117,12 +117,6 @@ dependencies = [ "derive_arbitrary", ] -[[package]] -name = "arrayref" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" - [[package]] name = "arrayvec" version = "0.5.2" @@ -238,17 +232,6 @@ dependencies = [ "wyz", ] -[[package]] -name = "blake2b_simd" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" -dependencies = [ - "arrayref", - "arrayvec", - "constant_time_eq", -] - [[package]] name = "block-buffer" version = "0.9.0" @@ -492,12 +475,6 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - [[package]] name = "cpp_demangle" version = "0.3.2" @@ -739,7 +716,7 @@ dependencies = [ "rayon", "structopt", "target-lexicon", - "term", + "termcolor", "thiserror", "walkdir", "wat", @@ -937,16 +914,6 @@ dependencies = [ "dirs-sys-next", ] -[[package]] -name = "dirs" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" -dependencies = [ - "cfg-if 0.1.10", - "dirs-sys", -] - [[package]] name = "dirs-next" version = "2.0.0" @@ -957,17 +924,6 @@ dependencies = [ "dirs-sys-next", ] -[[package]] -name = "dirs-sys" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" -dependencies = [ - "libc", - "redox_users 0.3.5", - "winapi", -] - [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -975,7 +931,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", - "redox_users 0.4.0", + "redox_users", "winapi", ] @@ -2285,17 +2241,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "redox_users" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" -dependencies = [ - "getrandom 0.1.16", - "redox_syscall 0.1.57", - "rust-argon2", -] - [[package]] name = "redox_users" version = "0.4.0" @@ -2409,18 +2354,6 @@ dependencies = [ "cc", ] -[[package]] -name = "rust-argon2" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" -dependencies = [ - "base64", - "blake2b_simd", - "constant_time_eq", - "crossbeam-utils", -] - [[package]] name = "rustc-demangle" version = "0.1.18" @@ -2767,16 +2700,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "term" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0863a3345e70f61d613eab32ee046ccd1bcc5f9105fe402c61fcd0c13eeb8b5" -dependencies = [ - "dirs", - "winapi", -] - [[package]] name = "termcolor" version = "1.1.2" diff --git a/cranelift/Cargo.toml b/cranelift/Cargo.toml index 7a4adc3e6f..62845231b5 100644 --- a/cranelift/Cargo.toml +++ b/cranelift/Cargo.toml @@ -31,7 +31,7 @@ cranelift-preopt = { path = "preopt", version = "0.69.0" } cranelift = { path = "umbrella", version = "0.69.0" } filecheck = "0.5.0" log = "0.4.8" -term = "0.6.1" +termcolor = "1.1.2" capstone = { version = "0.7.0", optional = true } wat = { version = "1.0.18", optional = true } target-lexicon = { version = "0.11", features = ["std"] } diff --git a/cranelift/src/wasm.rs b/cranelift/src/wasm.rs index 8083f9c983..20310f157c 100644 --- a/cranelift/src/wasm.rs +++ b/cranelift/src/wasm.rs @@ -21,7 +21,7 @@ use std::io::Read; use std::path::Path; use std::path::PathBuf; use structopt::StructOpt; -use term; +use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; /// For verbose printing: only print if the `$x` expression is true. macro_rules! vprintln { @@ -36,11 +36,11 @@ macro_rules! vcprintln { ($x: expr, $use_color: expr, $term: ident, $color: expr, $($tts:tt)*) => { if $x { if $use_color { - let _ = $term.fg($color); + $term.set_color(ColorSpec::new().set_fg(Some($color)))?; } println!($($tts)*); if $use_color { - let _ = $term.reset(); + $term.reset()?; } } }; @@ -50,11 +50,11 @@ macro_rules! vcprint { ($x: expr, $use_color: expr, $term: ident, $color: expr, $($tts:tt)*) => { if $x { if $use_color { - let _ = $term.fg($color); + $term.set_color(ColorSpec::new().set_fg(Some($color)))?; } print!($($tts)*); if $use_color { - let _ = $term.reset(); + $term.reset()?; } } }; @@ -113,25 +113,25 @@ pub struct Options { /// Use colors in output? [options: auto/never/always; default: auto] #[structopt(long("color"), default_value("auto"))] - color: Color, + color: ColorOpt, } #[derive(PartialEq, Eq)] -enum Color { +enum ColorOpt { Auto, Never, Always, } -impl std::str::FromStr for Color { +impl std::str::FromStr for ColorOpt { type Err = String; fn from_str(s: &str) -> Result { let s = s.to_lowercase(); match s.as_str() { - "auto" => Ok(Color::Auto), - "never" => Ok(Color::Never), - "always" => Ok(Color::Always), + "auto" => Ok(ColorOpt::Auto), + "never" => Ok(ColorOpt::Never), + "always" => Ok(ColorOpt::Always), _ => Err(format!("expected auto/never/always, found: {}", s)), } } @@ -149,14 +149,19 @@ pub fn run(options: &Options) -> Result<()> { } fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) -> Result<()> { - let mut terminal = term::stdout().unwrap(); - let use_color = - terminal.supports_color() && options.color == Color::Auto || options.color == Color::Always; + let color_choice = match options.color { + ColorOpt::Auto => ColorChoice::Auto, + ColorOpt::Always => ColorChoice::Always, + ColorOpt::Never => ColorChoice::Never, + }; + let mut terminal = StandardStream::stdout(color_choice); + let use_color = terminal.supports_color() && options.color == ColorOpt::Auto + || options.color == ColorOpt::Always; vcprint!( options.verbose, use_color, terminal, - term::color::YELLOW, + Color::Yellow, "Handling: " ); vprintln!(options.verbose, "\"{}\"", name); @@ -164,7 +169,7 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) - options.verbose, use_color, terminal, - term::color::MAGENTA, + Color::Magenta, "Translating... " ); @@ -192,13 +197,7 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) - DummyEnvironment::new(isa.frontend_config(), ReturnMode::NormalReturns, debug_info); translate_module(&module_binary, &mut dummy_environ)?; - vcprintln!( - options.verbose, - use_color, - terminal, - term::color::GREEN, - "ok" - ); + vcprintln!(options.verbose, use_color, terminal, Color::Green, "ok"); if options.just_decode { if !options.print { @@ -233,7 +232,7 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) - options.verbose, use_color, terminal, - term::color::MAGENTA, + Color::Magenta, "Checking... " ); } else { @@ -241,7 +240,7 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) - options.verbose, use_color, terminal, - term::color::MAGENTA, + Color::Magenta, "Compiling... " ); } @@ -351,12 +350,6 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) - println!("{}", timing::take_current()); } - vcprintln!( - options.verbose, - use_color, - terminal, - term::color::GREEN, - "ok" - ); + vcprintln!(options.verbose, use_color, terminal, Color::Green, "ok"); Ok(()) }