Migrate most of wasmtime from lazy_static to once_cell (#4368)

* Update tracing-core to a version which doesn't depend on lazy-static.

* Update crossbeam-utils to a version that doesn't depend on lazy-static.

* Update crossbeam-epoch to a version that doesn't depend on lazy-static.

* Update clap to a version that doesn't depend on lazy-static.

* Convert Wasmtime's own use of lazy_static to once_cell.

* Make `GDB_REGISTRATION`'s comment a doc comment.

* Fix compilation on Windows.
This commit is contained in:
Dan Gohman
2022-07-05 10:52:48 -07:00
committed by GitHub
parent d9e0e6a6a9
commit 371ae80ac3
25 changed files with 123 additions and 138 deletions

View File

@@ -2,36 +2,35 @@
use anyhow::{bail, Context, Result};
use clap::Parser;
use once_cell::sync::Lazy;
use std::fs;
use std::path::PathBuf;
use target_lexicon::Triple;
use wasmtime::Engine;
use wasmtime_cli_flags::CommonOptions;
lazy_static::lazy_static! {
static ref AFTER_HELP: String = {
format!(
"By default, no CPU features or presets will be enabled for the compilation.\n\
\n\
{}\
\n\
Usage examples:\n\
\n\
Compiling a WebAssembly module for the current platform:\n\
\n \
wasmtime compile example.wasm
\n\
Specifying the output file:\n\
\n \
wasmtime compile -o output.cwasm input.wasm\n\
\n\
Compiling for a specific platform (Linux) and CPU preset (Skylake):\n\
\n \
wasmtime compile --target x86_64-unknown-linux --cranelift-enable skylake foo.wasm\n",
crate::FLAG_EXPLANATIONS.as_str()
)
};
}
static AFTER_HELP: Lazy<String> = Lazy::new(|| {
format!(
"By default, no CPU features or presets will be enabled for the compilation.\n\
\n\
{}\
\n\
Usage examples:\n\
\n\
Compiling a WebAssembly module for the current platform:\n\
\n \
wasmtime compile example.wasm
\n\
Specifying the output file:\n\
\n \
wasmtime compile -o output.cwasm input.wasm\n\
\n\
Compiling for a specific platform (Linux) and CPU preset (Skylake):\n\
\n \
wasmtime compile --target x86_64-unknown-linux --cranelift-enable skylake foo.wasm\n",
crate::FLAG_EXPLANATIONS.as_str()
)
});
/// Compiles a WebAssembly module.
#[derive(Parser)]

View File

@@ -2,6 +2,7 @@
use anyhow::{anyhow, bail, Context as _, Result};
use clap::Parser;
use once_cell::sync::Lazy;
use std::fs::File;
use std::io::Read;
use std::thread;
@@ -65,11 +66,7 @@ fn parse_preloads(s: &str) -> Result<(String, PathBuf)> {
Ok((parts[0].into(), parts[1].into()))
}
lazy_static::lazy_static! {
static ref AFTER_HELP: String = {
crate::FLAG_EXPLANATIONS.to_string()
};
}
static AFTER_HELP: Lazy<String> = Lazy::new(|| crate::FLAG_EXPLANATIONS.to_string());
/// Runs a WebAssembly module
#[derive(Parser)]

View File

@@ -2,16 +2,13 @@
use anyhow::{Context as _, Result};
use clap::Parser;
use once_cell::sync::Lazy;
use std::path::PathBuf;
use wasmtime::{Engine, Store};
use wasmtime_cli_flags::CommonOptions;
use wasmtime_wast::WastContext;
lazy_static::lazy_static! {
static ref AFTER_HELP: String = {
crate::FLAG_EXPLANATIONS.to_string()
};
}
static AFTER_HELP: Lazy<String> = Lazy::new(|| crate::FLAG_EXPLANATIONS.to_string());
/// Runs a WebAssembly test script file
#[derive(Parser)]

View File

@@ -23,36 +23,41 @@
)
)]
use once_cell::sync::Lazy;
use wasmtime_cli_flags::{SUPPORTED_WASI_MODULES, SUPPORTED_WASM_FEATURES};
lazy_static::lazy_static! {
static ref FLAG_EXPLANATIONS: String = {
use std::fmt::Write;
static FLAG_EXPLANATIONS: Lazy<String> = Lazy::new(|| {
use std::fmt::Write;
let mut s = String::new();
let mut s = String::new();
// Explain --wasm-features.
writeln!(&mut s, "Supported values for `--wasm-features`:").unwrap();
writeln!(&mut s).unwrap();
let max = SUPPORTED_WASM_FEATURES.iter().max_by_key(|(name, _)| name.len()).unwrap();
for (name, desc) in SUPPORTED_WASM_FEATURES.iter() {
writeln!(&mut s, "{:width$} {}", name, desc, width = max.0.len() + 2).unwrap();
}
writeln!(&mut s).unwrap();
// Explain --wasm-features.
writeln!(&mut s, "Supported values for `--wasm-features`:").unwrap();
writeln!(&mut s).unwrap();
let max = SUPPORTED_WASM_FEATURES
.iter()
.max_by_key(|(name, _)| name.len())
.unwrap();
for (name, desc) in SUPPORTED_WASM_FEATURES.iter() {
writeln!(&mut s, "{:width$} {}", name, desc, width = max.0.len() + 2).unwrap();
}
writeln!(&mut s).unwrap();
// Explain --wasi-modules.
writeln!(&mut s, "Supported values for `--wasi-modules`:").unwrap();
writeln!(&mut s).unwrap();
let max = SUPPORTED_WASI_MODULES.iter().max_by_key(|(name, _)| name.len()).unwrap();
for (name, desc) in SUPPORTED_WASI_MODULES.iter() {
writeln!(&mut s, "{:width$} {}", name, desc, width = max.0.len() + 2).unwrap();
}
// Explain --wasi-modules.
writeln!(&mut s, "Supported values for `--wasi-modules`:").unwrap();
writeln!(&mut s).unwrap();
let max = SUPPORTED_WASI_MODULES
.iter()
.max_by_key(|(name, _)| name.len())
.unwrap();
for (name, desc) in SUPPORTED_WASI_MODULES.iter() {
writeln!(&mut s, "{:width$} {}", name, desc, width = max.0.len() + 2).unwrap();
}
writeln!(&mut s).unwrap();
writeln!(&mut s, "Features prefixed with '-' will be disabled.").unwrap();
writeln!(&mut s).unwrap();
writeln!(&mut s, "Features prefixed with '-' will be disabled.").unwrap();
s
};
}
s
});
pub mod commands;