Skip to content

Commit c052072

Browse files
feat(wash): Adds support for wasmcloud named things for packages
This also integrates the wkg.toml stuff directly into wasmcloud.toml Signed-off-by: Taylor Thomas <taylor@cosmonic.com>
1 parent e3bb292 commit c052072

File tree

60 files changed

+929
-248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+929
-248
lines changed

Cargo.lock

+23-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ serde_cbor = { version = "0.11", default-features = false }
290290
serde_json = { version = "1", default-features = false }
291291
serde_with = { version = "3", default-features = false }
292292
serde_yaml = { version = "0.9", default-features = false }
293-
serial_test = { version = "0.9", default-features = false }
293+
serial_test = { version = "3", default-features = false }
294294
sha2 = { version = "0.10", default-features = false }
295295
sysinfo = { version = "0.27", default-features = false }
296296
tempfile = { version = "3", default-features = false }

crates/wash-cli/src/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub struct BuildCommand {
6262
}
6363

6464
pub async fn handle_command(command: BuildCommand) -> Result<CommandOutput> {
65-
let config = load_config(command.config_path, Some(true))?;
65+
let config = load_config(command.config_path, Some(true)).await?;
6666

6767
match config.project_type {
6868
TypeConfig::Component(ref component_config) => {

crates/wash-cli/src/cmd/dev/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub async fn handle_command(
122122
) -> Result<CommandOutput> {
123123
let current_dir = std::env::current_dir()?;
124124
let project_path = cmd.code_dir.unwrap_or(current_dir);
125-
let project_cfg = load_config(Some(project_path.clone()), Some(true))?;
125+
let project_cfg = load_config(Some(project_path.clone()), Some(true)).await?;
126126

127127
let mut wash_dev_session = WashDevSession::from_sessions_file(&project_path)
128128
.await

crates/wash-cli/src/common/registry_cmd.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub async fn registry_push(
9191
cmd: RegistryPushCommand,
9292
output_kind: OutputKind,
9393
) -> Result<CommandOutput> {
94-
let project_config = load_config(cmd.project_config, Some(true)).ok();
94+
let project_config = load_config(cmd.project_config, Some(true)).await.ok();
9595
let image: Reference = resolve_artifact_ref(
9696
&cmd.url,
9797
&cmd.registry.unwrap_or_default(),
@@ -199,6 +199,7 @@ fn resolve_artifact_ref(
199199

200200
async fn resolve_registry_credentials(registry: &str) -> Result<RegistryCredential> {
201201
let credentials = if let Ok(credentials) = load_config(None, Some(true))
202+
.await
202203
.and_then(|config| config.resolve_registry_credentials(registry))
203204
{
204205
credentials

crates/wash-cli/src/wit.rs

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
// This is pretty much a copy of the wkg wit subcommand adapted for wash
22
use std::path::PathBuf;
33

4-
use anyhow::Ok;
4+
use anyhow::Context;
55
use clap::{Args, Subcommand};
66
use wash_lib::{
7-
build::monkey_patch_fetch_logging,
7+
build::{load_lock_file, monkey_patch_fetch_logging},
88
cli::{CommandOutput, CommonPackageArgs},
9+
parser::load_config,
910
};
1011
use wasm_pkg_client::{PublishOpts, Registry};
11-
use wasm_pkg_core::{
12-
lock::LockFile,
13-
wit::{self, OutputType},
14-
};
12+
use wasm_pkg_core::wit::{self, OutputType};
1513

1614
/// Commands for interacting with wit
1715
#[derive(Debug, Subcommand, Clone)]
@@ -25,7 +23,7 @@ pub enum WitCommand {
2523
/// dependencies and write them to the `deps` directory along with a lock file. If no lock file
2624
/// exists, it will fetch all dependencies. If a lock file exists, it will fetch any
2725
/// dependencies that are not in the lock file and update the lock file.
28-
Fetch(FetchArgs),
26+
Deps(DepsArgs),
2927
/// Publish a WIT package to a registry. This will automatically infer the package name from the
3028
/// WIT package.
3129
Publish(PublishArgs),
@@ -35,7 +33,7 @@ impl WitCommand {
3533
pub async fn run(self) -> anyhow::Result<CommandOutput> {
3634
match self {
3735
WitCommand::Build(args) => args.run().await,
38-
WitCommand::Fetch(args) => args.run().await,
36+
WitCommand::Deps(args) => args.run().await,
3937
WitCommand::Publish(args) => args.run().await,
4038
}
4139
}
@@ -54,10 +52,14 @@ pub struct BuildArgs {
5452

5553
#[clap(flatten)]
5654
pub common: CommonPackageArgs,
55+
56+
/// Path to the wasmcloud.toml file or parent folder to use for building
57+
#[clap(short = 'p', long = "config-path")]
58+
config_path: Option<PathBuf>,
5759
}
5860

5961
#[derive(Debug, Args, Clone)]
60-
pub struct FetchArgs {
62+
pub struct DepsArgs {
6163
/// The directory containing the WIT files to fetch dependencies for.
6264
#[clap(short = 'd', long = "wit-dir", default_value = "wit")]
6365
pub dir: PathBuf,
@@ -69,6 +71,10 @@ pub struct FetchArgs {
6971

7072
#[clap(flatten)]
7173
pub common: CommonPackageArgs,
74+
75+
/// Path to the wasmcloud.toml file or parent folder to use for building
76+
#[clap(short = 'p', long = "config-path")]
77+
config_path: Option<PathBuf>,
7278
}
7379

7480
#[derive(Args, Debug, Clone)]
@@ -87,8 +93,15 @@ pub struct PublishArgs {
8793
impl BuildArgs {
8894
pub async fn run(self) -> anyhow::Result<CommandOutput> {
8995
let client = self.common.get_client().await?;
90-
let wkg_config = wasm_pkg_core::config::Config::load().await?;
91-
let mut lock_file = LockFile::load(false).await?;
96+
// Attempt to load wasmcloud.toml. If it doesn't work, attempt to load wkg.toml
97+
let wkg_config = if let Ok(proj) = load_config(self.config_path, Some(true)).await {
98+
proj.package_config
99+
} else {
100+
wasm_pkg_core::config::Config::load().await?
101+
};
102+
let mut lock_file =
103+
load_lock_file(std::env::current_dir().context("failed to get current directory")?)
104+
.await?;
92105
let (pkg_ref, version, bytes) =
93106
wit::build_package(&wkg_config, self.dir, &mut lock_file, client).await?;
94107
let output_path = if let Some(path) = self.output_file {
@@ -118,11 +131,18 @@ impl BuildArgs {
118131
}
119132
}
120133

121-
impl FetchArgs {
134+
impl DepsArgs {
122135
pub async fn run(self) -> anyhow::Result<CommandOutput> {
123136
let client = self.common.get_client().await?;
124-
let wkg_config = wasm_pkg_core::config::Config::load().await?;
125-
let mut lock_file = LockFile::load(false).await?;
137+
// Attempt to load wasmcloud.toml. If it doesn't work, attempt to load wkg.toml
138+
let wkg_config = if let Ok(proj) = load_config(self.config_path, Some(true)).await {
139+
proj.package_config
140+
} else {
141+
wasm_pkg_core::config::Config::load().await?
142+
};
143+
let mut lock_file =
144+
load_lock_file(std::env::current_dir().context("failed to get current directory")?)
145+
.await?;
126146
monkey_patch_fetch_logging(wkg_config, self.dir, &mut lock_file, client).await?;
127147
// Now write out the lock file since everything else succeeded
128148
lock_file.write().await?;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
target = "wasm32-wasi"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/
2+
wit/deps/
3+
Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "ponger-config-component"
3+
edition = "2021"
4+
description = """
5+
A wit-based actor that returns data values in response to wRPC invocations.
6+
"""
7+
version = "0.1.0"
8+
9+
[lib]
10+
crate-type = ["cdylib"]
11+
12+
[dependencies]
13+
wit-bindgen = "0.34"
14+
15+
[workspace]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package test-components:testing@0.1.0;
2+
3+
/// Invoke a component with a `ping` function and, ideally, receive "pong"
4+
interface pingpong {
5+
/// Call ping, get a pong back
6+
ping: func() -> string;
7+
8+
/// Call ping, but quietly, and get a secret pong back
9+
ping-secret: func() -> string;
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
wit_bindgen::generate!({ generate_all });
2+
3+
use exports::test_components::testing::*;
4+
5+
struct Component;
6+
7+
impl pingpong::Guest for Component {
8+
fn ping() -> String {
9+
"helloworld".to_string()
10+
}
11+
12+
fn ping_secret() -> String {
13+
"helloworld".to_string()
14+
}
15+
}
16+
17+
export!(Component);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name = "ponger-config-component"
2+
language = "rust"
3+
type = "component"
4+
5+
[component]
6+
wasm_target = "wasm32-wasip2"
7+
8+
[overrides]
9+
"test-components:testing" = { path = "./extra-wit" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package test-components:ponger-config;
2+
3+
world component {
4+
export test-components:testing/pingpong@0.1.0;
5+
// These are not used in the test, but just making sure the build process can handle local and
6+
// remote deps
7+
import wasmcloud:secrets/store@0.1.0-draft;
8+
import wasmcloud:secrets/reveal@0.1.0-draft;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
target = "wasm32-wasi"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/
2+
wit/deps/
3+
Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "ponger-config-component"
3+
edition = "2021"
4+
description = """
5+
A wit-based actor that returns data values in response to wRPC invocations.
6+
"""
7+
version = "0.1.0"
8+
9+
[lib]
10+
crate-type = ["cdylib"]
11+
12+
[dependencies]
13+
wit-bindgen = "0.34"
14+
15+
[workspace]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package test-components:testing@0.1.0;
2+
3+
/// Invoke a component with a `ping` function and, ideally, receive "pong"
4+
interface pingpong {
5+
/// Call ping, get a pong back
6+
ping: func() -> string;
7+
8+
/// Call ping, but quietly, and get a secret pong back
9+
ping-secret: func() -> string;
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
wit_bindgen::generate!({ generate_all });
2+
3+
use exports::test_components::testing::*;
4+
5+
struct Component;
6+
7+
impl pingpong::Guest for Component {
8+
fn ping() -> String {
9+
"helloworld".to_string()
10+
}
11+
12+
fn ping_secret() -> String {
13+
"helloworld".to_string()
14+
}
15+
}
16+
17+
export!(Component);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is automatically generated.
2+
# It is not intended for manual editing.
3+
version = 1
4+
5+
[[packages]]
6+
name = "wasmcloud:secrets"
7+
registry = "wasmcloud.com"
8+
9+
[[packages.versions]]
10+
requirement = "=0.1.0-draft"
11+
version = "0.1.0-draft"
12+
digest = "sha256:aab5d8d6ecbc17d8237f269e05170fabcf8704738c60b8f1bf09a13fc6855ffb"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name = "ponger-config-component"
2+
language = "rust"
3+
type = "component"
4+
5+
[component]
6+
wasm_target = "wasm32-wasip2"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package test-components:ponger-config;
2+
3+
world component {
4+
export test-components:testing/pingpong@0.1.0;
5+
// These are not used in the test, but just making sure the build process can handle local and
6+
// remote deps
7+
import wasmcloud:secrets/store@0.1.0-draft;
8+
import wasmcloud:secrets/reveal@0.1.0-draft;
9+
}

0 commit comments

Comments
 (0)