Fix make lint / remove unnecessary code

This commit is contained in:
Felix Schütt
2022-12-19 11:13:20 +01:00
parent d2b118f36f
commit 1d4bc0446c
13 changed files with 84 additions and 99 deletions

View File

@@ -69,7 +69,7 @@ mod tests {
let sz = 18 * WASM_PAGE_SIZE; let sz = 18 * WASM_PAGE_SIZE;
let mut memory = Vec::new(); let mut memory = Vec::new();
memory.resize(sz, 0); memory.resize(sz, 0);
let mut ret = VMTinyMemory { let mut ret = Self {
mem: memory, mem: memory,
memory_definition: None, memory_definition: None,
}; };

View File

@@ -210,28 +210,25 @@ fn memory_grow() -> Result<(), String> {
fn function_new() -> Result<(), String> { fn function_new() -> Result<(), String> {
let mut store = Store::default(); let mut store = Store::default();
let function = Function::new_typed(&mut store, || {}); let function = Function::new_typed(&mut store, || {});
assert_eq!( assert_eq!(function.ty(&mut store), FunctionType::new(vec![], vec![]));
function.ty(&mut store).clone(),
FunctionType::new(vec![], vec![])
);
let function = Function::new_typed(&mut store, |_a: i32| {}); let function = Function::new_typed(&mut store, |_a: i32| {});
assert_eq!( assert_eq!(
function.ty(&mut store).clone(), function.ty(&mut store),
FunctionType::new(vec![Type::I32], vec![]) FunctionType::new(vec![Type::I32], vec![])
); );
let function = Function::new_typed(&mut store, |_a: i32, _b: i64, _c: f32, _d: f64| {}); let function = Function::new_typed(&mut store, |_a: i32, _b: i64, _c: f32, _d: f64| {});
assert_eq!( assert_eq!(
function.ty(&mut store).clone(), function.ty(&mut store),
FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]) FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![])
); );
let function = Function::new_typed(&mut store, || -> i32 { 1 }); let function = Function::new_typed(&mut store, || -> i32 { 1 });
assert_eq!( assert_eq!(
function.ty(&mut store).clone(), function.ty(&mut store),
FunctionType::new(vec![], vec![Type::I32]) FunctionType::new(vec![], vec![Type::I32])
); );
let function = Function::new_typed(&mut store, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }); let function = Function::new_typed(&mut store, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) });
assert_eq!( assert_eq!(
function.ty(&mut store).clone(), function.ty(&mut store),
FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]) FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64])
); );
Ok(()) Ok(())
@@ -246,14 +243,11 @@ fn function_new_env() -> Result<(), String> {
let my_env = MyEnv {}; let my_env = MyEnv {};
let env = FunctionEnv::new(&mut store, my_env); let env = FunctionEnv::new(&mut store, my_env);
let function = Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<MyEnv>| {}); let function = Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<MyEnv>| {});
assert_eq!( assert_eq!(function.ty(&mut store), FunctionType::new(vec![], vec![]));
function.ty(&mut store).clone(),
FunctionType::new(vec![], vec![])
);
let function = let function =
Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<MyEnv>, _a: i32| {}); Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<MyEnv>, _a: i32| {});
assert_eq!( assert_eq!(
function.ty(&mut store).clone(), function.ty(&mut store),
FunctionType::new(vec![Type::I32], vec![]) FunctionType::new(vec![Type::I32], vec![])
); );
let function = Function::new_typed_with_env( let function = Function::new_typed_with_env(
@@ -262,13 +256,13 @@ fn function_new_env() -> Result<(), String> {
|_env: FunctionEnvMut<MyEnv>, _a: i32, _b: i64, _c: f32, _d: f64| {}, |_env: FunctionEnvMut<MyEnv>, _a: i32, _b: i64, _c: f32, _d: f64| {},
); );
assert_eq!( assert_eq!(
function.ty(&mut store).clone(), function.ty(&mut store),
FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]) FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![])
); );
let function = let function =
Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<MyEnv>| -> i32 { 1 }); Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<MyEnv>| -> i32 { 1 });
assert_eq!( assert_eq!(
function.ty(&mut store).clone(), function.ty(&mut store),
FunctionType::new(vec![], vec![Type::I32]) FunctionType::new(vec![], vec![Type::I32])
); );
let function = Function::new_typed_with_env( let function = Function::new_typed_with_env(
@@ -277,7 +271,7 @@ fn function_new_env() -> Result<(), String> {
|_env: FunctionEnvMut<MyEnv>| -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }, |_env: FunctionEnvMut<MyEnv>| -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) },
); );
assert_eq!( assert_eq!(
function.ty(&mut store).clone(), function.ty(&mut store),
FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]) FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64])
); );
Ok(()) Ok(())
@@ -294,35 +288,35 @@ fn function_new_dynamic() -> Result<(), String> {
&function_type, &function_type,
|_values: &[Value]| unimplemented!(), |_values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty(&mut store).clone(), function_type); assert_eq!(function.ty(&mut store), function_type);
let function_type = FunctionType::new(vec![Type::I32], vec![]); let function_type = FunctionType::new(vec![Type::I32], vec![]);
let function = Function::new( let function = Function::new(
&mut store, &mut store,
&function_type, &function_type,
|_values: &[Value]| unimplemented!(), |_values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty(&mut store).clone(), function_type); assert_eq!(function.ty(&mut store), function_type);
let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]); let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]);
let function = Function::new( let function = Function::new(
&mut store, &mut store,
&function_type, &function_type,
|_values: &[Value]| unimplemented!(), |_values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty(&mut store).clone(), function_type); assert_eq!(function.ty(&mut store), function_type);
let function_type = FunctionType::new(vec![], vec![Type::I32]); let function_type = FunctionType::new(vec![], vec![Type::I32]);
let function = Function::new( let function = Function::new(
&mut store, &mut store,
&function_type, &function_type,
|_values: &[Value]| unimplemented!(), |_values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty(&mut store).clone(), function_type); assert_eq!(function.ty(&mut store), function_type);
let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]); let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]);
let function = Function::new( let function = Function::new(
&mut store, &mut store,
&function_type, &function_type,
|_values: &[Value]| unimplemented!(), |_values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty(&mut store).clone(), function_type); assert_eq!(function.ty(&mut store), function_type);
// Using array signature // Using array signature
let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]); let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]);
@@ -356,7 +350,7 @@ fn function_new_dynamic_env() -> Result<(), String> {
&function_type, &function_type,
|_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(), |_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty(&mut store).clone(), function_type); assert_eq!(function.ty(&mut store), function_type);
let function_type = FunctionType::new(vec![Type::I32], vec![]); let function_type = FunctionType::new(vec![Type::I32], vec![]);
let function = Function::new_with_env( let function = Function::new_with_env(
&mut store, &mut store,
@@ -364,7 +358,7 @@ fn function_new_dynamic_env() -> Result<(), String> {
&function_type, &function_type,
|_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(), |_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty(&mut store).clone(), function_type); assert_eq!(function.ty(&mut store), function_type);
let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]); let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]);
let function = Function::new_with_env( let function = Function::new_with_env(
&mut store, &mut store,
@@ -372,7 +366,7 @@ fn function_new_dynamic_env() -> Result<(), String> {
&function_type, &function_type,
|_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(), |_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty(&mut store).clone(), function_type); assert_eq!(function.ty(&mut store), function_type);
let function_type = FunctionType::new(vec![], vec![Type::I32]); let function_type = FunctionType::new(vec![], vec![Type::I32]);
let function = Function::new_with_env( let function = Function::new_with_env(
&mut store, &mut store,
@@ -380,7 +374,7 @@ fn function_new_dynamic_env() -> Result<(), String> {
&function_type, &function_type,
|_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(), |_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty(&mut store).clone(), function_type); assert_eq!(function.ty(&mut store), function_type);
let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]); let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]);
let function = Function::new_with_env( let function = Function::new_with_env(
&mut store, &mut store,
@@ -388,7 +382,7 @@ fn function_new_dynamic_env() -> Result<(), String> {
&function_type, &function_type,
|_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(), |_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(),
); );
assert_eq!(function.ty(&mut store).clone(), function_type); assert_eq!(function.ty(&mut store), function_type);
// Using array signature // Using array signature
let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]); let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]);

View File

@@ -367,7 +367,7 @@ pub mod reference_types {
let global: &Global = instance.exports.get_global("global")?; let global: &Global = instance.exports.get_global("global")?;
{ {
let er = ExternRef::new(&mut store, 3usize); let er = ExternRef::new(&mut store, 3usize);
global.set(&mut store, Value::ExternRef(Some(er.clone())))?; global.set(&mut store, Value::ExternRef(Some(er)))?;
} }
let get_from_global: TypedFunction<(), Option<ExternRef>> = instance let get_from_global: TypedFunction<(), Option<ExternRef>> = instance
.exports .exports
@@ -398,7 +398,7 @@ pub mod reference_types {
let er = ExternRef::new(&mut store, 3usize); let er = ExternRef::new(&mut store, 3usize);
let result = pass_extern_ref.call(&mut store, Some(er.clone())); let result = pass_extern_ref.call(&mut store, Some(er));
assert!(result.is_err()); assert!(result.is_err());
Ok(()) Ok(())
@@ -442,7 +442,7 @@ pub mod reference_types {
let result = grow_table_with_ref.call(&mut store, Some(er1.clone()), 10_000)?; let result = grow_table_with_ref.call(&mut store, Some(er1.clone()), 10_000)?;
assert_eq!(result, -1); assert_eq!(result, -1);
let result = grow_table_with_ref.call(&mut store, Some(er1.clone()), 8)?; let result = grow_table_with_ref.call(&mut store, Some(er1), 8)?;
assert_eq!(result, 2); assert_eq!(result, 2);
for i in 2..10 { for i in 2..10 {
@@ -454,7 +454,7 @@ pub mod reference_types {
} }
{ {
fill_table_with_ref.call(&mut store, Some(er2.clone()), 0, 2)?; fill_table_with_ref.call(&mut store, Some(er2), 0, 2)?;
} }
{ {
@@ -462,7 +462,7 @@ pub mod reference_types {
table2.set(&mut store, 1, Value::ExternRef(Some(er3.clone())))?; table2.set(&mut store, 1, Value::ExternRef(Some(er3.clone())))?;
table2.set(&mut store, 2, Value::ExternRef(Some(er3.clone())))?; table2.set(&mut store, 2, Value::ExternRef(Some(er3.clone())))?;
table2.set(&mut store, 3, Value::ExternRef(Some(er3.clone())))?; table2.set(&mut store, 3, Value::ExternRef(Some(er3.clone())))?;
table2.set(&mut store, 4, Value::ExternRef(Some(er3.clone())))?; table2.set(&mut store, 4, Value::ExternRef(Some(er3)))?;
} }
{ {

View File

@@ -185,17 +185,17 @@ fn test_run() {
let newpath = format!("{wasmer_dll_dir};{path}"); let newpath = format!("{wasmer_dll_dir};{path}");
let exe_dir = match std::path::Path::new(&manifest_dir).parent() { let exe_dir = match std::path::Path::new(&manifest_dir).parent() {
Some(parent) => format!("{}", parent.display()), Some(parent) => format!("{}", parent.display()),
None => format!("{manifest_dir}"), None => manifest_dir.to_string(),
}; };
for test in TESTS.iter() { for test in TESTS.iter() {
let mut manifest_dir_parent = std::path::Path::new(&manifest_dir); let manifest_dir_parent = std::path::Path::new(&manifest_dir);
let mut manifest_dir_parent = manifest_dir_parent.parent().unwrap(); let manifest_dir_parent = manifest_dir_parent.parent().unwrap();
let c_file_path = manifest_dir_parent.join(&format!("{test}.c")); let c_file_path = manifest_dir_parent.join(&format!("{test}.c"));
if target.contains("msvc") { if target.contains("msvc") {
let mut build = cc::Build::new(); let mut build = cc::Build::new();
let mut build = build let build = build
.cargo_metadata(false) .cargo_metadata(false)
.warnings(true) .warnings(true)
.static_crt(true) .static_crt(true)
@@ -217,12 +217,12 @@ fn test_run() {
fixup_symlinks( fixup_symlinks(
&[ &[
format!("{}/include", config.wasmer_dir), format!("{}/include", config.wasmer_dir),
format!("{}", config.root_dir), config.root_dir.to_string(),
], ],
&mut log, &mut log,
&config.root_dir, &config.root_dir,
) )
.expect(&format!("failed to fix symlinks: {log}")); .unwrap_or_else(|_| panic!("failed to fix symlinks: {log}"));
println!("{log}"); println!("{log}");
} }
@@ -244,11 +244,11 @@ fn test_run() {
let vcvars_bat_path = find_vcvarsall(&compiler).expect("no vcvarsall.bat"); let vcvars_bat_path = find_vcvarsall(&compiler).expect("no vcvarsall.bat");
let vcvars_bat_path_parent = std::path::Path::new(&vcvars_bat_path).parent().unwrap(); let vcvars_bat_path_parent = std::path::Path::new(&vcvars_bat_path).parent().unwrap();
let vcvars_modified_output = vcvars_bat_path_parent.join("compile-windows.bat"); let _vcvars_modified_output = vcvars_bat_path_parent.join("compile-windows.bat");
let vcvars_bat_file = std::fs::read_to_string(&vcvars_bat_path).unwrap(); let vcvars_bat_file = std::fs::read_to_string(&vcvars_bat_path).unwrap();
let batch_formatted = format!("{}\\", vcvars_bat_path_parent.display()); let batch_formatted = format!("{}\\", vcvars_bat_path_parent.display());
let vcvars_bat_file = vcvars_bat_file let vcvars_bat_file = vcvars_bat_file
.replace("%~dp0", &batch_formatted.replace("\\", "\\\\")) .replace("%~dp0", &batch_formatted.replace('\\', "\\\\"))
.replace("\"%1\"", "\"x64\""); .replace("\"%1\"", "\"x64\"");
let vcvars_modified = format!("{vcvars_bat_file}\r\n{command:?}"); let vcvars_modified = format!("{vcvars_bat_file}\r\n{command:?}");
let path = std::path::Path::new(&manifest_dir).join("compile-windows.bat"); let path = std::path::Path::new(&manifest_dir).join("compile-windows.bat");
@@ -292,7 +292,7 @@ fn test_run() {
println!("setting current dir = {exe_dir}"); println!("setting current dir = {exe_dir}");
let output = command let output = command
.output() .output()
.expect(&format!("failed to run {command:#?}")); .unwrap_or_else(|_| panic!("failed to run {command:#?}"));
if !output.status.success() { if !output.status.success() {
println!("{output:#?}"); println!("{output:#?}");
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
@@ -315,18 +315,18 @@ fn test_run() {
fixup_symlinks( fixup_symlinks(
&[ &[
format!("{}/include", config.wasmer_dir), format!("{}/include", config.wasmer_dir),
format!("{}", config.root_dir), config.root_dir.to_string(),
], ],
&mut log, &mut log,
&config.root_dir, &config.root_dir,
) )
.expect(&format!("failed to fix symlinks: {log}")); .unwrap_or_else(|_| panic!("failed to fix symlinks: {log}"));
} }
command.arg(&c_file_path); command.arg(&c_file_path);
if !config.wasmer_dir.is_empty() { if !config.wasmer_dir.is_empty() {
command.arg("-L"); command.arg("-L");
command.arg(&format!("{}/lib/", config.wasmer_dir)); command.arg(&format!("{}/lib/", config.wasmer_dir));
command.arg(&format!("-lwasmer")); command.arg(&"-lwasmer".to_string());
command.arg(&format!("-Wl,-rpath,{}/lib/", config.wasmer_dir)); command.arg(&format!("-Wl,-rpath,{}/lib/", config.wasmer_dir));
} }
command.arg("-o"); command.arg("-o");
@@ -365,7 +365,7 @@ fn test_run() {
println!("execute: {command:#?}"); println!("execute: {command:#?}");
let output = command let output = command
.output() .output()
.expect(&format!("failed to run {command:#?}")); .unwrap_or_else(|_| panic!("failed to run {command:#?}"));
if !output.status.success() { if !output.status.success() {
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr));
@@ -434,7 +434,7 @@ fn fixup_symlinks(
let entry = entry?; let entry = entry?;
let path = entry.path(); let path = entry.path();
let path_display = format!("{}", path.display()); let path_display = format!("{}", path.display());
if path_display.ends_with("h") { if path_display.ends_with('h') {
paths_headers.push(path_display); paths_headers.push(path_display);
} }
} }
@@ -488,7 +488,7 @@ fn find_vcvarsall(compiler: &cc::Tool) -> Option<String> {
let path = compiler.path(); let path = compiler.path();
let path = format!("{}", path.display()); let path = format!("{}", path.display());
let split = path.split("VC").nth(0)?; let split = path.split("VC").next()?;
Some(format!("{split}VC\\Auxiliary\\Build\\vcvarsall.bat")) Some(format!("{split}VC\\Auxiliary\\Build\\vcvarsall.bat"))
} }

View File

@@ -203,12 +203,12 @@ fn test_ok() {
let libwasmer_so_path = format!("{}/lib/libwasmer.so", config.wasmer_dir); let libwasmer_so_path = format!("{}/lib/libwasmer.so", config.wasmer_dir);
let exe_dir = format!("{manifest_dir}/../wasm-c-api/example"); let exe_dir = format!("{manifest_dir}/../wasm-c-api/example");
let path = std::env::var("PATH").unwrap_or_default(); let path = std::env::var("PATH").unwrap_or_default();
let newpath = format!("{};{path}", format!("{wasmer_dll_dir}").replace("/", "\\")); let newpath = format!("{};{path}", wasmer_dll_dir.to_string().replace('/', "\\"));
if target.contains("msvc") { if target.contains("msvc") {
for test in CAPI_BASE_TESTS.iter() { for test in CAPI_BASE_TESTS.iter() {
let mut build = cc::Build::new(); let mut build = cc::Build::new();
let mut build = build let build = build
.cargo_metadata(false) .cargo_metadata(false)
.warnings(true) .warnings(true)
.static_crt(true) .static_crt(true)
@@ -256,12 +256,12 @@ fn test_ok() {
&[ &[
format!("{}/include/", config.wasmer_dir), format!("{}/include/", config.wasmer_dir),
format!("{}/wasm-c-api/include/", config.root_dir), format!("{}/wasm-c-api/include/", config.root_dir),
format!("{}", config.root_dir), config.root_dir.to_string(),
], ],
&mut log, &mut log,
&config.root_dir, &config.root_dir,
) )
.expect(&format!("failed to fix symlinks: {log}")); .unwrap_or_else(|_| panic!("failed to fix symlinks: {log}"));
println!("{log}"); println!("{log}");
} }
command.arg("/link"); command.arg("/link");
@@ -276,7 +276,7 @@ fn test_ok() {
// compile // compile
let output = command let output = command
.output() .output()
.expect(&format!("failed to compile {command:#?}")); .unwrap_or_else(|_| panic!("failed to compile {command:#?}"));
if !output.status.success() { if !output.status.success() {
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
@@ -298,7 +298,7 @@ fn test_ok() {
println!("setting current dir = {exe_dir}"); println!("setting current dir = {exe_dir}");
let output = command let output = command
.output() .output()
.expect(&format!("failed to run {command:#?}")); .unwrap_or_else(|_| panic!("failed to run {command:#?}"));
if !output.status.success() { if !output.status.success() {
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
@@ -336,18 +336,18 @@ fn test_ok() {
&[ &[
format!("{}/include/", config.wasmer_dir), format!("{}/include/", config.wasmer_dir),
format!("{}/wasm-c-api/include/", config.root_dir), format!("{}/wasm-c-api/include/", config.root_dir),
format!("{}", config.root_dir), config.root_dir.to_string(),
], ],
&mut log, &mut log,
&config.root_dir, &config.root_dir,
) )
.expect(&format!("failed to fix symlinks: {log}")); .unwrap_or_else(|_| panic!("failed to fix symlinks: {log}"));
} }
command.arg(&format!("{manifest_dir}/../{test}.c")); command.arg(&format!("{manifest_dir}/../{test}.c"));
if !config.wasmer_dir.is_empty() { if !config.wasmer_dir.is_empty() {
command.arg("-L"); command.arg("-L");
command.arg(&format!("{}/lib/", config.wasmer_dir)); command.arg(&format!("{}/lib/", config.wasmer_dir));
command.arg(&format!("-lwasmer")); command.arg(&"-lwasmer".to_string());
command.arg(&format!("-Wl,-rpath,{}/lib/", config.wasmer_dir)); command.arg(&format!("-Wl,-rpath,{}/lib/", config.wasmer_dir));
} }
command.arg("-o"); command.arg("-o");
@@ -359,7 +359,7 @@ fn test_ok() {
// compile // compile
let output = command let output = command
.output() .output()
.expect(&format!("failed to compile {command:#?}")); .unwrap_or_else(|_| panic!("failed to compile {command:#?}"));
if !output.status.success() { if !output.status.success() {
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
@@ -374,7 +374,7 @@ fn test_ok() {
println!("execute: {command:#?}"); println!("execute: {command:#?}");
let output = command let output = command
.output() .output()
.expect(&format!("failed to run {command:#?}")); .unwrap_or_else(|_| panic!("failed to run {command:#?}"));
if !output.status.success() { if !output.status.success() {
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
@@ -450,7 +450,7 @@ fn fixup_symlinks(
let entry = entry?; let entry = entry?;
let path = entry.path(); let path = entry.path();
let path_display = format!("{}", path.display()); let path_display = format!("{}", path.display());
if path_display.ends_with("h") { if path_display.ends_with('h') {
paths_headers.push(path_display); paths_headers.push(path_display);
} }
} }
@@ -504,7 +504,7 @@ fn find_vcvars64(compiler: &cc::Tool) -> Option<String> {
let path = compiler.path(); let path = compiler.path();
let path = format!("{}", path.display()); let path = format!("{}", path.display());
let split = path.split("VC").nth(0)?; let split = path.split("VC").next()?;
Some(format!("{split}VC\\Auxiliary\\Build\\vcvars64.bat")) Some(format!("{split}VC\\Auxiliary\\Build\\vcvars64.bat"))
} }

View File

@@ -593,22 +593,12 @@ impl CreateExe {
); );
} }
let mut libwasmer_path = tempdir_path.join("libwasmer.a"); println!("Library Path: {}", library.display());
std::fs::copy(&library, &libwasmer_path)?;
println!("Library Path: {}", libwasmer_path.display());
/* Cross compilation is only possible with zig */ /* Cross compilation is only possible with zig */
println!("Using zig binary: {}", zig_binary_path.display()); println!("Using zig binary: {}", zig_binary_path.display());
let zig_triple = triple_to_zig_triple(target); let zig_triple = triple_to_zig_triple(target);
println!("Using zig target triple: {}", &zig_triple); println!("Using zig target triple: {}", &zig_triple);
let lib_filename = libwasmer_path
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string();
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)?;
@@ -625,6 +615,9 @@ impl CreateExe {
// copy all include files into one folder for easier debugging // copy all include files into one folder for easier debugging
for h in header_code_paths.iter_mut() { for h in header_code_paths.iter_mut() {
if h.display().to_string().is_empty() {
*h = std::env::current_dir()?;
}
if h.is_dir() { if h.is_dir() {
if debug_dir.is_some() { if debug_dir.is_some() {
println!("copying {} to {}", h.display(), temp_include_dir.display()); println!("copying {} to {}", h.display(), temp_include_dir.display());
@@ -638,13 +631,6 @@ impl CreateExe {
} }
std::fs::copy(&h, temp_include_dir.join(h.file_name().unwrap()))?; std::fs::copy(&h, temp_include_dir.join(h.file_name().unwrap()))?;
} }
if !h.is_dir() {
h.pop();
}
if h.display().to_string().is_empty() {
*h = std::env::current_dir()?;
}
} }
/* Compile main function */ /* Compile main function */
@@ -689,13 +675,19 @@ impl CreateExe {
cmd.arg(target_path); cmd.arg(target_path);
} }
cmd.arg(&c_src_path.canonicalize().unwrap()); if debug_dir.is_some() {
cmd.arg(libwasmer_path.canonicalize().unwrap().join(&lib_filename)); let target_c_file_path = tempdir_path.join("wasmer_main.c");
std::fs::copy(&c_src_path, &target_c_file_path)?;
cmd.arg(target_c_file_path);
let target_libwasmer_path = tempdir_path.join("libwasmer.a");
std::fs::copy(&setup.library, &target_libwasmer_path)?;
cmd.arg(target_libwasmer_path);
} else {
cmd.arg(&c_src_path.canonicalize().unwrap());
cmd.arg(&setup.library);
}
if zig_triple.contains("windows") { if zig_triple.contains("windows") {
let mut libwasmer_parent = libwasmer_path.clone();
libwasmer_parent.pop();
let mut winsdk_path = library.clone(); let mut winsdk_path = library.clone();
winsdk_path.pop(); winsdk_path.pop();
winsdk_path.pop(); winsdk_path.pop();
@@ -729,7 +721,7 @@ impl CreateExe {
); );
} }
std::fs::copy(volume_obj, &target_path)?; std::fs::copy(volume_obj, &target_path)?;
cmd.arg(target_path.clone()); cmd.arg(target_path);
} }
if debug_dir.is_some() { if debug_dir.is_some() {

View File

@@ -86,7 +86,7 @@ pub struct LocalPackage {
} }
impl LocalPackage { impl LocalPackage {
pub fn get_path(&self, #[cfg(test)] test_name: &str) -> Result<PathBuf, String> { pub fn get_path(&self, #[cfg(test)] _test_name: &str) -> Result<PathBuf, String> {
Ok(self.path.clone()) Ok(self.path.clone())
} }
pub fn get_commands(&self, #[cfg(test)] test_name: &str) -> Result<Vec<String>, String> { pub fn get_commands(&self, #[cfg(test)] test_name: &str) -> Result<Vec<String>, String> {

View File

@@ -167,7 +167,7 @@ fn test_stdin() {
// Let's call the `_start` function, which is our `main` function in Rust. // Let's call the `_start` function, which is our `main` function in Rust.
let start = instance.exports.get_function("_start").unwrap(); let start = instance.exports.get_function("_start").unwrap();
let result = start.call(&mut store, &[]); let result = start.call(&mut store, &[]);
assert!(!result.is_err()); assert!(result.is_ok());
// We assure stdin is now empty // We assure stdin is now empty
let mut buf = Vec::new(); let mut buf = Vec::new();

View File

@@ -419,6 +419,6 @@ fn large_number_local(mut config: crate::Config) -> Result<()> {
.get_function("large_local")? .get_function("large_local")?
.call(&mut store, &[]) .call(&mut store, &[])
.unwrap(); .unwrap();
assert_eq!(&Value::I64(1 as i64), result.get(0).unwrap()); assert_eq!(&Value::I64(1_i64), result.get(0).unwrap());
Ok(()) Ok(())
} }

View File

@@ -246,11 +246,11 @@ fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()>
let mut store = config.store(); let mut store = config.store();
fn f(a: i32, b: i64, c: f32, d: f64) -> (f64, f32, i64, i32) { fn f(a: i32, b: i64, c: f32, d: f64) -> (f64, f32, i64, i32) {
(d * 4.0, c * 3.0, b * 2, a * 1) (d * 4.0, c * 3.0, b * 2, a)
} }
fn f_ok(a: i32, b: i64, c: f32, d: f64) -> Result<(f64, f32, i64, i32), Infallible> { fn f_ok(a: i32, b: i64, c: f32, d: f64) -> Result<(f64, f32, i64, i32), Infallible> {
Ok((d * 4.0, c * 3.0, b * 2, a * 1)) Ok((d * 4.0, c * 3.0, b * 2, a))
} }
fn long_f( fn long_f(
@@ -313,7 +313,7 @@ fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> {
assert_eq!(*guard, 100); assert_eq!(*guard, 100);
*guard = 101; *guard = 101;
(d * 4.0, c * 3.0, b * 2, a * 1) (d * 4.0, c * 3.0, b * 2, a)
} }
fn f_ok( fn f_ok(
@@ -327,7 +327,7 @@ fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> {
assert_eq!(*guard, 100); assert_eq!(*guard, 100);
*guard = 101; *guard = 101;
Ok((d * 4.0, c * 3.0, b * 2, a * 1)) Ok((d * 4.0, c * 3.0, b * 2, a))
} }
#[derive(Clone)] #[derive(Clone)]
@@ -401,7 +401,7 @@ fn dynamic_host_function_without_env(config: crate::Config) -> anyhow::Result<()
Value::F64(values[3].unwrap_f64() * 4.0), Value::F64(values[3].unwrap_f64() * 4.0),
Value::F32(values[2].unwrap_f32() * 3.0), Value::F32(values[2].unwrap_f32() * 3.0),
Value::I64(values[1].unwrap_i64() * 2), Value::I64(values[1].unwrap_i64() * 2),
Value::I32(values[0].unwrap_i32() * 1), Value::I32(values[0].unwrap_i32()),
]) ])
}, },
); );
@@ -457,7 +457,7 @@ fn dynamic_host_function_with_env(config: crate::Config) -> anyhow::Result<()> {
Value::F64(values[3].unwrap_f64() * 4.0), Value::F64(values[3].unwrap_f64() * 4.0),
Value::F32(values[2].unwrap_f32() * 3.0), Value::F32(values[2].unwrap_f32() * 3.0),
Value::I64(values[1].unwrap_i64() * 2), Value::I64(values[1].unwrap_i64() * 2),
Value::I32(values[0].unwrap_i32() * 1), Value::I32(values[0].unwrap_i32()),
]) ])
}, },
); );

View File

@@ -322,7 +322,7 @@ fn create_obj(args: Vec<&'static str>, keyword_needle: &str, keyword: &str) -> a
let object_path = operating_dir.join("wasm.obj"); let object_path = operating_dir.join("wasm.obj");
let output: Vec<u8> = WasmerCreateObj { let output: Vec<u8> = WasmerCreateObj {
current_dir: operating_dir.clone(), current_dir: operating_dir,
wasm_path, wasm_path,
output_object_path: object_path.clone(), output_object_path: object_path.clone(),
compiler: Compiler::Cranelift, compiler: Compiler::Cranelift,
@@ -337,7 +337,7 @@ fn create_obj(args: Vec<&'static str>, keyword_needle: &str, keyword: &str) -> a
"create-obj successfully completed but object output file `{}` missing", "create-obj successfully completed but object output file `{}` missing",
object_path.display() object_path.display()
); );
let mut object_header_path = object_path.clone(); let mut object_header_path = object_path;
object_header_path.set_extension("h"); object_header_path.set_extension("h");
assert!( assert!(
object_header_path.exists(), object_header_path.exists(),

View File

@@ -1,7 +1,7 @@
use anyhow::bail; use anyhow::bail;
use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use wasmer_integration_tests_cli::{get_repo_root_path, get_wasmer_path, ASSET_PATH, C_ASSET_PATH}; use wasmer_integration_tests_cli::get_wasmer_path;
#[test] #[test]
fn login_works() -> anyhow::Result<()> { fn login_works() -> anyhow::Result<()> {

View File

@@ -40,9 +40,8 @@ mod tests {
*/ */
let command_success = command.status.success(); let command_success = command.status.success();
let test_success = !stderr.contains("** TEST FAILED **"); let test_success = !stderr.contains("** TEST FAILED **");
let success = command_success && test_success;
success command_success && test_success
} }
fn remove_existing_artificats() -> Output { fn remove_existing_artificats() -> Output {