From 1cb29bbfa176bd4451a70be266c19df23c31e5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 17 Jan 2023 10:31:07 +0100 Subject: [PATCH 01/38] Fix feature flags for make-build-wasmer-headless --- lib/cli/Cargo.toml | 2 +- lib/vfs/Cargo.toml | 2 +- lib/wasi/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index a1960afa947..514c5f67ca3 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -162,7 +162,7 @@ llvm = [ debug = ["fern", "wasmer-wasi/logging"] disable-all-logging = ["wasmer-wasi/disable-all-logging"] headless = [] -headless-minimal = ["headless", "disable-all-logging", "wasi"] +headless-minimal = ["headless", "disable-all-logging", "wasi", "compiler", "webc_runner", "static-artifact-create"] # Optional enable-serde = [ diff --git a/lib/vfs/Cargo.toml b/lib/vfs/Cargo.toml index cd44f06d4f0..25ce6cc62fe 100644 --- a/lib/vfs/Cargo.toml +++ b/lib/vfs/Cargo.toml @@ -20,7 +20,7 @@ anyhow = { version = "1.0.66", optional = true } default = ["host-fs", "mem-fs", "webc-fs", "static-fs"] host-fs = ["libc"] mem-fs = ["slab"] -webc-fs = ["webc", "anyhow"] +webc-fs = ["webc", "mem-fs", "anyhow"] static-fs = ["webc", "anyhow", "mem-fs"] enable-serde = [ "serde", diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index b975d874c8b..b7f26f5d85a 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -50,7 +50,7 @@ tracing-wasm = "0.2" default = ["sys-default"] wasix = [] -webc_runner = ["webc", "serde_cbor", "anyhow", "serde", "wasmer/compiler", "wasmer/cranelift"] +webc_runner = ["webc", "serde_cbor", "anyhow", "serde", "wasmer/compiler", "wasmer/cranelift", "wasmer-vfs/webc-fs"] webc_runner_rt_emscripten = ["wasmer-emscripten"] webc_runner_rt_wasi = [] From a674471a8f3a93154915a31029074e963fbb1149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= <12084016+fschutt@users.noreply.github.com> Date: Tue, 17 Jan 2023 19:39:29 +0100 Subject: [PATCH 02/38] Disable compilers in wasi/Cargo.toml Co-authored-by: Syrus Akbary --- lib/wasi/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index b7f26f5d85a..9c0f44e65cf 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -50,7 +50,7 @@ tracing-wasm = "0.2" default = ["sys-default"] wasix = [] -webc_runner = ["webc", "serde_cbor", "anyhow", "serde", "wasmer/compiler", "wasmer/cranelift", "wasmer-vfs/webc-fs"] +webc_runner = ["webc", "serde_cbor", "anyhow", "serde", "wasmer-vfs/webc-fs"] webc_runner_rt_emscripten = ["wasmer-emscripten"] webc_runner_rt_wasi = [] From 9091054b21aef6b501d2755dd50fe932c4242c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= <12084016+fschutt@users.noreply.github.com> Date: Tue, 17 Jan 2023 19:40:17 +0100 Subject: [PATCH 03/38] Disable compiler feature for headless-minimal again. Co-authored-by: Syrus Akbary --- lib/cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 514c5f67ca3..9fb50a1fb8d 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -162,7 +162,7 @@ llvm = [ debug = ["fern", "wasmer-wasi/logging"] disable-all-logging = ["wasmer-wasi/disable-all-logging"] headless = [] -headless-minimal = ["headless", "disable-all-logging", "wasi", "compiler", "webc_runner", "static-artifact-create"] +headless-minimal = ["headless", "disable-all-logging", "wasi", "webc_runner", "static-artifact-create"] # Optional enable-serde = [ From 71fdf26e089a12378cc2d032608f4a91c1fdcf69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 17 Jan 2023 20:22:40 +0100 Subject: [PATCH 04/38] Remove dependency on wasmer/compiler from webc-runner --- lib/wasi/Cargo.toml | 6 ++++++ lib/wasi/src/runners/emscripten.rs | 20 +++++++++++++++++--- lib/wasi/src/runners/wasi.rs | 18 +++++++++++++++--- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 9c0f44e65cf..2a15355d3c2 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -53,6 +53,12 @@ wasix = [] webc_runner = ["webc", "serde_cbor", "anyhow", "serde", "wasmer-vfs/webc-fs"] webc_runner_rt_emscripten = ["wasmer-emscripten"] webc_runner_rt_wasi = [] +emscripten_cranelift = ["wasmer/cranelift"] +wasi_cranelift = ["wasmer/cranelift"] +emscripten_singlepass = ["wasmer/singlepass"] +wasi_singlepass = ["wasmer/singlepass"] +emscripten_llvm = ["wasmer/llvm"] +wasi_llvm = ["wasmer/llvm"] sys = ["wasmer/sys", "wasix", "wasmer-wasi-types/sys"] sys-default = ["wasmer/wat", "wasmer/compiler", "sys", "logging", "host-fs", "sys-poll", "host-vnet" ] diff --git a/lib/wasi/src/runners/emscripten.rs b/lib/wasi/src/runners/emscripten.rs index cbfb5ce0051..acf6df06edf 100644 --- a/lib/wasi/src/runners/emscripten.rs +++ b/lib/wasi/src/runners/emscripten.rs @@ -6,7 +6,7 @@ use anyhow::anyhow; use serde::{Deserialize, Serialize}; use std::error::Error as StdError; use std::sync::Arc; -use wasmer::{Cranelift, FunctionEnv, Instance, Module, Store}; +use wasmer::{FunctionEnv, Instance, Module, Store}; use wasmer_emscripten::{ generate_emscripten_env, is_emscripten_module, run_emscripten_instance, EmEnv, EmscriptenGlobals, @@ -33,6 +33,7 @@ impl crate::runners::Runner for EmscriptenRunner { .starts_with("https://webc.org/runner/emscripten")) } + #[allow(unreachable_code)] fn run_command( &mut self, command_name: &str, @@ -43,8 +44,21 @@ impl crate::runners::Runner for EmscriptenRunner { let main_args = container.get_main_args_for_command(command_name); let atom_bytes = container.get_atom(&container.get_package_name(), &atom_name)?; - let compiler = Cranelift::default(); - let mut store = Store::new(compiler); + #[cfg(feature = "emscripten_cranelift")] + let mut store = Store::new(wasmer::Cranelift::default()); + #[cfg(feature = "emscripten_llvm")] + let mut store = Store::new(wasmer::Llvm::default()); + #[cfg(feature = "emscripten_singlepass")] + let mut store = Store::new(wasmer::Singlepass::default()); + #[cfg(not(any( + feature = "emscripten_cranelift", + feature = "emscripten_llvm", + feature = "emscripten_singlepass" + )))] + let mut store = { + return Err(anyhow::anyhow!("wasmer-wasi needs one of emscripten_cranelift or emscripten_llvm or emscripten_singlepass features enabled").into()); + }; + let mut module = Module::new(&store, atom_bytes)?; module.set_name(&atom_name); diff --git a/lib/wasi/src/runners/wasi.rs b/lib/wasi/src/runners/wasi.rs index d73ee69c7e7..8dfd9c5da2b 100644 --- a/lib/wasi/src/runners/wasi.rs +++ b/lib/wasi/src/runners/wasi.rs @@ -7,7 +7,7 @@ use anyhow::Context; use serde::{Deserialize, Serialize}; use std::error::Error as StdError; use std::sync::Arc; -use wasmer::{Cranelift, Instance, Module, Store}; +use wasmer::{Instance, Module, Store}; use wasmer_vfs::webc_fs::WebcFileSystem; use webc::{Command, WebCMmap}; @@ -42,8 +42,20 @@ impl crate::runners::Runner for WasiRunner { let atom_name = container.get_atom_name_for_command("wasi", command_name)?; let atom_bytes = container.get_atom(&container.get_package_name(), &atom_name)?; - let compiler = Cranelift::default(); - let mut store = Store::new(compiler); + #[cfg(feature = "wasi_cranelift")] + let mut store = Store::new(wasmer::Cranelift::default()); + #[cfg(feature = "wasi_llvm")] + let mut store = Store::new(wasmer::Llvm::default()); + #[cfg(feature = "wasi_singlepass")] + let mut store = Store::new(wasmer::Singlepass::default()); + #[cfg(not(any( + feature = "wasi_cranelift", + feature = "wasi_llvm", + feature = "wasi_singlepass" + )))] + let mut store = { + return Err(anyhow::anyhow!("wasmer-wasi needs one of wasi_cranelift or wasi_llvm or wasi_singlepass features enabled").into()); + }; let mut module = Module::new(&store, atom_bytes)?; module.set_name(&atom_name); From 8715e221e7b5c783b40ead24439262f614e675d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 17 Jan 2023 20:39:35 +0100 Subject: [PATCH 05/38] Allow unused variables --- lib/wasi/src/runners/emscripten.rs | 2 +- lib/wasi/src/runners/wasi.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/wasi/src/runners/emscripten.rs b/lib/wasi/src/runners/emscripten.rs index acf6df06edf..9dd6fa4af01 100644 --- a/lib/wasi/src/runners/emscripten.rs +++ b/lib/wasi/src/runners/emscripten.rs @@ -33,7 +33,7 @@ impl crate::runners::Runner for EmscriptenRunner { .starts_with("https://webc.org/runner/emscripten")) } - #[allow(unreachable_code)] + #[allow(unreachable_code, unused_variables)] fn run_command( &mut self, command_name: &str, diff --git a/lib/wasi/src/runners/wasi.rs b/lib/wasi/src/runners/wasi.rs index 8dfd9c5da2b..7a36179846d 100644 --- a/lib/wasi/src/runners/wasi.rs +++ b/lib/wasi/src/runners/wasi.rs @@ -33,6 +33,7 @@ impl crate::runners::Runner for WasiRunner { Ok(command.runner.starts_with("https://webc.org/runner/wasi")) } + #[allow(unreachable_code, unused_variables)] fn run_command( &mut self, command_name: &str, From 1ca0de826d51854daac85d6f920ad16214335aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 17 Jan 2023 20:51:27 +0100 Subject: [PATCH 06/38] Minimize dependencies of wasmer-headless build --- lib/cli/Cargo.toml | 2 +- lib/cli/src/commands/create_obj.rs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 9fb50a1fb8d..bf19710af7f 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -162,7 +162,7 @@ llvm = [ debug = ["fern", "wasmer-wasi/logging"] disable-all-logging = ["wasmer-wasi/disable-all-logging"] headless = [] -headless-minimal = ["headless", "disable-all-logging", "wasi", "webc_runner", "static-artifact-create"] +headless-minimal = ["headless", "disable-all-logging", "wasi", "webc", "static-artifact-create"] # Optional enable-serde = [ diff --git a/lib/cli/src/commands/create_obj.rs b/lib/cli/src/commands/create_obj.rs index b369590984d..1f715ff1fdf 100644 --- a/lib/cli/src/commands/create_obj.rs +++ b/lib/cli/src/commands/create_obj.rs @@ -11,9 +11,6 @@ use std::path::PathBuf; use wasmer::*; -#[cfg(feature = "webc_runner")] -use webc::{ParseOptions, WebCMmap}; - #[derive(Debug, Parser)] /// The options for the `wasmer create-exe` subcommand pub struct CreateObj { @@ -99,7 +96,7 @@ impl CreateObj { println!("Format: {:?}", object_format); let atoms = - if let Ok(pirita) = WebCMmap::parse(input_path.clone(), &ParseOptions::default()) { + if let Ok(pirita) = webc::WebCMmap::parse(input_path.clone(), &webc::ParseOptions::default()) { crate::commands::create_exe::compile_pirita_into_directory( &pirita, &output_directory_path, From 0678e90cbdf034637e4d2f89ec78b8c8801d4138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 17 Jan 2023 21:02:44 +0100 Subject: [PATCH 07/38] Fix headless-minimal properly --- lib/cli/Cargo.toml | 2 +- lib/cli/src/cli.rs | 9 ++--- lib/cli/src/commands.rs | 10 +++--- lib/cli/src/commands/create_exe.rs | 5 +-- lib/cli/src/commands/create_obj.rs | 53 ++++++++++++++-------------- lib/cli/src/commands/gen_c_header.rs | 6 ++-- lib/cli/src/commands/init.rs | 4 +-- lib/cli/src/common.rs | 4 +++ 8 files changed, 47 insertions(+), 46 deletions(-) diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index bf19710af7f..a1960afa947 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -162,7 +162,7 @@ llvm = [ debug = ["fern", "wasmer-wasi/logging"] disable-all-logging = ["wasmer-wasi/disable-all-logging"] headless = [] -headless-minimal = ["headless", "disable-all-logging", "wasi", "webc", "static-artifact-create"] +headless-minimal = ["headless", "disable-all-logging", "wasi"] # Optional enable-serde = [ diff --git a/lib/cli/src/cli.rs b/lib/cli/src/cli.rs index be137ce53a0..5b65f312951 100644 --- a/lib/cli/src/cli.rs +++ b/lib/cli/src/cli.rs @@ -6,14 +6,13 @@ use crate::commands::Binfmt; use crate::commands::Compile; #[cfg(any(feature = "static-artifact-create", feature = "wasmer-artifact-create"))] use crate::commands::CreateExe; -#[cfg(feature = "static-artifact-create")] -use crate::commands::CreateObj; #[cfg(feature = "wast")] use crate::commands::Wast; use crate::commands::{ - Add, Cache, Config, GenCHeader, Init, Inspect, List, Login, Publish, Run, SelfUpdate, Validate, - Whoami, + Add, Cache, Config, Init, Inspect, List, Login, Publish, Run, SelfUpdate, Validate, Whoami, }; +#[cfg(feature = "static-artifact-create")] +use crate::commands::{CreateObj, GenCHeader}; use crate::error::PrettyError; use clap::{CommandFactory, ErrorKind, Parser}; @@ -130,6 +129,7 @@ enum WasmerCLIOptions { CreateObj(CreateObj), /// Generate the C static_defs.h header file for the input .wasm module + #[cfg(feature = "static-artifact-create")] GenCHeader(GenCHeader), /// Get various configuration information needed @@ -181,6 +181,7 @@ impl WasmerCLIOptions { Self::List(list) => list.execute(), Self::Login(login) => login.execute(), Self::Publish(publish) => publish.execute(), + #[cfg(feature = "static-artifact-create")] Self::GenCHeader(gen_heder) => gen_heder.execute(), #[cfg(feature = "wast")] Self::Wast(wast) => wast.execute(), diff --git a/lib/cli/src/commands.rs b/lib/cli/src/commands.rs index a70d8d42db2..fa241435f1b 100644 --- a/lib/cli/src/commands.rs +++ b/lib/cli/src/commands.rs @@ -10,6 +10,7 @@ mod config; mod create_exe; #[cfg(feature = "static-artifact-create")] mod create_obj; +#[cfg(feature = "static-artifact-create")] mod gen_c_header; mod init; mod inspect; @@ -29,19 +30,18 @@ pub use binfmt::*; pub use compile::*; #[cfg(any(feature = "static-artifact-create", feature = "wasmer-artifact-create"))] pub use create_exe::*; -#[cfg(feature = "static-artifact-create")] -pub use create_obj::*; use serde::{Deserialize, Serialize}; #[cfg(feature = "wast")] pub use wast::*; pub use { - add::*, cache::*, config::*, gen_c_header::*, init::*, inspect::*, list::*, login::*, - publish::*, run::*, self_update::*, validate::*, whoami::*, + add::*, cache::*, config::*, init::*, inspect::*, list::*, login::*, publish::*, run::*, + self_update::*, validate::*, whoami::*, }; +#[cfg(feature = "static-artifact-create")] +pub use {create_obj::*, gen_c_header::*}; /// The kind of object format to emit. #[derive(Debug, Copy, Clone, PartialEq, Eq, clap::Parser, Serialize, Deserialize)] -#[cfg(any(feature = "static-artifact-create", feature = "wasmer-artifact-create"))] pub enum ObjectFormat { /// Serialize the entire module into an object file. Serialized, diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index c804aa86823..84f1db388fc 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -1,6 +1,7 @@ //! Create a standalone native executable for a given Wasm file. use super::ObjectFormat; +use crate::common::normalize_path; use crate::store::CompilerOptions; use anyhow::{Context, Result}; use clap::Parser; @@ -1319,10 +1320,6 @@ fn link_exe_from_dir( Ok(()) } -pub(crate) fn normalize_path(s: &str) -> String { - s.strip_prefix(r"\\?\").unwrap_or(s).to_string() -} - /// Link compiled objects using the system linker #[allow(clippy::too_many_arguments)] fn link_objects_system_linker( diff --git a/lib/cli/src/commands/create_obj.rs b/lib/cli/src/commands/create_obj.rs index 1f715ff1fdf..15f5a5c041c 100644 --- a/lib/cli/src/commands/create_obj.rs +++ b/lib/cli/src/commands/create_obj.rs @@ -70,7 +70,7 @@ pub struct CreateObj { impl CreateObj { /// Runs logic for the `create-obj` subcommand pub fn execute(&self) -> Result<()> { - let path = crate::commands::create_exe::normalize_path(&format!("{}", self.path.display())); + let path = crate::common::normalize_path(&format!("{}", self.path.display())); let target_triple = self.target_triple.clone().unwrap_or_else(Triple::host); let starting_cd = env::current_dir()?; let input_path = starting_cd.join(&path); @@ -95,31 +95,32 @@ impl CreateObj { println!("Target: {}", target.triple()); println!("Format: {:?}", object_format); - let atoms = - if let Ok(pirita) = webc::WebCMmap::parse(input_path.clone(), &webc::ParseOptions::default()) { - crate::commands::create_exe::compile_pirita_into_directory( - &pirita, - &output_directory_path, - &self.compiler, - &self.cpu_features, - &target_triple, - object_format, - &prefix, - crate::commands::AllowMultiWasm::Reject(self.atom.clone()), - self.debug_dir.is_some(), - ) - } else { - crate::commands::create_exe::prepare_directory_from_single_wasm_file( - &input_path, - &output_directory_path, - &self.compiler, - &target_triple, - &self.cpu_features, - object_format, - &prefix, - self.debug_dir.is_some(), - ) - }?; + let atoms = if let Ok(pirita) = + webc::WebCMmap::parse(input_path.clone(), &webc::ParseOptions::default()) + { + crate::commands::create_exe::compile_pirita_into_directory( + &pirita, + &output_directory_path, + &self.compiler, + &self.cpu_features, + &target_triple, + object_format, + &prefix, + crate::commands::AllowMultiWasm::Reject(self.atom.clone()), + self.debug_dir.is_some(), + ) + } else { + crate::commands::create_exe::prepare_directory_from_single_wasm_file( + &input_path, + &output_directory_path, + &self.compiler, + &target_triple, + &self.cpu_features, + object_format, + &prefix, + self.debug_dir.is_some(), + ) + }?; // Copy output files into target path, depending on whether // there are one or many files being compiled diff --git a/lib/cli/src/commands/gen_c_header.rs b/lib/cli/src/commands/gen_c_header.rs index 4ddff10d8b2..2a309af21a6 100644 --- a/lib/cli/src/commands/gen_c_header.rs +++ b/lib/cli/src/commands/gen_c_header.rs @@ -7,8 +7,6 @@ use wasmer_types::compilation::symbols::ModuleMetadataSymbolRegistry; use wasmer_types::{CpuFeature, MetadataHeader, Triple}; use webc::WebC; -use super::normalize_path; - #[derive(Debug, Parser)] /// The options for the `wasmer gen-c-header` subcommand pub struct GenCHeader { @@ -50,7 +48,7 @@ pub struct GenCHeader { impl GenCHeader { /// Runs logic for the `gen-c-header` subcommand pub fn execute(&self) -> Result<(), anyhow::Error> { - let path = crate::commands::normalize_path(&format!("{}", self.path.display())); + let path = crate::common::normalize_path(&format!("{}", self.path.display())); let mut file = std::fs::read(&path) .map_err(|e| anyhow::anyhow!("{e}")) .with_context(|| anyhow::anyhow!("{path}"))?; @@ -126,7 +124,7 @@ impl GenCHeader { metadata_length, ); - let output = normalize_path(&self.output.display().to_string()); + let output = crate::common::normalize_path(&self.output.display().to_string()); std::fs::write(&output, &header_file_src) .map_err(|e| anyhow::anyhow!("{e}")) diff --git a/lib/cli/src/commands/init.rs b/lib/cli/src/commands/init.rs index f6b1fb89e83..584c7764d3b 100644 --- a/lib/cli/src/commands/init.rs +++ b/lib/cli/src/commands/init.rs @@ -428,8 +428,8 @@ fn construct_manifest( .join(&format!("{package_name}.wasm")); let canonicalized_outpath = outpath.canonicalize().unwrap_or(outpath); let outpath_str = - crate::commands::normalize_path(&canonicalized_outpath.display().to_string()); - let manifest_canonicalized = crate::commands::normalize_path( + crate::common::normalize_path(&canonicalized_outpath.display().to_string()); + let manifest_canonicalized = crate::common::normalize_path( &manifest_path .parent() .and_then(|p| p.canonicalize().ok()) diff --git a/lib/cli/src/common.rs b/lib/cli/src/common.rs index 81af03197cd..a06ded1fd19 100644 --- a/lib/cli/src/common.rs +++ b/lib/cli/src/common.rs @@ -51,3 +51,7 @@ pub fn get_cache_dir() -> PathBuf { } } } + +pub(crate) fn normalize_path(s: &str) -> String { + s.strip_prefix(r"\\?\").unwrap_or(s).to_string() +} From e2755b71078ffb9103561762474b2b295e6c02c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 17 Jan 2023 20:04:29 +0100 Subject: [PATCH 08/38] Fix make lint --- lib/api/src/sys/imports.rs | 1 + lib/api/src/sys/instance.rs | 2 ++ lib/api/src/sys/module.rs | 1 + lib/c-api/src/wasm_c_api/engine.rs | 10 ++++---- lib/cli/src/commands/create_exe.rs | 10 ++++---- lib/cli/src/commands/init.rs | 4 +-- lib/cli/src/commands/publish.rs | 4 +-- lib/cli/src/commands/run.rs | 2 +- lib/compiler-llvm/src/abi/aarch64_systemv.rs | 13 +++------- lib/compiler-llvm/src/abi/x86_64_systemv.rs | 13 +++------- lib/compiler-llvm/src/translator/code.rs | 1 + lib/compiler-singlepass/src/arm64_decl.rs | 3 ++- lib/compiler-singlepass/src/codegen.rs | 4 +-- lib/compiler-singlepass/src/emitter_arm64.rs | 26 ++++++++++++++------ lib/compiler-singlepass/src/machine_arm64.rs | 2 ++ lib/compiler/src/engine/artifact.rs | 3 +++ lib/compiler/src/engine/resolver.rs | 1 + lib/compiler/src/engine/tunables.rs | 3 +++ lib/emscripten/src/syscalls/mod.rs | 1 + lib/vbus/src/lib.rs | 2 +- lib/vm/src/vmcontext.rs | 4 +-- lib/wasi/src/runtime.rs | 7 +++--- lib/wasi/src/state/mod.rs | 12 ++++----- lib/wasi/src/syscalls/mod.rs | 3 +-- 24 files changed, 74 insertions(+), 58 deletions(-) diff --git a/lib/api/src/sys/imports.rs b/lib/api/src/sys/imports.rs index a08d1b6adad..fd753c40ff9 100644 --- a/lib/api/src/sys/imports.rs +++ b/lib/api/src/sys/imports.rs @@ -174,6 +174,7 @@ impl Imports { /// Resolve and return a vector of imports in the order they are defined in the `module`'s source code. /// /// This means the returned `Vec` might be a subset of the imports contained in `self`. + #[allow(clippy::result_large_err)] pub fn imports_for_module(&self, module: &Module) -> Result, LinkError> { let mut ret = vec![]; for import in module.imports() { diff --git a/lib/api/src/sys/instance.rs b/lib/api/src/sys/instance.rs index 4e0d90d3f18..877749ca789 100644 --- a/lib/api/src/sys/instance.rs +++ b/lib/api/src/sys/instance.rs @@ -111,6 +111,7 @@ impl Instance { /// Those are, as defined by the spec: /// * Link errors that happen when plugging the imports into the instance /// * Runtime errors that happen when running the module `start` function. + #[allow(clippy::result_large_err)] pub fn new( store: &mut impl AsStoreMut, module: &Module, @@ -158,6 +159,7 @@ impl Instance { /// Those are, as defined by the spec: /// * Link errors that happen when plugging the imports into the instance /// * Runtime errors that happen when running the module `start` function. + #[allow(clippy::result_large_err)] pub fn new_by_index( store: &mut impl AsStoreMut, module: &Module, diff --git a/lib/api/src/sys/module.rs b/lib/api/src/sys/module.rs index 9d49179265e..a83f5f10f04 100644 --- a/lib/api/src/sys/module.rs +++ b/lib/api/src/sys/module.rs @@ -311,6 +311,7 @@ impl Module { } } + #[allow(clippy::result_large_err)] #[cfg(feature = "compiler")] pub(crate) fn instantiate( &self, diff --git a/lib/c-api/src/wasm_c_api/engine.rs b/lib/c-api/src/wasm_c_api/engine.rs index 0c69c78db56..0cb0a54d615 100644 --- a/lib/c-api/src/wasm_c_api/engine.rs +++ b/lib/c-api/src/wasm_c_api/engine.rs @@ -117,7 +117,7 @@ pub struct wasm_config_t { /// cbindgen:ignore #[no_mangle] pub extern "C" fn wasm_config_new() -> Box { - Box::new(wasm_config_t::default()) + Box::::default() } /// Delete a Wasmer config object. @@ -256,11 +256,11 @@ use wasmer_api::CompilerConfig; fn get_default_compiler_config() -> Box { cfg_if! { if #[cfg(feature = "cranelift")] { - Box::new(wasmer_compiler_cranelift::Cranelift::default()) + Box::::default() } else if #[cfg(feature = "llvm")] { - Box::new(wasmer_compiler_llvm::LLVM::default()) + Box::::default() } else if #[cfg(feature = "singlepass")] { - Box::new(wasmer_compiler_singlepass::Singlepass::default()) + Box::::default() } else { compile_error!("Please enable one of the compiler backends") } @@ -368,7 +368,7 @@ pub extern "C" fn wasm_engine_new_with_config( wasmer_compiler_t::CRANELIFT => { cfg_if! { if #[cfg(feature = "cranelift")] { - Box::new(wasmer_compiler_cranelift::Cranelift::default()) + Box::::default() } else { return return_with_error("Wasmer has not been compiled with the `cranelift` feature."); } diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 84f1db388fc..9f75d8deb2f 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -867,7 +867,7 @@ fn write_volume_obj( object_name, )?; - let mut writer = BufWriter::new(File::create(&output_path)?); + let mut writer = BufWriter::new(File::create(output_path)?); volumes_object .write_stream(&mut writer) .map_err(|err| anyhow::anyhow!(err.to_string()))?; @@ -1050,7 +1050,7 @@ pub(crate) fn create_header_files_in_dir( &ModuleMetadataSymbolRegistry { prefix: prefix.clone(), }, - metadata_length as usize, + metadata_length, ); std::fs::write(&header_file_path, &header_file_src).map_err(|e| { @@ -1195,7 +1195,7 @@ fn link_exe_from_dir( .as_ref() .ok_or_else(|| anyhow::anyhow!("could not find zig in $PATH {}", directory.display()))?; - let mut cmd = Command::new(&zig_binary_path); + let mut cmd = Command::new(zig_binary_path); cmd.arg("build-exe"); cmd.arg("--verbose-cc"); cmd.arg("--verbose-link"); @@ -1872,7 +1872,7 @@ pub(super) mod utils { let path_var = std::env::var("PATH").unwrap_or_default(); #[cfg(unix)] let system_path_var = std::process::Command::new("getconf") - .args(&["PATH"]) + .args(["PATH"]) .output() .map(|output| output.stdout) .unwrap_or_default(); @@ -2265,7 +2265,7 @@ mod http_fetch { pub(crate) fn list_dir(target: &Path) -> Vec { use walkdir::WalkDir; - WalkDir::new(&target) + WalkDir::new(target) .into_iter() .filter_map(|e| e.ok()) .map(|entry| entry.path().to_path_buf()) diff --git a/lib/cli/src/commands/init.rs b/lib/cli/src/commands/init.rs index 584c7764d3b..b31f7ec14dd 100644 --- a/lib/cli/src/commands/init.rs +++ b/lib/cli/src/commands/init.rs @@ -160,7 +160,7 @@ impl Init { .collect::>() .join(NEWLINE); - std::fs::write(&path, &toml_string) + std::fs::write(path, &toml_string) .with_context(|| format!("Unable to write to \"{}\"", path.display()))?; Ok(()) @@ -493,7 +493,7 @@ fn construct_manifest( } fn parse_cargo_toml(manifest_path: &PathBuf) -> Result { let mut metadata = MetadataCommand::new(); - metadata.manifest_path(&manifest_path); + metadata.manifest_path(manifest_path); metadata.no_deps(); metadata.features(CargoOpt::AllFeatures); diff --git a/lib/cli/src/commands/publish.rs b/lib/cli/src/commands/publish.rs index 889a39f1457..7f2136cd17a 100644 --- a/lib/cli/src/commands/publish.rs +++ b/lib/cli/src/commands/publish.rs @@ -247,7 +247,7 @@ fn append_path_to_tar_gz( .metadata() .map_err(|e| (normalized_path.clone(), e))?; builder - .append_path_with_name(&normalized_path, &target_path) + .append_path_with_name(&normalized_path, target_path) .map_err(|e| (normalized_path.clone(), e))?; Ok(normalized_path) } @@ -386,7 +386,7 @@ fn apply_migration(conn: &mut Connection, migration_number: i32) -> Result<(), M tx.execute_batch(migration_to_apply) .map_err(|e| MigrationError::TransactionFailed(migration_number, format!("{}", e)))?; - tx.pragma_update(None, "user_version", &(migration_number + 1)) + tx.pragma_update(None, "user_version", (migration_number + 1)) .map_err(|e| MigrationError::TransactionFailed(migration_number, format!("{}", e)))?; tx.commit() .map_err(|_| MigrationError::CommitFailed(migration_number)) diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index e3c968ebd6b..b53c5644475 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -124,7 +124,7 @@ impl RunWithPathBuf { let default = HashMap::default(); let fs = manifest.fs.as_ref().unwrap_or(&default); for (alias, real_dir) in fs.iter() { - let real_dir = self_clone.path.join(&real_dir); + let real_dir = self_clone.path.join(real_dir); if !real_dir.exists() { #[cfg(feature = "debug")] if self_clone.debug { diff --git a/lib/compiler-llvm/src/abi/aarch64_systemv.rs b/lib/compiler-llvm/src/abi/aarch64_systemv.rs index 8bcb65a008c..63069de8a22 100644 --- a/lib/compiler-llvm/src/abi/aarch64_systemv.rs +++ b/lib/compiler-llvm/src/abi/aarch64_systemv.rs @@ -21,19 +21,14 @@ impl Abi for Aarch64SystemV { // Given a function definition, retrieve the parameter that is the vmctx pointer. fn get_vmctx_ptr_param<'ctx>(&self, func_value: &FunctionValue<'ctx>) -> PointerValue<'ctx> { func_value - .get_nth_param( - if func_value + .get_nth_param(u32::from( + func_value .get_enum_attribute( AttributeLoc::Param(0), Attribute::get_named_enum_kind_id("sret"), ) - .is_some() - { - 1 - } else { - 0 - }, - ) + .is_some(), + )) .unwrap() .into_pointer_value() } diff --git a/lib/compiler-llvm/src/abi/x86_64_systemv.rs b/lib/compiler-llvm/src/abi/x86_64_systemv.rs index 7075193080a..2e444d078a0 100644 --- a/lib/compiler-llvm/src/abi/x86_64_systemv.rs +++ b/lib/compiler-llvm/src/abi/x86_64_systemv.rs @@ -23,19 +23,14 @@ impl Abi for X86_64SystemV { // Given a function definition, retrieve the parameter that is the vmctx pointer. fn get_vmctx_ptr_param<'ctx>(&self, func_value: &FunctionValue<'ctx>) -> PointerValue<'ctx> { func_value - .get_nth_param( - if func_value + .get_nth_param(u32::from( + func_value .get_enum_attribute( AttributeLoc::Param(0), Attribute::get_named_enum_kind_id("sret"), ) - .is_some() - { - 1 - } else { - 0 - }, - ) + .is_some(), + )) .unwrap() .into_pointer_value() } diff --git a/lib/compiler-llvm/src/translator/code.rs b/lib/compiler-llvm/src/translator/code.rs index 8bdd065532c..8d35957c9de 100644 --- a/lib/compiler-llvm/src/translator/code.rs +++ b/lib/compiler-llvm/src/translator/code.rs @@ -1048,6 +1048,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Ok(()) } + #[allow(clippy::unnecessary_cast)] fn resolve_memory_ptr( &mut self, memory_index: MemoryIndex, diff --git a/lib/compiler-singlepass/src/arm64_decl.rs b/lib/compiler-singlepass/src/arm64_decl.rs index b810cfa763c..1bcf54c20f8 100644 --- a/lib/compiler-singlepass/src/arm64_decl.rs +++ b/lib/compiler-singlepass/src/arm64_decl.rs @@ -8,6 +8,7 @@ use std::slice::Iter; use wasmer_types::{CallingConvention, Type}; /// General-purpose registers. +#[allow(clippy::upper_case_acronyms)] #[repr(u8)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] pub enum GPR { @@ -48,7 +49,7 @@ pub enum GPR { /// NEON registers. #[repr(u8)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] -#[allow(dead_code)] +#[allow(dead_code, clippy::upper_case_acronyms)] pub enum NEON { V0 = 0, V1 = 1, diff --git a/lib/compiler-singlepass/src/codegen.rs b/lib/compiler-singlepass/src/codegen.rs index 9b24e3be68f..c9ab5760d45 100644 --- a/lib/compiler-singlepass/src/codegen.rs +++ b/lib/compiler-singlepass/src/codegen.rs @@ -1143,7 +1143,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { let fsm = FunctionStateMap::new( machine.new_machine_state(), - local_func_index.index() as usize, + local_func_index.index(), 32, (0..local_types.len()) .map(|_| WasmAbstractValue::Runtime) @@ -6057,7 +6057,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { .emit_call_register(this.machine.get_grp_for_call()) }, // [vmctx, func_index] -> funcref - iter::once(Location::Imm32(function_index as u32)), + iter::once(Location::Imm32(function_index)), iter::once(WpType::I64), )?; diff --git a/lib/compiler-singlepass/src/emitter_arm64.rs b/lib/compiler-singlepass/src/emitter_arm64.rs index 948fe793ced..104d7787c9b 100644 --- a/lib/compiler-singlepass/src/emitter_arm64.rs +++ b/lib/compiler-singlepass/src/emitter_arm64.rs @@ -805,6 +805,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } + #[allow(clippy::unnecessary_cast)] fn emit_ldria( &mut self, sz: Size, @@ -849,6 +850,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } + #[allow(clippy::unnecessary_cast)] fn emit_ldpia( &mut self, sz: Size, @@ -1248,9 +1250,9 @@ impl EmitterARM64 for Assembler { (Size::S64, Location::Imm64(val), Location::GPR(dst)) => { let dst = dst.into_index() as u32; if val < 0x1000 { - dynasm!(self ; mov W(dst), val as u64); + dynasm!(self ; mov W(dst), val); } else if encode_logical_immediate_64bit(val as _).is_some() { - dynasm!(self ; orr X(dst), xzr, val as u64); + dynasm!(self ; orr X(dst), xzr, val); } else { codegen_error!("singleplasse can't emit MOV S64 {}, {:?}", val, dst); } @@ -1594,6 +1596,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } + #[allow(clippy::unnecessary_cast)] fn emit_add_lsl( &mut self, sz: Size, @@ -1621,6 +1624,7 @@ impl EmitterARM64 for Assembler { Ok(()) } + #[allow(clippy::unnecessary_cast)] fn emit_cmp(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S64, Location::GPR(src), Location::GPR(dst)) => { @@ -1642,7 +1646,7 @@ impl EmitterARM64 for Assembler { if imm >= 0x1000 { codegen_error!("singlepass CMP with imm too large {}", imm); } - dynasm!(self ; cmp X(dst), imm as u32); + dynasm!(self ; cmp X(dst), imm); } (Size::S64, Location::Imm64(imm), Location::GPR(dst)) => { let dst = dst.into_index() as u32; @@ -1683,10 +1687,10 @@ impl EmitterARM64 for Assembler { } (Size::S64, Location::Imm64(imm), Location::GPR(dst)) => { let dst = dst.into_index() as u32; - if encode_logical_immediate_64bit(imm as u64).is_none() { + if encode_logical_immediate_64bit(imm).is_none() { codegen_error!("singlepass TST with incompatible imm {}", imm); } - dynasm!(self ; tst X(dst), imm as u64); + dynasm!(self ; tst X(dst), imm); } (Size::S32, Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -1724,7 +1728,6 @@ impl EmitterARM64 for Assembler { if imm > 63 { codegen_error!("singlepass LSL with incompatible imm {}", imm); } - let imm = imm as u32; let dst = dst.into_index() as u32; dynasm!(self ; lsl X(dst), X(src1), imm); } @@ -1768,7 +1771,7 @@ impl EmitterARM64 for Assembler { if imm > 31 { codegen_error!("singlepass LSL with incompatible imm {}", imm); } - dynasm!(self ; lsl W(dst), W(src1), imm as u32); + dynasm!(self ; lsl W(dst), W(src1), imm); } _ => codegen_error!( "singlepass can't emit LSL {:?} {:?} {:?} {:?}", @@ -1780,6 +1783,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } + #[allow(clippy::unnecessary_cast)] fn emit_asr( &mut self, sz: Size, @@ -1843,7 +1847,7 @@ impl EmitterARM64 for Assembler { if imm == 0 || imm > 31 { codegen_error!("singlepass ASR with incompatible imm {}", imm); } - dynasm!(self ; asr W(dst), W(src1), imm as u32); + dynasm!(self ; asr W(dst), W(src1), imm); } _ => codegen_error!( "singlepass can't emit ASR {:?} {:?} {:?} {:?}", @@ -1855,6 +1859,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } + #[allow(clippy::unnecessary_cast)] fn emit_lsr( &mut self, sz: Size, @@ -1930,6 +1935,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } + #[allow(clippy::unnecessary_cast)] fn emit_ror( &mut self, sz: Size, @@ -1998,6 +2004,7 @@ impl EmitterARM64 for Assembler { Ok(()) } + #[allow(clippy::unnecessary_cast)] fn emit_or( &mut self, sz: Size, @@ -2046,6 +2053,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } + #[allow(clippy::unnecessary_cast)] fn emit_and( &mut self, sz: Size, @@ -2094,6 +2102,7 @@ impl EmitterARM64 for Assembler { } Ok(()) } + #[allow(clippy::unnecessary_cast)] fn emit_eor( &mut self, sz: Size, @@ -3209,6 +3218,7 @@ impl EmitterARM64 for Assembler { } } +#[allow(clippy::unnecessary_cast)] pub fn gen_std_trampoline_arm64( sig: &FunctionType, calling_convention: CallingConvention, diff --git a/lib/compiler-singlepass/src/machine_arm64.rs b/lib/compiler-singlepass/src/machine_arm64.rs index b07e0f46ed9..4788e50618a 100644 --- a/lib/compiler-singlepass/src/machine_arm64.rs +++ b/lib/compiler-singlepass/src/machine_arm64.rs @@ -168,6 +168,7 @@ impl MachineARM64 { } } + #[allow(clippy::unnecessary_cast)] fn location_to_reg( &mut self, sz: Size, @@ -320,6 +321,7 @@ impl MachineARM64 { _ => codegen_error!("singlepass can't emit location_to_reg {:?} {:?}", sz, src), } } + #[allow(clippy::unnecessary_cast)] fn location_to_neon( &mut self, sz: Size, diff --git a/lib/compiler/src/engine/artifact.rs b/lib/compiler/src/engine/artifact.rs index b9ac9029227..a0c6d9bb1ea 100644 --- a/lib/compiler/src/engine/artifact.rs +++ b/lib/compiler/src/engine/artifact.rs @@ -300,6 +300,7 @@ impl Artifact { } /// Do preinstantiation logic that is executed before instantiating + #[allow(clippy::result_large_err)] pub fn preinstantiate(&self) -> Result<(), InstantiationError> { Ok(()) } @@ -309,6 +310,7 @@ impl Artifact { /// # Safety /// /// See [`InstanceHandle::new`]. + #[allow(clippy::result_large_err)] pub unsafe fn instantiate( &self, tunables: &dyn Tunables, @@ -389,6 +391,7 @@ impl Artifact { /// # Safety /// /// See [`InstanceHandle::finish_instantiation`]. + #[allow(clippy::result_large_err)] pub unsafe fn finish_instantiation( &self, trap_handler: Option<*const TrapHandlerFn<'static>>, diff --git a/lib/compiler/src/engine/resolver.rs b/lib/compiler/src/engine/resolver.rs index 9fac5fc0aec..e4699370bd0 100644 --- a/lib/compiler/src/engine/resolver.rs +++ b/lib/compiler/src/engine/resolver.rs @@ -60,6 +60,7 @@ fn get_runtime_size(context: &StoreObjects, extern_: &VMExtern) -> Option { /// a `Resolver`. /// /// If all imports are satisfied returns an `Imports` instance required for a module instantiation. +#[allow(clippy::result_large_err)] pub fn resolve_imports( module: &ModuleInfo, imports: &[VMExtern], diff --git a/lib/compiler/src/engine/tunables.rs b/lib/compiler/src/engine/tunables.rs index 9eab1ce85f1..12b16ea563b 100644 --- a/lib/compiler/src/engine/tunables.rs +++ b/lib/compiler/src/engine/tunables.rs @@ -65,6 +65,7 @@ pub trait Tunables { /// /// # Safety /// - `memory_definition_locations` must point to a valid locations in VM memory. + #[allow(clippy::result_large_err)] unsafe fn create_memories( &self, context: &mut StoreObjects, @@ -98,6 +99,7 @@ pub trait Tunables { /// # Safety /// /// To be done + #[allow(clippy::result_large_err)] unsafe fn create_tables( &self, context: &mut StoreObjects, @@ -128,6 +130,7 @@ pub trait Tunables { /// Allocate memory for just the globals of the current module, /// with initializers applied. + #[allow(clippy::result_large_err)] fn create_globals( &self, context: &mut StoreObjects, diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 42ce7b1ece4..41ba7761c69 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -405,6 +405,7 @@ pub fn ___syscall192(mut ctx: FunctionEnvMut, _which: c_int, mut varargs: } /// lseek +#[allow(clippy::unnecessary_cast)] pub fn ___syscall140(ctx: FunctionEnvMut, _which: i32, mut varargs: VarArgs) -> i32 { // -> c_int debug!("emscripten::___syscall140 (lseek) {}", _which); diff --git a/lib/vbus/src/lib.rs b/lib/vbus/src/lib.rs index e51ec11ffac..0b6696d64ff 100644 --- a/lib/vbus/src/lib.rs +++ b/lib/vbus/src/lib.rs @@ -285,7 +285,7 @@ pub struct UnsupportedVirtualBus {} impl VirtualBus for UnsupportedVirtualBus { fn new_spawn(&self) -> SpawnOptions { - SpawnOptions::new(Box::new(UnsupportedVirtualBusSpawner::default())) + SpawnOptions::new(Box::::default()) } fn listen(&self) -> Result> { diff --git a/lib/vm/src/vmcontext.rs b/lib/vm/src/vmcontext.rs index f87df89c471..d682f53d554 100644 --- a/lib/vm/src/vmcontext.rs +++ b/lib/vm/src/vmcontext.rs @@ -404,7 +404,7 @@ pub(crate) unsafe fn memory32_atomic_check32( let dst = mem.base.offset(dst) as *mut u32; let atomic_dst = AtomicPtr::new(dst); let read_val = *atomic_dst.load(Ordering::Acquire); - let ret = if read_val == val { 0 } else { 1 }; + let ret = u32::from(read_val != val); Ok(ret) } @@ -435,7 +435,7 @@ pub(crate) unsafe fn memory32_atomic_check64( let dst = mem.base.offset(dst) as *mut u64; let atomic_dst = AtomicPtr::new(dst); let read_val = *atomic_dst.load(Ordering::Acquire); - let ret = if read_val == val { 0 } else { 1 }; + let ret = u32::from(read_val != val); Ok(ret) } diff --git a/lib/wasi/src/runtime.rs b/lib/wasi/src/runtime.rs index 1394e010b8a..6b6893a77b8 100644 --- a/lib/wasi/src/runtime.rs +++ b/lib/wasi/src/runtime.rs @@ -123,14 +123,15 @@ impl PluggableRuntimeImplementation { } } +#[allow(clippy::derivable_impls)] impl Default for PluggableRuntimeImplementation { fn default() -> Self { Self { #[cfg(not(feature = "host-vnet"))] - networking: Box::new(wasmer_vnet::UnsupportedVirtualNetworking::default()), + networking: Box::::default(), #[cfg(feature = "host-vnet")] - networking: Box::new(wasmer_wasi_local_networking::LocalNetworking::default()), - bus: Box::new(UnsupportedVirtualBus::default()), + networking: Box::::default(), + bus: Box::::default(), thread_id_seed: Default::default(), } } diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index 69f83ee548e..0715d645bde 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -356,11 +356,11 @@ pub struct WasiFs { pub(crate) fn default_fs_backing() -> Box { cfg_if::cfg_if! { if #[cfg(feature = "host-fs")] { - Box::new(wasmer_vfs::host_fs::FileSystem::default()) + Box::::default() } else if #[cfg(feature = "mem-fs")] { - Box::new(wasmer_vfs::mem_fs::FileSystem::default()) + Box::::default() } else { - Box::new(FallbackFileSystem::default()) + Box::::default() } } } @@ -1550,7 +1550,7 @@ impl WasiFs { fn create_stdout(&self, inodes: &mut WasiInodes) { self.create_std_dev_inner( inodes, - Box::new(Stdout::default()), + Box::::default(), "stdout", __WASI_STDOUT_FILENO, STDOUT_DEFAULT_RIGHTS, @@ -1560,7 +1560,7 @@ impl WasiFs { fn create_stdin(&self, inodes: &mut WasiInodes) { self.create_std_dev_inner( inodes, - Box::new(Stdin::default()), + Box::::default(), "stdin", __WASI_STDIN_FILENO, STDIN_DEFAULT_RIGHTS, @@ -1570,7 +1570,7 @@ impl WasiFs { fn create_stderr(&self, inodes: &mut WasiInodes) { self.create_std_dev_inner( inodes, - Box::new(Stderr::default()), + Box::::default(), "stderr", __WASI_STDERR_FILENO, STDERR_DEFAULT_RIGHTS, diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index ebf755d920a..01328a25ad3 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -877,8 +877,7 @@ pub fn fd_pread( Kind::File { handle, .. } => { if let Some(h) = handle { wasi_try_ok!( - h.seek(std::io::SeekFrom::Start(offset as u64)) - .map_err(map_io_err), + h.seek(std::io::SeekFrom::Start(offset)).map_err(map_io_err), env ); wasi_try_ok!(read_bytes(h, &memory, iovs), env) From 912f21ab03ab3534c917348a902b525e8f7cbce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 17 Jan 2023 21:23:07 +0100 Subject: [PATCH 09/38] Fix make lint --- lib/c-api/src/wasm_c_api/wasi/mod.rs | 4 ++-- lib/cache/src/hash.rs | 2 +- lib/cli/build.rs | 2 +- lib/cli/src/commands/publish.rs | 2 +- lib/emscripten/src/env/mod.rs | 4 ++-- lib/registry/src/lib.rs | 4 ++-- lib/vfs/src/webc_fs.rs | 3 ++- lib/wasi/src/lib.rs | 4 ++-- lib/wasi/src/state/pipe.rs | 4 ++-- lib/wasi/src/syscalls/mod.rs | 6 ++++-- tests/lib/test-generator/src/lib.rs | 3 +-- tests/lib/wast/src/wast.rs | 2 +- tests/wasi-wast/src/wasitests.rs | 4 ++-- 13 files changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/c-api/src/wasm_c_api/wasi/mod.rs b/lib/c-api/src/wasm_c_api/wasi/mod.rs index 1f3354d0a77..fb7395e1e49 100644 --- a/lib/c-api/src/wasm_c_api/wasi/mod.rs +++ b/lib/c-api/src/wasm_c_api/wasi/mod.rs @@ -342,7 +342,7 @@ pub unsafe extern "C" fn wasi_env_read_stdout( buffer: *mut c_char, buffer_len: usize, ) -> isize { - let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len as usize); + let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len); let mut store_mut = env.store.store_mut(); let state = env.inner.data_mut(&mut store_mut).state(); @@ -365,7 +365,7 @@ pub unsafe extern "C" fn wasi_env_read_stderr( buffer: *mut c_char, buffer_len: usize, ) -> isize { - let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len as usize); + let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len); let mut store_mut = env.store.store_mut(); let state = env.inner.data_mut(&mut store_mut).state(); if let Ok(mut stderr) = state.stderr() { diff --git a/lib/cache/src/hash.rs b/lib/cache/src/hash.rs index 29e7fa7ce65..2a4b6fb7b5a 100644 --- a/lib/cache/src/hash.rs +++ b/lib/cache/src/hash.rs @@ -31,7 +31,7 @@ impl ToString for Hash { /// Create the hexadecimal representation of the /// stored hash. fn to_string(&self) -> String { - hex::encode(&self.to_array()) + hex::encode(self.to_array()) } } diff --git a/lib/cli/build.rs b/lib/cli/build.rs index f9aecaaf01c..4444630121c 100644 --- a/lib/cli/build.rs +++ b/lib/cli/build.rs @@ -4,7 +4,7 @@ use std::process::Command; pub fn main() { // Set WASMER_GIT_HASH let git_hash = Command::new("git") - .args(&["rev-parse", "HEAD"]) + .args(["rev-parse", "HEAD"]) .output() .ok() .and_then(|output| String::from_utf8(output.stdout).ok()) diff --git a/lib/cli/src/commands/publish.rs b/lib/cli/src/commands/publish.rs index 7f2136cd17a..0c6756de48a 100644 --- a/lib/cli/src/commands/publish.rs +++ b/lib/cli/src/commands/publish.rs @@ -386,7 +386,7 @@ fn apply_migration(conn: &mut Connection, migration_number: i32) -> Result<(), M tx.execute_batch(migration_to_apply) .map_err(|e| MigrationError::TransactionFailed(migration_number, format!("{}", e)))?; - tx.pragma_update(None, "user_version", (migration_number + 1)) + tx.pragma_update(None, "user_version", migration_number + 1) .map_err(|e| MigrationError::TransactionFailed(migration_number, format!("{}", e)))?; tx.commit() .map_err(|_| MigrationError::CommitFailed(migration_number)) diff --git a/lib/emscripten/src/env/mod.rs b/lib/emscripten/src/env/mod.rs index a560a416912..03e05fb7417 100644 --- a/lib/emscripten/src/env/mod.rs +++ b/lib/emscripten/src/env/mod.rs @@ -79,9 +79,9 @@ pub fn ___build_environment(mut ctx: FunctionEnvMut, environ: c_int) { let environment = emscripten_memory_pointer!(memory.view(&ctx), environ) as *mut c_int; let (mut pool_offset, env_ptr, mut pool_ptr) = unsafe { let (pool_offset, _pool_slice): (u32, &mut [u8]) = - allocate_on_stack(&mut ctx, TOTAL_ENV_SIZE as u32); + allocate_on_stack(&mut ctx, TOTAL_ENV_SIZE); let (env_offset, _env_slice): (u32, &mut [u8]) = - allocate_on_stack(&mut ctx, (MAX_ENV_VALUES * 4) as u32); + allocate_on_stack(&mut ctx, MAX_ENV_VALUES * 4); let env_ptr = emscripten_memory_pointer!(memory.view(&ctx), env_offset) as *mut c_int; let pool_ptr = emscripten_memory_pointer!(memory.view(&ctx), pool_offset) as *mut u8; *env_ptr = pool_offset as i32; diff --git a/lib/registry/src/lib.rs b/lib/registry/src/lib.rs index bb6f6a162c8..d1300bdfbb4 100644 --- a/lib/registry/src/lib.rs +++ b/lib/registry/src/lib.rs @@ -418,7 +418,7 @@ pub fn try_unpack_targz>( let target_targz_path = target_targz_path.as_ref(); let target_path = target_path.as_ref(); let open_file = || { - std::fs::File::open(&target_targz_path) + std::fs::File::open(target_targz_path) .map_err(|e| anyhow::anyhow!("failed to open {}: {e}", target_targz_path.display())) }; @@ -860,7 +860,7 @@ fn get_bytes( } if let Some(path) = stream_response_into.as_ref() { - let mut file = std::fs::File::create(&path).map_err(|e| { + let mut file = std::fs::File::create(path).map_err(|e| { anyhow::anyhow!("failed to download {url} into {}: {e}", path.display()) })?; diff --git a/lib/vfs/src/webc_fs.rs b/lib/vfs/src/webc_fs.rs index 34402356357..6b6d467cb8c 100644 --- a/lib/vfs/src/webc_fs.rs +++ b/lib/vfs/src/webc_fs.rs @@ -66,7 +66,8 @@ where ) -> Result, FsError> { match get_volume_name_opt(path) { Some(volume) => { - let file = (*self.webc) + let file = self + .webc .volumes .get(&volume) .ok_or(FsError::EntityNotFound)? diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 79a518c6fff..340a5d63745 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -102,7 +102,7 @@ impl From for WasiThreadId { } impl From for u32 { fn from(t: WasiThreadId) -> u32 { - t.0 as u32 + t.0 } } @@ -117,7 +117,7 @@ impl From for WasiBusProcessId { } impl From for u32 { fn from(id: WasiBusProcessId) -> u32 { - id.0 as u32 + id.0 } } diff --git a/lib/wasi/src/state/pipe.rs b/lib/wasi/src/state/pipe.rs index 4781ab0a02f..d91f6a108d5 100644 --- a/lib/wasi/src/state/pipe.rs +++ b/lib/wasi/src/state/pipe.rs @@ -50,7 +50,7 @@ impl WasiPipe { let buf_len = buf.len(); if buf_len > 0 { let reader = buf.as_ref(); - let read = read_bytes(reader, memory, iov).map(|_| buf_len as usize)?; + let read = read_bytes(reader, memory, iov).map(|_| buf_len)?; buf.advance(read); return Ok(read); } @@ -101,7 +101,7 @@ impl Read for WasiPipe { let buf_len = inner_buf.len(); if buf_len > 0 { let mut reader = inner_buf.as_ref(); - let read = reader.read(buf).map(|_| buf_len as usize)?; + let read = reader.read(buf).map(|_| buf_len)?; inner_buf.advance(read); return Ok(read); } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 01328a25ad3..d69eaca8543 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -998,6 +998,7 @@ pub fn fd_prestat_dir_name( /// Output: /// - `u32 *nwritten` /// Number of bytes written +#[allow(clippy::unnecessary_cast)] pub fn fd_pwrite( ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, @@ -2781,7 +2782,7 @@ pub fn path_rename( // implements the logic of "I'm not actually a file, I'll try to be as needed". let result = if let Some(h) = handle { drop(guard); - state.fs_rename(&source_path, &host_adjusted_target_path) + state.fs_rename(source_path, &host_adjusted_target_path) } else { let path_clone = path.clone(); drop(guard); @@ -3594,6 +3595,7 @@ pub fn thread_spawn( /// ## Parameters /// /// * `duration` - Amount of time that the thread should sleep +#[allow(clippy::unnecessary_cast)] pub fn thread_sleep( ctx: FunctionEnvMut<'_, WasiEnv>, duration: Timestamp, @@ -5462,7 +5464,7 @@ pub unsafe fn sock_send_file( { let mut fd_map = state.fs.fd_map.write().unwrap(); let fd_entry = wasi_try_ok!(fd_map.get_mut(&in_fd).ok_or(Errno::Badf)); - fd_entry.offset = offset as u64; + fd_entry.offset = offset; } // Enter a loop that will process all the data diff --git a/tests/lib/test-generator/src/lib.rs b/tests/lib/test-generator/src/lib.rs index e3256e3c264..b1e4a16e09c 100644 --- a/tests/lib/test-generator/src/lib.rs +++ b/tests/lib/test-generator/src/lib.rs @@ -85,8 +85,7 @@ pub fn extract_name(path: impl AsRef) -> String { .expect("filename should have a stem") .to_str() .expect("filename should be representable as a string") - .replace('-', "_") - .replace('/', "_") + .replace(['-', '/'], "_") } pub fn with_test_module( diff --git a/tests/lib/wast/src/wast.rs b/tests/lib/wast/src/wast.rs index 50bc02b3883..80b02adc276 100644 --- a/tests/lib/wast/src/wast.rs +++ b/tests/lib/wast/src/wast.rs @@ -437,7 +437,7 @@ impl Wast { // Checks if the `assert_unlinkable` message matches the expected one fn matches_message_assert_unlinkable(expected: &str, actual: &str) -> bool { - actual.contains(&expected) + actual.contains(expected) } // Checks if the `assert_invalid` message matches the expected one diff --git a/tests/wasi-wast/src/wasitests.rs b/tests/wasi-wast/src/wasitests.rs index 2a204d8a587..d01d048c13e 100644 --- a/tests/wasi-wast/src/wasitests.rs +++ b/tests/wasi-wast/src/wasitests.rs @@ -124,7 +124,7 @@ fn compile_wasm_for_version( ) -> io::Result { //let out_dir = base_dir; //base_dir.join("..").join(version.get_directory_name()); if !out_dir.exists() { - fs::create_dir(&out_dir)?; + fs::create_dir(out_dir)?; } let wasm_out_name = { let mut wasm_out_name = out_dir.join(rs_mod_name); @@ -134,7 +134,7 @@ fn compile_wasm_for_version( println!("Reading contents from file `{}`", file); let file_contents: String = { let mut fc = String::new(); - let mut f = fs::OpenOptions::new().read(true).open(&file)?; + let mut f = fs::OpenOptions::new().read(true).open(file)?; f.read_to_string(&mut fc)?; fc }; From 8183474d109c9fc3c358fa146477e038abe9e3e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 17 Jan 2023 21:38:25 +0100 Subject: [PATCH 10/38] Adjust feature flags --- Cargo.toml | 8 ++++---- lib/c-api/Cargo.toml | 6 ++++++ lib/cli/Cargo.toml | 2 +- lib/wasi-experimental-io-devices/Cargo.toml | 2 +- tests/lib/wast/Cargo.toml | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 25dbdf20a83..ef50a99fad6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,16 +100,16 @@ engine = ["universal"] universal = [] cache = ["wasmer-cache"] wast = ["wasmer-wast"] -wasi = ["wasmer-wasi"] +wasi = ["wasmer-wasi", "wasmer-wasi/emscripten_cranelift", "wasmer-wasi/wasi_cranelift"] emscripten = ["wasmer-emscripten"] wat = ["wasmer/wat"] compiler = [ "wasmer/compiler", "wasmer-compiler/translator", ] -singlepass = ["wasmer-compiler-singlepass", "compiler"] -cranelift = ["wasmer-compiler-cranelift", "compiler"] -llvm = ["wasmer-compiler-llvm", "compiler"] +singlepass = ["wasmer-compiler-singlepass", "compiler", "wasmer-wasi/emscripten_singlepass", "wasmer-wasi/wasi_singlepass"] +cranelift = ["wasmer-compiler-cranelift", "compiler", "wasmer-wasi/emscripten_cranelift", "wasmer-wasi/wasi_cranelift"] +llvm = ["wasmer-compiler-llvm", "compiler", "wasmer-wasi/emscripten_llvm", "wasmer-wasi/wasi_llvm"] middlewares = ["wasmer-middlewares"] wasmer-artifact-load = ["wasmer-compiler/wasmer-artifact-load"] wasmer-artifact-create = ["wasmer-compiler/wasmer-artifact-create"] diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index 6f5190fa317..a10090903b5 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -78,14 +78,20 @@ compiler-headless = [ ] singlepass = [ "wasmer-compiler-singlepass", + "wasmer-wasi/emscripten_singlepass", + "wasmer-wasi/wasi_singlepass", "compiler", ] cranelift = [ "wasmer-compiler-cranelift", + "wasmer-wasi/emscripten_cranelift", + "wasmer-wasi/wasi_cranelift", "compiler", ] llvm = [ "wasmer-compiler-llvm", + "wasmer-wasi/emscripten_llvm", + "wasmer-wasi/wasi_llvm", "compiler", ] wasmer-artifact-load = ["wasmer-compiler/wasmer-artifact-load"] diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index a1960afa947..6be7a2f305e 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -32,7 +32,7 @@ wasmer-compiler-singlepass = { version = "=3.1.0", path = "../compiler-singlepas wasmer-compiler-llvm = { version = "=3.1.0", path = "../compiler-llvm", optional = true } wasmer-emscripten = { version = "=3.1.0", path = "../emscripten", optional = true } wasmer-vm = { version = "=3.1.0", path = "../vm" } -wasmer-wasi = { version = "=3.1.0", path = "../wasi", optional = true } +wasmer-wasi = { version = "=3.1.0", path = "../wasi", features = ["emscripten_cranelift", "wasi_cranelift"], optional = true } wasmer-wasi-experimental-io-devices = { version = "=3.1.0", path = "../wasi-experimental-io-devices", optional = true, features = ["link_external_libs"] } wasmer-wast = { version = "=3.1.0", path = "../../tests/lib/wast", optional = true } wasmer-cache = { version = "=3.1.0", path = "../cache", optional = true } diff --git a/lib/wasi-experimental-io-devices/Cargo.toml b/lib/wasi-experimental-io-devices/Cargo.toml index 2d867fe0f22..30f91dfd45f 100644 --- a/lib/wasi-experimental-io-devices/Cargo.toml +++ b/lib/wasi-experimental-io-devices/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" maintenance = { status = "experimental" } [dependencies] -wasmer-wasi = { version = "=3.1.0", path = "../wasi", default-features=false } +wasmer-wasi = { version = "=3.1.0", path = "../wasi", default-features=false, features = ["emscripten_cranelift", "wasi_cranelift"] } tracing = "0.1" minifb = { version = "0.23", optional = true } nix = "0.25.0" diff --git a/tests/lib/wast/Cargo.toml b/tests/lib/wast/Cargo.toml index 4d9507ae097..5ed6c8a7242 100644 --- a/tests/lib/wast/Cargo.toml +++ b/tests/lib/wast/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] anyhow = "1.0" wasmer = { path = "../../../lib/api", version = "=3.1.0", default-features = false } -wasmer-wasi = { path = "../../../lib/wasi", version = "=3.1.0" } +wasmer-wasi = { path = "../../../lib/wasi", version = "=3.1.0", features = ["emscripten_cranelift", "wasi_cranelift"] } wasmer-vfs = { path = "../../../lib/vfs", version = "=3.1.0" } wast = "38.0" serde = "1" From a483d047de82c89a295d3fbf7ce813dfdea1ed32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 18 Jan 2023 10:45:12 +0100 Subject: [PATCH 11/38] Address review comments --- Cargo.toml | 8 ++++---- lib/c-api/Cargo.toml | 6 ------ lib/cli/Cargo.toml | 2 +- lib/cli/src/commands/run.rs | 3 +++ lib/wasi-experimental-io-devices/Cargo.toml | 2 +- lib/wasi/Cargo.toml | 6 ------ lib/wasi/src/runners/emscripten.rs | 18 ++---------------- lib/wasi/src/runners/wasi.rs | 17 ++--------------- tests/lib/wast/Cargo.toml | 2 +- tests/lib/wast/src/spectest.rs | 1 + 10 files changed, 15 insertions(+), 50 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ef50a99fad6..25dbdf20a83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,16 +100,16 @@ engine = ["universal"] universal = [] cache = ["wasmer-cache"] wast = ["wasmer-wast"] -wasi = ["wasmer-wasi", "wasmer-wasi/emscripten_cranelift", "wasmer-wasi/wasi_cranelift"] +wasi = ["wasmer-wasi"] emscripten = ["wasmer-emscripten"] wat = ["wasmer/wat"] compiler = [ "wasmer/compiler", "wasmer-compiler/translator", ] -singlepass = ["wasmer-compiler-singlepass", "compiler", "wasmer-wasi/emscripten_singlepass", "wasmer-wasi/wasi_singlepass"] -cranelift = ["wasmer-compiler-cranelift", "compiler", "wasmer-wasi/emscripten_cranelift", "wasmer-wasi/wasi_cranelift"] -llvm = ["wasmer-compiler-llvm", "compiler", "wasmer-wasi/emscripten_llvm", "wasmer-wasi/wasi_llvm"] +singlepass = ["wasmer-compiler-singlepass", "compiler"] +cranelift = ["wasmer-compiler-cranelift", "compiler"] +llvm = ["wasmer-compiler-llvm", "compiler"] middlewares = ["wasmer-middlewares"] wasmer-artifact-load = ["wasmer-compiler/wasmer-artifact-load"] wasmer-artifact-create = ["wasmer-compiler/wasmer-artifact-create"] diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index a10090903b5..6f5190fa317 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -78,20 +78,14 @@ compiler-headless = [ ] singlepass = [ "wasmer-compiler-singlepass", - "wasmer-wasi/emscripten_singlepass", - "wasmer-wasi/wasi_singlepass", "compiler", ] cranelift = [ "wasmer-compiler-cranelift", - "wasmer-wasi/emscripten_cranelift", - "wasmer-wasi/wasi_cranelift", "compiler", ] llvm = [ "wasmer-compiler-llvm", - "wasmer-wasi/emscripten_llvm", - "wasmer-wasi/wasi_llvm", "compiler", ] wasmer-artifact-load = ["wasmer-compiler/wasmer-artifact-load"] diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 6be7a2f305e..a1960afa947 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -32,7 +32,7 @@ wasmer-compiler-singlepass = { version = "=3.1.0", path = "../compiler-singlepas wasmer-compiler-llvm = { version = "=3.1.0", path = "../compiler-llvm", optional = true } wasmer-emscripten = { version = "=3.1.0", path = "../emscripten", optional = true } wasmer-vm = { version = "=3.1.0", path = "../vm" } -wasmer-wasi = { version = "=3.1.0", path = "../wasi", features = ["emscripten_cranelift", "wasi_cranelift"], optional = true } +wasmer-wasi = { version = "=3.1.0", path = "../wasi", optional = true } wasmer-wasi-experimental-io-devices = { version = "=3.1.0", path = "../wasi-experimental-io-devices", optional = true, features = ["link_external_libs"] } wasmer-wast = { version = "=3.1.0", path = "../../tests/lib/wast", optional = true } wasmer-cache = { version = "=3.1.0", path = "../cache", optional = true } diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index b53c5644475..337158aa344 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "cache")] use crate::common::get_cache_dir; #[cfg(feature = "debug")] use crate::logging; @@ -10,7 +11,9 @@ use clap::Parser; use std::collections::HashMap; use std::ops::Deref; use std::path::PathBuf; +#[cfg(feature = "cache")] use std::str::FromStr; +#[cfg(feature = "emscripten")] use wasmer::FunctionEnv; use wasmer::*; #[cfg(feature = "cache")] diff --git a/lib/wasi-experimental-io-devices/Cargo.toml b/lib/wasi-experimental-io-devices/Cargo.toml index 30f91dfd45f..2d867fe0f22 100644 --- a/lib/wasi-experimental-io-devices/Cargo.toml +++ b/lib/wasi-experimental-io-devices/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" maintenance = { status = "experimental" } [dependencies] -wasmer-wasi = { version = "=3.1.0", path = "../wasi", default-features=false, features = ["emscripten_cranelift", "wasi_cranelift"] } +wasmer-wasi = { version = "=3.1.0", path = "../wasi", default-features=false } tracing = "0.1" minifb = { version = "0.23", optional = true } nix = "0.25.0" diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 2a15355d3c2..9c0f44e65cf 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -53,12 +53,6 @@ wasix = [] webc_runner = ["webc", "serde_cbor", "anyhow", "serde", "wasmer-vfs/webc-fs"] webc_runner_rt_emscripten = ["wasmer-emscripten"] webc_runner_rt_wasi = [] -emscripten_cranelift = ["wasmer/cranelift"] -wasi_cranelift = ["wasmer/cranelift"] -emscripten_singlepass = ["wasmer/singlepass"] -wasi_singlepass = ["wasmer/singlepass"] -emscripten_llvm = ["wasmer/llvm"] -wasi_llvm = ["wasmer/llvm"] sys = ["wasmer/sys", "wasix", "wasmer-wasi-types/sys"] sys-default = ["wasmer/wat", "wasmer/compiler", "sys", "logging", "host-fs", "sys-poll", "host-vnet" ] diff --git a/lib/wasi/src/runners/emscripten.rs b/lib/wasi/src/runners/emscripten.rs index 9dd6fa4af01..bcad14b0f10 100644 --- a/lib/wasi/src/runners/emscripten.rs +++ b/lib/wasi/src/runners/emscripten.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "webc_runner_rt_wasi")] +#![cfg(feature = "webc_runner_rt_emscripten")] //! WebC container support for running Emscripten modules use crate::runners::WapmContainer; @@ -44,21 +44,7 @@ impl crate::runners::Runner for EmscriptenRunner { let main_args = container.get_main_args_for_command(command_name); let atom_bytes = container.get_atom(&container.get_package_name(), &atom_name)?; - #[cfg(feature = "emscripten_cranelift")] - let mut store = Store::new(wasmer::Cranelift::default()); - #[cfg(feature = "emscripten_llvm")] - let mut store = Store::new(wasmer::Llvm::default()); - #[cfg(feature = "emscripten_singlepass")] - let mut store = Store::new(wasmer::Singlepass::default()); - #[cfg(not(any( - feature = "emscripten_cranelift", - feature = "emscripten_llvm", - feature = "emscripten_singlepass" - )))] - let mut store = { - return Err(anyhow::anyhow!("wasmer-wasi needs one of emscripten_cranelift or emscripten_llvm or emscripten_singlepass features enabled").into()); - }; - + let mut store = Store::default(); let mut module = Module::new(&store, atom_bytes)?; module.set_name(&atom_name); diff --git a/lib/wasi/src/runners/wasi.rs b/lib/wasi/src/runners/wasi.rs index 7a36179846d..4925b59864b 100644 --- a/lib/wasi/src/runners/wasi.rs +++ b/lib/wasi/src/runners/wasi.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "webc_runner_rt_emscripten")] +#![cfg(feature = "webc_runner_rt_wasi")] //! WebC container support for running WASI modules use crate::runners::WapmContainer; @@ -43,20 +43,7 @@ impl crate::runners::Runner for WasiRunner { let atom_name = container.get_atom_name_for_command("wasi", command_name)?; let atom_bytes = container.get_atom(&container.get_package_name(), &atom_name)?; - #[cfg(feature = "wasi_cranelift")] - let mut store = Store::new(wasmer::Cranelift::default()); - #[cfg(feature = "wasi_llvm")] - let mut store = Store::new(wasmer::Llvm::default()); - #[cfg(feature = "wasi_singlepass")] - let mut store = Store::new(wasmer::Singlepass::default()); - #[cfg(not(any( - feature = "wasi_cranelift", - feature = "wasi_llvm", - feature = "wasi_singlepass" - )))] - let mut store = { - return Err(anyhow::anyhow!("wasmer-wasi needs one of wasi_cranelift or wasi_llvm or wasi_singlepass features enabled").into()); - }; + let mut store = Store::default(); let mut module = Module::new(&store, atom_bytes)?; module.set_name(&atom_name); diff --git a/tests/lib/wast/Cargo.toml b/tests/lib/wast/Cargo.toml index 5ed6c8a7242..4d9507ae097 100644 --- a/tests/lib/wast/Cargo.toml +++ b/tests/lib/wast/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] anyhow = "1.0" wasmer = { path = "../../../lib/api", version = "=3.1.0", default-features = false } -wasmer-wasi = { path = "../../../lib/wasi", version = "=3.1.0", features = ["emscripten_cranelift", "wasi_cranelift"] } +wasmer-wasi = { path = "../../../lib/wasi", version = "=3.1.0" } wasmer-vfs = { path = "../../../lib/vfs", version = "=3.1.0" } wast = "38.0" serde = "1" diff --git a/tests/lib/wast/src/spectest.rs b/tests/lib/wast/src/spectest.rs index b4d44938491..7eda1b643b4 100644 --- a/tests/lib/wast/src/spectest.rs +++ b/tests/lib/wast/src/spectest.rs @@ -2,6 +2,7 @@ use wasmer::*; /// Return an instance implementing the "spectest" interface used in the /// spec testsuite. +#[allow(clippy::print_stdout)] pub fn spectest_importobject(store: &mut Store) -> Imports { let print = Function::new_typed(store, || {}); let print_i32 = Function::new_typed(store, |val: i32| println!("{}: i32", val)); From a70a4922ad7d82ebabcfefc74f20cd161f08f1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 18 Jan 2023 12:21:16 +0100 Subject: [PATCH 12/38] Fix feature flags and misleading error message --- lib/api/src/sys/store.rs | 27 +++++++++++++-------------- lib/cli/Cargo.toml | 3 +++ lib/compiler/src/engine/inner.rs | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/api/src/sys/store.rs b/lib/api/src/sys/store.rs index 032b6c60d23..04d94e6ca62 100644 --- a/lib/api/src/sys/store.rs +++ b/lib/api/src/sys/store.rs @@ -66,6 +66,13 @@ impl Store { } } + /// Creates a new headless `Store` without any compilers enabled that can + /// be used to execute `Module`s, but not compile them. + #[cfg(feature = "compiler")] + pub fn headless() -> Self { + Self::new(EngineBuilder::headless().engine()) + } + #[cfg(feature = "compiler")] #[deprecated( since = "3.0.0", @@ -173,21 +180,13 @@ impl Default for Store { #[allow(unreachable_code, unused_mut)] fn get_engine() -> Engine { cfg_if::cfg_if! { - if #[cfg(feature = "compiler")] { - - cfg_if::cfg_if! { - if #[cfg(any(feature = "cranelift", feature = "llvm", feature = "singlepass"))] - { - let config = get_config(); - EngineBuilder::new(Box::new(config) as Box) - .engine() - } else { - EngineBuilder::headless() - .engine() - } - } + if #[cfg(any(feature = "cranelift", feature = "llvm", feature = "singlepass"))] + { + let config = get_config(); + EngineBuilder::new(Box::new(config) as Box) + .engine() } else { - compile_error!("No default engine chosen") + compile_error!("No compiler [cranelift, llvm, singlepass] enabled, use Store::headless() instead of Store::default() for a headless engine") } } } diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index a1960afa947..f58df9798a8 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -149,14 +149,17 @@ experimental-io-devices = [ ] singlepass = [ "wasmer-compiler-singlepass", + "wasmer/singlepass", "compiler", ] cranelift = [ "wasmer-compiler-cranelift", + "wasmer/cranelift", "compiler", ] llvm = [ "wasmer-compiler-llvm", + "wasmer/llvm", "compiler", ] debug = ["fern", "wasmer-wasi/logging"] diff --git a/lib/compiler/src/engine/inner.rs b/lib/compiler/src/engine/inner.rs index 0347b87b729..3abe6f6cd0e 100644 --- a/lib/compiler/src/engine/inner.rs +++ b/lib/compiler/src/engine/inner.rs @@ -267,7 +267,7 @@ impl EngineInner { pub fn compiler(&self) -> Result<&dyn Compiler, CompileError> { match self.compiler.as_ref() { None => Err(CompileError::Codegen( - "The Engine is not compiled in.".to_string(), + "No compiler compiled into executable".to_string(), )), Some(compiler) => Ok(&**compiler), } From 9c052489ffcc5a83e60a2220c08234e2c8322ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 18 Jan 2023 12:28:21 +0100 Subject: [PATCH 13/38] Revert changes to Store::default and remove Store::headless again --- lib/api/src/sys/store.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/api/src/sys/store.rs b/lib/api/src/sys/store.rs index 04d94e6ca62..bb90e7de06f 100644 --- a/lib/api/src/sys/store.rs +++ b/lib/api/src/sys/store.rs @@ -66,13 +66,6 @@ impl Store { } } - /// Creates a new headless `Store` without any compilers enabled that can - /// be used to execute `Module`s, but not compile them. - #[cfg(feature = "compiler")] - pub fn headless() -> Self { - Self::new(EngineBuilder::headless().engine()) - } - #[cfg(feature = "compiler")] #[deprecated( since = "3.0.0", @@ -180,11 +173,18 @@ impl Default for Store { #[allow(unreachable_code, unused_mut)] fn get_engine() -> Engine { cfg_if::cfg_if! { - if #[cfg(any(feature = "cranelift", feature = "llvm", feature = "singlepass"))] - { - let config = get_config(); - EngineBuilder::new(Box::new(config) as Box) - .engine() + if #[cfg(feature = "compiler")] { + cfg_if::cfg_if! { + if #[cfg(any(feature = "cranelift", feature = "llvm", feature = "singlepass"))] + { + let config = get_config(); + EngineBuilder::new(Box::new(config) as Box) + .engine() + } else { + EngineBuilder::headless() + .engine() + } + } } else { compile_error!("No compiler [cranelift, llvm, singlepass] enabled, use Store::headless() instead of Store::default() for a headless engine") } From 70080236783b909e9e883aefcc49fa02a64887e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 18 Jan 2023 12:53:13 +0100 Subject: [PATCH 14/38] Fix make lint --- lib/cli/src/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index 49b897c7bc3..87da6d5bd9b 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -152,7 +152,7 @@ impl CompilerOptions { use std::fs::File; use std::io::Write; use wasmer_compiler_llvm::{ - CompiledKind, InkwellMemoryBuffer, InkwellModule, LLVMCallbacks, LLVM, + CompiledKind, InkwellMemoryBuffer, InkwellModule, LLVMCallbacks, }; use wasmer_types::entity::EntityRef; let mut config = LLVM::new(); From caeca9a7a82739152e4a9a4d724dc7ce1a080133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= <12084016+fschutt@users.noreply.github.com> Date: Wed, 18 Jan 2023 15:33:36 +0100 Subject: [PATCH 15/38] Revert error message text --- lib/api/src/sys/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api/src/sys/store.rs b/lib/api/src/sys/store.rs index bb90e7de06f..6f7cf6ac9fd 100644 --- a/lib/api/src/sys/store.rs +++ b/lib/api/src/sys/store.rs @@ -186,7 +186,7 @@ impl Default for Store { } } } else { - compile_error!("No compiler [cranelift, llvm, singlepass] enabled, use Store::headless() instead of Store::default() for a headless engine") + compile_error!("No default engine chosen") } } } From 8d3e7c0dadc638cec97265415a46c32f035ae073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 18 Jan 2023 16:02:26 +0100 Subject: [PATCH 16/38] Refactor WasiRunner / EmscriptenRunner to take a Store as an argument --- lib/cli/Cargo.toml | 3 --- lib/cli/src/commands/run.rs | 5 +++-- lib/wasi/src/runners/emscripten.rs | 31 ++++++++++++++++++++----- lib/wasi/src/runners/wasi.rs | 36 +++++++++++++++++++++++++----- 4 files changed, 60 insertions(+), 15 deletions(-) diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index f58df9798a8..a1960afa947 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -149,17 +149,14 @@ experimental-io-devices = [ ] singlepass = [ "wasmer-compiler-singlepass", - "wasmer/singlepass", "compiler", ] cranelift = [ "wasmer-compiler-cranelift", - "wasmer/cranelift", "compiler", ] llvm = [ "wasmer-compiler-llvm", - "wasmer/llvm", "compiler", ] debug = ["fern", "wasmer-wasi/logging"] diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index 337158aa344..5764c1e887c 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -352,7 +352,7 @@ impl RunWithPathBuf { return r; } - let mut runner = wasmer_wasi::runners::wasi::WasiRunner::default(); + let mut runner = wasmer_wasi::runners::wasi::WasiRunner::new(Store::default()); runner.set_args(args.to_vec()); result = Some(if id.is_empty() { runner.run(&container).map_err(|e| format!("{e}")) @@ -367,7 +367,8 @@ impl RunWithPathBuf { return r; } - let mut runner = wasmer_wasi::runners::emscripten::EmscriptenRunner::default(); + let mut runner = + wasmer_wasi::runners::emscripten::EmscriptenRunner::new(Store::default()); runner.set_args(args.to_vec()); result = Some(if id.is_empty() { runner.run(&container).map_err(|e| format!("{e}")) diff --git a/lib/wasi/src/runners/emscripten.rs b/lib/wasi/src/runners/emscripten.rs index bcad14b0f10..fd92bbb74f9 100644 --- a/lib/wasi/src/runners/emscripten.rs +++ b/lib/wasi/src/runners/emscripten.rs @@ -13,12 +13,34 @@ use wasmer_emscripten::{ }; use webc::{Command, WebCMmap}; -#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct EmscriptenRunner { args: Vec, + #[serde(skip, default)] + store: Store, } impl EmscriptenRunner { + /// Constructs a new `EmscriptenRunner` given an `Engine` + pub fn new(store: Store) -> Self { + Self { + args: Vec::new(), + store, + } + } + + /// Returns the current arguments for this `EmscriptenRunner` + pub fn get_args(&self) -> Vec { + self.args.clone() + } + + /// Builder method to provide CLI args to the runner + pub fn with_args(mut self, args: Vec) -> Self { + self.set_args(args); + self + } + + /// Set the CLI args pub fn set_args(&mut self, args: Vec) { self.args = args; } @@ -44,15 +66,14 @@ impl crate::runners::Runner for EmscriptenRunner { let main_args = container.get_main_args_for_command(command_name); let atom_bytes = container.get_atom(&container.get_package_name(), &atom_name)?; - let mut store = Store::default(); - let mut module = Module::new(&store, atom_bytes)?; + let mut module = Module::new(&self.store, atom_bytes)?; module.set_name(&atom_name); let (mut globals, env) = - prepare_emscripten_env(&mut store, &module, container.webc.clone(), &atom_name)?; + prepare_emscripten_env(&mut self.store, &module, container.webc.clone(), &atom_name)?; exec_module( - &mut store, + &mut self.store, &module, &mut globals, env, diff --git a/lib/wasi/src/runners/wasi.rs b/lib/wasi/src/runners/wasi.rs index 4925b59864b..e010a51406a 100644 --- a/lib/wasi/src/runners/wasi.rs +++ b/lib/wasi/src/runners/wasi.rs @@ -11,12 +11,34 @@ use wasmer::{Instance, Module, Store}; use wasmer_vfs::webc_fs::WebcFileSystem; use webc::{Command, WebCMmap}; -#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct WasiRunner { args: Vec, + #[serde(skip, default)] + store: Store, } impl WasiRunner { + /// Constructs a new `WasiRunner` given an `Engine` + pub fn new(store: Store) -> Self { + Self { + args: Vec::new(), + store, + } + } + + /// Returns the current arguments for this `WasiRunner` + pub fn get_args(&self) -> Vec { + self.args.clone() + } + + /// Builder method to provide CLI args to the runner + pub fn with_args(mut self, args: Vec) -> Self { + self.set_args(args); + self + } + + /// Set the CLI args pub fn set_args(&mut self, args: Vec) { self.args = args; } @@ -43,13 +65,17 @@ impl crate::runners::Runner for WasiRunner { let atom_name = container.get_atom_name_for_command("wasi", command_name)?; let atom_bytes = container.get_atom(&container.get_package_name(), &atom_name)?; - let mut store = Store::default(); - let mut module = Module::new(&store, atom_bytes)?; + let mut module = Module::new(&self.store, atom_bytes)?; module.set_name(&atom_name); - let env = prepare_webc_env(&mut store, container.webc.clone(), &atom_name, &self.args)?; + let env = prepare_webc_env( + &mut self.store, + container.webc.clone(), + &atom_name, + &self.args, + )?; - exec_module(&mut store, &module, env)?; + exec_module(&mut self.store, &module, env)?; Ok(()) } From 3d73c536d624e965c15732cdfab02a983d173af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 18 Jan 2023 16:25:24 +0100 Subject: [PATCH 17/38] Fix unit tests on Linux --- lib/cli/src/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index 87da6d5bd9b..49b897c7bc3 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -152,7 +152,7 @@ impl CompilerOptions { use std::fs::File; use std::io::Write; use wasmer_compiler_llvm::{ - CompiledKind, InkwellMemoryBuffer, InkwellModule, LLVMCallbacks, + CompiledKind, InkwellMemoryBuffer, InkwellModule, LLVMCallbacks, LLVM, }; use wasmer_types::entity::EntityRef; let mut config = LLVM::new(); From de62fdd07502ccbbc5c05ebcc204cfd54542d88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 18 Jan 2023 16:55:06 +0100 Subject: [PATCH 18/38] Remove uses of Store::default in create-exe and wasmer run --- lib/cli/src/commands/create_exe.rs | 8 +++--- lib/cli/src/commands/run.rs | 41 +++++++++++++++++++----------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 9f75d8deb2f..08b28860fa6 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -224,7 +224,7 @@ impl CreateExe { return Err(anyhow::anyhow!("input path cannot be a directory")); } - let (_, compiler_type) = self.compiler.get_store_for_target(target.clone())?; + let (store, compiler_type) = self.compiler.get_store_for_target(target.clone())?; println!("Compiler: {}", compiler_type.to_string()); println!("Target: {}", target.triple()); println!("Format: {:?}", object_format); @@ -271,7 +271,7 @@ impl CreateExe { ) }?; - get_module_infos(&tempdir, &atoms, object_format)?; + get_module_infos(&tempdir, &atoms, object_format, &store)?; let mut entrypoint = get_entrypoint(&tempdir)?; create_header_files_in_dir(&tempdir, &mut entrypoint, &atoms, &self.precompiled_atom)?; link_exe_from_dir( @@ -962,14 +962,14 @@ fn get_module_infos( directory: &Path, atoms: &[(String, Vec)], object_format: ObjectFormat, + store: &Store, ) -> Result, anyhow::Error> { let mut entrypoint = get_entrypoint(directory).with_context(|| anyhow::anyhow!("get module infos"))?; let mut module_infos = BTreeMap::new(); for (atom_name, atom_bytes) in atoms { - let store = Store::default(); - let module = Module::from_binary(&store, atom_bytes.as_slice()) + let module = Module::from_binary(store, atom_bytes.as_slice()) .map_err(|e| anyhow::anyhow!("could not deserialize module {atom_name}: {e}"))?; if let Some(s) = entrypoint .atoms diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index 5764c1e887c..b351f0c7610 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -198,12 +198,13 @@ impl RunWithPathBuf { #[cfg(feature = "webc_runner")] { if let Ok(pf) = WapmContainer::new(self.path.clone()) { - return Self::run_container( - pf, - &self.command_name.clone().unwrap_or_default(), - &self.args, - ) - .map_err(|e| anyhow!("Could not run PiritaFile: {e}")); + return self + .run_container( + pf, + &self.command_name.clone().unwrap_or_default(), + &self.args, + ) + .map_err(|e| anyhow!("Could not run PiritaFile: {e}")); } } let (mut store, module) = self.get_store_module()?; @@ -343,7 +344,12 @@ impl RunWithPathBuf { } #[cfg(feature = "webc_runner")] - fn run_container(container: WapmContainer, id: &str, args: &[String]) -> Result<(), String> { + fn run_container( + &self, + container: WapmContainer, + id: &str, + args: &[String], + ) -> Result<(), anyhow::Error> { let mut result = None; #[cfg(feature = "wasi")] @@ -352,12 +358,15 @@ impl RunWithPathBuf { return r; } - let mut runner = wasmer_wasi::runners::wasi::WasiRunner::new(Store::default()); + let (store, _compiler_type) = self.store.get_store()?; + let mut runner = wasmer_wasi::runners::wasi::WasiRunner::new(store); runner.set_args(args.to_vec()); result = Some(if id.is_empty() { - runner.run(&container).map_err(|e| format!("{e}")) + runner.run(&container).map_err(|e| anyhow::anyhow!("{e}")) } else { - runner.run_cmd(&container, id).map_err(|e| format!("{e}")) + runner + .run_cmd(&container, id) + .map_err(|e| anyhow::anyhow!("{e}")) }); } @@ -367,17 +376,19 @@ impl RunWithPathBuf { return r; } - let mut runner = - wasmer_wasi::runners::emscripten::EmscriptenRunner::new(Store::default()); + let (store, _compiler_type) = self.store.get_store()?; + let mut runner = wasmer_wasi::runners::emscripten::EmscriptenRunner::new(store); runner.set_args(args.to_vec()); result = Some(if id.is_empty() { - runner.run(&container).map_err(|e| format!("{e}")) + runner.run(&container).map_err(|e| anyhow::anyhow!("{e}")) } else { - runner.run_cmd(&container, id).map_err(|e| format!("{e}")) + runner + .run_cmd(&container, id) + .map_err(|e| anyhow::anyhow!("{e}")) }); } - result.unwrap_or_else(|| Err("neither emscripten or wasi file".to_string())) + result.unwrap_or_else(|| Err(anyhow::anyhow!("neither emscripten or wasi file"))) } fn get_store_module(&self) -> Result<(Store, Module)> { From 790fcfca5978f73547d6c86fe5751d31344a31e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 18 Jan 2023 18:39:00 +0100 Subject: [PATCH 19/38] Debug why get_store_for_target fails --- lib/cli/src/commands/create_exe.rs | 6 ++++-- lib/compiler/src/engine/unwind/systemv.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 08b28860fa6..a6ab8916afd 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -224,9 +224,11 @@ impl CreateExe { return Err(anyhow::anyhow!("input path cannot be a directory")); } - let (store, compiler_type) = self.compiler.get_store_for_target(target.clone())?; + let (store, compiler_type) = self + .compiler + .get_store_for_target(Target::new(target_triple, Default::default()))?; println!("Compiler: {}", compiler_type.to_string()); - println!("Target: {}", target.triple()); + println!("Target: {:?}", target); println!("Format: {:?}", object_format); println!( "Using path `{}` as libwasmer path.", diff --git a/lib/compiler/src/engine/unwind/systemv.rs b/lib/compiler/src/engine/unwind/systemv.rs index 38d51e219f4..11e08e4b34b 100644 --- a/lib/compiler/src/engine/unwind/systemv.rs +++ b/lib/compiler/src/engine/unwind/systemv.rs @@ -36,7 +36,7 @@ impl UnwindRegistry { ) -> Result<(), String> { match info { CompiledFunctionUnwindInfo::Dwarf => {} - _ => return Err("unsupported unwind information".to_string()), + _ => return Err(format!("unsupported unwind information {info:?}")), }; Ok(()) } From 2ce32dba799a76d088ad89d74657353266877e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 18 Jan 2023 19:00:47 +0100 Subject: [PATCH 20/38] Debug why get_store_for_target returns wrong UnwindInfo --- lib/cli/src/commands/create_exe.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index a6ab8916afd..630ff768d74 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -224,9 +224,7 @@ impl CreateExe { return Err(anyhow::anyhow!("input path cannot be a directory")); } - let (store, compiler_type) = self - .compiler - .get_store_for_target(Target::new(target_triple, Default::default()))?; + let (store, compiler_type) = self.compiler.get_store_for_target(target.clone())?; println!("Compiler: {}", compiler_type.to_string()); println!("Target: {:?}", target); println!("Format: {:?}", object_format); From be30f664b22748e4249c7cd7ad5bf9ef0338bbc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 18 Jan 2023 19:07:59 +0100 Subject: [PATCH 21/38] Print store information on CI --- lib/cli/src/commands/create_exe.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 630ff768d74..a3248a83a94 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -232,6 +232,7 @@ impl CreateExe { "Using path `{}` as libwasmer path.", cross_compilation.library.display() ); + println!("store: {:#?}", store); if !cross_compilation.library.exists() { return Err(anyhow::anyhow!("library path does not exist")); } From 321c1f3c834e9d547fed9eb2582a71088851eb52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 18 Jan 2023 19:21:21 +0100 Subject: [PATCH 22/38] Try to imitate the previous Store creation with get_config(( --- lib/cli/src/commands/create_exe.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index a3248a83a94..b6ec395b12c 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -224,7 +224,29 @@ impl CreateExe { return Err(anyhow::anyhow!("input path cannot be a directory")); } - let (store, compiler_type) = self.compiler.get_store_for_target(target.clone())?; + let (_, compiler_type) = self.compiler.get_store_for_target(target.clone())?; + + fn get_config() -> impl wasmer_compiler::CompilerConfig + 'static { + cfg_if::cfg_if! { + if #[cfg(feature = "cranelift")] { + wasmer_compiler_cranelift::Cranelift::default() + } else if #[cfg(feature = "llvm")] { + wasmer_compiler_llvm::LLVM::default() + } else if #[cfg(feature = "singlepass")] { + wasmer_compiler_singlepass::Singlepass::default() + } else { + compile_error!("No default compiler chosen") + } + } + } + + let engine = + EngineBuilder::new(Box::new(get_config()) as Box) + .engine(); + + let tunables = BaseTunables::for_target(engine.target()); + let store = Store::new_with_tunables(&engine, tunables); + println!("Compiler: {}", compiler_type.to_string()); println!("Target: {:?}", target); println!("Format: {:?}", object_format); From 5c927b974dcf77a34a18be8bd56eba874fe944d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 09:20:57 +0100 Subject: [PATCH 23/38] Fix create-exe to work --- lib/cli/src/commands/create_exe.rs | 80 ++++++++++++++++++++++-------- lib/cli/src/store.rs | 6 +-- 2 files changed, 63 insertions(+), 23 deletions(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index b6ec395b12c..00c21de7254 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -2,7 +2,7 @@ use super::ObjectFormat; use crate::common::normalize_path; -use crate::store::CompilerOptions; +use crate::store::{CompilerOptions, CompilerType}; use anyhow::{Context, Result}; use clap::Parser; use serde::{Deserialize, Serialize}; @@ -224,37 +224,31 @@ impl CreateExe { return Err(anyhow::anyhow!("input path cannot be a directory")); } - let (_, compiler_type) = self.compiler.get_store_for_target(target.clone())?; + let (_, ct) = self.compiler.get_store_for_target(target.clone())?; - fn get_config() -> impl wasmer_compiler::CompilerConfig + 'static { - cfg_if::cfg_if! { - if #[cfg(feature = "cranelift")] { - wasmer_compiler_cranelift::Cranelift::default() - } else if #[cfg(feature = "llvm")] { - wasmer_compiler_llvm::LLVM::default() - } else if #[cfg(feature = "singlepass")] { - wasmer_compiler_singlepass::Singlepass::default() - } else { - compile_error!("No default compiler chosen") - } - } - } + let compiler_type = if self.compiler.singlepass { + CompilerType::Singlepass + } else if self.compiler.cranelift { + CompilerType::Cranelift + } else if self.compiler.llvm { + CompilerType::LLVM + } else { + ct // default compiler type + }; - let engine = - EngineBuilder::new(Box::new(get_config()) as Box) - .engine(); + let engine = EngineBuilder::new(get_config(&compiler_type)?).engine(); let tunables = BaseTunables::for_target(engine.target()); let store = Store::new_with_tunables(&engine, tunables); println!("Compiler: {}", compiler_type.to_string()); - println!("Target: {:?}", target); + println!("Target: {}", target.triple()); println!("Format: {:?}", object_format); println!( "Using path `{}` as libwasmer path.", cross_compilation.library.display() ); - println!("store: {:#?}", store); + if !cross_compilation.library.exists() { return Err(anyhow::anyhow!("library path does not exist")); } @@ -324,6 +318,52 @@ impl CreateExe { } } +fn get_config( + compiler: &CompilerType, +) -> Result, anyhow::Error> { + match compiler { + CompilerType::Cranelift => { + #[cfg(feature = "cranelift")] + { + Ok(Box::new(wasmer_compiler_cranelift::Cranelift::default())) + } + #[cfg(not(feature = "cranelift"))] + { + Err(anyhow::anyhow!( + "compiler \"cranelift\" not embedded in wasmer-cli" + )) + } + } + CompilerType::Singlepass => { + #[cfg(feature = "singlepass")] + { + Ok(Box::new(wasmer_compiler_singlepass::Singlepass::default())) + } + #[cfg(not(feature = "singlepass"))] + { + Err(anyhow::anyhow!( + "compiler \"singlepass\" not embedded in wasmer-cli" + )) + } + } + CompilerType::LLVM => { + #[cfg(feature = "llvm")] + { + Ok(Box::new(wasmer_compiler_llvm::LLVM::default())) + } + #[cfg(not(feature = "llvm"))] + { + Err(anyhow::anyhow!( + "compiler \"llvm\" not embedded in wasmer-cli" + )) + } + } + CompilerType::Headless => Err(anyhow::anyhow!( + "cannot compile .wasm files to object files with compiler \"headless\"" + )), + } +} + fn write_entrypoint(directory: &Path, entrypoint: &Entrypoint) -> Result<(), anyhow::Error> { std::fs::write( directory.join("entrypoint.json"), diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index 49b897c7bc3..1d2c55904cb 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -30,15 +30,15 @@ pub struct StoreOptions { pub struct CompilerOptions { /// Use Singlepass compiler. #[clap(long, conflicts_with_all = &["cranelift", "llvm"])] - singlepass: bool, + pub singlepass: bool, /// Use Cranelift compiler. #[clap(long, conflicts_with_all = &["singlepass", "llvm"])] - cranelift: bool, + pub cranelift: bool, /// Use LLVM compiler. #[clap(long, conflicts_with_all = &["singlepass", "cranelift"])] - llvm: bool, + pub llvm: bool, /// Enable compiler internal verification. #[clap(long)] From 1042053b6e058430d7e8990da576360b24bd8a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 09:22:45 +0100 Subject: [PATCH 24/38] Revert "Fix make lint" This reverts commit 912f21ab03ab3534c917348a902b525e8f7cbce1. --- lib/c-api/src/wasm_c_api/wasi/mod.rs | 4 ++-- lib/cache/src/hash.rs | 2 +- lib/cli/build.rs | 2 +- lib/cli/src/commands/publish.rs | 2 +- lib/emscripten/src/env/mod.rs | 4 ++-- lib/registry/src/lib.rs | 4 ++-- lib/vfs/src/webc_fs.rs | 3 +-- lib/wasi/src/lib.rs | 4 ++-- lib/wasi/src/state/pipe.rs | 4 ++-- lib/wasi/src/syscalls/mod.rs | 6 ++---- tests/lib/test-generator/src/lib.rs | 3 ++- tests/lib/wast/src/wast.rs | 2 +- tests/wasi-wast/src/wasitests.rs | 4 ++-- 13 files changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/c-api/src/wasm_c_api/wasi/mod.rs b/lib/c-api/src/wasm_c_api/wasi/mod.rs index fb7395e1e49..1f3354d0a77 100644 --- a/lib/c-api/src/wasm_c_api/wasi/mod.rs +++ b/lib/c-api/src/wasm_c_api/wasi/mod.rs @@ -342,7 +342,7 @@ pub unsafe extern "C" fn wasi_env_read_stdout( buffer: *mut c_char, buffer_len: usize, ) -> isize { - let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len); + let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len as usize); let mut store_mut = env.store.store_mut(); let state = env.inner.data_mut(&mut store_mut).state(); @@ -365,7 +365,7 @@ pub unsafe extern "C" fn wasi_env_read_stderr( buffer: *mut c_char, buffer_len: usize, ) -> isize { - let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len); + let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len as usize); let mut store_mut = env.store.store_mut(); let state = env.inner.data_mut(&mut store_mut).state(); if let Ok(mut stderr) = state.stderr() { diff --git a/lib/cache/src/hash.rs b/lib/cache/src/hash.rs index 2a4b6fb7b5a..29e7fa7ce65 100644 --- a/lib/cache/src/hash.rs +++ b/lib/cache/src/hash.rs @@ -31,7 +31,7 @@ impl ToString for Hash { /// Create the hexadecimal representation of the /// stored hash. fn to_string(&self) -> String { - hex::encode(self.to_array()) + hex::encode(&self.to_array()) } } diff --git a/lib/cli/build.rs b/lib/cli/build.rs index 4444630121c..f9aecaaf01c 100644 --- a/lib/cli/build.rs +++ b/lib/cli/build.rs @@ -4,7 +4,7 @@ use std::process::Command; pub fn main() { // Set WASMER_GIT_HASH let git_hash = Command::new("git") - .args(["rev-parse", "HEAD"]) + .args(&["rev-parse", "HEAD"]) .output() .ok() .and_then(|output| String::from_utf8(output.stdout).ok()) diff --git a/lib/cli/src/commands/publish.rs b/lib/cli/src/commands/publish.rs index 0c6756de48a..7f2136cd17a 100644 --- a/lib/cli/src/commands/publish.rs +++ b/lib/cli/src/commands/publish.rs @@ -386,7 +386,7 @@ fn apply_migration(conn: &mut Connection, migration_number: i32) -> Result<(), M tx.execute_batch(migration_to_apply) .map_err(|e| MigrationError::TransactionFailed(migration_number, format!("{}", e)))?; - tx.pragma_update(None, "user_version", migration_number + 1) + tx.pragma_update(None, "user_version", (migration_number + 1)) .map_err(|e| MigrationError::TransactionFailed(migration_number, format!("{}", e)))?; tx.commit() .map_err(|_| MigrationError::CommitFailed(migration_number)) diff --git a/lib/emscripten/src/env/mod.rs b/lib/emscripten/src/env/mod.rs index 03e05fb7417..a560a416912 100644 --- a/lib/emscripten/src/env/mod.rs +++ b/lib/emscripten/src/env/mod.rs @@ -79,9 +79,9 @@ pub fn ___build_environment(mut ctx: FunctionEnvMut, environ: c_int) { let environment = emscripten_memory_pointer!(memory.view(&ctx), environ) as *mut c_int; let (mut pool_offset, env_ptr, mut pool_ptr) = unsafe { let (pool_offset, _pool_slice): (u32, &mut [u8]) = - allocate_on_stack(&mut ctx, TOTAL_ENV_SIZE); + allocate_on_stack(&mut ctx, TOTAL_ENV_SIZE as u32); let (env_offset, _env_slice): (u32, &mut [u8]) = - allocate_on_stack(&mut ctx, MAX_ENV_VALUES * 4); + allocate_on_stack(&mut ctx, (MAX_ENV_VALUES * 4) as u32); let env_ptr = emscripten_memory_pointer!(memory.view(&ctx), env_offset) as *mut c_int; let pool_ptr = emscripten_memory_pointer!(memory.view(&ctx), pool_offset) as *mut u8; *env_ptr = pool_offset as i32; diff --git a/lib/registry/src/lib.rs b/lib/registry/src/lib.rs index d1300bdfbb4..bb6f6a162c8 100644 --- a/lib/registry/src/lib.rs +++ b/lib/registry/src/lib.rs @@ -418,7 +418,7 @@ pub fn try_unpack_targz>( let target_targz_path = target_targz_path.as_ref(); let target_path = target_path.as_ref(); let open_file = || { - std::fs::File::open(target_targz_path) + std::fs::File::open(&target_targz_path) .map_err(|e| anyhow::anyhow!("failed to open {}: {e}", target_targz_path.display())) }; @@ -860,7 +860,7 @@ fn get_bytes( } if let Some(path) = stream_response_into.as_ref() { - let mut file = std::fs::File::create(path).map_err(|e| { + let mut file = std::fs::File::create(&path).map_err(|e| { anyhow::anyhow!("failed to download {url} into {}: {e}", path.display()) })?; diff --git a/lib/vfs/src/webc_fs.rs b/lib/vfs/src/webc_fs.rs index 6b6d467cb8c..34402356357 100644 --- a/lib/vfs/src/webc_fs.rs +++ b/lib/vfs/src/webc_fs.rs @@ -66,8 +66,7 @@ where ) -> Result, FsError> { match get_volume_name_opt(path) { Some(volume) => { - let file = self - .webc + let file = (*self.webc) .volumes .get(&volume) .ok_or(FsError::EntityNotFound)? diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 340a5d63745..79a518c6fff 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -102,7 +102,7 @@ impl From for WasiThreadId { } impl From for u32 { fn from(t: WasiThreadId) -> u32 { - t.0 + t.0 as u32 } } @@ -117,7 +117,7 @@ impl From for WasiBusProcessId { } impl From for u32 { fn from(id: WasiBusProcessId) -> u32 { - id.0 + id.0 as u32 } } diff --git a/lib/wasi/src/state/pipe.rs b/lib/wasi/src/state/pipe.rs index d91f6a108d5..4781ab0a02f 100644 --- a/lib/wasi/src/state/pipe.rs +++ b/lib/wasi/src/state/pipe.rs @@ -50,7 +50,7 @@ impl WasiPipe { let buf_len = buf.len(); if buf_len > 0 { let reader = buf.as_ref(); - let read = read_bytes(reader, memory, iov).map(|_| buf_len)?; + let read = read_bytes(reader, memory, iov).map(|_| buf_len as usize)?; buf.advance(read); return Ok(read); } @@ -101,7 +101,7 @@ impl Read for WasiPipe { let buf_len = inner_buf.len(); if buf_len > 0 { let mut reader = inner_buf.as_ref(); - let read = reader.read(buf).map(|_| buf_len)?; + let read = reader.read(buf).map(|_| buf_len as usize)?; inner_buf.advance(read); return Ok(read); } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index d69eaca8543..01328a25ad3 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -998,7 +998,6 @@ pub fn fd_prestat_dir_name( /// Output: /// - `u32 *nwritten` /// Number of bytes written -#[allow(clippy::unnecessary_cast)] pub fn fd_pwrite( ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, @@ -2782,7 +2781,7 @@ pub fn path_rename( // implements the logic of "I'm not actually a file, I'll try to be as needed". let result = if let Some(h) = handle { drop(guard); - state.fs_rename(source_path, &host_adjusted_target_path) + state.fs_rename(&source_path, &host_adjusted_target_path) } else { let path_clone = path.clone(); drop(guard); @@ -3595,7 +3594,6 @@ pub fn thread_spawn( /// ## Parameters /// /// * `duration` - Amount of time that the thread should sleep -#[allow(clippy::unnecessary_cast)] pub fn thread_sleep( ctx: FunctionEnvMut<'_, WasiEnv>, duration: Timestamp, @@ -5464,7 +5462,7 @@ pub unsafe fn sock_send_file( { let mut fd_map = state.fs.fd_map.write().unwrap(); let fd_entry = wasi_try_ok!(fd_map.get_mut(&in_fd).ok_or(Errno::Badf)); - fd_entry.offset = offset; + fd_entry.offset = offset as u64; } // Enter a loop that will process all the data diff --git a/tests/lib/test-generator/src/lib.rs b/tests/lib/test-generator/src/lib.rs index b1e4a16e09c..e3256e3c264 100644 --- a/tests/lib/test-generator/src/lib.rs +++ b/tests/lib/test-generator/src/lib.rs @@ -85,7 +85,8 @@ pub fn extract_name(path: impl AsRef) -> String { .expect("filename should have a stem") .to_str() .expect("filename should be representable as a string") - .replace(['-', '/'], "_") + .replace('-', "_") + .replace('/', "_") } pub fn with_test_module( diff --git a/tests/lib/wast/src/wast.rs b/tests/lib/wast/src/wast.rs index 80b02adc276..50bc02b3883 100644 --- a/tests/lib/wast/src/wast.rs +++ b/tests/lib/wast/src/wast.rs @@ -437,7 +437,7 @@ impl Wast { // Checks if the `assert_unlinkable` message matches the expected one fn matches_message_assert_unlinkable(expected: &str, actual: &str) -> bool { - actual.contains(expected) + actual.contains(&expected) } // Checks if the `assert_invalid` message matches the expected one diff --git a/tests/wasi-wast/src/wasitests.rs b/tests/wasi-wast/src/wasitests.rs index d01d048c13e..2a204d8a587 100644 --- a/tests/wasi-wast/src/wasitests.rs +++ b/tests/wasi-wast/src/wasitests.rs @@ -124,7 +124,7 @@ fn compile_wasm_for_version( ) -> io::Result { //let out_dir = base_dir; //base_dir.join("..").join(version.get_directory_name()); if !out_dir.exists() { - fs::create_dir(out_dir)?; + fs::create_dir(&out_dir)?; } let wasm_out_name = { let mut wasm_out_name = out_dir.join(rs_mod_name); @@ -134,7 +134,7 @@ fn compile_wasm_for_version( println!("Reading contents from file `{}`", file); let file_contents: String = { let mut fc = String::new(); - let mut f = fs::OpenOptions::new().read(true).open(file)?; + let mut f = fs::OpenOptions::new().read(true).open(&file)?; f.read_to_string(&mut fc)?; fc }; From fd5962dd66c620281ee89707399d5fa4a1ae07f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 09:23:10 +0100 Subject: [PATCH 25/38] Revert "Fix make lint" This reverts commit e2755b71078ffb9103561762474b2b295e6c02c1. --- lib/api/src/sys/imports.rs | 1 - lib/api/src/sys/instance.rs | 2 -- lib/api/src/sys/module.rs | 1 - lib/c-api/src/wasm_c_api/engine.rs | 10 ++++---- lib/cli/src/commands/create_exe.rs | 10 ++++---- lib/cli/src/commands/init.rs | 4 +-- lib/cli/src/commands/publish.rs | 4 +-- lib/cli/src/commands/run.rs | 2 +- lib/compiler-llvm/src/abi/aarch64_systemv.rs | 13 +++++++--- lib/compiler-llvm/src/abi/x86_64_systemv.rs | 13 +++++++--- lib/compiler-llvm/src/translator/code.rs | 1 - lib/compiler-singlepass/src/arm64_decl.rs | 3 +-- lib/compiler-singlepass/src/codegen.rs | 4 +-- lib/compiler-singlepass/src/emitter_arm64.rs | 26 ++++++-------------- lib/compiler-singlepass/src/machine_arm64.rs | 2 -- lib/compiler/src/engine/artifact.rs | 3 --- lib/compiler/src/engine/resolver.rs | 1 - lib/compiler/src/engine/tunables.rs | 3 --- lib/emscripten/src/syscalls/mod.rs | 1 - lib/vbus/src/lib.rs | 2 +- lib/vm/src/vmcontext.rs | 4 +-- lib/wasi/src/runtime.rs | 7 +++--- lib/wasi/src/state/mod.rs | 12 ++++----- lib/wasi/src/syscalls/mod.rs | 3 ++- 24 files changed, 58 insertions(+), 74 deletions(-) diff --git a/lib/api/src/sys/imports.rs b/lib/api/src/sys/imports.rs index fd753c40ff9..a08d1b6adad 100644 --- a/lib/api/src/sys/imports.rs +++ b/lib/api/src/sys/imports.rs @@ -174,7 +174,6 @@ impl Imports { /// Resolve and return a vector of imports in the order they are defined in the `module`'s source code. /// /// This means the returned `Vec` might be a subset of the imports contained in `self`. - #[allow(clippy::result_large_err)] pub fn imports_for_module(&self, module: &Module) -> Result, LinkError> { let mut ret = vec![]; for import in module.imports() { diff --git a/lib/api/src/sys/instance.rs b/lib/api/src/sys/instance.rs index 877749ca789..4e0d90d3f18 100644 --- a/lib/api/src/sys/instance.rs +++ b/lib/api/src/sys/instance.rs @@ -111,7 +111,6 @@ impl Instance { /// Those are, as defined by the spec: /// * Link errors that happen when plugging the imports into the instance /// * Runtime errors that happen when running the module `start` function. - #[allow(clippy::result_large_err)] pub fn new( store: &mut impl AsStoreMut, module: &Module, @@ -159,7 +158,6 @@ impl Instance { /// Those are, as defined by the spec: /// * Link errors that happen when plugging the imports into the instance /// * Runtime errors that happen when running the module `start` function. - #[allow(clippy::result_large_err)] pub fn new_by_index( store: &mut impl AsStoreMut, module: &Module, diff --git a/lib/api/src/sys/module.rs b/lib/api/src/sys/module.rs index a83f5f10f04..9d49179265e 100644 --- a/lib/api/src/sys/module.rs +++ b/lib/api/src/sys/module.rs @@ -311,7 +311,6 @@ impl Module { } } - #[allow(clippy::result_large_err)] #[cfg(feature = "compiler")] pub(crate) fn instantiate( &self, diff --git a/lib/c-api/src/wasm_c_api/engine.rs b/lib/c-api/src/wasm_c_api/engine.rs index 0cb0a54d615..0c69c78db56 100644 --- a/lib/c-api/src/wasm_c_api/engine.rs +++ b/lib/c-api/src/wasm_c_api/engine.rs @@ -117,7 +117,7 @@ pub struct wasm_config_t { /// cbindgen:ignore #[no_mangle] pub extern "C" fn wasm_config_new() -> Box { - Box::::default() + Box::new(wasm_config_t::default()) } /// Delete a Wasmer config object. @@ -256,11 +256,11 @@ use wasmer_api::CompilerConfig; fn get_default_compiler_config() -> Box { cfg_if! { if #[cfg(feature = "cranelift")] { - Box::::default() + Box::new(wasmer_compiler_cranelift::Cranelift::default()) } else if #[cfg(feature = "llvm")] { - Box::::default() + Box::new(wasmer_compiler_llvm::LLVM::default()) } else if #[cfg(feature = "singlepass")] { - Box::::default() + Box::new(wasmer_compiler_singlepass::Singlepass::default()) } else { compile_error!("Please enable one of the compiler backends") } @@ -368,7 +368,7 @@ pub extern "C" fn wasm_engine_new_with_config( wasmer_compiler_t::CRANELIFT => { cfg_if! { if #[cfg(feature = "cranelift")] { - Box::::default() + Box::new(wasmer_compiler_cranelift::Cranelift::default()) } else { return return_with_error("Wasmer has not been compiled with the `cranelift` feature."); } diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 00c21de7254..5ea79d90f08 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -930,7 +930,7 @@ fn write_volume_obj( object_name, )?; - let mut writer = BufWriter::new(File::create(output_path)?); + let mut writer = BufWriter::new(File::create(&output_path)?); volumes_object .write_stream(&mut writer) .map_err(|err| anyhow::anyhow!(err.to_string()))?; @@ -1113,7 +1113,7 @@ pub(crate) fn create_header_files_in_dir( &ModuleMetadataSymbolRegistry { prefix: prefix.clone(), }, - metadata_length, + metadata_length as usize, ); std::fs::write(&header_file_path, &header_file_src).map_err(|e| { @@ -1258,7 +1258,7 @@ fn link_exe_from_dir( .as_ref() .ok_or_else(|| anyhow::anyhow!("could not find zig in $PATH {}", directory.display()))?; - let mut cmd = Command::new(zig_binary_path); + let mut cmd = Command::new(&zig_binary_path); cmd.arg("build-exe"); cmd.arg("--verbose-cc"); cmd.arg("--verbose-link"); @@ -1935,7 +1935,7 @@ pub(super) mod utils { let path_var = std::env::var("PATH").unwrap_or_default(); #[cfg(unix)] let system_path_var = std::process::Command::new("getconf") - .args(["PATH"]) + .args(&["PATH"]) .output() .map(|output| output.stdout) .unwrap_or_default(); @@ -2328,7 +2328,7 @@ mod http_fetch { pub(crate) fn list_dir(target: &Path) -> Vec { use walkdir::WalkDir; - WalkDir::new(target) + WalkDir::new(&target) .into_iter() .filter_map(|e| e.ok()) .map(|entry| entry.path().to_path_buf()) diff --git a/lib/cli/src/commands/init.rs b/lib/cli/src/commands/init.rs index b31f7ec14dd..584c7764d3b 100644 --- a/lib/cli/src/commands/init.rs +++ b/lib/cli/src/commands/init.rs @@ -160,7 +160,7 @@ impl Init { .collect::>() .join(NEWLINE); - std::fs::write(path, &toml_string) + std::fs::write(&path, &toml_string) .with_context(|| format!("Unable to write to \"{}\"", path.display()))?; Ok(()) @@ -493,7 +493,7 @@ fn construct_manifest( } fn parse_cargo_toml(manifest_path: &PathBuf) -> Result { let mut metadata = MetadataCommand::new(); - metadata.manifest_path(manifest_path); + metadata.manifest_path(&manifest_path); metadata.no_deps(); metadata.features(CargoOpt::AllFeatures); diff --git a/lib/cli/src/commands/publish.rs b/lib/cli/src/commands/publish.rs index 7f2136cd17a..889a39f1457 100644 --- a/lib/cli/src/commands/publish.rs +++ b/lib/cli/src/commands/publish.rs @@ -247,7 +247,7 @@ fn append_path_to_tar_gz( .metadata() .map_err(|e| (normalized_path.clone(), e))?; builder - .append_path_with_name(&normalized_path, target_path) + .append_path_with_name(&normalized_path, &target_path) .map_err(|e| (normalized_path.clone(), e))?; Ok(normalized_path) } @@ -386,7 +386,7 @@ fn apply_migration(conn: &mut Connection, migration_number: i32) -> Result<(), M tx.execute_batch(migration_to_apply) .map_err(|e| MigrationError::TransactionFailed(migration_number, format!("{}", e)))?; - tx.pragma_update(None, "user_version", (migration_number + 1)) + tx.pragma_update(None, "user_version", &(migration_number + 1)) .map_err(|e| MigrationError::TransactionFailed(migration_number, format!("{}", e)))?; tx.commit() .map_err(|_| MigrationError::CommitFailed(migration_number)) diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index b351f0c7610..2c5fb3868fa 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -127,7 +127,7 @@ impl RunWithPathBuf { let default = HashMap::default(); let fs = manifest.fs.as_ref().unwrap_or(&default); for (alias, real_dir) in fs.iter() { - let real_dir = self_clone.path.join(real_dir); + let real_dir = self_clone.path.join(&real_dir); if !real_dir.exists() { #[cfg(feature = "debug")] if self_clone.debug { diff --git a/lib/compiler-llvm/src/abi/aarch64_systemv.rs b/lib/compiler-llvm/src/abi/aarch64_systemv.rs index 63069de8a22..8bcb65a008c 100644 --- a/lib/compiler-llvm/src/abi/aarch64_systemv.rs +++ b/lib/compiler-llvm/src/abi/aarch64_systemv.rs @@ -21,14 +21,19 @@ impl Abi for Aarch64SystemV { // Given a function definition, retrieve the parameter that is the vmctx pointer. fn get_vmctx_ptr_param<'ctx>(&self, func_value: &FunctionValue<'ctx>) -> PointerValue<'ctx> { func_value - .get_nth_param(u32::from( - func_value + .get_nth_param( + if func_value .get_enum_attribute( AttributeLoc::Param(0), Attribute::get_named_enum_kind_id("sret"), ) - .is_some(), - )) + .is_some() + { + 1 + } else { + 0 + }, + ) .unwrap() .into_pointer_value() } diff --git a/lib/compiler-llvm/src/abi/x86_64_systemv.rs b/lib/compiler-llvm/src/abi/x86_64_systemv.rs index 2e444d078a0..7075193080a 100644 --- a/lib/compiler-llvm/src/abi/x86_64_systemv.rs +++ b/lib/compiler-llvm/src/abi/x86_64_systemv.rs @@ -23,14 +23,19 @@ impl Abi for X86_64SystemV { // Given a function definition, retrieve the parameter that is the vmctx pointer. fn get_vmctx_ptr_param<'ctx>(&self, func_value: &FunctionValue<'ctx>) -> PointerValue<'ctx> { func_value - .get_nth_param(u32::from( - func_value + .get_nth_param( + if func_value .get_enum_attribute( AttributeLoc::Param(0), Attribute::get_named_enum_kind_id("sret"), ) - .is_some(), - )) + .is_some() + { + 1 + } else { + 0 + }, + ) .unwrap() .into_pointer_value() } diff --git a/lib/compiler-llvm/src/translator/code.rs b/lib/compiler-llvm/src/translator/code.rs index 8d35957c9de..8bdd065532c 100644 --- a/lib/compiler-llvm/src/translator/code.rs +++ b/lib/compiler-llvm/src/translator/code.rs @@ -1048,7 +1048,6 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { Ok(()) } - #[allow(clippy::unnecessary_cast)] fn resolve_memory_ptr( &mut self, memory_index: MemoryIndex, diff --git a/lib/compiler-singlepass/src/arm64_decl.rs b/lib/compiler-singlepass/src/arm64_decl.rs index 1bcf54c20f8..b810cfa763c 100644 --- a/lib/compiler-singlepass/src/arm64_decl.rs +++ b/lib/compiler-singlepass/src/arm64_decl.rs @@ -8,7 +8,6 @@ use std::slice::Iter; use wasmer_types::{CallingConvention, Type}; /// General-purpose registers. -#[allow(clippy::upper_case_acronyms)] #[repr(u8)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] pub enum GPR { @@ -49,7 +48,7 @@ pub enum GPR { /// NEON registers. #[repr(u8)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] -#[allow(dead_code, clippy::upper_case_acronyms)] +#[allow(dead_code)] pub enum NEON { V0 = 0, V1 = 1, diff --git a/lib/compiler-singlepass/src/codegen.rs b/lib/compiler-singlepass/src/codegen.rs index c9ab5760d45..9b24e3be68f 100644 --- a/lib/compiler-singlepass/src/codegen.rs +++ b/lib/compiler-singlepass/src/codegen.rs @@ -1143,7 +1143,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { let fsm = FunctionStateMap::new( machine.new_machine_state(), - local_func_index.index(), + local_func_index.index() as usize, 32, (0..local_types.len()) .map(|_| WasmAbstractValue::Runtime) @@ -6057,7 +6057,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { .emit_call_register(this.machine.get_grp_for_call()) }, // [vmctx, func_index] -> funcref - iter::once(Location::Imm32(function_index)), + iter::once(Location::Imm32(function_index as u32)), iter::once(WpType::I64), )?; diff --git a/lib/compiler-singlepass/src/emitter_arm64.rs b/lib/compiler-singlepass/src/emitter_arm64.rs index 104d7787c9b..948fe793ced 100644 --- a/lib/compiler-singlepass/src/emitter_arm64.rs +++ b/lib/compiler-singlepass/src/emitter_arm64.rs @@ -805,7 +805,6 @@ impl EmitterARM64 for Assembler { } Ok(()) } - #[allow(clippy::unnecessary_cast)] fn emit_ldria( &mut self, sz: Size, @@ -850,7 +849,6 @@ impl EmitterARM64 for Assembler { } Ok(()) } - #[allow(clippy::unnecessary_cast)] fn emit_ldpia( &mut self, sz: Size, @@ -1250,9 +1248,9 @@ impl EmitterARM64 for Assembler { (Size::S64, Location::Imm64(val), Location::GPR(dst)) => { let dst = dst.into_index() as u32; if val < 0x1000 { - dynasm!(self ; mov W(dst), val); + dynasm!(self ; mov W(dst), val as u64); } else if encode_logical_immediate_64bit(val as _).is_some() { - dynasm!(self ; orr X(dst), xzr, val); + dynasm!(self ; orr X(dst), xzr, val as u64); } else { codegen_error!("singleplasse can't emit MOV S64 {}, {:?}", val, dst); } @@ -1596,7 +1594,6 @@ impl EmitterARM64 for Assembler { } Ok(()) } - #[allow(clippy::unnecessary_cast)] fn emit_add_lsl( &mut self, sz: Size, @@ -1624,7 +1621,6 @@ impl EmitterARM64 for Assembler { Ok(()) } - #[allow(clippy::unnecessary_cast)] fn emit_cmp(&mut self, sz: Size, src: Location, dst: Location) -> Result<(), CompileError> { match (sz, src, dst) { (Size::S64, Location::GPR(src), Location::GPR(dst)) => { @@ -1646,7 +1642,7 @@ impl EmitterARM64 for Assembler { if imm >= 0x1000 { codegen_error!("singlepass CMP with imm too large {}", imm); } - dynasm!(self ; cmp X(dst), imm); + dynasm!(self ; cmp X(dst), imm as u32); } (Size::S64, Location::Imm64(imm), Location::GPR(dst)) => { let dst = dst.into_index() as u32; @@ -1687,10 +1683,10 @@ impl EmitterARM64 for Assembler { } (Size::S64, Location::Imm64(imm), Location::GPR(dst)) => { let dst = dst.into_index() as u32; - if encode_logical_immediate_64bit(imm).is_none() { + if encode_logical_immediate_64bit(imm as u64).is_none() { codegen_error!("singlepass TST with incompatible imm {}", imm); } - dynasm!(self ; tst X(dst), imm); + dynasm!(self ; tst X(dst), imm as u64); } (Size::S32, Location::GPR(src), Location::GPR(dst)) => { let src = src.into_index() as u32; @@ -1728,6 +1724,7 @@ impl EmitterARM64 for Assembler { if imm > 63 { codegen_error!("singlepass LSL with incompatible imm {}", imm); } + let imm = imm as u32; let dst = dst.into_index() as u32; dynasm!(self ; lsl X(dst), X(src1), imm); } @@ -1771,7 +1768,7 @@ impl EmitterARM64 for Assembler { if imm > 31 { codegen_error!("singlepass LSL with incompatible imm {}", imm); } - dynasm!(self ; lsl W(dst), W(src1), imm); + dynasm!(self ; lsl W(dst), W(src1), imm as u32); } _ => codegen_error!( "singlepass can't emit LSL {:?} {:?} {:?} {:?}", @@ -1783,7 +1780,6 @@ impl EmitterARM64 for Assembler { } Ok(()) } - #[allow(clippy::unnecessary_cast)] fn emit_asr( &mut self, sz: Size, @@ -1847,7 +1843,7 @@ impl EmitterARM64 for Assembler { if imm == 0 || imm > 31 { codegen_error!("singlepass ASR with incompatible imm {}", imm); } - dynasm!(self ; asr W(dst), W(src1), imm); + dynasm!(self ; asr W(dst), W(src1), imm as u32); } _ => codegen_error!( "singlepass can't emit ASR {:?} {:?} {:?} {:?}", @@ -1859,7 +1855,6 @@ impl EmitterARM64 for Assembler { } Ok(()) } - #[allow(clippy::unnecessary_cast)] fn emit_lsr( &mut self, sz: Size, @@ -1935,7 +1930,6 @@ impl EmitterARM64 for Assembler { } Ok(()) } - #[allow(clippy::unnecessary_cast)] fn emit_ror( &mut self, sz: Size, @@ -2004,7 +1998,6 @@ impl EmitterARM64 for Assembler { Ok(()) } - #[allow(clippy::unnecessary_cast)] fn emit_or( &mut self, sz: Size, @@ -2053,7 +2046,6 @@ impl EmitterARM64 for Assembler { } Ok(()) } - #[allow(clippy::unnecessary_cast)] fn emit_and( &mut self, sz: Size, @@ -2102,7 +2094,6 @@ impl EmitterARM64 for Assembler { } Ok(()) } - #[allow(clippy::unnecessary_cast)] fn emit_eor( &mut self, sz: Size, @@ -3218,7 +3209,6 @@ impl EmitterARM64 for Assembler { } } -#[allow(clippy::unnecessary_cast)] pub fn gen_std_trampoline_arm64( sig: &FunctionType, calling_convention: CallingConvention, diff --git a/lib/compiler-singlepass/src/machine_arm64.rs b/lib/compiler-singlepass/src/machine_arm64.rs index 4788e50618a..b07e0f46ed9 100644 --- a/lib/compiler-singlepass/src/machine_arm64.rs +++ b/lib/compiler-singlepass/src/machine_arm64.rs @@ -168,7 +168,6 @@ impl MachineARM64 { } } - #[allow(clippy::unnecessary_cast)] fn location_to_reg( &mut self, sz: Size, @@ -321,7 +320,6 @@ impl MachineARM64 { _ => codegen_error!("singlepass can't emit location_to_reg {:?} {:?}", sz, src), } } - #[allow(clippy::unnecessary_cast)] fn location_to_neon( &mut self, sz: Size, diff --git a/lib/compiler/src/engine/artifact.rs b/lib/compiler/src/engine/artifact.rs index 74baf98b927..e60a86142ed 100644 --- a/lib/compiler/src/engine/artifact.rs +++ b/lib/compiler/src/engine/artifact.rs @@ -299,7 +299,6 @@ impl Artifact { } /// Do preinstantiation logic that is executed before instantiating - #[allow(clippy::result_large_err)] pub fn preinstantiate(&self) -> Result<(), InstantiationError> { Ok(()) } @@ -309,7 +308,6 @@ impl Artifact { /// # Safety /// /// See [`InstanceHandle::new`]. - #[allow(clippy::result_large_err)] pub unsafe fn instantiate( &self, tunables: &dyn Tunables, @@ -390,7 +388,6 @@ impl Artifact { /// # Safety /// /// See [`InstanceHandle::finish_instantiation`]. - #[allow(clippy::result_large_err)] pub unsafe fn finish_instantiation( &self, trap_handler: Option<*const TrapHandlerFn<'static>>, diff --git a/lib/compiler/src/engine/resolver.rs b/lib/compiler/src/engine/resolver.rs index e4699370bd0..9fac5fc0aec 100644 --- a/lib/compiler/src/engine/resolver.rs +++ b/lib/compiler/src/engine/resolver.rs @@ -60,7 +60,6 @@ fn get_runtime_size(context: &StoreObjects, extern_: &VMExtern) -> Option { /// a `Resolver`. /// /// If all imports are satisfied returns an `Imports` instance required for a module instantiation. -#[allow(clippy::result_large_err)] pub fn resolve_imports( module: &ModuleInfo, imports: &[VMExtern], diff --git a/lib/compiler/src/engine/tunables.rs b/lib/compiler/src/engine/tunables.rs index 945908a18cb..596af921dc5 100644 --- a/lib/compiler/src/engine/tunables.rs +++ b/lib/compiler/src/engine/tunables.rs @@ -60,7 +60,6 @@ pub trait Tunables { /// /// # Safety /// - `memory_definition_locations` must point to a valid locations in VM memory. - #[allow(clippy::result_large_err)] unsafe fn create_memories( &self, context: &mut StoreObjects, @@ -94,7 +93,6 @@ pub trait Tunables { /// # Safety /// /// To be done - #[allow(clippy::result_large_err)] unsafe fn create_tables( &self, context: &mut StoreObjects, @@ -125,7 +123,6 @@ pub trait Tunables { /// Allocate memory for just the globals of the current module, /// with initializers applied. - #[allow(clippy::result_large_err)] fn create_globals( &self, context: &mut StoreObjects, diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 41ba7761c69..42ce7b1ece4 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -405,7 +405,6 @@ pub fn ___syscall192(mut ctx: FunctionEnvMut, _which: c_int, mut varargs: } /// lseek -#[allow(clippy::unnecessary_cast)] pub fn ___syscall140(ctx: FunctionEnvMut, _which: i32, mut varargs: VarArgs) -> i32 { // -> c_int debug!("emscripten::___syscall140 (lseek) {}", _which); diff --git a/lib/vbus/src/lib.rs b/lib/vbus/src/lib.rs index 0b6696d64ff..e51ec11ffac 100644 --- a/lib/vbus/src/lib.rs +++ b/lib/vbus/src/lib.rs @@ -285,7 +285,7 @@ pub struct UnsupportedVirtualBus {} impl VirtualBus for UnsupportedVirtualBus { fn new_spawn(&self) -> SpawnOptions { - SpawnOptions::new(Box::::default()) + SpawnOptions::new(Box::new(UnsupportedVirtualBusSpawner::default())) } fn listen(&self) -> Result> { diff --git a/lib/vm/src/vmcontext.rs b/lib/vm/src/vmcontext.rs index d682f53d554..f87df89c471 100644 --- a/lib/vm/src/vmcontext.rs +++ b/lib/vm/src/vmcontext.rs @@ -404,7 +404,7 @@ pub(crate) unsafe fn memory32_atomic_check32( let dst = mem.base.offset(dst) as *mut u32; let atomic_dst = AtomicPtr::new(dst); let read_val = *atomic_dst.load(Ordering::Acquire); - let ret = u32::from(read_val != val); + let ret = if read_val == val { 0 } else { 1 }; Ok(ret) } @@ -435,7 +435,7 @@ pub(crate) unsafe fn memory32_atomic_check64( let dst = mem.base.offset(dst) as *mut u64; let atomic_dst = AtomicPtr::new(dst); let read_val = *atomic_dst.load(Ordering::Acquire); - let ret = u32::from(read_val != val); + let ret = if read_val == val { 0 } else { 1 }; Ok(ret) } diff --git a/lib/wasi/src/runtime.rs b/lib/wasi/src/runtime.rs index 6b6893a77b8..1394e010b8a 100644 --- a/lib/wasi/src/runtime.rs +++ b/lib/wasi/src/runtime.rs @@ -123,15 +123,14 @@ impl PluggableRuntimeImplementation { } } -#[allow(clippy::derivable_impls)] impl Default for PluggableRuntimeImplementation { fn default() -> Self { Self { #[cfg(not(feature = "host-vnet"))] - networking: Box::::default(), + networking: Box::new(wasmer_vnet::UnsupportedVirtualNetworking::default()), #[cfg(feature = "host-vnet")] - networking: Box::::default(), - bus: Box::::default(), + networking: Box::new(wasmer_wasi_local_networking::LocalNetworking::default()), + bus: Box::new(UnsupportedVirtualBus::default()), thread_id_seed: Default::default(), } } diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index 0715d645bde..69f83ee548e 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -356,11 +356,11 @@ pub struct WasiFs { pub(crate) fn default_fs_backing() -> Box { cfg_if::cfg_if! { if #[cfg(feature = "host-fs")] { - Box::::default() + Box::new(wasmer_vfs::host_fs::FileSystem::default()) } else if #[cfg(feature = "mem-fs")] { - Box::::default() + Box::new(wasmer_vfs::mem_fs::FileSystem::default()) } else { - Box::::default() + Box::new(FallbackFileSystem::default()) } } } @@ -1550,7 +1550,7 @@ impl WasiFs { fn create_stdout(&self, inodes: &mut WasiInodes) { self.create_std_dev_inner( inodes, - Box::::default(), + Box::new(Stdout::default()), "stdout", __WASI_STDOUT_FILENO, STDOUT_DEFAULT_RIGHTS, @@ -1560,7 +1560,7 @@ impl WasiFs { fn create_stdin(&self, inodes: &mut WasiInodes) { self.create_std_dev_inner( inodes, - Box::::default(), + Box::new(Stdin::default()), "stdin", __WASI_STDIN_FILENO, STDIN_DEFAULT_RIGHTS, @@ -1570,7 +1570,7 @@ impl WasiFs { fn create_stderr(&self, inodes: &mut WasiInodes) { self.create_std_dev_inner( inodes, - Box::::default(), + Box::new(Stderr::default()), "stderr", __WASI_STDERR_FILENO, STDERR_DEFAULT_RIGHTS, diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 01328a25ad3..ebf755d920a 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -877,7 +877,8 @@ pub fn fd_pread( Kind::File { handle, .. } => { if let Some(h) = handle { wasi_try_ok!( - h.seek(std::io::SeekFrom::Start(offset)).map_err(map_io_err), + h.seek(std::io::SeekFrom::Start(offset as u64)) + .map_err(map_io_err), env ); wasi_try_ok!(read_bytes(h, &memory, iovs), env) From b7c868e890bf18684d80b30a9c3fa2742988d25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 12:46:59 +0100 Subject: [PATCH 26/38] Fix more errors on Windows --- lib/wasi/src/state/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wasi/src/state/types.rs b/lib/wasi/src/state/types.rs index f4aca85ab3f..d85c8dcb0bb 100644 --- a/lib/wasi/src/state/types.rs +++ b/lib/wasi/src/state/types.rs @@ -331,7 +331,7 @@ pub(crate) fn poll( .bytes_available_write()? .map(|s| s > 0) .unwrap_or(false); - let is_closed = file.is_open() == false; + let is_closed = !file.is_open(); tracing::debug!( "poll_evt can_read={} can_write={} is_closed={}", From c61a5d7cf5891bcd3e8e2ea6c5535d3ebec2eeb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 13:08:27 +0100 Subject: [PATCH 27/38] Store::default - create new store with BaseTunables --- lib/cli/src/commands/create_exe.rs | 65 +----------------------------- lib/cli/src/store.rs | 6 ++- 2 files changed, 6 insertions(+), 65 deletions(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 5ea79d90f08..9144d21e3ad 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -2,7 +2,7 @@ use super::ObjectFormat; use crate::common::normalize_path; -use crate::store::{CompilerOptions, CompilerType}; +use crate::store::CompilerOptions; use anyhow::{Context, Result}; use clap::Parser; use serde::{Deserialize, Serialize}; @@ -224,22 +224,7 @@ impl CreateExe { return Err(anyhow::anyhow!("input path cannot be a directory")); } - let (_, ct) = self.compiler.get_store_for_target(target.clone())?; - - let compiler_type = if self.compiler.singlepass { - CompilerType::Singlepass - } else if self.compiler.cranelift { - CompilerType::Cranelift - } else if self.compiler.llvm { - CompilerType::LLVM - } else { - ct // default compiler type - }; - - let engine = EngineBuilder::new(get_config(&compiler_type)?).engine(); - - let tunables = BaseTunables::for_target(engine.target()); - let store = Store::new_with_tunables(&engine, tunables); + let (store, compiler_type) = self.compiler.get_store_for_target(target.clone())?; println!("Compiler: {}", compiler_type.to_string()); println!("Target: {}", target.triple()); @@ -318,52 +303,6 @@ impl CreateExe { } } -fn get_config( - compiler: &CompilerType, -) -> Result, anyhow::Error> { - match compiler { - CompilerType::Cranelift => { - #[cfg(feature = "cranelift")] - { - Ok(Box::new(wasmer_compiler_cranelift::Cranelift::default())) - } - #[cfg(not(feature = "cranelift"))] - { - Err(anyhow::anyhow!( - "compiler \"cranelift\" not embedded in wasmer-cli" - )) - } - } - CompilerType::Singlepass => { - #[cfg(feature = "singlepass")] - { - Ok(Box::new(wasmer_compiler_singlepass::Singlepass::default())) - } - #[cfg(not(feature = "singlepass"))] - { - Err(anyhow::anyhow!( - "compiler \"singlepass\" not embedded in wasmer-cli" - )) - } - } - CompilerType::LLVM => { - #[cfg(feature = "llvm")] - { - Ok(Box::new(wasmer_compiler_llvm::LLVM::default())) - } - #[cfg(not(feature = "llvm"))] - { - Err(anyhow::anyhow!( - "compiler \"llvm\" not embedded in wasmer-cli" - )) - } - } - CompilerType::Headless => Err(anyhow::anyhow!( - "cannot compile .wasm files to object files with compiler \"headless\"" - )), - } -} - fn write_entrypoint(directory: &Path, entrypoint: &Entrypoint) -> Result<(), anyhow::Error> { std::fs::write( directory.join("entrypoint.json"), diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index 1d2c55904cb..bf3e44123b4 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -105,7 +105,8 @@ impl CompilerOptions { pub fn get_store_for_target(&self, target: Target) -> Result<(Store, CompilerType)> { let (compiler_config, compiler_type) = self.get_compiler_config()?; let engine = self.get_engine(target, compiler_config)?; - let store = Store::new(engine); + let tunables = BaseTunables::for_target(engine.target()); + let store = Store::new_with_tunables(&engine, tunables); Ok((store, compiler_type)) } @@ -313,7 +314,8 @@ impl StoreOptions { pub fn get_store_for_target(&self, target: Target) -> Result<(Store, CompilerType)> { let (compiler_config, compiler_type) = self.compiler.get_compiler_config()?; let engine = self.get_engine_with_compiler(target, compiler_config)?; - let store = Store::new(engine); + let tunables = BaseTunables::for_target(engine.target()); + let store = Store::new_with_tunables(&engine, tunables); Ok((store, compiler_type)) } From 32fbfc338c314e54d74ed713fa5598b0238e9431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 15:41:49 +0100 Subject: [PATCH 28/38] Disable set_target(Some(target)) for Engine builder See https://github.com/wasmerio/wasmer/issues/3508 --- lib/cli/src/store.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index bf3e44123b4..e813cedd4ee 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -119,7 +119,8 @@ impl CompilerOptions { let features = self.get_features(compiler_config.default_features_for_target(&target))?; let engine: Engine = wasmer_compiler::EngineBuilder::new(compiler_config) .set_features(Some(features)) - .set_target(Some(target)) + // https://github.com/wasmerio/wasmer/issues/3508 + // .set_target(Some(target)) .engine(); Ok(engine) From 6398b068658b0d3d6ec7a33c833f0fa8c6001f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 16:24:13 +0100 Subject: [PATCH 29/38] Enable set_target() again, but disable unwind info --- lib/cli/src/store.rs | 3 +-- lib/compiler-cranelift/src/translator/unwind.rs | 12 +++++++----- lib/compiler-singlepass/src/codegen.rs | 10 ++++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index e813cedd4ee..bf3e44123b4 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -119,8 +119,7 @@ impl CompilerOptions { let features = self.get_features(compiler_config.default_features_for_target(&target))?; let engine: Engine = wasmer_compiler::EngineBuilder::new(compiler_config) .set_features(Some(features)) - // https://github.com/wasmerio/wasmer/issues/3508 - // .set_target(Some(target)) + .set_target(Some(target)) .engine(); Ok(engine) diff --git a/lib/compiler-cranelift/src/translator/unwind.rs b/lib/compiler-cranelift/src/translator/unwind.rs index 1aff474ddce..a9627c05f41 100644 --- a/lib/compiler-cranelift/src/translator/unwind.rs +++ b/lib/compiler-cranelift/src/translator/unwind.rs @@ -47,11 +47,13 @@ pub(crate) fn compiled_function_unwind_info( .map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?; match unwind_info { - Some(UnwindInfo::WindowsX64(unwind)) => { - let size = unwind.emit_size(); - let mut data: Vec = vec![0; size]; - unwind.emit(&mut data[..]); - Ok(CraneliftUnwindInfo::WindowsX64(data)) + Some(UnwindInfo::WindowsX64(_unwind)) => { + // https://github.com/wasmerio/wasmer/issues/3508 + Ok(CraneliftUnwindInfo::None) + // let size = unwind.emit_size(); + // let mut data: Vec = vec![0; size]; + // unwind.emit(&mut data[..]); + // Ok(CraneliftUnwindInfo::WindowsX64(data)) } Some(UnwindInfo::SystemV(unwind)) => Ok(CraneliftUnwindInfo::Fde(unwind)), Some(_) | None => Ok(CraneliftUnwindInfo::None), diff --git a/lib/compiler-singlepass/src/codegen.rs b/lib/compiler-singlepass/src/codegen.rs index 9b24e3be68f..1ec7b923938 100644 --- a/lib/compiler-singlepass/src/codegen.rs +++ b/lib/compiler-singlepass/src/codegen.rs @@ -6661,10 +6661,12 @@ impl<'a, M: Machine> FuncGen<'a, M> { } } CallingConvention::WindowsFastcall => { - let unwind = self.machine.gen_windows_unwind_info(body_len); - if let Some(unwind) = unwind { - unwind_info = Some(CompiledFunctionUnwindInfo::WindowsX64(unwind)); - } + // https://github.com/wasmerio/wasmer/issues/3508 + // + // let unwind = self.machine.gen_windows_unwind_info(body_len); + // if let Some(unwind) = unwind { + // unwind_info = Some(CompiledFunctionUnwindInfo::WindowsX64(unwind)); + // } } _ => (), }; From f57716448942b354aa9e23feaf9450ab25be6af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 16:43:22 +0100 Subject: [PATCH 30/38] Revert "Enable set_target() again, but disable unwind info" This reverts commit 6398b068658b0d3d6ec7a33c833f0fa8c6001f25. --- lib/cli/src/store.rs | 3 ++- lib/compiler-cranelift/src/translator/unwind.rs | 12 +++++------- lib/compiler-singlepass/src/codegen.rs | 10 ++++------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index bf3e44123b4..e813cedd4ee 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -119,7 +119,8 @@ impl CompilerOptions { let features = self.get_features(compiler_config.default_features_for_target(&target))?; let engine: Engine = wasmer_compiler::EngineBuilder::new(compiler_config) .set_features(Some(features)) - .set_target(Some(target)) + // https://github.com/wasmerio/wasmer/issues/3508 + // .set_target(Some(target)) .engine(); Ok(engine) diff --git a/lib/compiler-cranelift/src/translator/unwind.rs b/lib/compiler-cranelift/src/translator/unwind.rs index a9627c05f41..1aff474ddce 100644 --- a/lib/compiler-cranelift/src/translator/unwind.rs +++ b/lib/compiler-cranelift/src/translator/unwind.rs @@ -47,13 +47,11 @@ pub(crate) fn compiled_function_unwind_info( .map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?; match unwind_info { - Some(UnwindInfo::WindowsX64(_unwind)) => { - // https://github.com/wasmerio/wasmer/issues/3508 - Ok(CraneliftUnwindInfo::None) - // let size = unwind.emit_size(); - // let mut data: Vec = vec![0; size]; - // unwind.emit(&mut data[..]); - // Ok(CraneliftUnwindInfo::WindowsX64(data)) + Some(UnwindInfo::WindowsX64(unwind)) => { + let size = unwind.emit_size(); + let mut data: Vec = vec![0; size]; + unwind.emit(&mut data[..]); + Ok(CraneliftUnwindInfo::WindowsX64(data)) } Some(UnwindInfo::SystemV(unwind)) => Ok(CraneliftUnwindInfo::Fde(unwind)), Some(_) | None => Ok(CraneliftUnwindInfo::None), diff --git a/lib/compiler-singlepass/src/codegen.rs b/lib/compiler-singlepass/src/codegen.rs index 1ec7b923938..9b24e3be68f 100644 --- a/lib/compiler-singlepass/src/codegen.rs +++ b/lib/compiler-singlepass/src/codegen.rs @@ -6661,12 +6661,10 @@ impl<'a, M: Machine> FuncGen<'a, M> { } } CallingConvention::WindowsFastcall => { - // https://github.com/wasmerio/wasmer/issues/3508 - // - // let unwind = self.machine.gen_windows_unwind_info(body_len); - // if let Some(unwind) = unwind { - // unwind_info = Some(CompiledFunctionUnwindInfo::WindowsX64(unwind)); - // } + let unwind = self.machine.gen_windows_unwind_info(body_len); + if let Some(unwind) = unwind { + unwind_info = Some(CompiledFunctionUnwindInfo::WindowsX64(unwind)); + } } _ => (), }; From e112604ef7c80e5a0e655866fb4db2b06d937973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 16:43:34 +0100 Subject: [PATCH 31/38] Revert "Disable set_target(Some(target)) for Engine builder" This reverts commit 32fbfc338c314e54d74ed713fa5598b0238e9431. --- lib/cli/src/store.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index e813cedd4ee..bf3e44123b4 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -119,8 +119,7 @@ impl CompilerOptions { let features = self.get_features(compiler_config.default_features_for_target(&target))?; let engine: Engine = wasmer_compiler::EngineBuilder::new(compiler_config) .set_features(Some(features)) - // https://github.com/wasmerio/wasmer/issues/3508 - // .set_target(Some(target)) + .set_target(Some(target)) .engine(); Ok(engine) From 17943e5e1129e72f3946f6948c013c3803b23495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 17:24:44 +0100 Subject: [PATCH 32/38] Refactor Artifact::new into separate sub-functions --- lib/cli/src/commands/create_exe.rs | 11 +++++++---- lib/compiler/src/engine/artifact.rs | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 9144d21e3ad..a6c465df222 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -971,15 +971,18 @@ fn get_module_infos( let mut module_infos = BTreeMap::new(); for (atom_name, atom_bytes) in atoms { - let module = Module::from_binary(store, atom_bytes.as_slice()) - .map_err(|e| anyhow::anyhow!("could not deserialize module {atom_name}: {e}"))?; + let tunables = BaseTunables::for_target(store.engine().target()); + let module_info = + Artifact::get_module_info(store.engine(), atom_bytes.as_slice(), &tunables) + .map_err(|e| anyhow::anyhow!("could not compile module {atom_name}: {e}"))?; + if let Some(s) = entrypoint .atoms .iter_mut() .find(|a| a.atom.as_str() == atom_name.as_str()) { - s.module_info = Some(module.info().clone()); - module_infos.insert(atom_name.clone(), module.info().clone()); + s.module_info = Some(module_info.clone()); + module_infos.insert(atom_name.clone(), module_info.clone()); } } diff --git a/lib/compiler/src/engine/artifact.rs b/lib/compiler/src/engine/artifact.rs index e60a86142ed..4bddbe11e4c 100644 --- a/lib/compiler/src/engine/artifact.rs +++ b/lib/compiler/src/engine/artifact.rs @@ -56,6 +56,17 @@ impl Artifact { data: &[u8], tunables: &dyn Tunables, ) -> Result { + let artifact = Self::get_artifact_build(engine, data, tunables)?; + let mut inner_engine = engine.inner_mut(); + Self::from_parts(&mut inner_engine, artifact) + } + + #[cfg(feature = "compiler")] + fn get_artifact_build( + engine: &Engine, + data: &[u8], + tunables: &dyn Tunables, + ) -> Result { let environ = ModuleEnvironment::new(); let mut inner_engine = engine.inner_mut(); let translation = environ.translate(data).map_err(CompileError::Wasm)?; @@ -79,7 +90,18 @@ impl Artifact { table_styles, )?; - Self::from_parts(&mut inner_engine, artifact) + Ok(artifact) + } + + /// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated. + #[cfg(feature = "compiler")] + pub fn get_module_info( + engine: &Engine, + data: &[u8], + tunables: &dyn Tunables, + ) -> Result { + let artifact = Self::get_artifact_build(engine, data, tunables)?; + Ok(artifact.create_module_info()) } /// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated. From 32b39e80efc5e51410d69348a4cabdb00aad2e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 19:13:28 +0100 Subject: [PATCH 33/38] Remove unnecessary printlns --- lib/cli/src/commands/create_exe.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index a6c465df222..80d72eb5690 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -1285,20 +1285,16 @@ fn link_exe_from_dir( cmd.args(files_winsdk); } - println!("running cmd: {cmd:?}"); + if debug { + println!("running cmd: {cmd:?}"); + cmd.stdout(Stdio::inherit()); + cmd.stderr(Stdio::inherit()); + } let compilation = cmd - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) .output() .context(anyhow!("Could not execute `zig`: {cmd:?}"))?; - println!( - "file {} exists: {:?}", - out_path.display(), - out_path.exists() - ); - if !compilation.status.success() { return Err(anyhow::anyhow!(String::from_utf8_lossy( &compilation.stderr @@ -1308,7 +1304,6 @@ fn link_exe_from_dir( // remove file if it exists - if not done, can lead to errors on copy let output_path_normalized = normalize_path(&format!("{}", output_path.display())); - println!("removing {output_path_normalized}"); let _ = std::fs::remove_file(&output_path_normalized); std::fs::copy( &normalize_path(&format!("{}", out_path.display())), From af67c8662123d92403972b2810f06f04071752cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 19:33:01 +0100 Subject: [PATCH 34/38] Fix wrong documentation --- lib/wasi/src/runners/emscripten.rs | 2 +- lib/wasi/src/runners/wasi.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/wasi/src/runners/emscripten.rs b/lib/wasi/src/runners/emscripten.rs index fd92bbb74f9..168f109c5c9 100644 --- a/lib/wasi/src/runners/emscripten.rs +++ b/lib/wasi/src/runners/emscripten.rs @@ -21,7 +21,7 @@ pub struct EmscriptenRunner { } impl EmscriptenRunner { - /// Constructs a new `EmscriptenRunner` given an `Engine` + /// Constructs a new `EmscriptenRunner` given an `Store` pub fn new(store: Store) -> Self { Self { args: Vec::new(), diff --git a/lib/wasi/src/runners/wasi.rs b/lib/wasi/src/runners/wasi.rs index e010a51406a..52b02fcbf99 100644 --- a/lib/wasi/src/runners/wasi.rs +++ b/lib/wasi/src/runners/wasi.rs @@ -19,7 +19,7 @@ pub struct WasiRunner { } impl WasiRunner { - /// Constructs a new `WasiRunner` given an `Engine` + /// Constructs a new `WasiRunner` given an `Store` pub fn new(store: Store) -> Self { Self { args: Vec::new(), From b26b48794cc7b00bb5f939dfdf40bba94e9ba86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 19:43:01 +0100 Subject: [PATCH 35/38] Move get_module_info into the Engine --- lib/cli/src/commands/create_exe.rs | 11 ++++------- lib/compiler/src/engine/artifact.rs | 24 +----------------------- lib/compiler/src/engine/inner.rs | 9 +++++++++ 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 80d72eb5690..7eb6f0362e2 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -224,7 +224,7 @@ impl CreateExe { return Err(anyhow::anyhow!("input path cannot be a directory")); } - let (store, compiler_type) = self.compiler.get_store_for_target(target.clone())?; + let (_, compiler_type) = self.compiler.get_store_for_target(target.clone())?; println!("Compiler: {}", compiler_type.to_string()); println!("Target: {}", target.triple()); @@ -273,7 +273,7 @@ impl CreateExe { ) }?; - get_module_infos(&tempdir, &atoms, object_format, &store)?; + get_module_infos(&tempdir, &atoms, object_format)?; let mut entrypoint = get_entrypoint(&tempdir)?; create_header_files_in_dir(&tempdir, &mut entrypoint, &atoms, &self.precompiled_atom)?; link_exe_from_dir( @@ -964,17 +964,14 @@ fn get_module_infos( directory: &Path, atoms: &[(String, Vec)], object_format: ObjectFormat, - store: &Store, ) -> Result, anyhow::Error> { let mut entrypoint = get_entrypoint(directory).with_context(|| anyhow::anyhow!("get module infos"))?; let mut module_infos = BTreeMap::new(); for (atom_name, atom_bytes) in atoms { - let tunables = BaseTunables::for_target(store.engine().target()); - let module_info = - Artifact::get_module_info(store.engine(), atom_bytes.as_slice(), &tunables) - .map_err(|e| anyhow::anyhow!("could not compile module {atom_name}: {e}"))?; + let module_info = Engine::get_module_info(atom_bytes.as_slice()) + .map_err(|e| anyhow::anyhow!("could not get module info for atom {atom_name}: {e}"))?; if let Some(s) = entrypoint .atoms diff --git a/lib/compiler/src/engine/artifact.rs b/lib/compiler/src/engine/artifact.rs index 4bddbe11e4c..2c917475273 100644 --- a/lib/compiler/src/engine/artifact.rs +++ b/lib/compiler/src/engine/artifact.rs @@ -56,19 +56,8 @@ impl Artifact { data: &[u8], tunables: &dyn Tunables, ) -> Result { - let artifact = Self::get_artifact_build(engine, data, tunables)?; let mut inner_engine = engine.inner_mut(); - Self::from_parts(&mut inner_engine, artifact) - } - - #[cfg(feature = "compiler")] - fn get_artifact_build( - engine: &Engine, - data: &[u8], - tunables: &dyn Tunables, - ) -> Result { let environ = ModuleEnvironment::new(); - let mut inner_engine = engine.inner_mut(); let translation = environ.translate(data).map_err(CompileError::Wasm)?; let module = translation.module; let memory_styles: PrimaryMap = module @@ -90,18 +79,7 @@ impl Artifact { table_styles, )?; - Ok(artifact) - } - - /// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated. - #[cfg(feature = "compiler")] - pub fn get_module_info( - engine: &Engine, - data: &[u8], - tunables: &dyn Tunables, - ) -> Result { - let artifact = Self::get_artifact_build(engine, data, tunables)?; - Ok(artifact.create_module_info()) + Self::from_parts(&mut inner_engine, artifact) } /// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated. diff --git a/lib/compiler/src/engine/inner.rs b/lib/compiler/src/engine/inner.rs index 3abe6f6cd0e..d1c979d80af 100644 --- a/lib/compiler/src/engine/inner.rs +++ b/lib/compiler/src/engine/inner.rs @@ -74,6 +74,15 @@ impl Engine { } } + /// Returns only the `ModuleInfo` given a `wasm` byte slice + #[cfg(feature = "compiler")] + pub fn get_module_info(data: &[u8]) -> Result { + // this is from `artifact_builder.rs` + let environ = crate::ModuleEnvironment::new(); + let translation = environ.translate(data).map_err(CompileError::Wasm)?; + Ok(translation.module) + } + /// Returns the name of this engine pub fn name(&self) -> &str { self.name.as_str() From 54f0f0cbe9aa4eea1afaf2bfd29b7053b2b51325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 19:45:14 +0100 Subject: [PATCH 36/38] Undo Store::new_with_tunables debugging code --- lib/cli/src/store.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index bf3e44123b4..1d2c55904cb 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -105,8 +105,7 @@ impl CompilerOptions { pub fn get_store_for_target(&self, target: Target) -> Result<(Store, CompilerType)> { let (compiler_config, compiler_type) = self.get_compiler_config()?; let engine = self.get_engine(target, compiler_config)?; - let tunables = BaseTunables::for_target(engine.target()); - let store = Store::new_with_tunables(&engine, tunables); + let store = Store::new(engine); Ok((store, compiler_type)) } @@ -314,8 +313,7 @@ impl StoreOptions { pub fn get_store_for_target(&self, target: Target) -> Result<(Store, CompilerType)> { let (compiler_config, compiler_type) = self.compiler.get_compiler_config()?; let engine = self.get_engine_with_compiler(target, compiler_config)?; - let tunables = BaseTunables::for_target(engine.target()); - let store = Store::new_with_tunables(&engine, tunables); + let store = Store::new(engine); Ok((store, compiler_type)) } From c1fec2f32e2c872c4d05e52e628804e8b6b094de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 19:54:23 +0100 Subject: [PATCH 37/38] Always import ModuleInfo --- lib/compiler/src/engine/inner.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compiler/src/engine/inner.rs b/lib/compiler/src/engine/inner.rs index d1c979d80af..240ef19c87d 100644 --- a/lib/compiler/src/engine/inner.rs +++ b/lib/compiler/src/engine/inner.rs @@ -22,9 +22,9 @@ use std::sync::{Arc, Mutex}; #[cfg(not(target_arch = "wasm32"))] use wasmer_types::{ entity::PrimaryMap, DeserializeError, FunctionBody, FunctionIndex, FunctionType, - LocalFunctionIndex, ModuleInfo, SignatureIndex, + LocalFunctionIndex, SignatureIndex, }; -use wasmer_types::{CompileError, Features, Target}; +use wasmer_types::{CompileError, Features, ModuleInfo, Target}; #[cfg(not(target_arch = "wasm32"))] use wasmer_types::{CustomSection, CustomSectionProtection, SectionIndex}; #[cfg(not(target_arch = "wasm32"))] From ff11cbd7059c0b138067cefb644713b584e1777c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 19 Jan 2023 19:59:03 +0100 Subject: [PATCH 38/38] Make CompilerOptions flags private again --- lib/cli/src/store.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index 1d2c55904cb..49b897c7bc3 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -30,15 +30,15 @@ pub struct StoreOptions { pub struct CompilerOptions { /// Use Singlepass compiler. #[clap(long, conflicts_with_all = &["cranelift", "llvm"])] - pub singlepass: bool, + singlepass: bool, /// Use Cranelift compiler. #[clap(long, conflicts_with_all = &["singlepass", "llvm"])] - pub cranelift: bool, + cranelift: bool, /// Use LLVM compiler. #[clap(long, conflicts_with_all = &["singlepass", "cranelift"])] - pub llvm: bool, + llvm: bool, /// Enable compiler internal verification. #[clap(long)]