Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create exe tests #3487

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/c-api/src/wasm_c_api/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion lib/cache/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
14 changes: 1 addition & 13 deletions lib/compiler/src/artifact_builders/artifact_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use wasmer_types::entity::PrimaryMap;
use wasmer_types::CompileModuleInfo;
use wasmer_types::{
CompileError, CpuFeature, CustomSection, Dwarf, FunctionIndex, LocalFunctionIndex, MemoryIndex,
MemoryStyle, ModuleInfo, OwnedDataInitializer, Pages, Relocation, SectionIndex, SignatureIndex,
MemoryStyle, ModuleInfo, OwnedDataInitializer, Relocation, SectionIndex, SignatureIndex,
TableIndex, TableStyle, Target,
};
use wasmer_types::{
Expand Down Expand Up @@ -119,17 +119,10 @@ impl ArtifactBuild {
compile_info,
data_initializers,
cpu_features: cpu_features.as_u64(),
module_start: None,
};
Ok(Self { serializable })
}

/// Specify the fixed virtual memory address for the compiled module
pub fn with_module_start(mut self, module_start: Option<Pages>) -> Self {
self.serializable.module_start = module_start;
self
}

/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.
#[cfg(not(feature = "compiler"))]
#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -150,11 +143,6 @@ impl ArtifactBuild {
Self { serializable }
}

/// Returns the memory start address for this compiled module
pub fn get_memory_start(&self) -> Option<Pages> {
self.serializable.module_start
}

/// Get Functions Bodies ref
pub fn get_function_bodies_ref(&self) -> &PrimaryMap<LocalFunctionIndex, FunctionBody> {
&self.serializable.compilation.function_bodies
Expand Down
4 changes: 1 addition & 3 deletions lib/compiler/src/engine/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ impl Artifact {
engine.target(),
memory_styles,
table_styles,
)?
.with_module_start(tunables.module_start());
)?;

Self::from_parts(&mut inner_engine, artifact)
}
Expand Down Expand Up @@ -712,7 +711,6 @@ impl Artifact {
compile_info: metadata.compile_info,
data_initializers: metadata.data_initializers,
cpu_features: metadata.cpu_features,
module_start: None,
});

let finished_function_lengths = finished_functions
Expand Down
5 changes: 0 additions & 5 deletions lib/compiler/src/engine/tunables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ use wasmer_vm::{VMMemoryDefinition, VMTableDefinition};
/// An engine delegates the creation of memories, tables, and globals
/// to a foreign implementor of this trait.
pub trait Tunables {
/// Fixed virtual memory address for the compiled module
fn module_start(&self) -> Option<Pages> {
None
}

/// Construct a `MemoryStyle` for the provided `MemoryType`
fn memory_style(&self, memory: &MemoryType) -> MemoryStyle;

Expand Down
4 changes: 2 additions & 2 deletions lib/emscripten/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ pub fn ___build_environment(mut ctx: FunctionEnvMut<EmEnv>, 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;
Expand Down
2 changes: 1 addition & 1 deletion lib/emscripten/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ pub fn ___syscall140(ctx: FunctionEnvMut<EmEnv>, _which: i32, mut varargs: VarAr
let result_ptr_value: WasmPtr<i64> = varargs.get(&ctx);
let whence: i32 = varargs.get(&ctx);
let offset = offset_low;
let ret = unsafe { lseek(fd, offset as _, whence) as i64 };
let ret = unsafe { lseek(fd, offset as _, whence) };
let memory = ctx.data().memory(0);
let memory = memory.view(&ctx);

Expand Down
4 changes: 2 additions & 2 deletions lib/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ pub fn try_unpack_targz<P: AsRef<Path>>(
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()))
};

Expand Down Expand Up @@ -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())
})?;

Expand Down
3 changes: 0 additions & 3 deletions lib/types/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::entity::PrimaryMap;
use crate::Pages;
use crate::{
compilation::target::CpuFeature, CompileModuleInfo, CompiledFunctionFrameInfo, CustomSection,
DeserializeError, Dwarf, Features, FunctionBody, FunctionIndex, LocalFunctionIndex,
Expand Down Expand Up @@ -62,8 +61,6 @@ pub struct SerializableModule {
pub data_initializers: Box<[OwnedDataInitializer]>,
/// CPU Feature flags for this compilation
pub cpu_features: u64,
/// The start memory address of this serializable module
pub module_start: Option<Pages>,
}

fn to_serialize_error(err: impl std::error::Error) -> SerializeError {
Expand Down
3 changes: 2 additions & 1 deletion lib/vfs/src/webc_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ where
) -> Result<Box<dyn VirtualFile + Send + Sync>, FsError> {
match get_volume_name_opt(path) {
Some(volume) => {
let file = (*self.webc)
let file = self
.webc
.volumes
.get(&volume)
.ok_or(FsError::EntityNotFound)?
Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl From<u32> for WasiThreadId {
}
impl From<WasiThreadId> for u32 {
fn from(t: WasiThreadId) -> u32 {
t.0 as u32
t.0
}
}

Expand All @@ -117,7 +117,7 @@ impl From<u32> for WasiBusProcessId {
}
impl From<WasiBusProcessId> for u32 {
fn from(id: WasiBusProcessId) -> u32 {
id.0 as u32
id.0
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/wasi/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ mod test {
_ => assert!(false),
}
let output = create_wasi_state("test_prog")
.args(&["--help", "--wat\0"])
.args(["--help", "--wat\0"])
.build();
match output {
Err(WasiStateCreationError::ArgumentContainsNulByte(_)) => assert!(true),
Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/src/state/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/wasi/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ pub fn fd_pread<M: MemorySize>(
Kind::File { handle, .. } => {
if let Some(h) = handle {
wasi_try_ok!(
h.seek(std::io::SeekFrom::Start(offset as u64))
h.seek(std::io::SeekFrom::Start(offset))
.map_err(map_io_err),
env
);
Expand Down Expand Up @@ -1058,7 +1058,7 @@ pub fn fd_pwrite<M: MemorySize>(
if let Some(handle) = handle {
wasi_try_ok!(
handle
.seek(std::io::SeekFrom::Start(offset as u64))
.seek(std::io::SeekFrom::Start(offset))
.map_err(map_io_err),
env
);
Expand Down Expand Up @@ -2782,7 +2782,7 @@ pub fn path_rename<M: MemorySize>(
// 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);
Expand Down Expand Up @@ -3602,7 +3602,7 @@ pub fn thread_sleep(
debug!("wasi::thread_sleep");

let env = ctx.data();
let duration = Duration::from_nanos(duration as u64);
let duration = Duration::from_nanos(duration);
env.sleep(duration)?;
Ok(Errno::Success)
}
Expand Down Expand Up @@ -5463,7 +5463,7 @@ pub unsafe fn sock_send_file<M: MemorySize>(
{
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
Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/tests/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn test_stdout() {
// Create the `WasiEnv`.
let mut stdout = Pipe::default();
let wasi_env = WasiState::new("command-name")
.args(&["Gordon"])
.args(["Gordon"])
.stdout(Box::new(stdout.clone()))
.finalize(&mut store)
.unwrap();
Expand Down Expand Up @@ -113,7 +113,7 @@ fn test_env() {
let mut stdout = Pipe::new();
let mut wasi_state_builder = WasiState::new("command-name");
wasi_state_builder
.args(&["Gordon"])
.args(["Gordon"])
.env("DOG", "X")
.env("TEST", "VALUE")
.env("TEST2", "VALUE2");
Expand Down
8 changes: 2 additions & 6 deletions tests/integration/cli/tests/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,7 @@ fn create_exe_works_with_file() -> anyhow::Result<()> {

// Ignored because of -lunwind linker issue on Windows
// see https://github.com/wasmerio/wasmer/issues/3459
//#[cfg_attr(target_os = "windows", ignore)]
// TODO: fix the cretae_exe with serialized object issue #3481
#[ignore]
#[cfg_attr(target_os = "windows", ignore)]
#[test]
fn create_exe_serialized_works() -> anyhow::Result<()> {
let temp_dir = tempfile::tempdir()?;
Expand Down Expand Up @@ -685,9 +683,7 @@ fn create_exe_with_object_input_symbols() -> anyhow::Result<()> {

// Ignored because of -lunwind linker issue on Windows
// see https://github.com/wasmerio/wasmer/issues/3459
//#[cfg_attr(target_os = "windows", ignore)]
// TODO: fix the cretae_exe with serialized object issue #3481
#[ignore]
#[cfg_attr(target_os = "windows", ignore)]
#[test]
fn create_exe_with_object_input_serialized() -> anyhow::Result<()> {
create_exe_with_object_input(vec![
Expand Down
3 changes: 1 addition & 2 deletions tests/lib/test-generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ pub fn extract_name(path: impl AsRef<Path>) -> 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<T>(
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/wast/src/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/wasi-wast/src/wasitests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn compile_wasm_for_version(
) -> io::Result<PathBuf> {
//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);
Expand All @@ -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
};
Expand Down