Skip to content

Commit

Permalink
Try out Boa
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianReeves committed May 27, 2024
1 parent 7aaa99b commit 2513dcb
Show file tree
Hide file tree
Showing 11 changed files with 520 additions and 1,328 deletions.
1,664 changes: 472 additions & 1,192 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[workspace]
resolver = "2"
members = ["crates/morphir-runtime",
"crates/morphir-runtime-sandbox",
]
default-members = ["crates/morphir-runtime-sandbox"]
members = ["crates/morphir-runtime", "crates/morphir-runtime-wasm"]
default-members = ["crates/morphir-runtime"]

[workspace.package]
version = "0.1.0"
Expand All @@ -14,6 +12,7 @@ authors = ["Damian Reeves"]
license = "Apache-2.0"

[workspace.dependencies]
boa_engine = "0.18.0"
deno_core = "0.283.0"
deno_ast = "0.38.2"
extism-pdk = "1.2.0"
Expand Down
16 changes: 16 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ pub fn build(b: *std.Build) void {
.dependOn(&b.addInstallFileWithDir(elm_docs_output, .prefix, b.pathJoin(&.{ "elm-out/finos/morphir", "docs.json" })).step);

verify_elm_package.dependOn(check_elm_docs);

// Setup cargo build
const cargo_build = b.step("cargo-build", "Build the Rust code.");
const morphir_runtime_wasm_crate = createCargoPackageBuildStep(b, "build-morphir-runtime-wasm", "Build morphir-runtime-wasm crate", "morphir-runtime-wasm", "wasm32-wasi");

cargo_build.dependOn(morphir_runtime_wasm_crate);

b.getInstallStep().dependOn(cargo_build);
}

const JavascriptRunTool = enum { bunx, npx };

pub fn createCargoPackageBuildStep(b: *std.Build, name: []const u8, description: []const u8, package: []const u8, target: []const u8) *std.Build.Step {
const cargo_build = b.step(name, description);
const tool_run = b.addSystemCommand(&.{ "cargo", "build", "--package", package, "--target", target });
tool_run.extra_file_dependencies = &.{ "Cargo.toml", "Cargo.lock" };
cargo_build.dependOn(&tool_run.step);
return cargo_build;
}
37 changes: 0 additions & 37 deletions crates/morphir-runtime-sandbox/src/lib.rs

This file was deleted.

17 changes: 0 additions & 17 deletions crates/morphir-runtime-sandbox/src/main.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "morphir-runtime-sandbox"
name = "morphir-runtime-wasm"
version.workspace = true
description = "Morphir runtime"
homepage.workspace = true
Expand All @@ -11,24 +11,16 @@ edition.workspace = true
[badges]
maintnance = { status = "actively-developer" }

[[bin]]
name = "morphirx"
path = "src/main.rs"

[lib]
crate_type = ["cdylib"]
name = "morphir_runtime"
path = "src/lib.rs"

[features]

[dependencies]
deno_core.workspace = true
deno_ast = { workspace = true, features = ["transpiling"] }
reqwest.workspace = true
tokio.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_v8.workspace = true
boa_engine.workspace = true
extism-pdk.workspace = true
serde_json.workspace = true

[build-dependencies]
deno_core.workspace = true
17 changes: 17 additions & 0 deletions crates/morphir-runtime-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use boa_engine::{Context, Source};
use extism_pdk::*;
use serde_json::Value;

#[plugin_fn]
pub fn jseval(code: String) -> FnResult<Json<Value>> {
// Instantiate the execution context
let mut context = Context::default();
let source = Source::from_bytes(code.as_bytes());

// Parse the source code
let result = context.eval(source).unwrap();
let json = result.to_json(&mut context).unwrap();

let json = Json(json);
Ok(json)
}
11 changes: 6 additions & 5 deletions crates/morphir-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ maintnance = { status = "actively-developer" }

[[bin]]
name = "morphirx"
path = "src/main"
path = "src/main.rs"

[lib]
name = "morphir_runtime"
path = "src/lib.rs"

[features]

[dependencies]
deno_core.workspace = true
deno_ast = { workspace = true, features = ["transpiling"] }
reqwest.workspace = true
tokio.workspace = true
boa_engine.workspace = true

[build-dependencies]
deno_core.workspace = true
23 changes: 0 additions & 23 deletions crates/morphir-runtime/build.rs

This file was deleted.

1 change: 1 addition & 0 deletions crates/morphir-runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

37 changes: 0 additions & 37 deletions crates/morphir-runtime/src/runtime.js

This file was deleted.

0 comments on commit 2513dcb

Please sign in to comment.