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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ jobs:

- name: Test
run: nix develop --command cargo test --workspace

- name: Derive tests
run: nix develop --command cargo test -p pack-abi --features derive
43 changes: 42 additions & 1 deletion Cargo.lock

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

24 changes: 21 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
[package]
name = "pack"
[workspace]
members = [
"crates/pack-abi",
"crates/pack-derive",
"crates/pack-guest",
"crates/pack-guest-macros",
]

[workspace.package]
version = "0.2.0"
edition = "2021"

[workspace.dependencies]
pack-abi = { version = "0.2.0", path = "crates/pack-abi", default-features = false }
pack-derive = { version = "0.2.0", path = "crates/pack-derive" }
pack-guest = { version = "0.2.0", path = "crates/pack-guest" }
pack-guest-macros = { version = "0.2.0", path = "crates/pack-guest-macros" }

[package]
name = "pack"
version.workspace = true
edition.workspace = true
description = "A package runtime with extended WIT support for recursive types"

[[bin]]
Expand Down Expand Up @@ -35,7 +53,7 @@ wasm-encoder = "0.219"
sha2 = "0.10"

# Re-export pack-abi types for unified Value/FromValue/ConversionError
pack-abi = { path = "crates/pack-abi", features = ["std", "serde"] }
pack-abi = { workspace = true, features = ["std", "serde"] }

[dev-dependencies]
wat = "1.0" # For writing test modules in WAT
Expand Down
6 changes: 3 additions & 3 deletions crates/pack-abi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pack-abi"
version = "0.1.0"
edition = "2021"
version.workspace = true
edition.workspace = true
description = "Graph-encoded ABI for Pack runtime - supports recursive types"

[features]
Expand All @@ -16,6 +16,6 @@ hashbrown = "0.14"
# SHA-256 for type hashing (no_std compatible)
sha2 = { version = "0.10", default-features = false }
# Optional derive macro
pack-derive = { path = "../pack-derive", optional = true }
pack-derive = { workspace = true, optional = true }
# Optional serde support for host-side usage
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }
8 changes: 6 additions & 2 deletions crates/pack-abi/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ impl TypeHash {
/// Format as hex string (for debugging).
#[cfg(feature = "std")]
pub fn to_hex(&self) -> String {
use alloc::format;
self.0.iter().map(|b| format!("{:02x}", b)).collect()
use core::fmt::Write;
let mut s = String::with_capacity(self.0.len() * 2);
for b in &self.0 {
let _ = write!(s, "{:02x}", b);
}
s
}
}

Expand Down
43 changes: 22 additions & 21 deletions crates/pack-abi/tests/derive_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//! Tests for the GraphValue derive macro
//!
//! Run with: cargo test -p pack-abi --features derive

#![cfg(feature = "derive")]

use pack_abi::{GraphValue, Value};

Expand All @@ -18,7 +22,7 @@ fn struct_to_value() {
let value: Value = point.into();

match value {
Value::Record(fields) => {
Value::Record { fields, .. } => {
assert_eq!(fields.len(), 2);
assert_eq!(fields[0].0, "x");
assert_eq!(fields[0].1, Value::S64(10));
Expand All @@ -31,10 +35,13 @@ fn struct_to_value() {

#[test]
fn value_to_struct() {
let value = Value::Record(vec![
("x".to_string(), Value::S64(10)),
("y".to_string(), Value::S64(20)),
]);
let value = Value::Record {
type_name: String::new(),
fields: vec![
("x".to_string(), Value::S64(10)),
("y".to_string(), Value::S64(20)),
],
};

let point: Point = value.try_into().unwrap();
assert_eq!(point.x, 10);
Expand Down Expand Up @@ -117,9 +124,9 @@ fn enum_unit_variant() {
let value: Value = original.clone().into();

match &value {
Value::Variant { tag, payload } => {
Value::Variant { tag, payload, .. } => {
assert_eq!(*tag, 2);
assert!(payload.is_none());
assert!(payload.is_empty());
}
_ => panic!("Expected Variant"),
}
Expand All @@ -134,10 +141,10 @@ fn enum_single_payload() {
let value: Value = original.clone().into();

match &value {
Value::Variant { tag, payload } => {
Value::Variant { tag, payload, .. } => {
assert_eq!(*tag, 0);
assert!(payload.is_some());
assert_eq!(**payload.as_ref().unwrap(), Value::F64(5.0));
assert_eq!(payload.len(), 1);
assert_eq!(payload[0], Value::F64(5.0));
}
_ => panic!("Expected Variant"),
}
Expand All @@ -152,17 +159,11 @@ fn enum_tuple_payload() {
let value: Value = original.clone().into();

match &value {
Value::Variant { tag, payload } => {
Value::Variant { tag, payload, .. } => {
assert_eq!(*tag, 1);
assert!(payload.is_some());
match payload.as_ref().unwrap().as_ref() {
Value::Tuple(items) => {
assert_eq!(items.len(), 2);
assert_eq!(items[0], Value::F64(10.0));
assert_eq!(items[1], Value::F64(20.0));
}
_ => panic!("Expected Tuple payload"),
}
assert_eq!(payload.len(), 2);
assert_eq!(payload[0], Value::F64(10.0));
assert_eq!(payload[1], Value::F64(20.0));
}
_ => panic!("Expected Variant"),
}
Expand Down Expand Up @@ -248,7 +249,7 @@ fn rename_attribute() {
let value: Value = person.into();

match value {
Value::Record(fields) => {
Value::Record { fields, .. } => {
assert!(fields.iter().any(|(name, _)| name == "full_name"));
assert!(fields.iter().any(|(name, _)| name == "age"));
}
Expand Down
4 changes: 2 additions & 2 deletions crates/pack-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pack-derive"
version = "0.1.0"
edition = "2021"
version.workspace = true
edition.workspace = true
description = "Derive macros for pack-abi Value conversion"

[lib]
Expand Down
6 changes: 3 additions & 3 deletions crates/pack-guest-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pack-guest-macros"
version = "0.1.0"
edition = "2021"
version.workspace = true
edition.workspace = true
description = "Proc macros for Pack guest packages"
license = "MIT OR Apache-2.0"

Expand All @@ -12,4 +12,4 @@ proc-macro = true
proc-macro2 = "1"
quote = "1"
syn = { version = "2", features = ["full"] }
pack-abi = { path = "../pack-abi", features = ["std"] }
pack-abi = { workspace = true, features = ["std"] }
Loading
Loading