Skip to content

Commit 0aa9a5e

Browse files
committed
Upgrade wasm-tools to 0.224
- Integrate upstream metadata overhaul - WitPrinter interface change
1 parent c00c42b commit 0aa9a5e

File tree

8 files changed

+190
-110
lines changed

8 files changed

+190
-110
lines changed

Cargo.lock

Lines changed: 95 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ tracing-subscriber = { version = "0.3.18", default-features = false, features =
3939
wasm-pkg-common = { version = "0.9.0", path = "crates/wasm-pkg-common" }
4040
wasm-pkg-client = { version = "0.9.0", path = "crates/wasm-pkg-client" }
4141
wasm-pkg-core = { version = "0.9.0", path = "crates/wasm-pkg-core" }
42-
wasm-metadata = "0.219"
43-
wit-component = "0.219"
44-
wit-parser = "0.219"
42+
wasm-metadata = "0.224"
43+
wit-component = "0.224"
44+
wit-parser = "0.224"

crates/wasm-pkg-client/src/oci/publisher.rs

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::collections::BTreeMap;
22

33
use oci_client::{Reference, RegistryOperation};
44
use tokio::io::AsyncReadExt;
5-
use wasm_metadata::LinkType;
65

76
use crate::publisher::PackagePublisher;
87
use crate::{PackageRef, PublishingSource, Version};
@@ -22,44 +21,39 @@ impl PackagePublisher for OciBackend {
2221
// to remove this and use the stream directly.
2322
let mut buf = Vec::new();
2423
data.read_to_end(&mut buf).await?;
25-
let meta = wasm_metadata::RegistryMetadata::from_wasm(&buf).map_err(|e| {
26-
crate::Error::InvalidComponent(anyhow::anyhow!("Unable to parse component: {e}"))
24+
let payload = wasm_metadata::Payload::from_binary(&buf).map_err(|e| {
25+
crate::Error::InvalidComponent(anyhow::anyhow!("Unable to parse WASM: {e}"))
2726
})?;
27+
let meta = payload.metadata();
2828
let (config, layer) = oci_wasm::WasmConfig::from_raw_component(buf, None)
2929
.map_err(crate::Error::InvalidComponent)?;
3030
let mut annotations = BTreeMap::from_iter([(
3131
"org.opencontainers.image.version".to_string(),
3232
version.to_string(),
3333
)]);
34-
if let Some(meta) = meta {
35-
if let Some(desc) = meta.get_description() {
36-
annotations.insert(
37-
"org.opencontainers.image.description".to_string(),
38-
desc.to_owned(),
39-
);
40-
}
41-
if let Some(licenses) = meta.get_license() {
42-
annotations.insert(
43-
"org.opencontainers.image.licenses".to_string(),
44-
licenses.to_owned(),
45-
);
46-
}
47-
if let Some(sources) = meta.get_links() {
48-
for link in sources {
49-
if link.ty == LinkType::Repository {
50-
annotations.insert(
51-
"org.opencontainers.image.source".to_string(),
52-
link.value.to_owned(),
53-
);
54-
}
55-
if link.ty == LinkType::Homepage {
56-
annotations.insert(
57-
"org.opencontainers.image.url".to_string(),
58-
link.value.to_owned(),
59-
);
60-
}
61-
}
62-
}
34+
if let Some(desc) = &meta.description {
35+
annotations.insert(
36+
"org.opencontainers.image.description".to_string(),
37+
desc.to_string(),
38+
);
39+
}
40+
if let Some(licenses) = &meta.licenses {
41+
annotations.insert(
42+
"org.opencontainers.image.licenses".to_string(),
43+
licenses.to_string(),
44+
);
45+
}
46+
if let Some(source) = &meta.source {
47+
annotations.insert(
48+
"org.opencontainers.image.source".to_string(),
49+
source.to_string(),
50+
);
51+
}
52+
if let Some(homepage) = &meta.homepage {
53+
annotations.insert(
54+
"org.opencontainers.image.url".to_string(),
55+
homepage.to_string(),
56+
);
6357
}
6458

6559
let reference: Reference = self.make_reference(package, Some(version));

crates/wasm-pkg-core/src/config.rs

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use anyhow::{Context, Result};
99
use semver::VersionReq;
1010
use serde::{Deserialize, Serialize};
1111
use tokio::io::AsyncWriteExt;
12-
use wasm_metadata::{Link, LinkType, RegistryMetadata};
1312

1413
/// The default name of the configuration file.
1514
pub const CONFIG_FILE_NAME: &str = "wkg.toml";
@@ -75,55 +74,45 @@ pub struct Override {
7574
pub struct Metadata {
7675
/// The authors of the package.
7776
#[serde(default, skip_serializing_if = "Option::is_none")]
78-
pub authors: Option<Vec<String>>,
79-
/// The categories of the package.
80-
#[serde(default, skip_serializing_if = "Option::is_none")]
81-
pub categories: Option<Vec<String>>,
77+
pub author: Option<String>,
8278
/// The package description.
8379
#[serde(default, skip_serializing_if = "Option::is_none")]
8480
pub description: Option<String>,
8581
/// The package license.
8682
#[serde(default, skip_serializing_if = "Option::is_none")]
87-
pub license: Option<String>,
88-
/// The package documentation URL.
83+
pub licenses: Option<String>,
84+
/// The package source code URL.
8985
#[serde(default, skip_serializing_if = "Option::is_none")]
90-
pub documentation: Option<String>,
86+
pub source: Option<String>,
9187
/// The package homepage URL.
9288
#[serde(default, skip_serializing_if = "Option::is_none")]
9389
pub homepage: Option<String>,
94-
/// The package repository URL.
90+
/// The package source control revision.
9591
#[serde(default, skip_serializing_if = "Option::is_none")]
96-
pub repository: Option<String>,
92+
pub revision: Option<String>,
9793
}
9894

99-
impl From<Metadata> for wasm_metadata::RegistryMetadata {
100-
fn from(value: Metadata) -> Self {
101-
let mut meta = RegistryMetadata::default();
102-
meta.set_authors(value.authors);
103-
meta.set_categories(value.categories);
104-
meta.set_description(value.description);
105-
meta.set_license(value.license);
106-
let mut links = Vec::new();
107-
if let Some(documentation) = value.documentation {
108-
links.push(Link {
109-
ty: LinkType::Documentation,
110-
value: documentation,
111-
});
95+
impl Metadata {
96+
pub fn update_wasm_metadata(self, wasm_metadata: &mut wasm_metadata::Metadata) -> Result<()> {
97+
if let Some(author) = self.author {
98+
wasm_metadata.author = Some(author.parse()?);
99+
}
100+
if let Some(description) = self.description {
101+
wasm_metadata.description = Some(description.parse()?);
102+
}
103+
if let Some(licenses) = self.licenses {
104+
wasm_metadata.licenses = Some(licenses.parse()?);
105+
}
106+
if let Some(source) = self.source {
107+
wasm_metadata.source = Some(source.parse()?);
112108
}
113-
if let Some(homepage) = value.homepage {
114-
links.push(Link {
115-
ty: LinkType::Homepage,
116-
value: homepage,
117-
});
109+
if let Some(homepage) = self.homepage {
110+
wasm_metadata.homepage = Some(homepage.parse()?);
118111
}
119-
if let Some(repository) = value.repository {
120-
links.push(Link {
121-
ty: LinkType::Repository,
122-
value: repository,
123-
});
112+
if let Some(revision) = self.revision {
113+
wasm_metadata.revision = Some(revision.parse()?);
124114
}
125-
meta.set_links((!links.is_empty()).then_some(links));
126-
meta
115+
Ok(())
127116
}
128117
}
129118

@@ -144,13 +133,12 @@ mod tests {
144133
},
145134
)])),
146135
metadata: Some(Metadata {
147-
authors: Some(vec!["foo".to_string(), "bar".to_string()]),
148-
categories: Some(vec!["foo".to_string(), "bar".to_string()]),
149-
description: Some("foo".to_string()),
150-
license: Some("foo".to_string()),
151-
documentation: Some("foo".to_string()),
152-
homepage: Some("foo".to_string()),
153-
repository: Some("foo".to_string()),
136+
author: Some("Foo Bar".to_string()),
137+
description: Some("Foobar baz".to_string()),
138+
licenses: Some("FBB".to_string()),
139+
source: Some("https://gitfoo/bar".to_string()),
140+
homepage: Some("https://foo.bar".to_string()),
141+
revision: Some("f00ba4".to_string()),
154142
}),
155143
};
156144

0 commit comments

Comments
 (0)