Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update upstream and apply fetch rework #2

Merged
merged 42 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1666b96
deps: update to latest starlingmonkey
guybedford May 28, 2024
105096f
fixup splicing
guybedford May 29, 2024
7cf3552
latest starlingmonkey
guybedford May 29, 2024
8a8b7a9
update rust toolchain
guybedford May 29, 2024
2b79e0d
fixup tests
guybedford May 29, 2024
d1e48b3
workflow fix
guybedford May 29, 2024
9ece1e4
fix tests
guybedford May 29, 2024
d166aa1
try latest merge
guybedford May 29, 2024
7f7d4b5
latest
guybedford May 30, 2024
e12ec9e
fixup
guybedford May 30, 2024
63e3453
do not stub imports that are part of the target world (#109)
karthik2804 May 30, 2024
3023028
test with update-upstream-and-apply-fetch-rework starling
noise64 Jun 3, 2024
aaef119
update StarlingMonkey
noise64 Jun 4, 2024
544b4ed
use the Bytecode Alliance org repository for StarlingMonkey (#115)
karthik2804 Jun 4, 2024
1c92d24
deps: update to latest starlingmonkey
guybedford May 28, 2024
1a0c843
fixup splicing
guybedford May 29, 2024
510f96d
latest starlingmonkey
guybedford May 29, 2024
9d6e84e
update rust toolchain
guybedford May 29, 2024
3323f11
fixup tests
guybedford May 29, 2024
0c4ff50
workflow fix
guybedford May 29, 2024
39bb48c
fix tests
guybedford May 29, 2024
566ff29
try latest merge
guybedford May 29, 2024
816b513
latest
guybedford May 30, 2024
dd37c60
fixup
guybedford May 30, 2024
d65e34d
latest
guybedford Jun 4, 2024
90ec48e
add fetch test
guybedford Jun 4, 2024
926022d
Merge remote-tracking branch 'upstream/wip-latest-starlingmonkey' int…
noise64 Jun 5, 2024
1a05680
update StarlingMonkey
noise64 Jun 10, 2024
102c88b
update StarlingMonkey
noise64 Jun 12, 2024
fd6ce0c
add fetch-sync test runner + some tests
noise64 Jun 12, 2024
5def551
increase loop count guard + more fetch sync tests
noise64 Jun 12, 2024
f042888
update StarlingMonkey, use runEventLoopUntilInterest() without loops
noise64 Jun 12, 2024
f20a43c
added test case for patch call with body
noise64 Jun 12, 2024
56391a4
update StarlingMonkey
noise64 Jun 13, 2024
775a58c
remove custom test filter
noise64 Jun 13, 2024
25ae60c
cleanups / patch text tests
noise64 Jun 13, 2024
16a79da
update globals test
noise64 Jun 13, 2024
4a783bb
add fetch-sync tests for array buffer / text
noise64 Jun 13, 2024
4c5e192
cleanup
noise64 Jun 13, 2024
9741f63
change package json for golem npm publish
noise64 Jun 13, 2024
cdfca05
use golem fork jco
noise64 Jun 14, 2024
75435d3
bump version
noise64 Jun 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading