Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit e290052

Browse files
vigoonoise64
andauthored
wasm-rquickjs integration (#289)
* JS templates for using wasm-rquickjs * Published deps * Generating d.ts * TS * Quick js and ts: up-to-date checks and template fixes * Make worker oplog streaming * wasm-rquickjs 0.0.4 * Fix * Fix * Fix * StubGen fix --------- Co-authored-by: Dávid István Bíró <[email protected]>
1 parent d9e24b3 commit e290052

File tree

98 files changed

+1549
-609
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1549
-609
lines changed

Cargo.lock

Lines changed: 546 additions & 441 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ axum = { version = "0.7.9", features = ["multipart"] }
3636
base64 = "0.22.1"
3737
blake3 = "1.5.5"
3838
bytes = "1.10.1"
39+
camino = "1.1.10"
3940
cargo-component = "0.21.1"
4041
cargo-component-core = "0.21.1"
4142
cargo_metadata = "0.20.0"
@@ -121,6 +122,7 @@ wax = "0.6.0"
121122
wasm-metadata = { version = "0.228", features = ["oci"] }
122123
wasmparser = "0.228.0"
123124
wasm-encoder = "0.228.0"
125+
wasm-rquickjs = "0.0.4"
124126
wit-bindgen-rust = "0.40.0"
125127
wit-component = "0.228"
126128
wit-encoder = "0.228"

Makefile.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ exec --fail-on-error cargo test --package golem-cli :tag:uses_cargo --test integ
153153
'''
154154

155155
[tasks.template-integration-tests]
156-
dependencies = ["install-golem-cli-debug"]
156+
dependencies = ["build"]
157157
description = "Run template integration tests"
158158
script_runner = "@duckscript"
159159
script = '''

golem-cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ auditable-serde = { version = "0.8.0" }
5050
base64 = { workspace = true }
5151
blake3 = { workspace = true }
5252
bytes = { workspace = true }
53+
camino = { workspace = true }
5354
cargo-component = { workspace = true }
5455
cargo-component-core = { workspace = true }
5556
cargo_toml = { workspace = true }
@@ -112,6 +113,7 @@ walkdir = { workspace = true }
112113
wax = { workspace = true }
113114
wasmparser = { workspace = true }
114115
wasm-encoder = { workspace = true }
116+
wasm-rquickjs = { workspace = true }
115117
wit-bindgen-rust = { workspace = true }
116118
wit-component = { workspace = true }
117119
wit-encoder = { workspace = true }

golem-cli/src/app/build/clean.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ pub fn clean_app(ctx: &ApplicationContext) -> anyhow::Result<()> {
5252

5353
for build_step in &properties.build {
5454
let build_dir = build_step
55-
.dir
56-
.as_ref()
55+
.dir()
5756
.map(|dir| {
5857
ctx.application
5958
.component_source_dir(component_name)
@@ -66,7 +65,7 @@ pub fn clean_app(ctx: &ApplicationContext) -> anyhow::Result<()> {
6665
});
6766

6867
paths.extend(
69-
compile_and_collect_globs(&build_dir, &build_step.targets)?
68+
compile_and_collect_globs(&build_dir, &build_step.targets())?
7069
.into_iter()
7170
.map(|path| ("build output", path)),
7271
);

golem-cli/src/app/build/external_command.rs renamed to golem-cli/src/app/build/command.rs

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::app::build::task_result_marker::{ResolvedExternalCommandMarkerHash, TaskResultMarker};
15+
use crate::app::build::task_result_marker::{
16+
GenerateQuickJSCrateCommandMarkerHash, GenerateQuickJSDTSCommandMarkerHash,
17+
ResolvedExternalCommandMarkerHash, TaskResultMarker,
18+
};
1619
use crate::app::build::{delete_path_logged, is_up_to_date, valid_env_vars};
1720
use crate::app::context::ApplicationContext;
1821
use crate::app::error::CustomCommandError;
1922
use crate::fs::compile_and_collect_globs;
2023
use crate::log::{log_action, log_skipping_up_to_date, LogColorize, LogIndent};
2124
use crate::model::app_raw;
2225
use anyhow::{anyhow, Context};
26+
use camino::Utf8Path;
2327
use std::collections::HashMap;
2428
use std::path::Path;
2529
use std::process::Command;
@@ -90,6 +94,111 @@ pub fn execute_custom_command(
9094
Ok(())
9195
}
9296

97+
pub fn execute_build_command(
98+
ctx: &ApplicationContext,
99+
base_build_dir: &Path,
100+
command: &app_raw::BuildCommand,
101+
additional_env_vars: HashMap<String, String>,
102+
) -> anyhow::Result<()> {
103+
match command {
104+
app_raw::BuildCommand::External(external_command) => {
105+
execute_external_command(ctx, base_build_dir, external_command, additional_env_vars)
106+
}
107+
app_raw::BuildCommand::QuickJSCrate(command) => {
108+
let base_build_dir = Utf8Path::from_path(base_build_dir).unwrap();
109+
let wit = base_build_dir.join(&command.wit);
110+
let js = base_build_dir.join(&command.js);
111+
let generate_quickjs_crate = base_build_dir.join(&command.generate_quickjs_crate);
112+
113+
let task_result_marker = TaskResultMarker::new(
114+
&ctx.application.task_result_marker_dir(),
115+
GenerateQuickJSCrateCommandMarkerHash {
116+
build_dir: base_build_dir.as_std_path(),
117+
command,
118+
},
119+
)?;
120+
121+
let skip_up_to_date_checks =
122+
ctx.config.skip_up_to_date_checks || !task_result_marker.is_up_to_date();
123+
124+
if is_up_to_date(
125+
skip_up_to_date_checks,
126+
|| {
127+
vec![
128+
wit.clone().into_std_path_buf(),
129+
js.clone().into_std_path_buf(),
130+
]
131+
},
132+
|| vec![generate_quickjs_crate.clone().into_std_path_buf()],
133+
) {
134+
log_skipping_up_to_date(format!(
135+
"executing WASM RQuickJS wrapper generator in directory {}",
136+
base_build_dir.log_color_highlight()
137+
));
138+
return Ok(());
139+
}
140+
141+
log_action(
142+
"Executing",
143+
format!(
144+
"WASM RQuickJS wrapper generator in directory {}",
145+
base_build_dir.log_color_highlight()
146+
),
147+
);
148+
149+
task_result_marker.result({
150+
wasm_rquickjs::generate_wrapper_crate(
151+
&wit,
152+
&js,
153+
&generate_quickjs_crate,
154+
command.world.as_deref(),
155+
)
156+
})
157+
}
158+
app_raw::BuildCommand::QuickJSDTS(command) => {
159+
let base_build_dir = Utf8Path::from_path(base_build_dir).unwrap();
160+
let wit = &base_build_dir.join(&command.wit);
161+
let generate_quickjs_dts = &base_build_dir.join(&command.generate_quickjs_dts);
162+
163+
let task_result_marker = TaskResultMarker::new(
164+
&ctx.application.task_result_marker_dir(),
165+
GenerateQuickJSDTSCommandMarkerHash {
166+
build_dir: base_build_dir.as_std_path(),
167+
command,
168+
},
169+
)?;
170+
171+
let skip_up_to_date_checks =
172+
ctx.config.skip_up_to_date_checks || !task_result_marker.is_up_to_date();
173+
174+
if is_up_to_date(
175+
skip_up_to_date_checks,
176+
|| vec![wit.clone().into_std_path_buf()],
177+
|| vec![generate_quickjs_dts.clone().into_std_path_buf()],
178+
) {
179+
log_skipping_up_to_date(format!(
180+
"executing WASM RQuickJS d.ts generator in directory {}",
181+
base_build_dir.log_color_highlight()
182+
));
183+
return Ok(());
184+
}
185+
186+
log_action(
187+
"Executing",
188+
format!(
189+
"WASM RQuickJS d.ts generator in directory {}",
190+
base_build_dir.log_color_highlight()
191+
),
192+
);
193+
194+
task_result_marker.result({
195+
wasm_rquickjs::generate_dts(wit, generate_quickjs_dts, command.world.as_deref())
196+
.context("Failed to generate QuickJS DTS")
197+
})
198+
}
199+
}
200+
}
201+
93202
pub fn execute_external_command(
94203
ctx: &ApplicationContext,
95204
base_build_dir: &Path,

golem-cli/src/app/build/componentize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::app::build::external_command::execute_external_command;
15+
use crate::app::build::command::execute_build_command;
1616
use crate::app::context::ApplicationContext;
1717
use crate::log::{log_action, log_warn_action, LogColorize, LogIndent};
1818
use crate::model::app::{AppComponentName, DependencyType};
@@ -52,7 +52,7 @@ pub fn componentize(ctx: &mut ApplicationContext) -> anyhow::Result<()> {
5252
.context("Failed to get env vars for build step")?;
5353

5454
for build_step in &component_properties.build {
55-
execute_external_command(
55+
execute_build_command(
5656
ctx,
5757
ctx.application.component_source_dir(&component_name),
5858
build_step,

golem-cli/src/app/build/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ use chrono::{DateTime, Utc};
2525
use std::cmp::Ordering;
2626
use std::collections::HashMap;
2727
use std::ffi::OsString;
28+
use std::fmt::Debug;
2829
use std::path::{Path, PathBuf};
2930
use std::time::SystemTime;
3031
use tracing::debug;
3132
use walkdir::WalkDir;
3233

3334
pub mod add_metadata;
3435
pub mod clean;
36+
pub mod command;
3537
pub mod componentize;
36-
pub mod external_command;
3738
pub mod gen_rpc;
3839
pub mod link;
3940
pub mod task_result_marker;
@@ -114,8 +115,8 @@ fn delete_path_logged(context: &str, path: &Path) -> anyhow::Result<()> {
114115

115116
fn is_up_to_date<S, T, FS, FT>(skip_check: bool, sources: FS, targets: FT) -> bool
116117
where
117-
S: IntoIterator<Item = PathBuf>,
118-
T: IntoIterator<Item = PathBuf>,
118+
S: Debug + IntoIterator<Item = PathBuf>,
119+
T: Debug + IntoIterator<Item = PathBuf>,
119120
FS: FnOnce() -> S,
120121
FT: FnOnce() -> T,
121122
{
@@ -167,6 +168,7 @@ where
167168
}
168169

169170
let targets = targets();
171+
debug!(targets=?targets, "collected targets");
170172

171173
let max_target_modified = max_modified_short_circuit_on_missing(targets);
172174

@@ -179,6 +181,7 @@ where
179181
};
180182

181183
let sources = sources();
184+
debug!(source=?sources, "collected sources");
182185

183186
let max_source_modified = max_modified_short_circuit_on_missing(sources);
184187

golem-cli/src/app/build/task_result_marker.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::app::build::task_result_marker::TaskResultMarkerHashSourceKind::{Hash
1616
use crate::fs;
1717
use crate::log::log_warn_action;
1818
use crate::model::app::{AppComponentName, DependentComponent};
19+
use crate::model::app_raw::{GenerateQuickJSCrate, GenerateQuickJSDTS};
1920
use crate::model::ProjectId;
2021
use crate::model::{app_raw, ComponentName};
2122
use anyhow::{anyhow, bail, Context};
@@ -92,6 +93,46 @@ impl TaskResultMarkerHashSource for ResolvedExternalCommandMarkerHash<'_> {
9293
}
9394
}
9495

96+
#[derive(Serialize)]
97+
pub struct GenerateQuickJSCrateCommandMarkerHash<'a> {
98+
pub build_dir: &'a Path,
99+
pub command: &'a GenerateQuickJSCrate,
100+
}
101+
102+
impl TaskResultMarkerHashSource for GenerateQuickJSCrateCommandMarkerHash<'_> {
103+
fn kind() -> &'static str {
104+
"GenerateQuickJSCrateCommandMarkerHash"
105+
}
106+
107+
fn id(&self) -> anyhow::Result<Option<String>> {
108+
Ok(None)
109+
}
110+
111+
fn source(&self) -> anyhow::Result<TaskResultMarkerHashSourceKind> {
112+
Ok(HashFromString(serde_json::to_string(self)?))
113+
}
114+
}
115+
116+
#[derive(Serialize)]
117+
pub struct GenerateQuickJSDTSCommandMarkerHash<'a> {
118+
pub build_dir: &'a Path,
119+
pub command: &'a GenerateQuickJSDTS,
120+
}
121+
122+
impl TaskResultMarkerHashSource for GenerateQuickJSDTSCommandMarkerHash<'_> {
123+
fn kind() -> &'static str {
124+
"GenerateQuickJSDTSCommandMarkerHash"
125+
}
126+
127+
fn id(&self) -> anyhow::Result<Option<String>> {
128+
Ok(None)
129+
}
130+
131+
fn source(&self) -> anyhow::Result<TaskResultMarkerHashSourceKind> {
132+
Ok(HashFromString(serde_json::to_string(self)?))
133+
}
134+
}
135+
95136
pub struct ComponentGeneratorMarkerHash<'a> {
96137
pub component_name: &'a AppComponentName,
97138
pub generator_kind: &'a str,

golem-cli/src/app/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use crate::app::build::build_app;
1616
use crate::app::build::clean::clean_app;
17-
use crate::app::build::external_command::execute_custom_command;
17+
use crate::app::build::command::execute_custom_command;
1818
use crate::app::error::{format_warns, AppValidationError, CustomCommandError};
1919
use crate::app::remote_components::RemoteComponents;
2020
use crate::config::ProfileName;

0 commit comments

Comments
 (0)