Skip to content

Commit

Permalink
Upgrade to QuickJS NG (#669)
Browse files Browse the repository at this point in the history
* Upgrade to QuickJS NG

* Update deps

* Remove comment

* Fix errors

* No need for opt-level 3 for tests

* Refactor child_process tests

* Revert to mimalloc

* Updated testrunner progress GUI

* Temporary disable custom allocator

* Revert remove allocator

* Add back opt level 3 for tests to try dealing with compiler error

* Trim text in test

* Update lockfile

* Update deps

* Change width

* Temporary disable spawn_tests in crate

* Dont spawn worker async

* Update deps

* Update test runner

* Fix precision issue

* Update
  • Loading branch information
richarddavison authored Nov 17, 2024
1 parent 151d4d7 commit 711b2df
Show file tree
Hide file tree
Showing 70 changed files with 452 additions and 398 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,18 @@ jobs:
platform: linux
arch: x86_64
toolchain: stable
- os: ubuntu-latest
platform: linux
arch: aarch64
toolchain: stable
- os: macos-latest
platform: darwin
arch: x86_64
toolchain: stable
- os: macos-latest
platform: darwin
arch: aarch64
toolchain: stable
- os: windows-latest
platform: windows
arch: x86_64
Expand Down
82 changes: 24 additions & 58 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ opt-level = 3
panic = "abort"

[profile.test]
opt-level = 3 #required for large number parsing
opt-level = 3
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ test-e2e: js
test-ci: export JS_MINIFY = 0
test-ci: export RUST_BACKTRACE = 1
test-ci: clean-js | toolchain js
cargo $(TOOLCHAIN) -Z build-std -Z build-std-features test --target $(CURRENT_TARGET) -- --nocapture --show-output
cargo $(TOOLCHAIN) -Z build-std -Z build-std-features test --target $(CURRENT_TARGET) -- --nocapture --show-output
cargo $(TOOLCHAIN) run -r --target $(CURRENT_TARGET) -- test -d bundle/js/__tests__/unit

libs-arm64: lib/arm64/libzstd.a lib/zstd.h
Expand Down
2 changes: 1 addition & 1 deletion libs/llrt_context/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "Apache-2.0"
repository = "https://github.com/awslabs/llrt"

[dependencies]
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "3af3f46b13eb89a2694e5e4e2e73924a20fa9dd1", features = [
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "2627859ac65c714e35d3232fa8c59b40668cfa7e", features = [
"futures",
], default-features = false }
tokio = { version = "1", features = ["sync"], default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion libs/llrt_json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ path = "src/lib.rs"
[dependencies]
itoa = "1"
llrt_utils = { version = "0.3.0-beta", path = "../llrt_utils", default-features = false }
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "3af3f46b13eb89a2694e5e4e2e73924a20fa9dd1", default-features = false }
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "2627859ac65c714e35d3232fa8c59b40668cfa7e", default-features = false }
ryu = "1"
simd-json = { version = "0.14", default-features = false, features = [
"big-int-as-float",
Expand Down
2 changes: 1 addition & 1 deletion libs/llrt_numbers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ path = "src/lib.rs"
[dependencies]
itoa = "1"
llrt_utils = { version = "0.3.0-beta", path = "../llrt_utils", default-features = false }
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "3af3f46b13eb89a2694e5e4e2e73924a20fa9dd1", default-features = false }
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "2627859ac65c714e35d3232fa8c59b40668cfa7e", default-features = false }
rand = "0.8"
ryu = "1"

Expand Down
3 changes: 2 additions & 1 deletion libs/llrt_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ path = "src/lib.rs"

[dependencies]
nanoid = "0.4.0"
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "3af3f46b13eb89a2694e5e4e2e73924a20fa9dd1", features = [
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "2627859ac65c714e35d3232fa8c59b40668cfa7e", features = [
"futures",
"parallel",
"loader",
], default-features = false }
rand = "0.8.5"
tokio = { version = "1", features = ["full"] }
25 changes: 24 additions & 1 deletion libs/llrt_test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::path::PathBuf;
use std::{
fs,
path::{Path, PathBuf},
};

use rquickjs::{
async_with,
function::IntoArgs,
loader::{BuiltinLoader, Resolver},
markers::ParallelSend,
module::{Evaluated, ModuleDef},
promise::MaybePromise,
Expand All @@ -16,9 +20,28 @@ pub async fn given_file(content: &str) -> PathBuf {
path
}

struct TestResolver;

impl Resolver for TestResolver {
fn resolve(&mut self, _ctx: &Ctx<'_>, base: &str, name: &str) -> Result<String> {
if !name.starts_with(".") {
return Ok(name.into());
}
let base = Path::new(base);
let combined_path = base.join(name);
Ok(fs::canonicalize(combined_path)
.unwrap()
.to_string_lossy()
.to_string())
}
}

pub async fn given_runtime() -> (AsyncRuntime, AsyncContext) {
let rt = AsyncRuntime::new().unwrap();
rt.set_loader((TestResolver,), (BuiltinLoader::default(),))
.await;
let ctx = AsyncContext::full(&rt).await.unwrap();

(rt, ctx)
}

Expand Down
2 changes: 1 addition & 1 deletion libs/llrt_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fs = ["tokio/fs"]
bytearray-buffer = ["tokio/sync"]

[dependencies]
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "3af3f46b13eb89a2694e5e4e2e73924a20fa9dd1", features = [
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "2627859ac65c714e35d3232fa8c59b40668cfa7e", features = [
"array-buffer",
], default-features = false }
tokio = { version = "1", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion libs/llrt_utils/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ where
Self::define(globals)?;
let custom_inspect_symbol =
Symbol::for_description(globals, CUSTOM_INSPECT_SYMBOL_DESCRIPTION)?;
if let Some(proto) = Class::<C>::prototype(globals.ctx().clone()) {
if let Some(proto) = Class::<C>::prototype(globals.ctx())? {
proto.prop(
custom_inspect_symbol,
Accessor::from(|this: This<Class<'js, C>>, ctx| this.borrow().custom_inspect(ctx)),
Expand Down
2 changes: 1 addition & 1 deletion llrt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tracing-core = "0.1.32"
tokio = { version = "1", features = ["full"] }

[target.'cfg(not(target_os = "windows"))'.dependencies]
snmalloc-rs = { version = "0.3.6", features = ["lto"] }
mimalloc = { version = "*" }

[[bin]]
name = "llrt"
Expand Down
5 changes: 4 additions & 1 deletion llrt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ use llrt_core::compiler::compile_file;

#[cfg(not(target_os = "windows"))]
#[global_allocator]
static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

// #[global_allocator]
// static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
Expand Down
15 changes: 8 additions & 7 deletions llrt_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ uncompressed = []
macro = ["rquickjs/macro"]
bindgen = ["rquickjs/bindgen"]

[package.metadata.patch.rquickjs-core]
version = "*"
patches = ["patches/promise-poll.patch"]
# [package.metadata.patch.rquickjs-core]
# version = "*"
# #patches = ["patches/promise-poll.patch"]
# patches = ["patches/promise-poll.patch"]

[patch.crates-io]
rquickjs-core = { path = "target/patch/rquickjs-core-0.6.2" }
# [patch.crates-io]
# rquickjs-core = { path = "target/patch/rquickjs-core-0.6.2" }

[dependencies]
llrt_context = { path = "../libs/llrt_context" }
Expand All @@ -30,7 +31,7 @@ chrono = { version = "0.4", default-features = false, features = ["std"] }
quick-xml = "0.37"
phf = "0.11"

rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "3af3f46b13eb89a2694e5e4e2e73924a20fa9dd1", features = [
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "2627859ac65c714e35d3232fa8c59b40668cfa7e", features = [
"full-async",
"parallel",
"rust-alloc",
Expand Down Expand Up @@ -82,7 +83,7 @@ md-5 = { version = "0.10" }
md-5 = { version = "0.10", features = ["asm"] }

[build-dependencies]
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "3af3f46b13eb89a2694e5e4e2e73924a20fa9dd1", features = [
rquickjs = { git = "https://github.com/DelSkayn/rquickjs.git", rev = "2627859ac65c714e35d3232fa8c59b40668cfa7e", features = [
"full-async",
"rust-alloc",
], default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion llrt_core/src/module_loader/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use std::{
borrow::Cow,
collections::HashMap,
env, fs,
env,
fs::{self},
path::{Path, PathBuf},
rc::Rc,
sync::Mutex,
Expand Down
4 changes: 1 addition & 3 deletions llrt_core/src/modules/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ impl ModuleDef for ConsoleModule {
}

fn evaluate<'js>(ctx: &Ctx<'js>, exports: &Exports<'js>) -> Result<()> {
Class::<Console>::register(ctx)?;

export_default(ctx, exports, |default| {
Class::<Console>::define(default)?;

Expand Down Expand Up @@ -954,7 +952,7 @@ fn get_dimensions(ctx: Ctx<'_>) -> Result<Array<'_>> {
Ok(array)
}

#[derive(rquickjs::class::Trace)]
#[derive(rquickjs::class::Trace, rquickjs::JsLifetime)]
#[rquickjs::class]
pub struct Console {}

Expand Down
Loading

0 comments on commit 711b2df

Please sign in to comment.