Skip to content

Commit c326f50

Browse files
authored
ct-engine: entry point with web bindings (#247)
feat: Introduce entry point, ct-engine, with web bindings
1 parent b8b68fd commit c326f50

File tree

33 files changed

+572
-265
lines changed

33 files changed

+572
-265
lines changed

.github/workflows/rust.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107

108108
nix-build:
109109
name: 'Nix build'
110-
needs: ['precheck']
110+
needs: ['precheck', 'build-wasm-components']
111111
runs-on: 'ubuntu-latest'
112112
strategy:
113113
matrix:

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
# "rust/common-tools",
1414
# "rust/common-tracing",
1515
# "rust/common-wit",
16+
"rust/ct-common",
1617
"rust/ct-engine",
1718
"rust/ct-js-vm",
1819
"rust/ct-runtime",
@@ -43,6 +44,7 @@ clap = { version = "4.5" }
4344
#common-test-fixtures = { path = "./rust/common-test-fixtures" }
4445
#common-tracing = { path = "./rust/common-tracing" }
4546
#common-wit = { path = "./rust/common-wit" }
47+
ct-common = { path = "./rust/ct-common" }
4648
ct-runtime = { path = "./rust/ct-runtime" }
4749
#criterion = { version = "0.5" }
4850
#darling = { version = "0.20" }
@@ -105,7 +107,6 @@ wit-bindgen-rt = { version = "0.33" }
105107
#wit-parser = { version = "0.218" }
106108

107109
[profile.release]
108-
codegen-units = 1
109110
opt-level = "s"
110111
debug = false
111112
strip = true

flake.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,9 @@
261261
262262
bash ./wit/wit-tools.sh deps
263263
wasm-pack build --target web -m no-install ./rust/ct-engine
264-
#cp ./typescript/common-runtime/README.md ./rust/common-runtime/pkg/README.md
265-
#cp ./typescript/common-runtime/example.html ./rust/common-runtime/pkg/example.html
264+
265+
cp ./typescript/ct-engine/README.md ./rust/ct-engine/pkg/README.md
266+
cp ./typescript/ct-engine/example.html ./rust/ct-engine/pkg/example.html
266267
'';
267268
installPhase = ''
268269
mkdir -p $out

rust/ct-common/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "ct-common"
3+
description = "Shared utilites for Common Tools"
4+
version = "0.1.0"
5+
edition = "2021"

rust/ct-common/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# ct-common

rust/ct-common/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! Utilities used throughout the system.
2+
3+
mod sync;
4+
5+
pub use sync::*;

rust/ct-runtime/src/sync.rs renamed to rust/ct-common/src/sync.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,29 @@
33
//! The traits herein are intended for use as a compatiblity mechanism for async
44
//! code that may target both `wasm32-unknown-unknown` as well as native targets
55
//! where the implementor may be shared across threads.
6-
#![allow(dead_code)]
7-
#![allow(missing_docs)]
86
7+
#[allow(missing_docs)]
98
#[cfg(not(target_arch = "wasm32"))]
109
pub trait ConditionalSend: Send {}
1110

1211
#[cfg(not(target_arch = "wasm32"))]
1312
impl<S> ConditionalSend for S where S: Send {}
1413

14+
#[allow(missing_docs)]
1515
#[cfg(not(target_arch = "wasm32"))]
1616
pub trait ConditionalSync: Send + Sync {}
1717

1818
#[cfg(not(target_arch = "wasm32"))]
1919
impl<S> ConditionalSync for S where S: Send + Sync {}
2020

21+
#[allow(missing_docs)]
2122
#[cfg(target_arch = "wasm32")]
2223
pub trait ConditionalSend {}
2324

2425
#[cfg(target_arch = "wasm32")]
2526
impl<S> ConditionalSend for S {}
2627

28+
#[allow(missing_docs)]
2729
#[cfg(target_arch = "wasm32")]
2830
pub trait ConditionalSync {}
2931

rust/ct-engine/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ crate-type = ["cdylib", "rlib"]
1010
[dependencies]
1111
tracing = { workspace = true }
1212
ct-runtime = { workspace = true }
13+
thiserror = { workspace = true }
1314

1415
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
1516
tokio = { workspace = true, features = [
@@ -28,6 +29,7 @@ tracing-wasm = "~0.2"
2829
wasm-bindgen = { workspace = true }
2930
wasm-bindgen-futures = { workspace = true }
3031
web-sys = { workspace = true }
32+
js-sys = { workspace = true }
3133

3234
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
3335
wasm-bindgen-test = { workspace = true }

rust/ct-engine/src/bin/engine.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,5 @@ pub fn main() {
66
#[cfg(not(target_arch = "wasm32"))]
77
#[tokio::main]
88
pub async fn main() -> ct_runtime::Result<()> {
9-
use ct_runtime::{HostFeatures, Instance, Module, ModuleDefinition, Runtime, VirtualMachine};
10-
11-
println!("Running test case in lieu of a service.");
12-
13-
let source = r#"
14-
export const run = (input) => {
15-
input.foo = input.foo + 1;
16-
return input;
17-
}
18-
"#;
19-
let definition = ModuleDefinition {
20-
vm: VirtualMachine::JavaScript,
21-
source: source.into(),
22-
};
23-
24-
struct Host;
25-
impl HostFeatures for Host {
26-
fn host_callback(input: String) -> std::result::Result<String, String> {
27-
Ok(input)
28-
}
29-
}
30-
let runtime = Runtime::<Host>::new()?;
31-
let mut module = runtime.module(definition)?;
32-
let mut instance = module.instantiate()?;
33-
34-
let input = r#"{"foo":9}"#;
35-
let output = instance.run(input.into())?;
36-
assert_eq!(output, r#"{"foo":10}"#);
37-
389
Ok(())
3910
}

0 commit comments

Comments
 (0)