Skip to content

Commit f6d8498

Browse files
committed
WIP
1 parent f57f279 commit f6d8498

Some content is hidden

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

57 files changed

+1271
-246
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ members = [
44
"rust/common-javascript-interpreter",
55
"rust/common-macros",
66
"rust/common-protos",
7-
"rust/common-runtime",
7+
# "rust/common-runtime",
8+
"rust/common-runtime-experiment",
89
"rust/common-test-fixtures",
910
"rust/common-tracing",
1011
"rust/common-wit",
@@ -28,7 +29,7 @@ common-builder = { path = "./rust/common-builder" }
2829
common-javascript-interpreter = { path = "./rust/common-javasript-interpreter" }
2930
common-macros = { path = "./rust/common-macros" }
3031
common-protos = { path = "./rust/common-protos", default-features = false }
31-
common-runtime = { path = "./rust/common-runtime" }
32+
common-runtime = { path = "./rust/common-runtime-experiment" }
3233
common-test-fixtures = { path = "./rust/common-test-fixtures" }
3334
common-tracing = { path = "./rust/common-tracing" }
3435
common-wit = { path = "./rust/common-wit" }

rust/common-javascript-interpreter/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ common-test-fixtures = { workspace = true }
2525
crate-type = ["cdylib"]
2626

2727
[package.metadata.component.target]
28-
path = "wit/deps/script/script.wit"
29-
world = "common"
30-
31-
[package.metadata.component.target.dependencies."common:module"]
32-
path = "wit/deps/module/module.wit"
28+
path = "wit/deps/function/function.wit"
29+
world = "virtual-module"
3330

3431
[package.metadata.component.target.dependencies."common:data"]
3532
path = "wit/deps/data/data.wit"

rust/common-javascript-interpreter/build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::process::Command;
33
const TYPESCRIPT_SOURCE_DEPENDENCIES: &[&str] = &[
44
"common/io/wit/io.wit",
55
"common/data/wit/data.wit",
6-
"common/module/wit/module.wit",
7-
"common/script/wit/script.wit",
6+
"common/function/wit/function.wit",
87
];
98

109
fn main() {

rust/common-javascript-interpreter/wit/deps.lock

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ sha512 = "aa6f16d180975d35dde3ebcd1b6a21992ee9e38ba9edf3f5535ff3415c3933792c8be5
66
sha256 = "3d6c8ae11439a90d1260d64030dc9ac003a72f2f7277df787b95c5a8f54d7474"
77
sha512 = "87c77c5a22fdc2c9850ff9e6672f94a86c7c32a6f665d714caca5613f6bc2a1cca76d7ebb26ddf3bae80c32d5d692baab803aff61207aaaa87ffdbd8e6cdc109"
88

9-
[module]
10-
sha256 = "cc4b0b5358ef2f51743b26a09a4a81bca23cb647f0561691387d28bc48dbbd26"
11-
sha512 = "7ff0a2fc4fa76decae57a3a8b8ee7f68c25c813eb1405e90e0c89a8045056b9cf5c1f3fa419845579cf920fd7e00f9c923b25664dc282dbff232a1dbd6e295d2"
12-
139
[script]
14-
path = "../../../typescript/common/script/wit"
15-
sha256 = "a0eca742d07bf481984e31f05de30d89da0016b92a896bee3b83d6abada7ebf1"
16-
sha512 = "f8849fd3c07f9e553c7909b90e53ee8a34c8f4a6982ebbb1fe2493e9f7db75d3d51f34e967794714903443abf9a6f180a74bfc555a4ac43c76832eba6ecd9aa6"
17-
deps = ["data", "io", "module"]
10+
path = "../../../typescript/common/function/wit"
11+
sha256 = "4d2c15922d458487d376361c47a3dc62089540d2ebc0a1b2fc9e524c323d02b3"
12+
sha512 = "a7d6f665016bdb9bbb72d3cbf533266cc5390a133056499e5a2a01896b93685f50144c547b2fcede78a01d1b92cce9d2666e5e30dce5a1dd6397a7b5a3f9abcc"
13+
deps = ["data", "io"]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
script = "../../../typescript/common/script/wit"
1+
script = "../../../typescript/common/function/wit"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[package]
2+
name = "common-runtime"
3+
description = "A Common runtime"
4+
version = "0.1.0"
5+
edition = "2021"
6+
7+
[dependencies]
8+
anyhow = { workspace = true }
9+
async-trait = { workspace = true }
10+
async-stream = { workspace = true }
11+
blake3 = { workspace = true }
12+
bytes = { workspace = true }
13+
common-protos = { workspace = true, features = ["runtime", "builder"] }
14+
common-tracing = { workspace = true }
15+
common-wit = { workspace = true }
16+
http = { workspace = true }
17+
mime_guess = { workspace = true }
18+
rand = { workspace = true }
19+
serde = { workspace = true }
20+
serde_json = { workspace = true }
21+
sieve-cache = { workspace = true }
22+
thiserror = { workspace = true }
23+
tracing = { workspace = true }
24+
tracing-subscriber = { workspace = true }
25+
26+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
27+
clap = { workspace = true, features = ["derive"] }
28+
tokio = { workspace = true, features = ["rt-multi-thread", "io-util", "process", "fs"] }
29+
tonic = { workspace = true, features = ["codegen", "prost", "transport"] }
30+
tower-http = { workspace = true, features = ["cors"] }
31+
wasmtime = { workspace = true }
32+
wasmtime-wasi = { workspace = true }
33+
wasmtime-wasi-http = { workspace = true }
34+
35+
[target.'cfg(target_arch = "wasm32")'.dependencies]
36+
getrandom = { workspace = true, features = ["js"]}
37+
tokio = { workspace = true, features = ["rt"] }
38+
tonic = { workspace = true, features = ["codegen", "prost"] }
39+
tonic-web-wasm-client = { workspace = true }
40+
41+
[build-dependencies]
42+
tempfile = { workspace = true }
43+
44+
[dev-dependencies]
45+
common-builder = { workspace = true }
46+
common-test-fixtures = { workspace = true }
47+
48+
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
49+
criterion = { workspace = true, features = ["async_tokio"] }
50+
51+
# [[bench]]
52+
# name = "runtime_bench"
53+
# harness = false
54+
# required-features = ["bench"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# common-runtime
2+
3+
The Common Runtime is responsible for instantiating a Common Recipe and managing its lifecycle.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use common_protos::common;
2+
3+
/// Supported content types that may be embodied as a [crate::CommonModule]
4+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5+
pub enum ContentType {
6+
/// JavaScript or TypeScript code
7+
JavaScript,
8+
/// Python code
9+
Python,
10+
}
11+
12+
impl From<common::ContentType> for ContentType {
13+
fn from(value: common::ContentType) -> Self {
14+
match value {
15+
common::ContentType::JavaScript => ContentType::JavaScript,
16+
common::ContentType::Python => ContentType::Python,
17+
}
18+
}
19+
}
20+
21+
impl From<ContentType> for common::ContentType {
22+
fn from(value: ContentType) -> Self {
23+
match value {
24+
ContentType::JavaScript => common::ContentType::JavaScript,
25+
ContentType::Python => common::ContentType::Python,
26+
}
27+
}
28+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
use std::fmt::Debug;
2+
use thiserror::Error;
3+
4+
use crate::ModuleInstanceId;
5+
6+
/// Various errors that may be encountered when invoking runtime code.
7+
#[derive(Error, Debug)]
8+
pub enum CommonRuntimeError {
9+
/// A Wasm Component failed to prepare
10+
#[error("Failed to prepare a Wasm Component: {0}")]
11+
PreparationFailed(String),
12+
13+
/// A Wasm Component failed to link
14+
#[error("Failed to link a Wasm Component: {0}")]
15+
LinkFailed(String),
16+
17+
/// A sandbox failed to be created
18+
#[error("Failed to instantiate a sandbox: {0}")]
19+
SandboxCreationFailed(String),
20+
21+
/// A Common Module failed to be instantiated
22+
#[error("Failed to instantiate a Common Module: {0}")]
23+
ModuleInstantiationFailed(String),
24+
25+
/// An error occurred when a Common Module was run
26+
#[error("Failed to run a Common Module: {0}")]
27+
ModuleRunFailed(String),
28+
29+
/// An unexpected internal error occurred
30+
#[error("Internal error")]
31+
InternalError(String),
32+
33+
/// A specified Common Module ID was not valid
34+
#[error("Invalid Common Module ID: {0}")]
35+
InvalidModuleId(String),
36+
37+
/// The configured target was missing or invalid
38+
#[error("Invalid Common Module Target: {0}")]
39+
InvalidModuleTarget(String),
40+
41+
/// The configured target was missing or invalid
42+
#[error("Invalid Common Module Affinity: {0}")]
43+
InvalidModuleAffinity(String),
44+
45+
/// The specified Common Module instance ID did not correspond to a living
46+
/// instance
47+
#[error("Unknown Common Module instance ID: {0}")]
48+
UnknownInstanceId(ModuleInstanceId),
49+
50+
/// A provided Value was empty or of an unexpected shape
51+
#[error("Invalid Value")]
52+
InvalidValue,
53+
54+
/// The provided module sources were missing or otherwise invalid
55+
#[error("Invalid module source: {0}")]
56+
InvalidModuleSource(String),
57+
58+
/// The provided instantiation parameters are not supported
59+
#[error("Invalid instantiation parameters: {0}")]
60+
InvalidInstantiationParameters(String),
61+
}
62+
63+
#[cfg(not(target_arch = "wasm32"))]
64+
impl From<tonic::transport::Error> for CommonRuntimeError {
65+
fn from(value: tonic::transport::Error) -> Self {
66+
CommonRuntimeError::InternalError(format!("{value}"))
67+
}
68+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use std::collections::BTreeMap;
2+
3+
use crate::{sync::ConditionalSync, Value, ValueKind};
4+
5+
/// A convenience alias for the expected shape of Common Module outputs
6+
pub type Output = BTreeMap<String, Value>;
7+
8+
/// A convenience alias for the expected shape of Common Module output shapes
9+
pub type OutputShape = BTreeMap<String, ValueKind>;
10+
11+
/// A generic trait for a reference to state. The implementation may embody
12+
/// state that is opaque, readable and/or writable.
13+
pub trait InputOutput: Clone + Default + ConditionalSync + std::fmt::Debug {
14+
/// Attempt to read some [Value] from state that is assigned some well-known
15+
/// `key`. A value may be returned if it is part of the state, and the reader
16+
/// is allowed to read it.
17+
fn read(&self, key: &str) -> Option<Value>;
18+
19+
/// Write some [Value] to a well-known `key`. The write may or may not be
20+
/// accepted. There is no prescription made as to the transactional
21+
/// guarantees of a call to `write`. Subsequent calls to `read` for the same
22+
/// `key` may or may not reflect the effect of a `write`, regardless of
23+
/// whether or not it was considered to be successful.
24+
fn write(&mut self, key: &str, value: Value);
25+
26+
/// Get a mapping of the output keys to their set values. Keys with no set
27+
/// values will not be pressent in the output, even if they were allowed to
28+
/// be set.
29+
fn output(&self) -> &Output;
30+
31+
/// Get the shape of the output, which is the expected [ValueKind] that maps
32+
/// to each allowed key in the output space
33+
fn output_shape(&self) -> &OutputShape;
34+
}
35+
36+
impl<Io> InputOutput for Box<Io>
37+
where
38+
Io: InputOutput,
39+
{
40+
fn read(&self, key: &str) -> Option<Value> {
41+
self.as_ref().read(key)
42+
}
43+
44+
fn write(&mut self, key: &str, value: Value) {
45+
self.as_mut().write(key, value)
46+
}
47+
48+
fn output(&self) -> &Output {
49+
self.as_ref().output()
50+
}
51+
52+
fn output_shape(&self) -> &OutputShape {
53+
self.as_ref().output_shape()
54+
}
55+
}

0 commit comments

Comments
 (0)