Skip to content

Conversation

@SersemPeca
Copy link
Contributor

@SersemPeca SersemPeca commented Oct 3, 2025

This PR introduces a new abstraction over our communication layer and some new types for working with DAP.

(EDIT: an initial version of virtualized filesystem for the wasm case implemented in #400 by @SersemPeca : and merged into this PR as well)

resolving part of #339 (TODO #340)

TODOS: (alexander: in future PR-s):

  1. Use compression in wasm build

@SersemPeca SersemPeca changed the title feat/db-backend-wasm DRAFT:feat/db-backend-wasm Oct 3, 2025
@alehander92 alehander92 added enhancement New feature or request refactor A system was refactored db-backend wasm dap protocol labels Oct 3, 2025
@alehander92 alehander92 added this to the Stylus Milestone 4 milestone Oct 3, 2025
@SersemPeca SersemPeca requested a review from reo101 October 4, 2025 09:09
@SersemPeca SersemPeca force-pushed the feat/db-backend-wasm-poc branch from b243289 to 066265e Compare October 6, 2025 11:51
@SersemPeca SersemPeca changed the title DRAFT:feat/db-backend-wasm feat/db-backend-wasm Oct 6, 2025
@SersemPeca SersemPeca force-pushed the feat/db-backend-wasm-poc branch from 79aafc8 to b47de00 Compare October 6, 2025 15:12
@@ -0,0 +1,280 @@
#[cfg(feature = "browser-transport")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the rust/c compat code copied from existing compat layers/manually written or generated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of it is copied from already existing shims, we do have a couple of functions which I had to implement myself though

@@ -0,0 +1,171 @@
#ifndef TREE_SITTER_WASM_WCTYPE_H_
Copy link
Member

@alehander92 alehander92 Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are all those C/treesitter/sysroot files manual/custom, if not, what license are they, do they need attribution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are glibc header files

Copy link
Member

@alehander92 alehander92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, a few notes

@alehander92
Copy link
Member

PS: rust clippy fixes!

@SersemPeca SersemPeca force-pushed the feat/db-backend-wasm-poc branch 5 times, most recently from e2d9228 to 58c139b Compare October 7, 2025 15:23

impl DapTransport for BrowserTransport {
fn send(&mut self, msg: &DapMessage) -> Result<(), DapError> {
// 2) OR send as string (simpler, but pick one path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 2) OR send as string (simpler, but pick one path)

Some("response") => Ok(DapMessage::Response(serde_json::from_value(value)?)),
Some("event") => Ok(DapMessage::Event(serde_json::from_value(value)?)),
_ => Err(serde_json::Error::custom("Unknown DAP message type")),
_ => Err(serde_json::Error::custom("Unknown DAP message type"))?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ => Err(serde_json::Error::custom("Unknown DAP message type"))?,
_ => Err(serde_json::Error::custom("Unknown DAP message type")),

Comment on lines 39 to 55
// fn forward_raw_events<W: Write>(
// rx: &mpsc::Receiver<BackendResponse>,
// writer: &mut W,
// seq: &mut i64,
// ) -> Result<(), Box<dyn Error>> {
// while let Ok(BackendResponse::EventResponse((kind, _id, payload, raw))) = rx.try_recv() {
// if raw && matches!(kind, EventKind::MissingEventKind) {
// if let Ok(DapMessage::Event(mut ev)) = dap::from_json(&payload) {
// ev.base.seq = *seq;
// *seq += 1;
// dap::write_message(writer, &DapMessage::Event(ev))?;
// }
// }
// }
// Ok(())
// }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// fn forward_raw_events<W: Write>(
// rx: &mpsc::Receiver<BackendResponse>,
// writer: &mut W,
// seq: &mut i64,
// ) -> Result<(), Box<dyn Error>> {
// while let Ok(BackendResponse::EventResponse((kind, _id, payload, raw))) = rx.try_recv() {
// if raw && matches!(kind, EventKind::MissingEventKind) {
// if let Ok(DapMessage::Event(mut ev)) = dap::from_json(&payload) {
// ev.base.seq = *seq;
// *seq += 1;
// dap::write_message(writer, &DapMessage::Event(ev))?;
// }
// }
// }
// Ok(())
// }

Comment on lines 111 to 118
// pub fn run_stdio() -> Result<(), Box<dyn Error>> {
// let stdin = std::io::stdin();
// let stdout = std::io::stdout();
// let mut reader = BufReader::new(stdin.lock());
// let mut writer = stdout.lock();
// handle_client(&mut reader, &mut writer)
// }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// pub fn run_stdio() -> Result<(), Box<dyn Error>> {
// let stdin = std::io::stdin();
// let stdout = std::io::stdout();
// let mut reader = BufReader::new(stdin.lock());
// let mut writer = stdout.lock();
// handle_client(&mut reader, &mut writer)
// }

// duration code copied from
// https://rust-lang-nursery.github.io/rust-cookbook/datetime/duration.html
let start = Instant::now();
let _start = Instant::now();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let _start = Instant::now();

#define le32toh(x) (x)
#define le64toh(x) (x)


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines +38 to +44
let blq = () => {
console.log(":(((((");
console.log("Sending message", req);
worker.postMessage(req);
}

(async () => { await workerPromise; blq() })()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)))))

Comment on lines 72 to 74
# CPPFLAGS_wasm32_unknown_unknown = "--target=wasm32 --sysroot={cwd}/wasm-sysroot -isystem {cwd}/wasm-sysroot/include"
# CFLAGS_wasm32_unknown_unknown = "-I{cwd}/wasm-sysroot/include -DNDEBUG -Wbad-function-cast -Wcast-function-type -fno-builtin"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# CPPFLAGS_wasm32_unknown_unknown = "--target=wasm32 --sysroot={cwd}/wasm-sysroot -isystem {cwd}/wasm-sysroot/include"
# CFLAGS_wasm32_unknown_unknown = "-I{cwd}/wasm-sysroot/include -DNDEBUG -Wbad-function-cast -Wcast-function-type -fno-builtin"

rustup
binaryen
llvmPackages_21.clang-unwrapped
# clang
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# clang

Comment on lines 185 to 188
export CPPFLAGS_wasm32_unknown_unknown="--target=wasm32 --sysroot=$(pwd)/src/db-backend/wasm-sysroot -isystem $(pwd)/src/db-backend/wasm-sysroot/include"
export CFLAGS_wasm32_unknown_unknown="-I$(pwd)/src/db-backend/wasm-sysroot/include -DNDEBUG -Wbad-function-cast -Wcast-function-type -fno-builtin"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export CPPFLAGS_wasm32_unknown_unknown="--target=wasm32 --sysroot=$(pwd)/src/db-backend/wasm-sysroot -isystem $(pwd)/src/db-backend/wasm-sysroot/include"
export CFLAGS_wasm32_unknown_unknown="-I$(pwd)/src/db-backend/wasm-sysroot/include -DNDEBUG -Wbad-function-cast -Wcast-function-type -fno-builtin"
export CPPFLAGS_wasm32_unknown_unknown="--target=wasm32 --sysroot=$(pwd)/src/db-backend/wasm-sysroot -isystem $(pwd)/src/db-backend/wasm-sysroot/include"
export CFLAGS_wasm32_unknown_unknown="-I$(pwd)/src/db-backend/wasm-sysroot/include -DNDEBUG -Wbad-function-cast -Wcast-function-type -fno-builtin"

@SersemPeca SersemPeca force-pushed the feat/db-backend-wasm-poc branch from 236237c to 4665e4d Compare October 13, 2025 12:07
Copy link
Member

@alehander92 alehander92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great: thank you!

@alehander92 alehander92 merged commit ed610cf into main Oct 13, 2025
7 checks passed
@alehander92 alehander92 deleted the feat/db-backend-wasm-poc branch October 13, 2025 12:36
@github-actions github-actions bot locked and limited conversation to collaborators Oct 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

dap protocol db-backend enhancement New feature or request refactor A system was refactored wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants