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

53
Cargo.lock generated
View File

@@ -404,16 +404,16 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "3.1.15" version = "3.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85a35a599b11c089a7f49105658d089b8f2cf0882993c17daf6de15285c2c35d" checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83"
dependencies = [ dependencies = [
"atty", "atty",
"bitflags", "bitflags",
"clap_derive", "clap_derive",
"clap_lex", "clap_lex",
"indexmap", "indexmap",
"lazy_static", "once_cell",
"strsim", "strsim",
"termcolor", "termcolor",
"textwrap 0.15.0", "textwrap 0.15.0",
@@ -421,9 +421,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "3.1.7" version = "3.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1" checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro-error", "proc-macro-error",
@@ -434,9 +434,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_lex" name = "clap_lex"
version = "0.2.0" version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
dependencies = [ dependencies = [
"os_str_bytes", "os_str_bytes",
] ]
@@ -688,7 +688,7 @@ dependencies = [
name = "cranelift-serde" name = "cranelift-serde"
version = "0.87.0" version = "0.87.0"
dependencies = [ dependencies = [
"clap 3.1.15", "clap 3.2.8",
"cranelift-codegen", "cranelift-codegen",
"cranelift-reader", "cranelift-reader",
"serde_json", "serde_json",
@@ -701,7 +701,7 @@ dependencies = [
"anyhow", "anyhow",
"capstone", "capstone",
"cfg-if", "cfg-if",
"clap 3.1.15", "clap 3.2.8",
"cranelift", "cranelift",
"cranelift-codegen", "cranelift-codegen",
"cranelift-entity", "cranelift-entity",
@@ -814,26 +814,26 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-epoch" name = "crossbeam-epoch"
version = "0.9.8" version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" checksum = "07db9d94cbd326813772c968ccd25999e5f8ae22f4f8d1b11effa37ef6ce281d"
dependencies = [ dependencies = [
"autocfg 1.1.0", "autocfg 1.1.0",
"cfg-if", "cfg-if",
"crossbeam-utils", "crossbeam-utils",
"lazy_static",
"memoffset", "memoffset",
"once_cell",
"scopeguard", "scopeguard",
] ]
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.8" version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"lazy_static", "once_cell",
] ]
[[package]] [[package]]
@@ -1467,7 +1467,7 @@ dependencies = [
name = "islec" name = "islec"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap 3.1.15", "clap 3.2.8",
"cranelift-isle", "cranelift-isle",
"env_logger 0.9.0", "env_logger 0.9.0",
"miette", "miette",
@@ -2945,11 +2945,11 @@ dependencies = [
[[package]] [[package]]
name = "tracing-core" name = "tracing-core"
version = "0.1.26" version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f" checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7"
dependencies = [ dependencies = [
"lazy_static", "once_cell",
"valuable", "valuable",
] ]
@@ -3101,7 +3101,7 @@ dependencies = [
"io-extras", "io-extras",
"io-lifetimes", "io-lifetimes",
"is-terminal", "is-terminal",
"lazy_static", "once_cell",
"rustix", "rustix",
"system-interface", "system-interface",
"tempfile", "tempfile",
@@ -3164,7 +3164,6 @@ dependencies = [
"cap-tempfile", "cap-tempfile",
"io-extras", "io-extras",
"io-lifetimes", "io-lifetimes",
"lazy_static",
"rustix", "rustix",
"tempfile", "tempfile",
"tokio", "tokio",
@@ -3268,8 +3267,8 @@ dependencies = [
name = "wasm-spec-interpreter" name = "wasm-spec-interpreter"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"lazy_static",
"ocaml-interop", "ocaml-interop",
"once_cell",
"wat", "wat",
] ]
@@ -3326,7 +3325,6 @@ dependencies = [
"bincode", "bincode",
"cfg-if", "cfg-if",
"indexmap", "indexmap",
"lazy_static",
"libc", "libc",
"log", "log",
"object", "object",
@@ -3402,9 +3400,9 @@ dependencies = [
"directories-next", "directories-next",
"file-per-thread-logger", "file-per-thread-logger",
"filetime", "filetime",
"lazy_static",
"log", "log",
"more-asserts", "more-asserts",
"once_cell",
"pretty_env_logger", "pretty_env_logger",
"rustix", "rustix",
"serde", "serde",
@@ -3421,13 +3419,12 @@ version = "0.40.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
"clap 3.1.15", "clap 3.2.8",
"component-macro-test", "component-macro-test",
"criterion", "criterion",
"env_logger 0.9.0", "env_logger 0.9.0",
"filecheck", "filecheck",
"humantime 2.1.0", "humantime 2.1.0",
"lazy_static",
"libc", "libc",
"listenfd", "listenfd",
"memchr", "memchr",
@@ -3461,7 +3458,7 @@ name = "wasmtime-cli-flags"
version = "0.40.0" version = "0.40.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap 3.1.15", "clap 3.2.8",
"file-per-thread-logger", "file-per-thread-logger",
"pretty_env_logger", "pretty_env_logger",
"rayon", "rayon",
@@ -3596,8 +3593,8 @@ dependencies = [
name = "wasmtime-jit-debug" name = "wasmtime-jit-debug"
version = "0.40.0" version = "0.40.0"
dependencies = [ dependencies = [
"lazy_static",
"object", "object",
"once_cell",
"rustix", "rustix",
] ]

View File

@@ -30,12 +30,12 @@ wasmtime-wast = { path = "crates/wast", version = "=0.40.0" }
wasmtime-wasi = { path = "crates/wasi", version = "0.40.0" } wasmtime-wasi = { path = "crates/wasi", version = "0.40.0" }
wasmtime-wasi-crypto = { path = "crates/wasi-crypto", version = "0.40.0", optional = true } wasmtime-wasi-crypto = { path = "crates/wasi-crypto", version = "0.40.0", optional = true }
wasmtime-wasi-nn = { path = "crates/wasi-nn", version = "0.40.0", optional = true } wasmtime-wasi-nn = { path = "crates/wasi-nn", version = "0.40.0", optional = true }
clap = { version = "3.1.12", features = ["color", "suggestions", "derive"] } clap = { version = "3.2.0", features = ["color", "suggestions", "derive"] }
anyhow = "1.0.19" anyhow = "1.0.19"
target-lexicon = { version = "0.12.0", default-features = false } target-lexicon = { version = "0.12.0", default-features = false }
libc = "0.2.60" libc = "0.2.60"
humantime = "2.0.0" humantime = "2.0.0"
lazy_static = "1.4.0" once_cell = "1.12"
listenfd = "1.0.0" listenfd = "1.0.0"
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]

View File

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

View File

@@ -10,4 +10,4 @@ publish = false
cranelift-isle = { version = "*", path = "../isle/", features = ["miette-errors", "logging"] } cranelift-isle = { version = "*", path = "../isle/", features = ["miette-errors", "logging"] }
env_logger = { version = "0.9", default-features = false } env_logger = { version = "0.9", default-features = false }
miette = { version = "4.7.0", features = ["fancy"] } miette = { version = "4.7.0", features = ["fancy"] }
clap = { version = "3.1.12", features = ["derive"] } clap = { version = "3.2.0", features = ["derive"] }

View File

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

View File

@@ -31,7 +31,7 @@ rustix = { version = "0.35.6", features = ["process"] }
[dev-dependencies] [dev-dependencies]
filetime = "0.2.7" filetime = "0.2.7"
lazy_static = "1.3.0" once_cell = "1.12.0"
more-asserts = "0.2.1" more-asserts = "0.2.1"
pretty_env_logger = "0.4.0" pretty_env_logger = "0.4.0"
tempfile = "3" tempfile = "3"

View File

@@ -1,9 +1,7 @@
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use std::time::{Duration, SystemTime, SystemTimeError}; use std::time::{Duration, SystemTime, SystemTimeError};
lazy_static! { pub static NOW: Lazy<SystemTime> = Lazy::new(SystemTime::now);
pub static ref NOW: SystemTime = SystemTime::now(); // no need for RefCell and set_now() for now
}
#[derive(PartialOrd, PartialEq, Ord, Eq)] #[derive(PartialOrd, PartialEq, Ord, Eq)]
pub struct SystemTimeStub(SystemTime); pub struct SystemTimeStub(SystemTime);

View File

@@ -10,7 +10,7 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0.19" anyhow = "1.0.19"
clap = { version = "3.1.12", features = ["color", "suggestions", "derive"] } clap = { version = "3.2.0", features = ["color", "suggestions", "derive"] }
file-per-thread-logger = "0.1.1" file-per-thread-logger = "0.1.1"
pretty_env_logger = "0.4.0" pretty_env_logger = "0.4.0"
rayon = "1.5.0" rayon = "1.5.0"

View File

@@ -13,10 +13,10 @@ license = "Apache-2.0 WITH LLVM-exception"
# `build-libinterpret` feature set by this crate's parent). # `build-libinterpret` feature set by this crate's parent).
[dependencies] [dependencies]
ocaml-interop = { version = "0.8", optional = true } ocaml-interop = { version = "0.8", optional = true }
lazy_static = { version = "1.4", optional = true } once_cell = { version = "1.12.0", optional = true }
[dev-dependencies] [dev-dependencies]
wat = "1.0" wat = "1.0"
[features] [features]
build-libinterpret = ["ocaml-interop", "lazy_static"] build-libinterpret = ["ocaml-interop", "once_cell"]

View File

@@ -7,13 +7,11 @@
//! assert_eq!(results, &[Value::I32(43)]); //! assert_eq!(results, &[Value::I32(43)]);
//! ``` //! ```
use crate::Value; use crate::Value;
use lazy_static::lazy_static;
use ocaml_interop::{OCamlRuntime, ToOCaml}; use ocaml_interop::{OCamlRuntime, ToOCaml};
use once_cell::sync::Lazy;
use std::sync::Mutex; use std::sync::Mutex;
lazy_static! { static INTERPRET: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
static ref INTERPRET: Mutex<()> = Mutex::new(());
}
/// Interpret the first function in the passed WebAssembly module (in Wasm form, /// Interpret the first function in the passed WebAssembly module (in Wasm form,
/// currently, not WAT), optionally with the given parameters. If no parameters /// currently, not WAT), optionally with the given parameters. If no parameters

View File

@@ -11,7 +11,7 @@ readme = "README.md"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
lazy_static = {version = "1.3.0", optional = true } once_cell = {version = "1.12.0", optional = true }
object = { version = "0.28.0", default-features = false, features = ["std", "read_core"], optional = true } object = { version = "0.28.0", default-features = false, features = ["std", "read_core"], optional = true }
[target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(target_os = "linux")'.dependencies]
@@ -21,5 +21,5 @@ rustix = { version = "0.35.6", features = ["mm", "param", "time"], optional = tr
maintenance = { status = "actively-developed" } maintenance = { status = "actively-developed" }
[features] [features]
gdb_jit_int = ["lazy_static"] gdb_jit_int = ["once_cell"]
perf_jitdump = ["rustix", "object"] perf_jitdump = ["rustix", "object"]

View File

@@ -2,7 +2,7 @@
//! the __jit_debug_register_code() and __jit_debug_descriptor to register //! the __jit_debug_register_code() and __jit_debug_descriptor to register
//! or unregister generated object images with debuggers. //! or unregister generated object images with debuggers.
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use std::pin::Pin; use std::pin::Pin;
use std::ptr; use std::ptr;
use std::sync::Mutex; use std::sync::Mutex;
@@ -32,15 +32,13 @@ extern "C" {
fn __jit_debug_register_code(); fn __jit_debug_register_code();
} }
lazy_static! { /// The process controls access to the __jit_debug_descriptor by itself --
// The process controls access to the __jit_debug_descriptor by itself -- /// the GDB/LLDB accesses this structure and its data at the process startup
// the GDB/LLDB accesses this structure and its data at the process startup /// and when paused in __jit_debug_register_code.
// and when paused in __jit_debug_register_code. ///
// /// The GDB_REGISTRATION lock is needed for GdbJitImageRegistration to protect
// The GDB_REGISTRATION lock is needed for GdbJitImageRegistration to protect /// access to the __jit_debug_descriptor within this process.
// access to the __jit_debug_descriptor within this process. static GDB_REGISTRATION: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(Default::default()));
pub static ref GDB_REGISTRATION: Mutex<()> = Mutex::new(Default::default());
}
/// Registeration for JIT image /// Registeration for JIT image
pub struct GdbJitImageRegistration { pub struct GdbJitImageRegistration {

View File

@@ -1,10 +1,6 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]] version = 3
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
@@ -18,6 +14,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238"
[[package]]
name = "once_cell"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.10.2+wasi-snapshot-preview1" version = "0.10.2+wasi-snapshot-preview1"
@@ -28,8 +30,8 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
name = "wasi-tests" name = "wasi-tests"
version = "0.19.0" version = "0.19.0"
dependencies = [ dependencies = [
"lazy_static",
"libc", "libc",
"more-asserts", "more-asserts",
"once_cell",
"wasi", "wasi",
] ]

View File

@@ -10,7 +10,7 @@ publish = false
libc = "0.2.65" libc = "0.2.65"
wasi = "0.10.2" wasi = "0.10.2"
more-asserts = "0.2.1" more-asserts = "0.2.1"
lazy_static = "1.4" once_cell = "1.12.0"
# This crate is built with the wasm32-wasi target, so it's separate # This crate is built with the wasm32-wasi target, so it's separate
# from the main Wasmtime build, so use this directive to exclude it # from the main Wasmtime build, so use this directive to exclude it

View File

@@ -1,9 +1,8 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
pub mod config; pub mod config;
use once_cell::sync::Lazy;
lazy_static::lazy_static! { pub static TESTCONFIG: Lazy<config::TestConfig> = Lazy::new(config::TestConfig::from_env);
pub static ref TESTCONFIG: config::TestConfig = config::TestConfig::from_env();
}
// The `wasi` crate version 0.9.0 and beyond, doesn't // The `wasi` crate version 0.9.0 and beyond, doesn't
// seem to define these constants, so we do it ourselves. // seem to define these constants, so we do it ourselves.

View File

@@ -29,7 +29,7 @@ is-terminal = "0.3.0"
rustix = { version = "0.35.6", features = ["fs"] } rustix = { version = "0.35.6", features = ["fs"] }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
lazy_static = "1.4" once_cell = "1.12.0"
io-extras = "0.15.0" io-extras = "0.15.0"
[target.'cfg(windows)'.dependencies.windows-sys] [target.'cfg(windows)'.dependencies.windows-sys]

View File

@@ -9,6 +9,7 @@
// taken the time to improve it. See bug #2880. // taken the time to improve it. See bug #2880.
use anyhow::Context; use anyhow::Context;
use once_cell::sync::Lazy;
use std::ops::Deref; use std::ops::Deref;
use std::sync::mpsc::{self, Receiver, RecvTimeoutError, Sender, TryRecvError}; use std::sync::mpsc::{self, Receiver, RecvTimeoutError, Sender, TryRecvError};
use std::sync::Mutex; use std::sync::Mutex;
@@ -145,9 +146,7 @@ struct StdinPoll {
notify_rx: Receiver<PollState>, notify_rx: Receiver<PollState>,
} }
lazy_static::lazy_static! { static STDIN_POLL: Lazy<Mutex<StdinPoll>> = Lazy::new(StdinPoll::new);
static ref STDIN_POLL: Mutex<StdinPoll> = StdinPoll::new();
}
impl StdinPoll { impl StdinPoll {
pub fn new() -> Mutex<Self> { pub fn new() -> Mutex<Self> {

View File

@@ -23,7 +23,6 @@ io-lifetimes = { version = "0.7.0", default-features = false }
rustix = { version = "0.35.6", features = ["fs"] } rustix = { version = "0.35.6", features = ["fs"] }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
lazy_static = "1.4"
io-extras = "0.15.0" io-extras = "0.15.0"
[dev-dependencies] [dev-dependencies]

View File

@@ -34,11 +34,10 @@ bincode = "1.2.1"
indexmap = "1.6" indexmap = "1.6"
paste = "1.0.3" paste = "1.0.3"
psm = "0.1.11" psm = "0.1.11"
lazy_static = "1.4" once_cell = "1.12.0"
rayon = { version = "1.0", optional = true } rayon = { version = "1.0", optional = true }
object = { version = "0.28", default-features = false, features = ['read_core', 'elf'] } object = { version = "0.28", default-features = false, features = ['read_core', 'elf'] }
async-trait = { version = "0.1.51", optional = true } async-trait = { version = "0.1.51", optional = true }
once_cell = "1.12"
[target.'cfg(target_os = "windows")'.dependencies.windows-sys] [target.'cfg(target_os = "windows")'.dependencies.windows-sys]
version = "0.36.0" version = "0.36.0"

View File

@@ -3,6 +3,7 @@
#[cfg(feature = "component-model")] #[cfg(feature = "component-model")]
use crate::component::Component; use crate::component::Component;
use crate::{FrameInfo, Module}; use crate::{FrameInfo, Module};
use once_cell::sync::Lazy;
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
sync::{Arc, RwLock}, sync::{Arc, RwLock},
@@ -201,9 +202,7 @@ impl ModuleRegistry {
// it is also automatically registered with the singleton global module // it is also automatically registered with the singleton global module
// registry. When a `ModuleRegistry` is destroyed then all of its entries // registry. When a `ModuleRegistry` is destroyed then all of its entries
// are removed from the global module registry. // are removed from the global module registry.
lazy_static::lazy_static! { static GLOBAL_MODULES: Lazy<RwLock<GlobalModuleRegistry>> = Lazy::new(Default::default);
static ref GLOBAL_MODULES: RwLock<GlobalModuleRegistry> = Default::default();
}
type GlobalModuleRegistry = BTreeMap<usize, (usize, TrapInfo)>; type GlobalModuleRegistry = BTreeMap<usize, (usize, TrapInfo)>;

View File

@@ -2,14 +2,14 @@
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use clap::Parser; use clap::Parser;
use once_cell::sync::Lazy;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
use target_lexicon::Triple; use target_lexicon::Triple;
use wasmtime::Engine; use wasmtime::Engine;
use wasmtime_cli_flags::CommonOptions; use wasmtime_cli_flags::CommonOptions;
lazy_static::lazy_static! { static AFTER_HELP: Lazy<String> = Lazy::new(|| {
static ref AFTER_HELP: String = {
format!( format!(
"By default, no CPU features or presets will be enabled for the compilation.\n\ "By default, no CPU features or presets will be enabled for the compilation.\n\
\n\ \n\
@@ -30,8 +30,7 @@ lazy_static::lazy_static! {
wasmtime compile --target x86_64-unknown-linux --cranelift-enable skylake foo.wasm\n", wasmtime compile --target x86_64-unknown-linux --cranelift-enable skylake foo.wasm\n",
crate::FLAG_EXPLANATIONS.as_str() crate::FLAG_EXPLANATIONS.as_str()
) )
}; });
}
/// Compiles a WebAssembly module. /// Compiles a WebAssembly module.
#[derive(Parser)] #[derive(Parser)]

View File

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

View File

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

View File

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

View File

@@ -1,3 +1,4 @@
use once_cell::sync::Lazy;
use std::path::Path; use std::path::Path;
use std::sync::{Condvar, Mutex}; use std::sync::{Condvar, Mutex};
use wasmtime::{ use wasmtime::{
@@ -118,9 +119,7 @@ fn feature_found(path: &Path, name: &str) -> bool {
fn lock_pooling() -> impl Drop { fn lock_pooling() -> impl Drop {
const MAX_CONCURRENT_POOLING: u32 = 8; const MAX_CONCURRENT_POOLING: u32 = 8;
lazy_static::lazy_static! { static ACTIVE: Lazy<MyState> = Lazy::new(MyState::default);
static ref ACTIVE: MyState = MyState::default();
}
#[derive(Default)] #[derive(Default)]
struct MyState { struct MyState {