|
5 | 5 | use std::str::FromStr;
|
6 | 6 | use std::{borrow::Cow, fmt::Display};
|
7 | 7 |
|
8 |
| -use anyhow::{bail, Context, Result}; |
| 8 | +use anyhow::{bail, Result}; |
9 | 9 | use wasm_encoder::{CanonicalOption, Encode, Section};
|
10 |
| -use wit_parser::{parse_use_path, PackageId, ParsedUsePath, Resolve, WorldId}; |
| 10 | +use wit_parser::{Resolve, WorldId}; |
11 | 11 |
|
12 | 12 | mod encoding;
|
13 | 13 | mod gc;
|
@@ -79,43 +79,6 @@ impl From<StringEncoding> for wasm_encoder::CanonicalOption {
|
79 | 79 | }
|
80 | 80 | }
|
81 | 81 |
|
82 |
| -/// Handles world name resolution for cases when multiple packages may have been resolved. If this |
83 |
| -/// is the case, and we're dealing with input that contains a user-supplied world name (like via a |
84 |
| -/// CLI command, for instance), we want to ensure that the world name follows the following rules: |
85 |
| -/// |
86 |
| -/// * If there is a single resolved package with a single world, the world name name MAY be |
87 |
| -/// omitted. |
88 |
| -/// * If there is a single resolved package with multiple worlds, the world name MUST be supplied, |
89 |
| -/// but MAY or MAY NOT be fully-qualified. |
90 |
| -/// * If there are multiple resolved packages, the world name MUST be fully-qualified. |
91 |
| -pub fn resolve_world_from_name( |
92 |
| - resolve: &Resolve, |
93 |
| - resolved_packages: Vec<PackageId>, |
94 |
| - world_name: Option<&str>, |
95 |
| -) -> Result<WorldId> { |
96 |
| - match resolved_packages.len() { |
97 |
| - 0 => bail!("all of the supplied WIT source files were empty"), |
98 |
| - 1 => resolve.select_world(resolved_packages[0], world_name.as_deref()), |
99 |
| - _ => match world_name.as_deref() { |
100 |
| - Some(name) => { |
101 |
| - let world_path = parse_use_path(name).with_context(|| { |
102 |
| - format!("failed to parse world specifier `{name}`") |
103 |
| - })?; |
104 |
| - match world_path { |
105 |
| - ParsedUsePath::Name(name) => bail!("the world specifier must be of the fully-qualified, id-based form (ex: \"wasi:http/proxy\" rather than \"proxy\"); you used {name}"), |
106 |
| - ParsedUsePath::Package(pkg_name, _) => { |
107 |
| - match resolve.package_names.get(&pkg_name) { |
108 |
| - Some(pkg_id) => resolve.select_world(pkg_id.clone(), world_name.as_deref()), |
109 |
| - None => bail!("the world specifier you provided named {pkg_name}, but no package with that name was found"), |
110 |
| - } |
111 |
| - } |
112 |
| - } |
113 |
| - } |
114 |
| - None => bail!("the supplied WIT source files describe multiple packages; please provide a fully-qualified world-specifier to the `embed` command"), |
115 |
| - }, |
116 |
| - } |
117 |
| -} |
118 |
| - |
119 | 82 | /// A producer section to be added to all modules and components synthesized by
|
120 | 83 | /// this crate
|
121 | 84 | pub(crate) fn base_producers() -> wasm_metadata::Producers {
|
@@ -145,11 +108,9 @@ pub fn embed_component_metadata(
|
145 | 108 |
|
146 | 109 | #[cfg(test)]
|
147 | 110 | mod tests {
|
148 |
| - use std::path::Path; |
149 |
| - |
150 | 111 | use anyhow::Result;
|
151 | 112 | use wasmparser::Payload;
|
152 |
| - use wit_parser::{Resolve, UnresolvedPackageGroup}; |
| 113 | + use wit_parser::Resolve; |
153 | 114 |
|
154 | 115 | use super::{embed_component_metadata, StringEncoding};
|
155 | 116 |
|
@@ -184,12 +145,8 @@ world test-world {}
|
184 | 145 |
|
185 | 146 | // Parse pre-canned WIT to build resolver
|
186 | 147 | let mut resolver = Resolve::default();
|
187 |
| - let UnresolvedPackageGroup { |
188 |
| - mut packages, |
189 |
| - source_map, |
190 |
| - } = UnresolvedPackageGroup::parse(&Path::new("in-code.wit"), COMPONENT_WIT)?; |
191 |
| - let pkg_id = resolver.push(packages.remove(0), &source_map)?; |
192 |
| - let world = resolver.select_world(pkg_id, Some("test-world").into())?; |
| 148 | + let pkgs = resolver.push_str("in-code.wit", COMPONENT_WIT)?; |
| 149 | + let world = resolver.select_world(&pkgs, Some("test-world"))?; |
193 | 150 |
|
194 | 151 | // Embed component metadata
|
195 | 152 | embed_component_metadata(&mut bytes, &resolver, world, StringEncoding::UTF8)?;
|
|
0 commit comments