Skip to content

Commit a63834a

Browse files
authored
Handle multiple versions during wasm-tools component wit (#1665)
* Handle multiple versions during `wasm-tools component wit` This commits makes sure that if a component depends on multiple versions of a package that it is handled correctly. It fixes the behavior by appending the version string in case there are multiple packages with the same name and namespaces specifically when there is only one namespace for the given package name. Signed-off-by: karthik2804 <[email protected]> * add tests Signed-off-by: karthik2804 <[email protected]> --------- Signed-off-by: karthik2804 <[email protected]>
1 parent 021389c commit a63834a

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

src/bin/wasm-tools/component.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,11 +648,18 @@ impl WitOpts {
648648
dir.join("deps")
649649
};
650650
let packages_with_same_name = &names[&pkg.name.name];
651+
let packages_with_same_namespace = packages_with_same_name[&pkg.name.namespace];
651652
let stem = if packages_with_same_name.len() == 1 {
652-
pkg.name.name.clone()
653+
if packages_with_same_namespace == 1 {
654+
pkg.name.name.clone()
655+
} else {
656+
pkg.name
657+
.version
658+
.as_ref()
659+
.map(|ver| format!("{}@{}", pkg.name.name, ver))
660+
.unwrap_or_else(|| pkg.name.name.clone())
661+
}
653662
} else {
654-
let packages_with_same_namespace =
655-
packages_with_same_name[&pkg.name.namespace];
656663
if packages_with_same_namespace == 1 {
657664
format!("{}:{}", pkg.name.namespace, pkg.name.name)
658665
} else {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: component wit % --out-dir %tmpdir | component wit %tmpdir
2+
3+
package a:b@0.2.0 {
4+
interface foo {}
5+
}
6+
7+
package a:b {
8+
interface foo {}
9+
}
10+
11+
package a:c {
12+
world a {
13+
import a:b/foo@0.2.0;
14+
import a:b/foo;
15+
}
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package a:b {
2+
interface foo {
3+
}
4+
5+
}
6+
7+
8+
package a:[email protected] {
9+
interface foo {
10+
}
11+
12+
}
13+
14+
15+
package a:c {
16+
world a {
17+
import a:b/[email protected];
18+
import a:b/foo;
19+
}
20+
}

0 commit comments

Comments
 (0)