cargo clippy --fix

This commit is contained in:
Felix Schütt
2022-10-26 18:11:13 +02:00
parent 1e2617ca18
commit e8977ed335
4 changed files with 22 additions and 32 deletions

View File

@@ -15,8 +15,6 @@ use std::convert::TryInto;
use std::ffi::CStr;
use std::os::raw::c_char;
use std::slice;
#[cfg(feature = "pirita_file")]
use wasmer_api::{AsStoreMut, Imports, Module};
use std::sync::{Arc, Mutex};
use std::{
convert::TryFrom,
@@ -25,6 +23,8 @@ use std::{
io::{self, SeekFrom},
sync::MutexGuard,
};
#[cfg(feature = "pirita_file")]
use wasmer_api::{AsStoreMut, Imports, Module};
use wasmer_wasi::{
get_wasi_version, FsError, VirtualFile, WasiBidirectionalPipePair, WasiFile, WasiFunctionEnv,
WasiPipe, WasiState, WasiStateBuilder, WasiVersion,
@@ -521,7 +521,7 @@ fn test_wasi_pipe_with_destructor() {
let wasi_pipe_t_ptr = unsafe { &mut *wasi_pipe_t_ptr };
let second_wasi_pipe_t_ptr = unsafe { &mut *second_wasi_pipe_t_ptr };
let data = b"hello".into_iter().map(|v| *v as i8).collect::<Vec<_>>();
let data = b"hello".iter().map(|v| *v as i8).collect::<Vec<_>>();
let result = unsafe { wasi_pipe_write_bytes(wasi_pipe_t_ptr, data.as_ptr(), data.len()) };
assert_eq!(result, 5);
@@ -816,7 +816,6 @@ pub unsafe extern "C" fn wasi_config_overwrite_stderr(
.stderr(Box::from_raw(stderr_overwrite));
}
#[repr(C)]
pub struct wasi_filesystem_t {
ptr: *const c_char,

View File

@@ -12,7 +12,7 @@ use std::fs::File;
use std::io::prelude::*;
use std::io::BufWriter;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::process::Command;
use wasmer::*;
use wasmer_object::{emit_serialized, get_object_for_target};
@@ -400,13 +400,10 @@ impl CreateExe {
}
}))?;
let library = if let Some(v) = cross_subc.library_path.clone() {
v.clone().canonicalize().unwrap_or(v.clone())
v.canonicalize().unwrap_or(v)
} else {
{
let libwasmer_path = if target_triple
.clone()
.unwrap_or(Triple::host())
.operating_system
let libwasmer_path = if target_triple.unwrap_or(Triple::host()).operating_system
== wasmer_types::OperatingSystem::Windows
{
"lib/wasmer.lib"
@@ -427,10 +424,7 @@ impl CreateExe {
let _ = std::fs::create_dir_all(&target_file_path);
let files = untar(local_tarball.clone(), target_file_path.clone())?;
tarball_dir = target_file_path
.clone()
.canonicalize()
.unwrap_or(target_file_path.clone());
tarball_dir = target_file_path.canonicalize().unwrap_or(target_file_path);
files.into_iter().find(|f| f.contains(libwasmer_path)).ok_or_else(|| {
anyhow!("Could not find libwasmer for {} target in the provided tarball path.", target)})?
} else {
@@ -449,10 +443,9 @@ impl CreateExe {
.unwrap_or(target_file_path.clone());
tarball_dir = target_file_path
.clone()
.canonicalize()
.unwrap_or(target_file_path.clone());
let files = untar(tarball.clone(), target_file_path.clone())?;
let files = untar(tarball, target_file_path)?;
files.into_iter().find(|f| f.contains(libwasmer_path)).ok_or_else(|| {
anyhow!("Could not find libwasmer for {} target in the fetched release from Github: you can download it manually and specify its path with the --cross-compilation-library-path LIBRARY_PATH flag.", target)})?
}
@@ -546,7 +539,7 @@ impl CreateExe {
libwasmer_path.pop();
if let Some(entrypoint) = pirita_main_atom.as_ref() {
let c_code = Self::generate_pirita_wasmer_main_c_static(&pirita_atoms, entrypoint);
let c_code = Self::generate_pirita_wasmer_main_c_static(pirita_atoms, entrypoint);
std::fs::write(&c_src_path, c_code)?;
} else {
std::fs::write(&c_src_path, WASMER_STATIC_MAIN_C_SOURCE)?;
@@ -926,10 +919,10 @@ impl CreateExe {
let mut c_code_to_instantiate = String::new();
let mut deallocate_module = String::new();
let atom_to_run = Self::normalize_atom_name(&atom_to_run);
let atom_to_run = Self::normalize_atom_name(atom_to_run);
for atom_name in atom_names.iter() {
let atom_name = Self::normalize_atom_name(&atom_name);
let atom_name = Self::normalize_atom_name(atom_name);
c_code_to_instantiate.push_str(&format!(
"
@@ -948,13 +941,11 @@ impl CreateExe {
c_code_to_instantiate.push_str(&format!("wasm_module_t *module = atom_{atom_to_run};"));
let c_code = WASMER_STATIC_MAIN_C_SOURCE
WASMER_STATIC_MAIN_C_SOURCE
.replace("#define WASI", "#define WASI\r\n#define WASI_PIRITA")
.replace("// INSTANTIATE_MODULES", &c_code_to_instantiate)
.replace("##atom-name##", &atom_to_run)
.replace("wasm_module_delete(module);", &deallocate_module);
c_code
.replace("wasm_module_delete(module);", &deallocate_module)
}
#[cfg(feature = "pirita_file")]
@@ -1070,7 +1061,7 @@ impl CreateExe {
libwasmer_path.pop();
if let Some(entrypoint) = pirita_main_atom.as_ref() {
let c_code = Self::generate_pirita_wasmer_main_c_static(&pirita_atoms, entrypoint);
let c_code = Self::generate_pirita_wasmer_main_c_static(pirita_atoms, entrypoint);
std::fs::write(&c_src_path, c_code)?;
} else {
std::fs::write(&c_src_path, WASMER_STATIC_MAIN_C_SOURCE)?;
@@ -1146,7 +1137,10 @@ impl CreateExe {
#[test]
fn test_normalize_atom_name() {
assert_eq!(CreateExe::normalize_atom_name("atom-name-with-dash"), "atom_name_with_dash".to_string());
assert_eq!(
CreateExe::normalize_atom_name("atom-name-with-dash"),
"atom_name_with_dash".to_string()
);
}
fn triple_to_zig_triple(target_triple: &Triple) -> String {

View File

@@ -2,10 +2,7 @@
//! Create a standalone native executable for a given Wasm file.
use super::ObjectFormat;
use crate::{
commands::{CrossCompile, PrefixerFn},
store::CompilerOptions,
};
use crate::{commands::PrefixerFn, store::CompilerOptions};
use anyhow::{Context, Result};
use clap::Parser;
#[cfg(feature = "pirita_file")]

View File

@@ -143,7 +143,7 @@ pub fn compiler_test(attrs: TokenStream, input: TokenStream) -> TokenStream {
#llvm_compiler_test
}
};
x.into()
x
}
#[cfg(test)]