Skip to content

Commit

Permalink
Migrate to wasm component (#356)
Browse files Browse the repository at this point in the history
* Cleaned javy and wizen the input js file

* Update wizer and compatible wasmtime

* wizen input js file and optimize it with binaryen

* Migrate Guest(wasm engine) to component model and support hono

* Migrate Host(serve runtime) to component model and support hono

* Minor change in build.js for ec-wasm-js example

* Move apis crate to apis folder in arakoo-core

* Implemented fetch in component model

* Added jsonnet wit file

* Added jsonnet binding in component model

* Added Event fetch event listener for Hono

* programmatically adapt module to component in compiler

* Log messages on the basis of env variables
  • Loading branch information
redoC-A2k authored May 29, 2024
1 parent ca4ec1b commit 41966c4
Show file tree
Hide file tree
Showing 65 changed files with 1,739 additions and 2,292 deletions.
14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[workspace]
members = [
"JS/wasm/crates/apis",
"JS/wasm/crates/arakoo-core",
"JS/wasm/crates/cli",
"JS/wasm/crates/serve",
Expand All @@ -13,15 +12,20 @@ edition = "2021"
version = "0.0.1"

[workspace.dependencies]
wizer = "4.0.0"
wasmtime = "16"
wasmtime-wasi = "16"
wasi-common = "16"
wizer = "6.0.0"
wasmtime = { features = ["async"], version = "19" }
wasmtime-wasi = "19"
javy = { version = "2.1.0" }
anyhow = "1.0.79"
once_cell = "1.19.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_bytes = "0.11"
http = "1.1.0"
reqwest = { version = "0.12.4", features = [
"blocking","json"
] }

[profile.release]
lto = true
opt-level = 's'
Expand Down
35 changes: 23 additions & 12 deletions JS/jsonnet/src/jsonnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (!isArakoo) {
jsonnet_evaluate_snippet,
jsonnet_destroy,
jsonnet_make,
ext_string,
jsonnet_ext_string,
jsonnet_evaluate_file,
get_func,
set_func,
Expand All @@ -24,7 +24,7 @@ if (!isArakoo) {
}

extString(key, value) {
ext_string(this.vm, key, value);
jsonnet_ext_string(this.vm, key, value);
return this;
}

Expand Down Expand Up @@ -55,24 +55,35 @@ if (!isArakoo) {
};
} else {
Jsonnet = class Jsonnet {
constructor() {
this.vars = {};
constructor() {}

#getVm() {
if (!this.vm) {
this.vm = __jsonnet_make();
}
return this.vm;
}

evaluateSnippet(snippet) {
let vm = this.#getVm();
return __jsonnet_evaluate_snippet(vm, snippet);
}

extString(key, value) {
this.vars[key] = value;
let vm = this.#getVm();
__jsonnet_ext_string(vm, key, value);
return this;
}
evaluateSnippet(snippet) {
let vars = JSON.stringify(this.vars);
return __jsonnet_evaluate_snippet(vars, snippet);
}

evaluateFile(filename) {
let vars = JSON.stringify(this.vars);
return __jsonnet_evaluate_file(vars, filename);
let vm = this.#getVm();
return __jsonnet_evaluate_file(vm, filename);
}

destroy() {}
destroy() {
let vm = this.#getVm();
__jsonnet_destroy(vm);
}
};
}

Expand Down
56 changes: 28 additions & 28 deletions JS/jsonnet/src/jsonnet_wasm.d.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
/* tslint:disable */
/* eslint-disable */
/**
* @returns {number}
*/
* @returns {number}
*/
export function jsonnet_make(): number;
/**
* @param {number} vm
*/
* @param {number} vm
*/
export function jsonnet_destroy(vm: number): void;
/**
* @param {number} vm
* @param {string} filename
* @param {string} snippet
* @returns {string}
*/
* @param {number} vm
* @param {string} filename
* @param {string} snippet
* @returns {string}
*/
export function jsonnet_evaluate_snippet(vm: number, filename: string, snippet: string): string;
/**
* @param {number} vm
* @param {string} filename
* @returns {string}
*/
* @param {number} vm
* @param {string} filename
* @returns {string}
*/
export function jsonnet_evaluate_file(vm: number, filename: string): string;
/**
* @param {number} vm
* @param {string} key
* @param {string} value
*/
export function ext_string(vm: number, key: string, value: string): void;
* @param {number} vm
* @param {string} key
* @param {string} value
*/
export function jsonnet_ext_string(vm: number, key: string, value: string): void;
/**
* @param {string} name
* @returns {Function | undefined}
*/
* @param {string} name
* @returns {Function | undefined}
*/
export function get_func(name: string): Function | undefined;
/**
* @param {string} name
* @param {Function} func
*/
* @param {string} name
* @param {Function} func
*/
export function set_func(name: string, func: Function): void;
/**
* @param {number} vm
* @param {string} name
* @param {number} args_num
*/
* @param {number} vm
* @param {string} name
* @param {number} args_num
*/
export function register_native_callback(vm: number, name: string, args_num: number): void;
Loading

0 comments on commit 41966c4

Please sign in to comment.