Fix wasmer init tests on Windows

This commit is contained in:
Felix Schütt
2023-01-03 21:57:26 +01:00
parent d166bf8722
commit 23791ba892
2 changed files with 29 additions and 21 deletions

View File

@@ -817,8 +817,8 @@ fn run_c_compile(
.arg(utils::get_wasmer_include_directory()?);
for i in include_dirs {
command.arg("-I");
command.arg(normalize_path(&i.display().to_string()));
command = command.arg("-I");
command = command.arg(normalize_path(&i.display().to_string()));
}
// On some compiler -target isn't implemented

View File

@@ -418,27 +418,35 @@ fn construct_manifest(
log::warn!("{msg}");
}
let module_source = cargo_toml
.as_ref()
.map(|p| {
// Normalize the path to /target/release to be relative to the parent of the Cargo.toml
let outpath = p
.build_dir
.join("release")
.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 = manifest_path
.parent()
.and_then(|p| p.canonicalize().ok())
.unwrap_or_else(|| manifest_path.to_path_buf());
let diff = pathdiff::diff_paths(&outpath_str, &manifest_canonicalized).unwrap();
// Format in UNIX fashion (forward slashes)
let diff_str = diff.display().to_string();
let relative_str = diff_str
.strip_prefix('/')
.unwrap_or(&diff_str)
.replace("\\", "/");
Path::new(&relative_str).to_path_buf()
})
.unwrap_or_else(|| Path::new(&format!("{package_name}.wasm")).to_path_buf());
let modules = vec![wasmer_toml::Module {
name: package_name.to_string(),
source: cargo_toml
.as_ref()
.map(|p| {
// Normalize the path to /target/release to be relative to the parent of the Cargo.toml
let outpath = p
.build_dir
.join("release")
.join(&format!("{package_name}.wasm"));
let canonicalized_outpath = outpath.canonicalize().unwrap_or(outpath);
let outpath_str = format!("{}", canonicalized_outpath.display());
let manifest_canonicalized = manifest_path
.parent()
.and_then(|p| p.canonicalize().ok())
.unwrap_or_else(|| manifest_path.to_path_buf());
let manifest_str = format!("{}/", manifest_canonicalized.display());
let relative_str = outpath_str.replacen(&manifest_str, "", 1);
Path::new(&relative_str).to_path_buf()
})
.unwrap_or_else(|| Path::new(&format!("{package_name}.wasm")).to_path_buf()),
source: module_source,
kind: None,
abi: default_abi,
bindings: bindings.as_ref().and_then(|b| b.first_binding()),