Skip to content

Commit

Permalink
Merge pull request #2 from golemcloud/update-upstream-and-apply-fetch…
Browse files Browse the repository at this point in the history
…-rework

Update upstream and apply fetch rework
  • Loading branch information
noise64 authored Jun 14, 2024
2 parents 519256f + 75435d3 commit c27d60b
Show file tree
Hide file tree
Showing 31 changed files with 1,162 additions and 740 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ jobs:
with:
submodules: recursive

- name: Install Rust 1.68.2, 1.76.0
- name: Install Rust Toolchain
run: |
rustup toolchain install 1.68.2
rustup toolchain install 1.76.0
rustup target add wasm32-unknown-unknown --toolchain 1.76.0
rustup target add wasm32-wasi --toolchain 1.68.2
rustup toolchain install 1.77.1
rustup target add wasm32-wasi --toolchain 1.77.1
- uses: actions/setup-node@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "StarlingMonkey"]
path = StarlingMonkey
url = git@github.com:fermyon/StarlingMonkey
url = git@github.com:bytecodealliance/StarlingMonkey
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
JCO ?= ./node_modules/.bin/jco

ifndef JCO
JCO = $(error No jco in PATH. Run npm install -g @bytecodealliance/jco)
JCO = $(error No jco in PATH. Run npm install -g @golemcloud/jco)
endif

# ifndef WASM_OPT
Expand Down
2 changes: 1 addition & 1 deletion StarlingMonkey
Submodule StarlingMonkey updated 85 files
+47 −0 .github/workflows/main.yml
+5 −0 .gitignore
+10 −5 CMakeLists.txt
+49 −0 CODE_OF_CONDUCT.md
+27 −9 README.md
+2 −1 builtins/web/base64.cpp
+9 −5 builtins/web/console.cpp
+227 −6 builtins/web/crypto/crypto-algorithm.cpp
+3 −2 builtins/web/crypto/crypto-key.cpp
+64 −76 builtins/web/fetch/fetch-api.cpp
+150 −109 builtins/web/fetch/fetch_event.cpp
+3 −0 builtins/web/fetch/fetch_event.h
+499 −346 builtins/web/fetch/headers.cpp
+85 −20 builtins/web/fetch/headers.h
+231 −248 builtins/web/fetch/request-response.cpp
+76 −10 builtins/web/fetch/request-response.h
+7 −1 builtins/web/performance.cpp
+0 −11 builtins/web/streams/native-stream-source.cpp
+1 −2 builtins/web/streams/transform-stream.cpp
+3 −1 builtins/web/text-codec/text-encoder.cpp
+0 −3 builtins/web/timers.cpp
+5 −4 builtins/web/url.cpp
+77 −2 cmake/add_builtin.cmake
+0 −3 cmake/build-crates.cmake
+67 −40 cmake/builtins.cmake
+2 −2 cmake/openssl.cmake
+2 −2 cmake/spidermonkey.cmake
+1 −1 cmake/wasmtime.cmake
+62 −8 componentize.sh
+0 −1 crates/rust-encoding/.gitignore
+0 −34 crates/rust-encoding/Cargo.lock
+0 −17 crates/rust-encoding/Cargo.toml
+0 −54 crates/rust-encoding/cbindgen.toml
+0 −1 crates/rust-encoding/src/lib.rs
+11 −0 crates/rust-url/rust-url.h
+3 −0 deps/include/rust-encoding.h
+17 −5 host-apis/wasi-0.2.0-rc-2023-10-18/host_api.cpp
+14 −5 host-apis/wasi-0.2.0-rc-2023-12-05/host_api.cpp
+524 −249 host-apis/wasi-0.2.0/host_api.cpp
+64 −8 include/extension-api.h
+91 −45 include/host_api.h
+10 −0 runtime/decode.cpp
+10 −0 runtime/decode.h
+0 −1 runtime/encode.h
+104 −25 runtime/engine.cpp
+72 −24 runtime/event_loop.cpp
+13 −8 runtime/event_loop.h
+2 −39 runtime/js.cpp
+19 −0 runtime/log.h
+281 −54 runtime/script_loader.cpp
+4 −2 runtime/script_loader.h
+1 −1 rust-toolchain.toml
+1 −1 spin.toml
+46 −0 tests/e2e/smoke/expect_serve_body.txt
+0 −0 tests/e2e/smoke/expect_serve_stderr.txt
+2 −0 tests/e2e/smoke/expect_serve_stdout.txt
+0 −0 tests/e2e/smoke/nested-smoke-dependency.js
+1 −1 tests/e2e/smoke/smoke-dependency.js
+1 −1 tests/e2e/smoke/smoke.js
+0 −0 tests/e2e/syntax-err/expect_wizer_fail
+1 −0 tests/e2e/syntax-err/expect_wizer_stderr.txt
+1 −0 tests/e2e/syntax-err/syntax-err.js
+0 −0 tests/e2e/tla-err/expect_wizer_fail
+1 −0 tests/e2e/tla-err/expect_wizer_stderr.txt
+6 −0 tests/e2e/tla-err/tla-err.js
+1 −0 tests/e2e/tla-runtime-resolve/expect_serve_body.txt
+1 −0 tests/e2e/tla-runtime-resolve/expect_serve_stdout.txt
+18 −0 tests/e2e/tla-runtime-resolve/tla-runtime-resolve.js
+1 −0 tests/e2e/tla/expect_serve_body.txt
+10 −0 tests/e2e/tla/tla.js
+90 −0 tests/integration/assert.js
+378 −0 tests/integration/btoa/btoa.js
+2,028 −0 tests/integration/crypto/crypto.js
+157 −0 tests/integration/fetchsync/fetchsync.js
+6 −0 tests/integration/handlers.js
+282 −0 tests/integration/performance/performance.js
+72 −0 tests/integration/test-server.js
+285 −0 tests/integration/tests/performance.js
+586 −0 tests/integration/timers/timers.js
+128 −0 tests/test.sh
+43 −0 tests/tests.cmake
+10 −5 tests/wpt-harness/run-wpt.mjs
+1 −1 tests/wpt-harness/tests.json
+3 −2 tests/wpt-harness/wpt.cmake
+1 −1 tests/wpt-harness/wpt_builtins.cpp
10 changes: 8 additions & 2 deletions crates/spidermonkey-embedding-splicer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ fn parse_wit(path: &Path) -> Result<(Resolve, PackageId)> {
}

impl Guest for SpidermonkeyEmbeddingSplicerComponent {
fn stub_wasi(wasm: Vec<u8>, features: Vec<Features>) -> Result<Vec<u8>, String> {
stub_wasi(wasm, features).map_err(|e| e.to_string())
fn stub_wasi(
wasm: Vec<u8>,
features: Vec<Features>,
wit_source: Option<String>,
wit_path: Option<String>,
world_name: Option<String>,
) -> Result<Vec<u8>, String> {
stub_wasi(wasm, features, wit_source, wit_path, world_name).map_err(|e| e.to_string())
}

fn splice_bindings(
Expand Down
88 changes: 25 additions & 63 deletions crates/spidermonkey-embedding-splicer/src/splice.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
use walrus::{
ir::{
BinaryOp, Binop, Const, Instr, LoadKind, LocalGet, LocalSet, LocalTee, MemArg, Store,
StoreKind, UnaryOp, Unop, Value,
},
ir::{BinaryOp, Binop, Const, Instr, LoadKind, MemArg, Store, StoreKind, UnaryOp, Unop, Value},
ExportId, ExportItem, FunctionBuilder, FunctionId, LocalId, ValType,
};

use crate::*;

const DEBUG: bool = false;

//
// Parses the Spidermonkey binary into section data for reserialization
// into an output binary, and in the process:
Expand Down Expand Up @@ -39,10 +34,7 @@ pub fn splice(
exports: Vec<(String, CoreFn)>,
debug: bool,
) -> Result<Vec<u8>> {
let mut config = walrus::ModuleConfig::new();
if debug {
config.generate_dwarf(true);
}
let config = walrus::ModuleConfig::new();
let mut module = config.parse(&engine)?;

// since StarlingMonkey implements CLI Run and incoming handler,
Expand Down Expand Up @@ -76,7 +68,7 @@ pub fn splice(
// extract the native instructions from sample functions
// then inline the imported functions and main import gating function
// (erasing sample functions in the process)
synthesize_import_functions(&mut module, &imports)?;
synthesize_import_functions(&mut module, &imports, debug)?;

// create the exported functions as wrappers around the "cabi_call" function
synthesize_export_functions(&mut module, &exports)?;
Expand All @@ -94,6 +86,7 @@ fn get_export_fid(module: &walrus::Module, expt_id: &ExportId) -> FunctionId {
fn synthesize_import_functions(
module: &mut walrus::Module,
imports: &Vec<(String, String, CoreFn, Option<i32>)>,
debug: bool,
) -> Result<()> {
let mut coreabi_get_import: Option<ExportId> = None;
let mut cabi_realloc: Option<ExportId> = None;
Expand All @@ -116,8 +109,26 @@ fn synthesize_import_functions(

let cabi_realloc_fid = get_export_fid(module, &cabi_realloc.unwrap());

let coreabi_sample_fid = get_export_fid(module, coreabi_sample_ids.first().unwrap());
let coreabi_sample_i32 = module.funcs.get(coreabi_sample_fid).kind.unwrap_local();
let coreabi_sample_i32 = module
.funcs
.get(get_export_fid(module, &coreabi_sample_ids[0]))
.kind
.unwrap_local();
let _coreabi_sample_i64 = module
.funcs
.get(get_export_fid(module, &coreabi_sample_ids[1]))
.kind
.unwrap_local();
let _coreabi_sample_f32 = module
.funcs
.get(get_export_fid(module, &coreabi_sample_ids[2]))
.kind
.unwrap_local();
let _coreabi_sample_f64 = module
.funcs
.get(get_export_fid(module, &coreabi_sample_ids[3]))
.kind
.unwrap_local();

// These functions retrieve the corresponding type
// from a JS::HandleValue
Expand Down Expand Up @@ -179,7 +190,7 @@ fn synthesize_import_functions(
let tmp_local = module.locals.add(ValType::I64);

for (impt_specifier, impt_name, impt_sig, retptr_size) in imports.iter() {
if DEBUG {
if debug {
println!(
"> IMPORT {} {} > {:?}",
impt_specifier, impt_name, &impt_sig
Expand Down Expand Up @@ -226,55 +237,6 @@ fn synthesize_import_functions(

let mut func_body = func.func_body();

// copy the prelude instructions from the sample function (first block)
let coreabi_sample_i32 = module.funcs.get(coreabi_sample_fid).kind.unwrap_local();
let prelude_block = &coreabi_sample_i32
.block(coreabi_sample_i32.entry_block())
.instrs[0]
.0;
let prelude_seq = match prelude_block {
Instr::Block(prelude_block) => prelude_block.seq,
_ => {
eprintln!("Splicer error: unable to read prelude sequence, continuing for debug build but note binding functions will not work!");
return Ok(());
}
};

let prelude_block = coreabi_sample_i32.block(prelude_seq);
func_body.block(None, |prelude| {
for (instr, _) in &prelude_block.instrs {
match instr {
Instr::LocalGet(LocalGet { local }) => {
if local.eq(&vp_arg) {
prelude.instr(instr.clone());
} else {
prelude.local_get(tmp_local);
}
}
Instr::LocalSet(LocalSet { local }) => {
if local.eq(&vp_arg) {
prelude.instr(instr.clone());
} else {
prelude.local_set(tmp_local);
}
}
Instr::LocalTee(LocalTee { local }) => {
if local.eq(&vp_arg) {
prelude.instr(instr.clone());
} else {
prelude.local_tee(tmp_local);
}
}
Instr::BrIf(_) => {
prelude.br_if(prelude.id());
}
_ => {
prelude.instr(instr.clone());
}
};
}
});

// stack the return arg now as it chains with the
// args we're about to add to the stack
if impt_sig.ret.is_some() {
Expand Down
Loading

0 comments on commit c27d60b

Please sign in to comment.