Skip to content
Merged
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
30 changes: 30 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,36 @@ wasm-metadata = "0.254"
wit-component = "0.254"
wit-parser = "0.254"

[workspace.lints.rustdoc]
# Detects URLs that are not hyperlinks
bare_urls = "warn"
# Failures in resolving intra-doc link targets
broken_intra_doc_links = "warn"
# Codeblock attribute looks a lot like a known one
invalid_codeblock_attributes = "warn"
# Detects invalid HTML tags in doc comments
invalid_html_tags = "warn"
# Codeblock could not be parsed as valid Rust or is empty
invalid_rust_codeblocks = "warn"
# Detects crates with no crate-level documentation
missing_crate_level_docs = "warn"
# Linking from a public item to a private one
private_intra_doc_links = "warn"
# Detects redundant explicit links in doc comments
redundant_explicit_links = "warn"
# Detects unescaped backticks in doc comments
unescaped_backticks = "warn"

[workspace.lints.rust]
# `pub` items not reachable from crate root
unreachable_pub = "warn"
# Non-standard naming conventions (includes non-camel-case types, non-snake-case, non-upper-case globals)
bad_style = "warn"

[workspace.lints.clippy]
unnested_or_patterns = "warn"
unused_async = "warn"

# https://github.com/crate-ci/typos/blob/master/docs/reference.md
[workspace.metadata.typos.default]
extend-ignore-re = ["\\d\\w{4,}\\d"]
Expand Down
3 changes: 3 additions & 0 deletions crates/wasm-pkg-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ tempfile = { workspace = true }
rcgen = { workspace = true }
rstest = { workspace = true }
testcontainers = { workspace = true }

[lints]
workspace = true
2 changes: 1 addition & 1 deletion crates/wasm-pkg-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//! ```

pub mod caching;
mod decoded_component;
pub mod decoded_component;
mod loader;
pub mod local;
pub mod metadata;
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-pkg-client/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn registry_path_context(err: io::Error, path: &Path) -> Error {
}

impl LocalBackend {
pub fn new(registry_config: RegistryConfig) -> Result<Self, Error> {
pub(crate) fn new(registry_config: RegistryConfig) -> Result<Self, Error> {
let config = registry_config
.backend_config::<LocalConfig>(LOCAL_PROTOCOL)?
.ok_or_else(|| {
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-pkg-client/src/oci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) struct OciBackend {
}

impl OciBackend {
pub fn new(
pub(crate) fn new(
registry: &Registry,
registry_config: &RegistryConfig,
registry_meta: &RegistryMetadata,
Expand Down
3 changes: 3 additions & 0 deletions crates/wasm-pkg-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ tracing.workspace = true

[dev-dependencies]
tokio = { workspace = true, features = ["macros", "rt"] }

[lints]
workspace = true
3 changes: 3 additions & 0 deletions crates/wasm-pkg-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Types shared across the `wasm-pkg-*` crates,
//! references, content digests, registry metadata, and the common [`Error`] type.

use http::uri::InvalidUri;
use label::Label;

Expand Down
3 changes: 3 additions & 0 deletions crates/wasm-pkg-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ sha2 = { workspace = true }
rstest = { workspace = true }
glob = { workspace = true }
tokio = { workspace = true, features = ["rt", "macros", "process"] }

[lints]
workspace = true
8 changes: 4 additions & 4 deletions crates/wasm-pkg-core/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl Locker {
///
/// The returned file can be accessed to look at the path and also has
/// read/write access to the underlying file.
pub async fn try_open_rw(path: impl Into<PathBuf>) -> Result<Option<Self>> {
pub(crate) async fn try_open_rw(path: impl Into<PathBuf>) -> Result<Option<Self>> {
Self::open(
path.into(),
OpenOptions::new().read(true).write(true).create(true),
Expand All @@ -410,7 +410,7 @@ impl Locker {
///
/// The returned file can be accessed to look at the path and also has
/// read/write access to the underlying file.
pub async fn open_rw(path: impl Into<PathBuf>) -> Result<Self> {
pub(crate) async fn open_rw(path: impl Into<PathBuf>) -> Result<Self> {
Ok(Self::open(
path.into(),
OpenOptions::new().read(true).write(true).create(true),
Expand All @@ -433,7 +433,7 @@ impl Locker {
/// The returned file can be accessed to look at the path and also has read
/// access to the underlying file. Any writes to the file will return an
/// error.
pub async fn try_open_ro(path: impl Into<PathBuf>) -> Result<Option<Self>> {
pub(crate) async fn try_open_ro(path: impl Into<PathBuf>) -> Result<Option<Self>> {
Self::open(
path.into(),
OpenOptions::new().read(true),
Expand All @@ -454,7 +454,7 @@ impl Locker {
/// The returned file can be accessed to look at the path and also has read
/// access to the underlying file. Any writes to the file will return an
/// error.
pub async fn open_ro(path: impl Into<PathBuf>) -> Result<Self> {
pub(crate) async fn open_ro(path: impl Into<PathBuf>) -> Result<Self> {
Ok(Self::open(
path.into(),
OpenOptions::new().read(true),
Expand Down
15 changes: 7 additions & 8 deletions crates/wasm-pkg-core/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Manifest {
}

/// Loads a manifest file from the given path.
pub async fn load_from_path(path: impl AsRef<Path>) -> Result<Manifest> {
pub fn load_from_path(path: impl AsRef<Path>) -> Result<Manifest> {
let path = path.as_ref();
tracing::info!(path = %path.display(), "loading wkg manifest file");
let contents = std::fs::read_to_string(path)
Expand Down Expand Up @@ -114,28 +114,28 @@ impl Manifest {
if !tokio::fs::try_exists(&manifest_path).await? {
return Ok(Manifest::default());
}
Self::load_from_path(manifest_path).await
Self::load_from_path(manifest_path)
}

/// Tries to find the root workspace config
/// Returns `Ok(None)` when there is no `wkg.toml` ancestor that can be [`WorkspaceRootConfig`]
// TODO(maktychev): reconcile load_from_path and load_root_workspace
pub async fn load_root_workspace(cwd: &Path) -> Result<Option<WorkspaceRootConfig>> {
pub fn load_root_workspace(cwd: &Path) -> Result<Option<WorkspaceRootConfig>> {
let Some(manifest_file) = find_root_manifest_for_wd(cwd) else {
return Ok(None);
};
let manifest_dir = manifest_file
.parent()
.context("unexpectedly missing directory containing manifest")?;
let manifest = Self::load_from_path(&manifest_file).await?;
let manifest = Self::load_from_path(&manifest_file)?;

if let Some(root) = manifest.root() {
return Ok(Some(root.clone()));
}

// keep walking up if we have not found root
for file in find_root_iter(&manifest_file) {
let manifest = Self::load_from_path(&file).await?;
let manifest = Self::load_from_path(&file)?;
if let Some(WorkspaceConfig::Root(root)) = manifest.workspace
&& root.is_explicitly_listed_member(manifest_dir)
{
Expand Down Expand Up @@ -233,9 +233,8 @@ mod tests {
.write(&manifest_path)
.await
.expect("unable to write manifest");
let loaded_manifest = Manifest::load_from_path(manifest_path)
.await
.expect("unable to load manifest");
let loaded_manifest =
Manifest::load_from_path(manifest_path).expect("unable to load manifest");
assert_eq!(
manifest, loaded_manifest,
"manifest loaded from file does not match original manifest"
Expand Down
13 changes: 2 additions & 11 deletions crates/wasm-pkg-core/src/manifest/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,10 @@ members = ["pkg-a"]
fs::create_dir_all(root_dir.join("pkg-a/wit")).unwrap();

let expected = root_dir.canonicalize().unwrap();
let from_root = Manifest::load_root_workspace(root_dir)
.await
.unwrap()
.unwrap();
let from_root = Manifest::load_root_workspace(root_dir).unwrap().unwrap();
assert_eq!(from_root.root_dir.canonicalize().unwrap(), expected);

let from_member = Manifest::load_root_workspace(&root_dir.join("pkg-a/wit"))
.await
.unwrap()
.unwrap();
assert_eq!(from_member.root_dir.canonicalize().unwrap(), expected);
Expand All @@ -293,11 +289,6 @@ members = ["pkg-a"]
authors = "Webster Assembler"
"#,
);
assert!(
Manifest::load_root_workspace(root_dir)
.await
.unwrap()
.is_none()
);
assert!(Manifest::load_root_workspace(root_dir).unwrap().is_none());
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// NOTE: test "lib" code needs to be under ./tests/common/mod.rs otherwise there will
// be false clippy positives since ./tests/common.rs will be treated as a runnable test target
use std::path::{Path, PathBuf};

use tempfile::TempDir;
Expand All @@ -7,13 +9,13 @@ use wasm_pkg_client::{
};
use wasm_pkg_core::wit::WIT_DEPS_DIR;

pub fn fixture_dir() -> PathBuf {
pub(crate) fn fixture_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("fixtures")
}

pub async fn get_client() -> anyhow::Result<(TempDir, CachingClient<FileCache>)> {
pub(crate) async fn get_client() -> anyhow::Result<(TempDir, CachingClient<FileCache>)> {
// NOTE: `Client::with_global_defaults()` may pick up a user's redirect of `wasi` to a private registry
let client = Client::new(Config::default());
let cache_temp_dir = tempfile::tempdir()?;
Expand All @@ -23,7 +25,7 @@ pub async fn get_client() -> anyhow::Result<(TempDir, CachingClient<FileCache>)>
}

/// Loads the fixture with the given name into a temporary directory. This will copy the fixture from the tests/fixtures directory into a temporary directory and return the tempdir containing that directory (and its path)
pub async fn load_fixture(fixture: &str) -> anyhow::Result<(TempDir, PathBuf)> {
pub(crate) async fn load_fixture(fixture: &str) -> anyhow::Result<(TempDir, PathBuf)> {
let temp_dir = tempfile::tempdir()?;
let fixture_path = fixture_dir().join(fixture);
// This will error if it doesn't exist, which is what we want
Expand Down
3 changes: 3 additions & 0 deletions crates/wkg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ base64 = { workspace = true }
serde_json = { workspace = true }
tempfile = { workspace = true }
testcontainers = { workspace = true }

[lints]
workspace = true
30 changes: 16 additions & 14 deletions crates/wkg/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! The `wkg` CLI: fetches and publishes WIT and Wasm Components

use std::{
io::{Cursor, Seek},
path::PathBuf,
Expand Down Expand Up @@ -25,9 +27,9 @@ use wasm_pkg_core::{
};
use wit_component::DecodedWasm;

mod oci;
pub mod oci;
mod overlay;
mod wit;
pub mod wit;

use oci::OciCommands;
use wit::{BuildArgs, FetchArgs, UpdateArgs, WitCommands};
Expand Down Expand Up @@ -64,7 +66,7 @@ macro_rules! helpln {

#[derive(Parser, Debug)]
#[command(version)]
struct Cli {
pub struct Cli {
#[command(flatten)]
color: colorchoice_clap::Color,

Expand All @@ -73,14 +75,14 @@ struct Cli {
}

#[derive(Args, Debug)]
struct RegistryArgs {
pub struct RegistryArgs {
/// The registry domain to use. Overrides configuration file(s).
#[arg(long = "registry", value_name = "REGISTRY", env = "WKG_REGISTRY")]
registry: Option<Registry>,
}

#[derive(Args, Debug, Default)]
struct Common {
pub struct Common {
/// The path to the configuration file.
#[arg(long = "config", value_name = "CONFIG", env = "WKG_CONFIG_FILE")]
config: Option<PathBuf>,
Expand Down Expand Up @@ -128,7 +130,7 @@ impl Common {

#[derive(Subcommand, Debug)]
#[allow(clippy::large_enum_variant)]
enum Commands {
pub enum Commands {
/// Set registry configuration
Config(ConfigArgs),
/// Download a package from a registry
Expand All @@ -147,7 +149,7 @@ enum Commands {
}

#[derive(Args, Debug)]
struct ConfigArgs {
pub struct ConfigArgs {
/// The default registry domain to use. Overrides configuration file(s).
#[arg(long = "default-registry", value_name = "DEFAULT_REGISTRY")]
default_registry: Option<Registry>,
Expand Down Expand Up @@ -235,10 +237,10 @@ impl ConfigArgs {
}

#[derive(Args, Debug)]
struct GetArgs {
pub struct GetArgs {
/// Output path. If this ends with a '/', a filename based on the package
/// name, version, and format will be appended, e.g.
/// `name-space_name@1.0.0.wasm``.
/// `name-space_name@1.0.0.wasm`.
#[arg(long, short, default_value = "./")]
output: PathBuf,

Expand All @@ -259,7 +261,7 @@ struct GetArgs {
overwrite: bool,

/// The package to get, specified as `<namespace>:<name>` plus optional
/// `@<version>`, e.g. `wasi:cli" or `wasi:http@0.2.0`.
/// `@<version>`, e.g. `wasi:cli` or `wasi:http@0.2.0`.
package_spec: PackageSpec,

#[command(flatten)]
Expand All @@ -270,7 +272,7 @@ struct GetArgs {
}

#[derive(Args, Debug)]
struct PublishArgs {
pub struct PublishArgs {
/// The files and directories to publish.
/// If a directory is provided, the package is built to a tempfile before publishing.
paths: Vec<PathBuf>,
Expand Down Expand Up @@ -308,7 +310,7 @@ struct PublishArgs {
impl PublishArgs {
pub async fn run(mut self) -> anyhow::Result<()> {
let publish_opts = self.publish_opts()?;
let _root = self.workspace_root().await?;
let _root = self.workspace_root()?;
let path = match &self.paths[..] {
[] => {
anyhow::bail!(
Expand Down Expand Up @@ -446,7 +448,7 @@ impl PublishArgs {
Ok(())
}

async fn workspace_root(&mut self) -> anyhow::Result<Option<WorkspaceRootConfig>> {
fn workspace_root(&mut self) -> anyhow::Result<Option<WorkspaceRootConfig>> {
match self.workspace {
true if !self.paths.is_empty() => anyhow::bail!(
"`--workspace` selects every workspace member; do not also pass explicit \
Expand All @@ -457,7 +459,7 @@ impl PublishArgs {
false => return Ok(None),
}
let cwd = std::env::current_dir()?;
let Some(root) = Manifest::load_root_workspace(&cwd).await? else {
let Some(root) = Manifest::load_root_workspace(&cwd)? else {
bail!(
"`--workspace` called but unable to find workspace root from {}",
cwd.display(),
Expand Down
6 changes: 3 additions & 3 deletions crates/wkg/src/wit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub async fn temp_wit_file(package: &PackageRef, bytes: &[u8]) -> anyhow::Result
impl FetchArgs {
pub async fn run(self) -> anyhow::Result<()> {
let cwd = std::env::current_dir()?;
let mut root = Manifest::load_root_workspace(&cwd).await?;
let mut root = Manifest::load_root_workspace(&cwd)?;
let manifest_path = find_root_manifest_for_wd(&cwd);
if root.as_ref().is_some_and(|root| {
manifest_path
Expand All @@ -178,10 +178,10 @@ impl FetchArgs {
let manifest = match root.as_ref() {
Some(root) => {
let manifest_path = root.root_dir().join(MANIFEST_FILE_NAME);
Manifest::load_from_path(manifest_path).await?
Manifest::load_from_path(manifest_path)?
}
None => match manifest_path.as_ref() {
Some(path) => Manifest::load_from_path(path).await?,
Some(path) => Manifest::load_from_path(path)?,
None => Manifest::default(),
},
};
Expand Down
Loading