Skip to content

Commit

Permalink
chore(auraescript): upgrade deno
Browse files Browse the repository at this point in the history
  • Loading branch information
mccormickt committed Jun 25, 2024
1 parent ff384d6 commit 254b5cd
Show file tree
Hide file tree
Showing 14 changed files with 664 additions and 383 deletions.
936 changes: 601 additions & 335 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,17 @@
# ---------------------------------------------------------------------------- #

[workspace]
members = [
"aer",
"auraed",
"auraescript",
"client",
"ebpf-shared",
"proto",
]
exclude = [
"ebpf"
]
members = ["aer", "auraed", "auraescript", "client", "ebpf-shared", "proto"]
exclude = ["ebpf"]
resolver = "2"

[workspace.dependencies]
anyhow = "1.0.72"
chrono = { version = "0.4.26", default-features = false, features = ["clock", "std", "wasmbind"] } # default features except `oldtime`
chrono = { version = "0.4.26", default-features = false, features = [
"clock",
"std",
"wasmbind",
] } # default features except `oldtime`
client = { path = "./client" }
clap = { version = "4.3.21", features = ["derive"] }
fancy-regex = "0.11.0"
Expand All @@ -54,13 +49,16 @@ lazy_static = "1.4.0"
nix = "0.26.2"
proc-macro2 = "1.0"
proto = { path = "./proto" }
proto-reader = { path = "./crates/proto-reader" }
protobuf = "3.2.0"
protobuf-parse = "=3.2.0" # This crate makes no promises of stabilty, so we pin to the exact version
quote = "1.0"
serial_test = "1.0.0"
serde = "1.0.183"
serde_json = "1.0.104"
syn = { version = "1.0", features = ["full"] } # used in macros, so full doesn't affect binary size
syn = { version = "1.0", features = [
"full",
] } # used in macros, so full doesn't affect binary size
test-helpers = { path = "./crates/test-helpers" }
test-helpers-macros = { path = "./crates/test-helpers-macros" }
thiserror = "1.0.44"
Expand Down
7 changes: 4 additions & 3 deletions auraescript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ path = "src/bin/main.rs"
[dependencies]
anyhow = { workspace = true }
client = { workspace = true }
deno_ast = { version = "0.31.6", features = ["transpiling"] }
deno_runtime = { version = "0.138.0" }
deno_ast = { version = "0.38.2", features = ["transpiling"] }
deno_runtime = "0.161.0"
deno_core = "0.280.0"
macros = { package = "auraescript_macros", path = "./macros" }
proto = { workspace = true }
tokio = { workspace = true, features = ["fs", "rt-multi-thread"] }

[build-dependencies]
deno_runtime = "0.138.0"
deno_runtime = "0.161.0"
1 change: 1 addition & 0 deletions auraescript/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fn main() {
snapshot::create_runtime_snapshot(
"gen/runtime.bin".into(),
Default::default(),
Vec::new(),
)
}

Expand Down
4 changes: 2 additions & 2 deletions auraescript/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ heck = { workspace = true }
proc-macro2 = { workspace = true }
protobuf = "3.2.0"
protobuf-parse = { workspace = true }
proto-reader = { path = "../../crates/proto-reader" } # using workspace isn't working
proto-reader = { workspace = true }
quote = { workspace = true }
syn = { workspace = true }
syn = { workspace = true }
14 changes: 7 additions & 7 deletions auraescript/macros/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,25 @@ pub(crate) fn ops_generator(input: TokenStream) -> TokenStream {

// Magic OpState from deno (https://github.com/denoland/deno/blob/b6ac54815c1bcfa44a45b3f2c1c982829482477f/ops/lib.rs#L295)
quote! {
#[::deno_runtime::deno_core::op2(async)]
#[::deno_core::op2(async)]
#[serde]
pub(crate) async fn #op_ident(
op_state: Rc<RefCell<OpState>>, // Auto filled by deno macro, call from typescript ignoring this parameter
#[smi] client_rid: Option<::deno_runtime::deno_core::ResourceId>,
#[smi] client_rid: Option<::deno_core::ResourceId>,
#[serde] req: ::proto::#module::#input_type,
) -> std::result::Result<
::proto::#module::#output_type,
::anyhow::Error
> {
let client = match client_rid {
None => ::deno_runtime::deno_core::RcRef::new(::client::Client::default().await?),
None => ::deno_core::RcRef::new(::client::Client::default().await?),
Some(client_rid) => {
let as_client = {
let op_state = &op_state.borrow();
let rt = &op_state.resource_table; // get `ResourceTable` from JsRuntime `OpState`
rt.get::<crate::builtin::auraescript_client::AuraeScriptClient>(client_rid)?.clone() // get `Client` from its rid
};
::deno_runtime::deno_core::RcRef::map(as_client, |v| &v.0)
::deno_core::RcRef::map(as_client, |v| &v.0)
}
};
let res = ::client::#module::#service_name_in_snake_case::#client_ident::#name(
Expand All @@ -115,7 +115,7 @@ pub(crate) fn ops_generator(input: TokenStream) -> TokenStream {
// generate a OpDecl for each function for conveniently adding to the deno runtime
let op_decls: Vec<proc_macro2::TokenStream> = op_idents.map(|op_ident| {
quote! {
#op_ident::DECL
#op_ident()
}
}).collect();

Expand All @@ -128,11 +128,11 @@ pub(crate) fn ops_generator(input: TokenStream) -> TokenStream {

let expanded = quote! {
use ::std::{rc::Rc, cell::RefCell};
use ::deno_runtime::deno_core::{self, Op, OpState};
use ::deno_core::{self, op2, OpState};

#(#(#op_functions)*)*

pub(crate) fn op_decls() -> Vec<::deno_runtime::deno_core::OpDecl> {
pub(crate) fn op_decls() -> Vec<::deno_core::OpDecl> {
vec![#(#(#op_decls,)*)*]
}
};
Expand Down
2 changes: 1 addition & 1 deletion auraescript/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#![warn(clippy::unwrap_used)]

use auraescript::init;
use deno_runtime::deno_core::resolve_path;
use deno_core::resolve_path;
use std::env::current_dir;

#[tokio::main(flavor = "current_thread")]
Expand Down
14 changes: 8 additions & 6 deletions auraescript/src/builtin/auraescript_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(non_snake_case)]

use anyhow::Result;
use client::{AuraeConfig, Client};
use deno_runtime::deno_core::{self, op2, Op, OpState, Resource, ResourceId};
use deno_core::{self, op2, OpState, Resource, ResourceId};
use std::{cell::RefCell, rc::Rc};

// `AuraeConfig` `try_default`
Expand Down Expand Up @@ -64,12 +66,12 @@ pub(crate) async fn as__client_new(
Ok(rid)
}

pub(crate) fn op_decls() -> Vec<::deno_runtime::deno_core::OpDecl> {
pub(crate) fn op_decls() -> Vec<::deno_core::OpDecl> {
vec![
as__aurae_config__try_default::DECL,
as__aurae_config__from_options::DECL,
as__aurae_config__parse_from_file::DECL,
as__client_new::DECL,
as__aurae_config__try_default(),
as__aurae_config__from_options(),
as__aurae_config__parse_from_file(),
as__client_new(),
]
}

Expand Down
2 changes: 2 additions & 0 deletions auraescript/src/cells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
* *
\* -------------------------------------------------------------------------- */

#![allow(non_snake_case)]

macros::ops_generator!("../api/v0/cells/cells.proto", cells, CellService);
2 changes: 2 additions & 0 deletions auraescript/src/cri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* *
\* -------------------------------------------------------------------------- */

#![allow(non_snake_case)]

// TODO: macro doesn't support streaming. Does deno?
macros::ops_generator!(
"../api/cri/v1/release-1.26.proto",
Expand Down
2 changes: 2 additions & 0 deletions auraescript/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* *
\* -------------------------------------------------------------------------- */

#![allow(non_snake_case)]

macros::ops_generator!(
"../api/v0/discovery/discovery.proto",
discovery,
Expand Down
2 changes: 2 additions & 0 deletions auraescript/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* *
\* -------------------------------------------------------------------------- */

#![allow(non_snake_case)]

// TODO: macro doesn't support streaming. Does deno?
macros::ops_generator!(
"../api/grpc/health/v1/health.proto",
Expand Down
35 changes: 19 additions & 16 deletions auraescript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,18 @@
#![allow(unused_qualifications)]

use anyhow::{anyhow, bail, Error};
use deno_ast::{MediaType, ParseParams, SourceTextInfo};
use deno_ast::{EmitOptions, MediaType, ParseParams, SourceTextInfo};
use deno_core::{
self, error::AnyError, futures::FutureExt, resolve_import, url::Url,
ModuleLoadResponse, ModuleLoader, ModuleSource, ModuleSourceCode,
ModuleSpecifier, ModuleType, RequestedModuleType, ResolutionKind,
};
use deno_runtime::{
deno_core::{
self, error::AnyError, futures::FutureExt, resolve_import, url::Url,
FastString, ModuleLoader, ModuleSource, ModuleSourceCode,
ModuleSourceFuture, ModuleSpecifier, ModuleType, ResolutionKind,
Snapshot,
},
permissions::PermissionsContainer,
worker::{MainWorker, WorkerOptions},
BootstrapOptions, WorkerLogLevel,
};

use std::pin::Pin;
use std::rc::Rc;

mod builtin;
Expand All @@ -105,7 +103,7 @@ pub fn init(main_module: Url) -> MainWorker {
extensions: vec![auraescript::init_ops()],
module_loader: Rc::new(TypescriptModuleLoader),
get_error_class_fn: Some(&get_error_class_name),
startup_snapshot: Some(Snapshot::Static(RUNTIME_SNAPSHOT)),
startup_snapshot: Some(RUNTIME_SNAPSHOT),
bootstrap: BootstrapOptions {
args: vec![],
cpu_count: 1,
Expand All @@ -114,7 +112,6 @@ pub fn init(main_module: Url) -> MainWorker {
location: None,
log_level: WorkerLogLevel::Info,
no_color: false,
is_tty: false,
unstable: true,
user_agent: "".to_string(),
inspect: false,
Expand Down Expand Up @@ -164,9 +161,10 @@ impl ModuleLoader for TypescriptModuleLoader {
module_specifier: &ModuleSpecifier,
_maybe_referrer: Option<&ModuleSpecifier>,
_is_dyn_import: bool,
) -> Pin<Box<ModuleSourceFuture>> {
_requested_module_type: RequestedModuleType,
) -> ModuleLoadResponse {
let module_specifier = module_specifier.clone();
async move {
let future = async move {
let path = module_specifier
.to_file_path()
.map_err(|_| anyhow!("Only file: URLs are supported."))?;
Expand All @@ -192,25 +190,30 @@ impl ModuleLoader for TypescriptModuleLoader {
let code = std::fs::read_to_string(&path)?;
let code = if should_transpile {
let parsed = deno_ast::parse_module(ParseParams {
specifier: module_specifier.to_string(),
specifier: module_specifier.clone(),
text_info: SourceTextInfo::from_string(code),
media_type,
capture_tokens: false,
scope_analysis: false,
maybe_syntax: None,
})?;
parsed.transpile(&Default::default())?.text
parsed
.transpile(&Default::default(), &EmitOptions::default())?
.into_source()
.text
} else {
code
};
let module = ModuleSource::new_with_redirect(
module_type,
ModuleSourceCode::String(FastString::Owned(code.into())),
ModuleSourceCode::String(code.into()),
&module_specifier,
&module_specifier,
None,
);
Ok(module)
}
.boxed_local()
.boxed_local();
ModuleLoadResponse::Async(future)
}
}
2 changes: 2 additions & 0 deletions auraescript/src/observe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* *
\* -------------------------------------------------------------------------- */

#![allow(non_snake_case)]

macros::ops_generator!(
"../api/v0/observe/observe.proto",
observe,
Expand Down

0 comments on commit 254b5cd

Please sign in to comment.