mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 04:38:25 +00:00
cargo clippy --fix
This commit is contained in:
@@ -15,8 +15,6 @@ use std::convert::TryInto;
|
|||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
#[cfg(feature = "pirita_file")]
|
|
||||||
use wasmer_api::{AsStoreMut, Imports, Module};
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryFrom,
|
convert::TryFrom,
|
||||||
@@ -25,6 +23,8 @@ use std::{
|
|||||||
io::{self, SeekFrom},
|
io::{self, SeekFrom},
|
||||||
sync::MutexGuard,
|
sync::MutexGuard,
|
||||||
};
|
};
|
||||||
|
#[cfg(feature = "pirita_file")]
|
||||||
|
use wasmer_api::{AsStoreMut, Imports, Module};
|
||||||
use wasmer_wasi::{
|
use wasmer_wasi::{
|
||||||
get_wasi_version, FsError, VirtualFile, WasiBidirectionalPipePair, WasiFile, WasiFunctionEnv,
|
get_wasi_version, FsError, VirtualFile, WasiBidirectionalPipePair, WasiFile, WasiFunctionEnv,
|
||||||
WasiPipe, WasiState, WasiStateBuilder, WasiVersion,
|
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 wasi_pipe_t_ptr = unsafe { &mut *wasi_pipe_t_ptr };
|
||||||
let second_wasi_pipe_t_ptr = unsafe { &mut *second_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()) };
|
let result = unsafe { wasi_pipe_write_bytes(wasi_pipe_t_ptr, data.as_ptr(), data.len()) };
|
||||||
assert_eq!(result, 5);
|
assert_eq!(result, 5);
|
||||||
|
|
||||||
@@ -816,7 +816,6 @@ pub unsafe extern "C" fn wasi_config_overwrite_stderr(
|
|||||||
.stderr(Box::from_raw(stderr_overwrite));
|
.stderr(Box::from_raw(stderr_overwrite));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct wasi_filesystem_t {
|
pub struct wasi_filesystem_t {
|
||||||
ptr: *const c_char,
|
ptr: *const c_char,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use std::fs::File;
|
|||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::io::BufWriter;
|
use std::io::BufWriter;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{Command, Stdio};
|
use std::process::Command;
|
||||||
use wasmer::*;
|
use wasmer::*;
|
||||||
use wasmer_object::{emit_serialized, get_object_for_target};
|
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() {
|
let library = if let Some(v) = cross_subc.library_path.clone() {
|
||||||
v.clone().canonicalize().unwrap_or(v.clone())
|
v.canonicalize().unwrap_or(v)
|
||||||
} else {
|
} else {
|
||||||
{
|
{
|
||||||
let libwasmer_path = if target_triple
|
let libwasmer_path = if target_triple.unwrap_or(Triple::host()).operating_system
|
||||||
.clone()
|
|
||||||
.unwrap_or(Triple::host())
|
|
||||||
.operating_system
|
|
||||||
== wasmer_types::OperatingSystem::Windows
|
== wasmer_types::OperatingSystem::Windows
|
||||||
{
|
{
|
||||||
"lib/wasmer.lib"
|
"lib/wasmer.lib"
|
||||||
@@ -427,10 +424,7 @@ impl CreateExe {
|
|||||||
|
|
||||||
let _ = std::fs::create_dir_all(&target_file_path);
|
let _ = std::fs::create_dir_all(&target_file_path);
|
||||||
let files = untar(local_tarball.clone(), target_file_path.clone())?;
|
let files = untar(local_tarball.clone(), target_file_path.clone())?;
|
||||||
tarball_dir = target_file_path
|
tarball_dir = target_file_path.canonicalize().unwrap_or(target_file_path);
|
||||||
.clone()
|
|
||||||
.canonicalize()
|
|
||||||
.unwrap_or(target_file_path.clone());
|
|
||||||
files.into_iter().find(|f| f.contains(libwasmer_path)).ok_or_else(|| {
|
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)})?
|
anyhow!("Could not find libwasmer for {} target in the provided tarball path.", target)})?
|
||||||
} else {
|
} else {
|
||||||
@@ -449,10 +443,9 @@ impl CreateExe {
|
|||||||
.unwrap_or(target_file_path.clone());
|
.unwrap_or(target_file_path.clone());
|
||||||
|
|
||||||
tarball_dir = target_file_path
|
tarball_dir = target_file_path
|
||||||
.clone()
|
|
||||||
.canonicalize()
|
.canonicalize()
|
||||||
.unwrap_or(target_file_path.clone());
|
.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(|| {
|
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)})?
|
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();
|
libwasmer_path.pop();
|
||||||
|
|
||||||
if let Some(entrypoint) = pirita_main_atom.as_ref() {
|
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)?;
|
std::fs::write(&c_src_path, c_code)?;
|
||||||
} else {
|
} else {
|
||||||
std::fs::write(&c_src_path, WASMER_STATIC_MAIN_C_SOURCE)?;
|
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 c_code_to_instantiate = String::new();
|
||||||
let mut deallocate_module = 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() {
|
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!(
|
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};"));
|
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("#define WASI", "#define WASI\r\n#define WASI_PIRITA")
|
||||||
.replace("// INSTANTIATE_MODULES", &c_code_to_instantiate)
|
.replace("// INSTANTIATE_MODULES", &c_code_to_instantiate)
|
||||||
.replace("##atom-name##", &atom_to_run)
|
.replace("##atom-name##", &atom_to_run)
|
||||||
.replace("wasm_module_delete(module);", &deallocate_module);
|
.replace("wasm_module_delete(module);", &deallocate_module)
|
||||||
|
|
||||||
c_code
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "pirita_file")]
|
#[cfg(feature = "pirita_file")]
|
||||||
@@ -1070,7 +1061,7 @@ impl CreateExe {
|
|||||||
libwasmer_path.pop();
|
libwasmer_path.pop();
|
||||||
|
|
||||||
if let Some(entrypoint) = pirita_main_atom.as_ref() {
|
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)?;
|
std::fs::write(&c_src_path, c_code)?;
|
||||||
} else {
|
} else {
|
||||||
std::fs::write(&c_src_path, WASMER_STATIC_MAIN_C_SOURCE)?;
|
std::fs::write(&c_src_path, WASMER_STATIC_MAIN_C_SOURCE)?;
|
||||||
@@ -1146,7 +1137,10 @@ impl CreateExe {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_normalize_atom_name() {
|
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 {
|
fn triple_to_zig_triple(target_triple: &Triple) -> String {
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
//! Create a standalone native executable for a given Wasm file.
|
//! Create a standalone native executable for a given Wasm file.
|
||||||
|
|
||||||
use super::ObjectFormat;
|
use super::ObjectFormat;
|
||||||
use crate::{
|
use crate::{commands::PrefixerFn, store::CompilerOptions};
|
||||||
commands::{CrossCompile, PrefixerFn},
|
|
||||||
store::CompilerOptions,
|
|
||||||
};
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
#[cfg(feature = "pirita_file")]
|
#[cfg(feature = "pirita_file")]
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ pub fn compiler_test(attrs: TokenStream, input: TokenStream) -> TokenStream {
|
|||||||
#llvm_compiler_test
|
#llvm_compiler_test
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
x.into()
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user