Skip to content

Commit c6bd2aa

Browse files
authored
Merge pull request #146 from lann/upgrade-wasm-tools
Upgrade wasm-tools to 0.224
2 parents 55c0f40 + d2c8457 commit c6bd2aa

File tree

12 files changed

+185
-127
lines changed

12 files changed

+185
-127
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- uses: actions/checkout@v4
2020
- uses: dtolnay/rust-toolchain@stable
2121
with:
22-
targets: "wasm32-wasi"
22+
targets: "wasm32-wasip1"
2323
# We have to run these separately so we can deactivate a feature for one of the tests
2424
- name: Run client tests
2525
working-directory: ./crates/wasm-pkg-client

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: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ 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";
1615

1716
/// The structure for a wkg.toml configuration file. This file is entirely optional and is used for
1817
/// overriding and annotating wasm packages.
1918
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
19+
#[serde(deny_unknown_fields)]
2020
pub struct Config {
2121
/// Overrides for various packages
2222
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -60,6 +60,7 @@ impl Config {
6060
}
6161

6262
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
63+
#[serde(deny_unknown_fields)]
6364
pub struct Override {
6465
/// A path to the package on disk. If this is set, the package will be loaded from the given
6566
/// path. If this is not set, the package will be loaded from the registry.
@@ -72,59 +73,26 @@ pub struct Override {
7273
}
7374

7475
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
76+
#[serde(deny_unknown_fields)]
7577
pub struct Metadata {
76-
/// The authors of the package.
78+
/// The author(s) of the package.
7779
#[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>>,
80+
pub author: Option<String>,
8281
/// The package description.
8382
#[serde(default, skip_serializing_if = "Option::is_none")]
8483
pub description: Option<String>,
8584
/// The package license.
86-
#[serde(default, skip_serializing_if = "Option::is_none")]
87-
pub license: Option<String>,
88-
/// The package documentation URL.
89-
#[serde(default, skip_serializing_if = "Option::is_none")]
90-
pub documentation: Option<String>,
85+
#[serde(default, skip_serializing_if = "Option::is_none", alias = "license")]
86+
pub licenses: Option<String>,
87+
/// The package source code URL.
88+
#[serde(default, skip_serializing_if = "Option::is_none", alias = "repository")]
89+
pub source: Option<String>,
9190
/// The package homepage URL.
9291
#[serde(default, skip_serializing_if = "Option::is_none")]
9392
pub homepage: Option<String>,
94-
/// The package repository URL.
93+
/// The package source control revision.
9594
#[serde(default, skip_serializing_if = "Option::is_none")]
96-
pub repository: Option<String>,
97-
}
98-
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-
});
112-
}
113-
if let Some(homepage) = value.homepage {
114-
links.push(Link {
115-
ty: LinkType::Homepage,
116-
value: homepage,
117-
});
118-
}
119-
if let Some(repository) = value.repository {
120-
links.push(Link {
121-
ty: LinkType::Repository,
122-
value: repository,
123-
});
124-
}
125-
meta.set_links((!links.is_empty()).then_some(links));
126-
meta
127-
}
95+
pub revision: Option<String>,
12896
}
12997

13098
#[cfg(test)]
@@ -144,13 +112,12 @@ mod tests {
144112
},
145113
)])),
146114
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()),
115+
author: Some("Foo Bar".to_string()),
116+
description: Some("Foobar baz".to_string()),
117+
licenses: Some("FBB".to_string()),
118+
source: Some("https://gitfoo/bar".to_string()),
119+
homepage: Some("https://foo.bar".to_string()),
120+
revision: Some("f00ba4".to_string()),
154121
}),
155122
};
156123

0 commit comments

Comments
 (0)