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
2 changes: 1 addition & 1 deletion .github/workflows/bump-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
description: The new version of the interface package and crates, e.g. 0.1.0 or 0.2.0-dev
required: true
type: string
default: "0.1.2-dev" # the current version, kept current by scripts/bump-version.sh
default: "0.2.0-dev" # the current version, kept current by scripts/bump-version.sh

jobs:
# bumps the version with read only access, the changes are handed to the push job as a patch so
Expand Down
4 changes: 2 additions & 2 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 @@ -37,13 +37,13 @@ members = [
# the version of the cli and library crates, kept in step with the interface package by
# scripts/bump-version.sh
[workspace.package]
version = "0.1.2-dev"
version = "0.2.0-dev"

[workspace.dependencies]
anyhow = "1"
# published with the cli, the cli requires the library at exactly the same version, kept in step by
# scripts/bump-version.sh
componentized-constants = { path = "./crates/componentized-constants", version = "=0.1.2-dev" }
componentized-constants = { path = "./crates/componentized-constants", version = "=0.2.0-dev" }
futures = { version = "0.3", default-features = false, features = ["executor"] }
test-harness = { path = "./crates/test-harness" }
wasmtime = { version = "49", default-features = false, features = ["anyhow", "component-model", "component-model-async", "cranelift", "runtime"] }
Expand Down
2 changes: 1 addition & 1 deletion components/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Config values for the wasi:config/store interface, served from a list of key val

Imports:

- `componentized:constants/config-values@0.1.2-dev`: the key value pairs to serve, e.g. from a constants component
- `componentized:constants/config-values@0.2.0-dev`: the key value pairs to serve, e.g. from a constants component

Exports:

Expand Down
2 changes: 1 addition & 1 deletion components/config/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use wasmtime::{
component::{Component, Instance, Linker, Val},
};

const VALUES_INTERFACE: &str = "componentized:constants/config-values@0.1.2-dev";
const VALUES_INTERFACE: &str = "componentized:constants/config-values@0.2.0-dev";
const STORE_INTERFACE: &str = "wasi:config/store@0.2.0-rc.1";

/// An instance of the config component, importing `values` as the config values.
Expand Down
2 changes: 1 addition & 1 deletion components/factory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Imports:

Exports:

- `componentized:constants/factory@0.1.2-dev`: creates a component implementing a world from its WIT
- `componentized:constants/factory@0.2.0-dev`: creates a component implementing a world from its WIT
12 changes: 6 additions & 6 deletions components/factory/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg_attr(not(test), no_main)]

use crate::{
componentized::component::types::{Component, Error},
componentized::component::types::{ErrorCode, Wasm},
exports::componentized::constants::factory::{Guest, Overrides, WitSource},
};
use componentized_constants::{create_component, decode_world, parse_world};
Expand All @@ -16,10 +16,10 @@ impl Guest for Factory {
wit: WitSource,
world: Option<String>,
overrides: Option<Overrides>,
) -> Result<Component, Error> {
) -> Result<Wasm, ErrorCode> {
let (resolve, world) = match wit {
WitSource::Text(text) => parse_world(&text, world.as_deref()),
WitSource::Encoded(bytes) => decode_world(&bytes, world.as_deref()),
WitSource::Wit(text) => parse_world(&text, world.as_deref()),
WitSource::Wasm(bytes) => decode_world(&bytes, world.as_deref()),
WitSource::Parsed(wit) => parsed_world(wit, world.as_deref()),
}
.map_err(to_error)?;
Expand All @@ -44,8 +44,8 @@ fn parsed_world(
Ok((parsed.resolve, world))
}

fn to_error(err: anyhow::Error) -> Error {
Error::Other(Some(format!("{err:#}")))
fn to_error(err: anyhow::Error) -> ErrorCode {
ErrorCode::Other(Some(format!("{err:#}")))
}

wit_bindgen::generate!({
Expand Down
6 changes: 6 additions & 0 deletions components/factory/src/parsed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ impl Ids {
w::FunctionKind::Static(id) => K::Static(self.type_id(id)?),
w::FunctionKind::AsyncStatic(id) => K::AsyncStatic(self.type_id(id)?),
w::FunctionKind::Constructor(id) => K::Constructor(self.type_id(id)?),
w::FunctionKind::Getter => K::Getter,
w::FunctionKind::Setter => K::Setter,
w::FunctionKind::MethodGetter(id) => K::MethodGetter(self.type_id(id)?),
w::FunctionKind::MethodSetter(id) => K::MethodSetter(self.type_id(id)?),
w::FunctionKind::StaticGetter(id) => K::StaticGetter(self.type_id(id)?),
w::FunctionKind::StaticSetter(id) => K::StaticSetter(self.type_id(id)?),
},
params: func
.params
Expand Down
33 changes: 14 additions & 19 deletions components/factory/tests/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use wasmtime::{

const TYPES: &str = "componentized:component/types@0.0.0-dev";
const WIT_INTERFACE: &str = "componentized:component/wit@0.0.0-dev";
const FACTORY_INTERFACE: &str = "componentized:constants/factory@0.1.2-dev";
const FACTORY_INTERFACE: &str = "componentized:constants/factory@0.2.0-dev";

fn engine() -> &'static Engine {
static ENGINE: OnceLock<Engine> = OnceLock::new();
Expand Down Expand Up @@ -126,8 +126,8 @@ fn val_bytes(val: Val) -> Result<Vec<u8>> {
}

enum Wit<'a> {
Text(&'a str),
Encoded(Vec<u8>),
Wit(&'a str),
Wasm(Vec<u8>),
Parsed(Val),
}

Expand All @@ -148,8 +148,8 @@ fn create(
}))
};
let wit = match wit {
Wit::Text(text) => Val::Variant("text".into(), Some(Box::new(Val::String(text.into())))),
Wit::Encoded(bytes) => Val::Variant("encoded".into(), Some(Box::new(bytes_val(bytes)))),
Wit::Wit(text) => Val::Variant("wit".into(), Some(Box::new(Val::String(text.into())))),
Wit::Wasm(bytes) => Val::Variant("wasm".into(), Some(Box::new(bytes_val(bytes)))),
Wit::Parsed(wit) => Val::Variant("parsed".into(), Some(Box::new(wit))),
};
let result = call_async(
Expand Down Expand Up @@ -235,19 +235,15 @@ fn call_config(component: &[u8]) -> Result<Vec<Val>> {

#[test]
fn it_creates_components_from_wit_text() -> Result<()> {
let component = create(Wit::Text(WIT), Some("config"), None)?.map_err(|e| anyhow!(e))?;
let component = create(Wit::Wit(WIT), Some("config"), None)?.map_err(|e| anyhow!(e))?;
assert_eq!(call_config(&component)?, vec![string("hello"), point(1, 2)]);
Ok(())
}

#[test]
fn it_creates_components_from_encoded_wit() -> Result<()> {
let component = create(
Wit::Encoded(encode(WIT)?),
Some("other"),
Some("{answer: 7}"),
)?
.map_err(|e| anyhow!(e))?;
let component = create(Wit::Wasm(encode(WIT)?), Some("other"), Some("{answer: 7}"))?
.map_err(|e| anyhow!(e))?;
let actual = call(&component, &[], &[("", "answer")])?;
assert_eq!(actual, vec![Val::U32(7)]);
Ok(())
Expand All @@ -265,8 +261,7 @@ fn it_creates_components_from_parsed_wit() -> Result<()> {
fn it_creates_identical_components_from_encoded_and_parsed_wit() -> Result<()> {
// exercises every supported type, including aliases and imported types
let encoded = encode("crates/componentized-constants/tests/fixtures/all")?;
let from_encoded =
create(Wit::Encoded(encoded.clone()), None, None)?.map_err(|e| anyhow!(e))?;
let from_encoded = create(Wit::Wasm(encoded.clone()), None, None)?.map_err(|e| anyhow!(e))?;
let from_parsed =
create(Wit::Parsed(extract(encoded)?), None, None)?.map_err(|e| anyhow!(e))?;
assert!(from_encoded == from_parsed, "components differ");
Expand All @@ -276,7 +271,7 @@ fn it_creates_identical_components_from_encoded_and_parsed_wit() -> Result<()> {
#[test]
fn it_reimplements_the_world_of_a_parsed_component() -> Result<()> {
// components don't carry docs, so every value comes from the overrides
let original = create(Wit::Text(WIT), Some("config"), None)?.map_err(|e| anyhow!(e))?;
let original = create(Wit::Wit(WIT), Some("config"), None)?.map_err(|e| anyhow!(e))?;
let wit = extract(original)?;
let component = create(
Wit::Parsed(wit),
Expand All @@ -290,17 +285,17 @@ fn it_reimplements_the_world_of_a_parsed_component() -> Result<()> {

#[test]
fn it_returns_errors() -> Result<()> {
let err = create(Wit::Text(WIT), None, None)?.expect_err("multiple worlds");
let err = create(Wit::Wit(WIT), None, None)?.expect_err("multiple worlds");
assert!(err.contains("multiple worlds"), "{err}");

let err =
create(Wit::Text(WIT), Some("other"), Some("{answer: -1}"))?.expect_err("invalid override");
create(Wit::Wit(WIT), Some("other"), Some("{answer: -1}"))?.expect_err("invalid override");
assert!(err.contains("invalid override for `answer`"), "{err}");

let err = create(Wit::Encoded(vec![0, 1, 2]), None, None)?.expect_err("invalid wasm");
let err = create(Wit::Wasm(vec![0, 1, 2]), None, None)?.expect_err("invalid wasm");
assert!(!err.is_empty());

let original = create(Wit::Text(WIT), Some("config"), None)?.map_err(|e| anyhow!(e))?;
let original = create(Wit::Wit(WIT), Some("config"), None)?.map_err(|e| anyhow!(e))?;
let err = create(Wit::Parsed(extract(original)?), None, None)?.expect_err("missing values");
assert!(
err.contains("missing value for `example:factory/constants#greeting`"),
Expand Down
2 changes: 1 addition & 1 deletion components/math/wit/math.constants.wit
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package componentized:constants-component;

world math {
export componentized:constants/math@0.1.2-dev;
export componentized:constants/math@0.2.0-dev;
}
2 changes: 1 addition & 1 deletion components/math/wkg.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ registry = "componentized.dev"
[[packages.versions]]
requirement = "=0.0.0-dev"
version = "0.0.0-dev"
digest = "sha256:a286f387e5625023fbc5ec998de7a079e4279cc11fe569e56b443ad9cabbb4de"
digest = "sha256:2d7677a89ef49bef5d8d20848c431c76208753858f4871929066397d62542af7"

[[packages]]
name = "wasi:config"
Expand Down
20 changes: 10 additions & 10 deletions components/types/wit/types.constants.wit
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package componentized:constants-component;

world math {
export componentized:constants/%u8@0.1.2-dev;
export componentized:constants/%u16@0.1.2-dev;
export componentized:constants/%u32@0.1.2-dev;
export componentized:constants/%u64@0.1.2-dev;
export componentized:constants/%s8@0.1.2-dev;
export componentized:constants/%s16@0.1.2-dev;
export componentized:constants/%s32@0.1.2-dev;
export componentized:constants/%s64@0.1.2-dev;
export componentized:constants/%f32@0.1.2-dev;
export componentized:constants/%f64@0.1.2-dev;
export componentized:constants/%u8@0.2.0-dev;
export componentized:constants/%u16@0.2.0-dev;
export componentized:constants/%u32@0.2.0-dev;
export componentized:constants/%u64@0.2.0-dev;
export componentized:constants/%s8@0.2.0-dev;
export componentized:constants/%s16@0.2.0-dev;
export componentized:constants/%s32@0.2.0-dev;
export componentized:constants/%s64@0.2.0-dev;
export componentized:constants/%f32@0.2.0-dev;
export componentized:constants/%f64@0.2.0-dev;
}
2 changes: 1 addition & 1 deletion components/types/wkg.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ registry = "componentized.dev"
[[packages.versions]]
requirement = "=0.0.0-dev"
version = "0.0.0-dev"
digest = "sha256:a286f387e5625023fbc5ec998de7a079e4279cc11fe569e56b443ad9cabbb4de"
digest = "sha256:2d7677a89ef49bef5d8d20848c431c76208753858f4871929066397d62542af7"

[[packages]]
name = "wasi:config"
Expand Down
4 changes: 2 additions & 2 deletions components/wit/worlds.wit
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package componentized:constants-components;

world config {
include componentized:constants/config@0.1.2-dev;
include componentized:constants/config@0.2.0-dev;
}

world factory {
export componentized:constants/factory@0.1.2-dev;
export componentized:constants/factory@0.2.0-dev;
}
2 changes: 1 addition & 1 deletion components/wkg.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ registry = "componentized.dev"
[[packages.versions]]
requirement = "=0.0.0-dev"
version = "0.0.0-dev"
digest = "sha256:a286f387e5625023fbc5ec998de7a079e4279cc11fe569e56b443ad9cabbb4de"
digest = "sha256:2d7677a89ef49bef5d8d20848c431c76208753858f4871929066397d62542af7"

[[packages]]
name = "wasi:config"
Expand Down
2 changes: 1 addition & 1 deletion scripts/bump-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fi

old_re="${old//./\\.}"
# references to the package or one of its interfaces, an interface named for a keyword is escaped
# with `%`, e.g. `componentized:constants/%u8@0.1.2-dev`
# with `%`, e.g. `componentized:constants/%u8@0.2.0-dev`
ref_re="${PACKAGE}(/%?[a-z0-9-]+)?"
# the fetched wit dependencies and the wkg.lock files are left to `make wit`, wkg replaces the
# dependencies and updates the locks for the new version
Expand Down
20 changes: 3 additions & 17 deletions wit/factory.wit
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
/// Creates components whose exported functions return constant values.
interface factory {
use componentized:component/types@0.0.0-dev.{component, error};
use componentized:component/wit@0.0.0-dev.{wit};

/// WIT defining the world for the created component to implement.
variant wit-source {
/// WIT text. Packages the world depends on may be defined inline with
/// nested `package ns:name { ... }` blocks.
text(string),
/// A WIT package encoded as wasm, including its dependencies, e.g. from
/// `wasm-tools component wit --wasm` or `wkg build`.
encoded(component),
/// WIT parsed by `componentized:component/wit#extract`. When
/// extracted from a component, rather than a WIT package, the
/// component's world is implemented by default.
parsed(wit),
}
use componentized:component/types@0.0.0-dev.{wasm, error-code};
use componentized:component/wit@0.0.0-dev.{wit, wit-source};

/// Values replacing those from the WIT. The overrides are a record with
/// an optional field per world export. Interface exports are named by the
Expand All @@ -41,5 +27,5 @@ interface factory {
wit: wit-source,
%world: option<string>,
overrides: option<overrides>,
) -> result<component, error>;
) -> result<wasm, error-code>;
}
2 changes: 1 addition & 1 deletion wit/worlds.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package componentized:constants@0.1.2-dev;
package componentized:constants@0.2.0-dev;

world imports {
import config-values;
Expand Down
2 changes: 1 addition & 1 deletion wkg.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ registry = "componentized.dev"
[[packages.versions]]
requirement = "=0.0.0-dev"
version = "0.0.0-dev"
digest = "sha256:a286f387e5625023fbc5ec998de7a079e4279cc11fe569e56b443ad9cabbb4de"
digest = "sha256:2d7677a89ef49bef5d8d20848c431c76208753858f4871929066397d62542af7"

[[packages]]
name = "wasi:config"
Expand Down
Loading