Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #68 from golemcloud/vigoo/type-annotated-value-json
Browse files Browse the repository at this point in the history
TypeAnnotatedValue JSON format
  • Loading branch information
vigoo authored Aug 8, 2024
2 parents b5ebbdb + ec66872 commit 30809d3
Show file tree
Hide file tree
Showing 15 changed files with 1,825 additions and 1,547 deletions.
1,709 changes: 1,043 additions & 666 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion wasm-rpc-stubgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cargo-component-core = "=0.13.2"
cargo-component = "=0.13.2"
dir-diff = "0.3.3"
fs_extra = "1.3.0"
golem-wasm-ast = "0.3.0"
golem-wasm-ast = "0.4.0"
golem-wasm-rpc = { path = "../wasm-rpc", version = "0.0.0" }
heck = "0.5.0"
id-arena = "2.2.1"
Expand Down
5 changes: 3 additions & 2 deletions wasm-rpc-stubgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,9 @@ pub fn compose(args: ComposeArgs) -> anyhow::Result<()> {
.map_err(|err| anyhow!(err))?;

let state = AnalysisContext::new(stub_component);
let stub_exports = state.get_top_level_exports().map_err(|err| match err {
AnalysisFailure::Failed(msg) => anyhow!(msg),
let stub_exports = state.get_top_level_exports().map_err(|err| {
let AnalysisFailure { reason } = err;
anyhow!(reason)
})?;

for export in stub_exports {
Expand Down
23 changes: 12 additions & 11 deletions wasm-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ async-recursion = { version = "1.1.1", optional = true }
async-trait = { version = "0.1.77", optional = true }
bigdecimal = { version = "0.4.5", optional = true }
bincode = { version = "2.0.0-rc.3", optional = true }
golem-wasm-ast = { version = "0.3.0", features = [
"analysis",
"wave",
], optional = true }
serde = { version = "1.0.203", optional = true }
serde_json = { version = "1.0.117", optional = true }
prost = { version = "0.12.6", optional = true }
golem-wasm-ast = { version = "0.4.0", optional = true }
poem-openapi = { version = "5.0", optional = true }
serde = { version = "1.0", optional = true }
serde_json = { version = "1.0", optional = true }
prost = { version = "0.12", optional = true }
wasmtime = { version = "=21.0.1", features = [
"component-model",
], optional = true }
Expand All @@ -40,6 +38,7 @@ proptest-arbitrary-interop = "0.1.0"

[build-dependencies]
prost-build = "0.12.6"
cargo_metadata = "0.18.1"

[features]
default = ["host"]
Expand All @@ -48,20 +47,22 @@ host = [
"arbitrary",
"bincode",
"json",
"poem_openapi",
"protobuf",
"serde",
"text",
"typeinfo",
"wasmtime",
]
arbitrary = ["dep:arbitrary"]
bincode = ["dep:bincode"]
json = ["dep:serde", "dep:serde_json", "dep:bigdecimal", "typeinfo"]
bincode = ["dep:bincode", "golem-wasm-ast/bincode"]
json = ["dep:serde", "dep:serde_json", "dep:bigdecimal", "typeinfo", "golem-wasm-ast/json"]
poem_openapi = ["dep:poem-openapi", "json", "typeinfo", "golem-wasm-ast/poem_openapi"]
protobuf = ["dep:bincode", "dep:serde", "dep:prost"]
serde = ["dep:serde"]
stub = []
text = ["wasmtime", "dep:wasm-wave"]
typeinfo = ["dep:golem-wasm-ast"]
text = ["wasmtime", "dep:wasm-wave", "golem-wasm-ast/wave"]
typeinfo = ["dep:golem-wasm-ast", "golem-wasm-ast/analysis", "golem-wasm-ast/protobuf", "protobuf"]
wasmtime = ["dep:wasmtime", "dep:wasmtime-wasi", "dep:async-recursion", "typeinfo"]


Expand Down
18 changes: 15 additions & 3 deletions wasm-rpc/build.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
use cargo_metadata::MetadataCommand;
use std::io::Result;

fn main() -> Result<()> {
let wasm_ast_root = find_package_root("golem-wasm-ast");

let mut config = prost_build::Config::new();
config.extern_path(".wasm.ast", "::golem_wasm_ast::analysis::protobuf");
config.type_attribute(".", "#[cfg(feature = \"protobuf\")]");
config.type_attribute(
".",
"#[derive(bincode::Encode, bincode::Decode, serde::Serialize, serde::Deserialize)]",
"#[cfg_attr(feature=\"bincode\", derive(bincode::Encode, bincode::Decode))]",
);
config.compile_protos(
&[
"proto/wasm/rpc/type.proto",
"proto/wasm/rpc/val.proto",
"proto/wasm/rpc/witvalue.proto",
"proto/wasm/rpc/type_annotated_value.proto",
],
&["proto/"],
&[&format!("{wasm_ast_root}/proto"), &"proto".to_string()],
)?;
Ok(())
}

fn find_package_root(name: &str) -> String {
let metadata = MetadataCommand::new()
.manifest_path("./Cargo.toml")
.exec()
.unwrap();
let package = metadata.packages.iter().find(|p| p.name == name).unwrap();
package.manifest_path.parent().unwrap().to_string()
}
91 changes: 0 additions & 91 deletions wasm-rpc/proto/wasm/rpc/type.proto

This file was deleted.

19 changes: 10 additions & 9 deletions wasm-rpc/proto/wasm/rpc/type_annotated_value.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
syntax = "proto3";

package wasm.rpc;
import "wasm/rpc/type.proto";

import "wasm/ast/type.proto";

message TypeAnnotatedValue {
oneof type_annotated_value {
Expand Down Expand Up @@ -31,17 +32,17 @@ message TypeAnnotatedValue {
}

message TypedList {
Type typ = 1;
wasm.ast.Type typ = 1;
repeated TypeAnnotatedValue values = 2;
}

message TypedTuple {
repeated Type typ = 1;
repeated wasm.ast.Type typ = 1;
repeated TypeAnnotatedValue value = 2;
}

message TypedRecord {
repeated NameTypePair typ = 1;
repeated wasm.ast.NameTypePair typ = 1;
repeated NameValuePair value = 2;
}

Expand All @@ -51,7 +52,7 @@ message TypedFlags {
}

message TypedVariant {
TypeVariant typ = 1;
wasm.ast.TypeVariant typ = 1;
string case_name = 2;
TypeAnnotatedValue case_value = 3;
}
Expand All @@ -62,21 +63,21 @@ message TypedEnum {
}

message TypedOption {
Type typ = 1;
wasm.ast.Type typ = 1;
optional TypeAnnotatedValue value = 2;
}

message TypedResult {
Type ok = 1;
Type error = 2;
wasm.ast.Type ok = 1;
wasm.ast.Type error = 2;
oneof result_value {
TypeAnnotatedValue ok_value = 3;
TypeAnnotatedValue error_value = 4;
}
}

message TypedHandle {
TypeHandle typ = 1;
wasm.ast.TypeHandle typ = 1;
string uri = 2;
uint64 resource_id = 3;
}
Expand Down
Loading

0 comments on commit 30809d3

Please sign in to comment.