Skip to content

Commit

Permalink
Merge pull request #4276 from wasmerio/fix-module-bindings-path
Browse files Browse the repository at this point in the history
fix: module path using stripping a prefix
  • Loading branch information
syrusakbary authored Oct 25, 2023
2 parents 9127dde + 0b74f66 commit 6d98d63
Showing 2 changed files with 96 additions and 8 deletions.
35 changes: 28 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 68 additions & 1 deletion lib/registry/src/package/builder.rs
Original file line number Diff line number Diff line change
@@ -239,7 +239,15 @@ fn construct_tar_gz(

if let Some(bindings) = &module.bindings {
for path in bindings.referenced_files(manifest_dir)? {
append_path_to_tar_gz(&mut builder, manifest_dir, &path).map_err(
let relative_path = path.strip_prefix(manifest_dir).with_context(|| {
format!(
"\"{}\" should be inside \"{}\"",
path.display(),
manifest_dir.display(),
)
})?;

append_path_to_tar_gz(&mut builder, manifest_dir, relative_path).map_err(
|(normalized_path, _)| PackageBuildError::MissingBindings {
module: module.name.clone(),
path: normalized_path,
@@ -773,4 +781,63 @@ runner = "https://webc.org/runner/wcgi"

pretty_assertions::assert_eq!(map, expected);
}

#[test]
fn test_construct_wai_package_tar_gz() {
let manifest_str = r#"[package]
name = "wasmer/crumsort-wasm"
version = "0.2.4"
description = "Crumsort from Google made for WASM"
[[module]]
name = "crumsort-wasm"
source = "crumsort_wasm.wasm"
[module.bindings]
wai-version = "0.2.0"
exports = "crum-sort.wai"
"#;

let archive_dir = tempfile::tempdir().unwrap();

let manifest_dir = tempfile::tempdir().unwrap();

let mp = manifest_dir.path();
let manifest_path = mp.join("wasmer.toml");

std::fs::write(&manifest_path, manifest_str).unwrap();
std::fs::write(mp.join("crumsort_wasm.wasm"), "()").unwrap();
std::fs::write(mp.join("crum-sort.wai"), "/// crum-sort.wai").unwrap();

let manifest = wasmer_toml::Manifest::parse(&manifest_str).unwrap();
let meta = construct_tar_gz(&archive_dir.path(), &manifest, &manifest_path).unwrap();

let mut data = std::io::Cursor::new(std::fs::read(&meta.archive_path).unwrap());

let gz = flate2::read::GzDecoder::new(&mut data);
let mut archive = tar::Archive::new(gz);

let map = archive
.entries()
.unwrap()
.map(|res| {
let mut entry = res.unwrap();
let name = entry.path().unwrap().to_str().unwrap().to_string();
let mut contents = String::new();
entry.read_to_string(&mut contents).unwrap();
eprintln!("{name}:\n{contents}\n\n");
(name, contents)
})
.collect::<std::collections::HashMap<String, String>>();

let expected: std::collections::HashMap<String, String> = [
("wapm.toml".to_string(), manifest_str.to_string()),
("crum-sort.wai".to_string(), "/// crum-sort.wai".to_string()),
("crumsort_wasm.wasm".to_string(), "()".to_string()),
]
.into_iter()
.collect();

pretty_assertions::assert_eq!(map, expected);
}
}

0 comments on commit 6d98d63

Please sign in to comment.