Skip to content

Remove wasm-pkg-common as dependency #3166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pretty_assertions = "1.3"
regex = { workspace = true }
reqwest = { workspace = true }
rpassword = "7"
schemars = { version = "0.8.21", features = ["indexmap2", "semver"] }
schemars = { workspace = true }
semver = { workspace = true }
serde = { version = "1", features = ["derive"] }
serde_json = { workspace = true }
Expand Down Expand Up @@ -151,6 +151,7 @@ rusqlite = "0.34"
# If both `aws_lc_rs` and `ring` are enabled, a panic at runtime will occur.
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "logging", "tls12"] }
rustls-pki-types = "1.12"
schemars = { version = "0.8.22", features = ["indexmap2", "semver"] }
semver = "1"
serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1.0"
Expand All @@ -170,7 +171,6 @@ walkdir = "2"
wasm-encoder = "0.230"
wasm-metadata = "0.230"
wasm-pkg-client = "0.10"
wasm-pkg-common = "0.10"
wasmparser = "0.230"
wasmtime = "33.0.0"
wasmtime-wasi = "33.0.0"
Expand Down
3 changes: 1 addition & 2 deletions crates/manifest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ edition = { workspace = true }
[dependencies]
anyhow = { workspace = true }
indexmap = { workspace = true, features = ["serde"] }
schemars = { version = "0.8.21", features = ["indexmap2", "semver"] }
schemars = { workspace = true }
semver = { workspace = true, features = ["serde"] }
serde = { workspace = true }
spin-serde = { path = "../serde" }
terminal = { path = "../terminal" }
thiserror = { workspace = true }
toml = { workspace = true, features = ["preserve_order"] }
url = { workspace = true }
wasm-pkg-common = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
Expand Down
3 changes: 1 addition & 2 deletions crates/manifest/src/schema/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::fmt::Display;

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use wasm_pkg_common::{package::PackageRef, registry::Registry};
use spin_serde::{PackageRef, Registry};

/// Variable definition
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
Expand Down
8 changes: 6 additions & 2 deletions crates/serde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ edition = { workspace = true }
[dependencies]
anyhow = { workspace = true }
base64 = { workspace = true }
schemars = { version = "0.8.21", features = ["indexmap2", "semver"] }
http = { workspace = true }
schemars = { workspace = true }
semver = { workspace = true, features = ["serde"] }
serde = { workspace = true }
wasm-pkg-common = { workspace = true }

# Without this dependency, this crate will not compile on its own.
# We should figure out why.
futures-util = "0.3.30"
119 changes: 116 additions & 3 deletions crates/serde/src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::KebabId;
use anyhow::anyhow;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
use wasm_pkg_common::package::PackageRef;

/// Name of an import package dependency.
///
Expand Down Expand Up @@ -77,6 +76,120 @@ impl FromStr for DependencyPackageName {
}
}

/// A package reference, consisting of kebab-case namespace and name.
///
/// Ex: `wasm-pkg:client`
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Hash)]
#[serde(into = "String", try_from = "String")]
pub struct PackageRef {
/// The package namespace
pub namespace: String,
/// The package name
pub name: String,
}

impl PackageRef {
/// Returns the package namespace.
pub fn namespace(&self) -> &str {
&self.namespace
}

/// Returns the package name.
pub fn name(&self) -> &str {
&self.name
}
}

impl std::fmt::Display for PackageRef {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:{}", self.namespace, self.name)
}
}

impl From<PackageRef> for String {
fn from(value: PackageRef) -> Self {
value.to_string()
}
}

impl TryFrom<String> for PackageRef {
type Error = anyhow::Error;

fn try_from(mut value: String) -> Result<Self, Self::Error> {
let Some(colon) = value.find(':') else {
anyhow::bail!("missing expected ':'");
};
let name = value.split_off(colon + 1);
value.truncate(colon);
Ok(Self {
// TODO(rylev): parse both fields as labels
namespace: value,
name: name,
})
}
}

impl FromStr for PackageRef {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
s.to_string().try_into()
}
}

/// A registry identifier.
///
/// This must be a valid HTTP Host.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(into = "String", try_from = "String")]
pub struct Registry(http::uri::Authority);

impl Registry {
/// Returns the registry host, without port number.
pub fn host(&self) -> &str {
self.0.host()
}

/// Returns the registry port number, if given.
pub fn port(&self) -> Option<u16> {
self.0.port_u16()
}
}

impl AsRef<str> for Registry {
fn as_ref(&self) -> &str {
self.0.as_str()
}
}

impl std::fmt::Display for Registry {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}

impl From<Registry> for String {
fn from(value: Registry) -> Self {
value.to_string()
}
}

impl std::str::FromStr for Registry {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.parse()?))
}
}

impl TryFrom<String> for Registry {
type Error = anyhow::Error;

fn try_from(value: String) -> Result<Self, Self::Error> {
Ok(Self(value.try_into()?))
}
}

/// Name of an import dependency.
///
/// For example: `foo:bar/baz@0.1.0`, `foo:bar/baz`, `foo:bar@0.1.0`, `foo:bar`, `foo-bar`.
Expand All @@ -103,8 +216,8 @@ impl Ord for DependencyName {
(DependencyName::Plain(a), DependencyName::Plain(b)) => a.cmp(b),
(DependencyName::Package(a), DependencyName::Package(b)) => {
let big_ole_tup = (
a.package.namespace().as_ref(),
a.package.name().as_ref(),
a.package.namespace(),
a.package.name(),
a.interface.as_ref(),
a.version.as_ref(),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod version;

pub use version::{FixedStringVersion, FixedVersion, FixedVersionBackwardCompatible};

pub use dependencies::{DependencyName, DependencyPackageName};
pub use dependencies::{DependencyName, DependencyPackageName, PackageRef, Registry};

/// A "kebab-case" identifier.
pub type KebabId = id::Id<'-', false>;
Expand Down
Loading