-
-
Notifications
You must be signed in to change notification settings - Fork 27
feat/db-backend-wasm #389
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
feat/db-backend-wasm #389
Conversation
b243289 to
066265e
Compare
79aafc8 to
b47de00
Compare
src/db-backend/src/c_compat.rs
Outdated
| @@ -0,0 +1,280 @@ | |||
| #[cfg(feature = "browser-transport")] | |||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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_ | |||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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
|
PS: rust clippy fixes! |
e2d9228 to
58c139b
Compare
src/db-backend/src/transport.rs
Outdated
|
|
||
| impl DapTransport for BrowserTransport { | ||
| fn send(&mut self, msg: &DapMessage) -> Result<(), DapError> { | ||
| // 2) OR send as string (simpler, but pick one path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // 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"))?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| _ => Err(serde_json::Error::custom("Unknown DAP message type"))?, | |
| _ => Err(serde_json::Error::custom("Unknown DAP message type")), |
src/db-backend/src/dap_server.rs
Outdated
| // 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(()) | ||
| // } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // 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(()) | |
| // } |
src/db-backend/src/dap_server.rs
Outdated
| // 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) | ||
| // } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // 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) | |
| // } |
src/db-backend/src/dap_server.rs
Outdated
| // duration code copied from | ||
| // https://rust-lang-nursery.github.io/rust-cookbook/datetime/duration.html | ||
| let start = Instant::now(); | ||
| let _start = Instant::now(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let _start = Instant::now(); |
| #define le32toh(x) (x) | ||
| #define le64toh(x) (x) | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let blq = () => { | ||
| console.log(":((((("); | ||
| console.log("Sending message", req); | ||
| worker.postMessage(req); | ||
| } | ||
|
|
||
| (async () => { await workerPromise; blq() })() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)))))
src/db-backend/Cargo.toml
Outdated
| # 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" | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # clang |
| 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" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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" |
The build script will later be translated into a build.rs
…ing to separate dir
236237c to
4665e4d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great: thank you!
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):