Update to clap 3.* (#4082)

* Update to clap 3.0

This commit migrates all CLI commands internally used in this project
from structopt/clap2 to clap 3. The intent here is to ensure that we're
using maintained versions of the dependencies as structopt and clap 2
are less maintained nowadays. Most transitions were pretty
straightforward and mostly dealing with structopt/clap3 differences.

* Fix a number of `cargo deny` errors

This commit fixes a few errors around duplicate dependencies which
arose from the prior update to clap3. This also uses a new feature in
`deny.toml`, `skip-tree`, which allows having a bit more targeted
ignores for skips of duplicate version checks. This showed a few more
locations in Wasmtime itself where we could update some dependencies.
This commit is contained in:
Alex Crichton
2022-04-28 12:47:12 -05:00
committed by GitHub
parent 871a9d93f2
commit 5fe06f7345
30 changed files with 295 additions and 325 deletions

View File

@@ -41,7 +41,7 @@ indicatif = "0.13.0"
thiserror = "1.0.15"
walkdir = "2.2"
anyhow = "1.0.32"
structopt = "0.3.17"
clap = { version = "3.1.12", features = ["derive"] }
[features]
default = ["disas", "wasm", "cranelift-codegen/all-arch", "souper-harvest"]

View File

@@ -8,6 +8,6 @@ publish = false
[dependencies]
cranelift-isle = { version = "*", path = "../isle/" }
env_logger = { version = "0.8", default-features = false }
env_logger = { version = "0.9", default-features = false }
miette = { version = "3.0.0", features = ["fancy"] }
structopt = "0.3.23"
clap = { version = "3.1.12", features = ["derive"] }

View File

@@ -1,3 +1,4 @@
use clap::Parser;
use cranelift_isle::{compile, lexer, parser};
use miette::{Context, IntoDiagnostic, Result};
use std::{
@@ -5,17 +6,16 @@ use std::{
io::{self, Write},
path::PathBuf,
};
use structopt::StructOpt;
#[derive(StructOpt)]
#[derive(Parser)]
struct Opts {
/// The output file to write the generated Rust code to. `stdout` is used if
/// this is not given.
#[structopt(short, long, parse(from_os_str))]
#[clap(short, long)]
output: Option<PathBuf>,
/// The input ISLE DSL source files.
#[structopt(parse(from_os_str), required(true))]
#[clap(required = true)]
inputs: Vec<PathBuf>,
}
@@ -32,7 +32,7 @@ fn main() -> Result<()> {
)
}));
let opts = Opts::from_args();
let opts = Opts::parse();
let lexer = lexer::Lexer::from_files(opts.inputs)?;
let defs = parser::parse(lexer)?;

View File

@@ -14,7 +14,7 @@ name = "clif-json"
path = "src/clif-json.rs"
[dependencies]
clap = "2.32.0"
clap = { version = "3.1.12", features = ["derive"] }
serde_json = "1.0.26"
cranelift-codegen = { path = "../codegen", version = "0.84.0", features = ["enable-serde"] }
cranelift-reader = { path = "../reader", version = "0.84.0" }

View File

@@ -21,7 +21,7 @@
)
)]
use clap::{App, Arg, SubCommand};
use clap::Parser;
use cranelift_codegen::ir::Function;
use cranelift_reader::parse_functions;
use std::fs::File;
@@ -54,50 +54,40 @@ fn call_de(file: &File) -> Result<(), String> {
Ok(())
}
fn main() {
let matches = App::new("Cranelift JSON serializer/deserializer utility")
.subcommand(
SubCommand::with_name("serialize")
.display_order(1)
.about("Serializes Cranelift IR into JSON.")
.arg(Arg::with_name("pretty").short("p").help("pretty json"))
.arg(
Arg::with_name("FILE")
.required(true)
.value_name("FILE")
.help("Input file for serialization"),
),
)
.subcommand(
SubCommand::with_name("deserialize")
.about("Deserializes Cranelift IR into JSON.")
.arg(
Arg::with_name("FILE")
.required(true)
.value_name("FILE")
.help("Input file for deserialization"),
),
)
.get_matches();
/// Cranelift JSON serializer/deserializer utility
#[derive(Parser, Debug)]
#[clap(about)]
enum Args {
/// Serializes Cranelift IR into JSON
Serialize {
/// Generate pretty json
#[clap(long, short)]
pretty: bool,
let res_serde = match matches.subcommand() {
("serialize", Some(m)) => {
let mut file =
File::open(m.value_of("FILE").unwrap()).expect("Unable to open the file");
/// Input file for serialization
file: String,
},
/// Deserializes Cranelift IR into JSON
Deserialize {
/// Input file for deserialization
file: String,
},
}
fn main() {
let res_serde = match Args::parse() {
Args::Serialize { pretty, file } => {
let mut contents = String::new();
let mut file = File::open(file).expect("Unable to open the file");
file.read_to_string(&mut contents)
.expect("Unable to read the file");
match m.occurrences_of("pretty") {
0 => call_ser(&contents, false),
_ => call_ser(&contents, true),
}
call_ser(&contents, pretty)
}
("deserialize", Some(m)) => {
let file = File::open(m.value_of("FILE").unwrap()).expect("Unable to open the file");
Args::Deserialize { file } => {
let file = File::open(file).expect("Unable to open the file");
call_de(&file)
}
_ => Err("Invalid subcommand.".to_string()),
};
if let Err(mut msg) = res_serde {

View File

@@ -2,6 +2,7 @@
use crate::utils::{parse_sets_and_triple, read_to_string};
use anyhow::{Context as _, Result};
use clap::Parser;
use cranelift_codegen::cursor::{Cursor, FuncCursor};
use cranelift_codegen::flowgraph::ControlFlowGraph;
use cranelift_codegen::ir::types::{F32, F64};
@@ -16,24 +17,22 @@ use cranelift_reader::{parse_test, ParseOptions};
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle};
use std::collections::HashMap;
use std::path::PathBuf;
use structopt::StructOpt;
/// Reduce size of clif file causing panic during compilation.
#[derive(StructOpt)]
#[derive(Parser)]
pub struct Options {
/// Specify an input file to be used. Use '-' for stdin.
#[structopt(parse(from_os_str))]
file: PathBuf,
/// Configure Cranelift settings
#[structopt(long("set"))]
#[clap(long = "set")]
settings: Vec<String>,
/// Specify the target architecture.
target: String,
/// Be more verbose
#[structopt(short = "v", long = "verbose")]
#[clap(short, long)]
verbose: bool,
}

View File

@@ -5,19 +5,19 @@
use crate::utils::read_to_string;
use anyhow::{Context, Result};
use clap::Parser;
use cranelift_reader::parse_functions;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
/// Outputs .clif file
#[derive(StructOpt)]
#[derive(Parser)]
pub struct Options {
/// Specify input file(s) to be used. Use '-' for stdin.
#[structopt(required(true), parse(from_os_str))]
#[clap(required = true)]
files: Vec<PathBuf>,
/// Enable debug output on stderr/stdout
#[structopt(short = "d")]
#[clap(short)]
debug: bool,
}

View File

@@ -12,9 +12,9 @@
)
)]
use clap::Parser;
use cranelift_codegen::dbg::LOG_FILENAME_PREFIX;
use std::{option::Option, path::PathBuf};
use structopt::StructOpt;
use std::path::PathBuf;
mod bugpoint;
mod cat;
@@ -40,7 +40,7 @@ fn handle_debug_flag(debug: bool) {
}
/// Cranelift code generator utility.
#[derive(StructOpt)]
#[derive(Parser)]
enum Commands {
Test(TestOptions),
Run(run::Options),
@@ -63,58 +63,57 @@ enum Commands {
}
/// Run Cranelift tests
#[derive(StructOpt)]
#[derive(Parser)]
struct TestOptions {
/// Be more verbose
#[structopt(short = "v", long = "verbose")]
#[clap(short, long)]
verbose: bool,
/// Print pass timing report for test
#[structopt(short = "T")]
#[clap(short = 'T')]
time_passes: bool,
/// Enable debug output on stderr/stdout
#[structopt(short = "d")]
#[clap(short = 'd')]
debug: bool,
/// Specify an input file to be used. Use '-' for stdin.
#[structopt(required(true), parse(from_os_str))]
#[clap(required = true)]
files: Vec<PathBuf>,
}
/// Run specified pass(es) on an input file.
#[derive(StructOpt)]
#[derive(Parser)]
struct PassOptions {
/// Be more verbose
#[structopt(short = "v", long = "verbose")]
#[clap(short, long)]
verbose: bool,
/// Print pass timing report for test
#[structopt(short = "T")]
#[clap(short = 'T')]
time_passes: bool,
/// Enable debug output on stderr/stdout
#[structopt(short = "d")]
#[clap(short)]
debug: bool,
/// Specify an input file to be used. Use '-' for stdin.
#[structopt(parse(from_os_str))]
file: PathBuf,
/// Specify the target architecture.
target: String,
/// Specify pass(es) to be run on the input file
#[structopt(required(true))]
#[clap(required = true)]
passes: Vec<String>,
}
/// (Compiled without support for this subcommand)
#[derive(StructOpt)]
#[derive(Parser)]
struct CompiledWithoutSupportOptions {}
fn main() -> anyhow::Result<()> {
match Commands::from_args() {
match Commands::parse() {
Commands::Cat(c) => cat::run(&c)?,
Commands::Run(r) => run::run(&r)?,
Commands::Interpret(i) => interpret::run(&i)?,

View File

@@ -3,6 +3,7 @@
use crate::disasm::print_all;
use crate::utils::{parse_sets_and_triple, read_to_string};
use anyhow::{Context as _, Result};
use clap::Parser;
use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::settings::FlagsOrIsa;
use cranelift_codegen::timing;
@@ -10,37 +11,35 @@ use cranelift_codegen::Context;
use cranelift_reader::{parse_test, ParseOptions};
use std::path::Path;
use std::path::PathBuf;
use structopt::StructOpt;
/// Compiles Cranelift IR into target language
#[derive(StructOpt)]
#[derive(Parser)]
pub struct Options {
/// Print the resulting Cranelift IR
#[structopt(short("p"))]
#[clap(short)]
print: bool,
/// Print pass timing report
#[structopt(short("T"))]
#[clap(short = 'T')]
report_times: bool,
/// Print machine code disassembly
#[structopt(short("D"), long("disasm"))]
#[clap(short = 'D', long)]
disasm: bool,
/// Configure Cranelift settings
#[structopt(long("set"))]
#[clap(long = "set")]
settings: Vec<String>,
/// Specify the Cranelift target
#[structopt(long("target"))]
#[clap(long = "target")]
target: String,
/// Specify an input file to be used. Use '-' for stdin.
#[structopt(parse(from_os_str))]
files: Vec<PathBuf>,
/// Enable debug output on stderr/stdout
#[structopt(short = "d")]
#[clap(short)]
debug: bool,
}

View File

@@ -1,28 +1,28 @@
//! CLI tool to interpret Cranelift IR files.
use crate::utils::iterate_files;
use clap::Parser;
use cranelift_interpreter::environment::FunctionStore;
use cranelift_interpreter::interpreter::{Interpreter, InterpreterState};
use cranelift_interpreter::step::ControlFlow;
use cranelift_reader::{parse_run_command, parse_test, ParseError, ParseOptions};
use std::path::PathBuf;
use std::{fs, io};
use structopt::StructOpt;
use thiserror::Error;
/// Interpret clif code
#[derive(StructOpt)]
#[derive(Parser)]
pub struct Options {
/// Specify an input file to be used. Use '-' for stdin.
#[structopt(required(true), parse(from_os_str))]
#[clap(required = true)]
files: Vec<PathBuf>,
/// Enable debug output on stderr/stdout
#[structopt(short = "d")]
#[clap(short)]
debug: bool,
/// Be more verbose
#[structopt(short = "v", long = "verbose")]
#[clap(short, long)]
verbose: bool,
}

View File

@@ -5,20 +5,20 @@
use crate::utils::read_to_string;
use anyhow::Result;
use clap::Parser;
use cranelift_codegen::cfg_printer::CFGPrinter;
use cranelift_reader::parse_functions;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
/// Prints out cfg in GraphViz Dot format
#[derive(StructOpt)]
#[derive(Parser)]
pub struct Options {
/// Specify an input file to be used. Use '-' for stdin.
#[structopt(required(true), parse(from_os_str))]
#[clap(required = true)]
files: Vec<PathBuf>,
/// Enable debug output on stderr/stdout
#[structopt(short = "d")]
#[clap(short)]
debug: bool,
}

View File

@@ -2,27 +2,27 @@
use crate::utils::{iterate_files, read_to_string};
use anyhow::Result;
use clap::Parser;
use cranelift_codegen::isa::{CallConv, TargetIsa};
use cranelift_filetests::SingleFunctionCompiler;
use cranelift_native::builder as host_isa_builder;
use cranelift_reader::{parse_run_command, parse_test, Details, IsaSpec, ParseOptions};
use std::path::{Path, PathBuf};
use structopt::StructOpt;
use target_lexicon::Triple;
/// Execute clif code and verify with test expressions
#[derive(StructOpt)]
#[derive(Parser)]
pub struct Options {
/// Specify an input file to be used. Use '-' for stdin.
#[structopt(required(true), parse(from_os_str))]
#[clap(required = true)]
files: Vec<PathBuf>,
/// Enable debug output on stderr/stdout
#[structopt(short = "d")]
#[clap(short)]
debug: bool,
/// Be more verbose
#[structopt(short = "v", long = "verbose")]
#[clap(short, long)]
verbose: bool,
}

View File

@@ -1,11 +1,11 @@
use crate::utils::parse_sets_and_triple;
use anyhow::{Context as _, Result};
use clap::Parser;
use cranelift_codegen::Context;
use cranelift_wasm::{DummyEnvironment, ReturnMode};
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use std::path::{Path, PathBuf};
use std::{fs, io};
use structopt::StructOpt;
static WASM_MAGIC: &[u8] = &[0x00, 0x61, 0x73, 0x6D];
@@ -13,22 +13,21 @@ static WASM_MAGIC: &[u8] = &[0x00, 0x61, 0x73, 0x6D];
///
/// Candidates are emitted in Souper's text format:
/// <https://github.com/google/souper>
#[derive(StructOpt)]
#[derive(Parser)]
pub struct Options {
/// Specify an input file to be used. Use '-' for stdin.
#[structopt(parse(from_os_str))]
input: PathBuf,
/// Specify the output file to be used. Use '-' for stdout.
#[structopt(short("o"), long("output"), default_value("-"), parse(from_os_str))]
#[clap(short, long, default_value("-"))]
output: PathBuf,
/// Configure Cranelift settings
#[structopt(long("set"))]
#[clap(long = "set")]
settings: Vec<String>,
/// Specify the Cranelift target
#[structopt(long("target"))]
#[clap(long = "target")]
target: String,
}

View File

@@ -10,6 +10,7 @@
use crate::disasm::print_all;
use crate::utils::parse_sets_and_triple;
use anyhow::{Context as _, Result};
use clap::Parser;
use cranelift_codegen::ir::DisplayFunctionAnnotations;
use cranelift_codegen::print_errors::{pretty_error, pretty_verifier_error};
use cranelift_codegen::settings::FlagsOrIsa;
@@ -20,7 +21,6 @@ use cranelift_wasm::{translate_module, DummyEnvironment, FuncIndex, ReturnMode};
use std::io::Read;
use std::path::Path;
use std::path::PathBuf;
use structopt::StructOpt;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
/// For verbose printing: only print if the `$x` expression is true.
@@ -61,58 +61,57 @@ macro_rules! vcprint {
}
/// Compiles Wasm binary/text into Cranelift IR and then into target language
#[derive(StructOpt)]
#[derive(Parser)]
pub struct Options {
/// Be more verbose
#[structopt(short = "v", long = "verbose")]
#[clap(short, long)]
verbose: bool,
/// Print the resulting Cranelift IR
#[structopt(short("p"))]
#[clap(short)]
print: bool,
/// Print pass timing report
#[structopt(short("T"))]
#[clap(short = 'T')]
report_times: bool,
/// Print machine code disassembly
#[structopt(short("D"), long("disasm"))]
#[clap(short = 'D', long)]
disasm: bool,
/// Configure Cranelift settings
#[structopt(long("set"))]
#[clap(long = "set")]
settings: Vec<String>,
/// Specify the Cranelift target
#[structopt(long("target"))]
#[clap(long = "target")]
target: String,
/// Specify an input file to be used. Use '-' for stdin.
#[structopt(parse(from_os_str))]
files: Vec<PathBuf>,
/// Enable debug output on stderr/stdout
#[structopt(short = "d")]
#[clap(short)]
debug: bool,
/// Print bytecode size
#[structopt(short("X"))]
#[clap(short = 'X')]
print_size: bool,
/// Just decode Wasm into Cranelift IR, don't compile it to native code
#[structopt(short("t"))]
#[clap(short = 't')]
just_decode: bool,
/// Just checks the correctness of Cranelift IR translated from Wasm
#[structopt(short("c"))]
#[clap(short = 'c')]
check_translation: bool,
/// Display values' ranges and their locations
#[structopt(long("value-ranges"))]
#[clap(long = "value-ranges")]
value_ranges: bool,
/// Use colors in output? [options: auto/never/always; default: auto]
#[structopt(long("color"), default_value("auto"))]
#[clap(long = "color", default_value("auto"))]
color: ColorOpt,
}