diff options
author | Aram Drevekenin <aram@poor.dev> | 2023-08-09 22:26:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-09 22:26:00 +0200 |
commit | 1bedfc90021558cb201695444107afe5bddd2c17 (patch) | |
tree | 38dd31b5ab112aa9b1c3a54edb07331013bf7d87 | |
parent | c3e140cb4b3c0897329bf07ee7f51e9fd402b3df (diff) |
feat(plugins): use protocol buffers for serializing across the wasm boundary (#2686)
* work
* almost done with command protobuffers
* done translating command data structures
* mid transferring of every command to protobuff command
* transferred plugin_command.rs, now moving on to shim.rs
* plugin command working with protobufs
* protobuffers in update
* protobuf event tests
* various TODOs and comments
* fix zellij-tile
* clean up prost deps
* remove version mismatch error
* fix panic
* some cleanups
* clean up event protobuffers
* clean up command protobuffers
* clean up various protobufs
* refactor protobufs
* update comments
* some transformation fixes
* use protobufs for workers
* style(fmt): rustfmt
* style(fmt): rustfmt
* chore(build): add protoc
* chore(build): authenticate protoc
47 files changed, 6045 insertions, 1072 deletions
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 76e38d3cf..2d8423260 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -30,6 +30,10 @@ jobs: options: -v ${{ github.workspace }}/target:/usr/src/zellij --name ssh steps: - uses: actions/checkout@v3 + - name: Install Protoc + uses: arduino/setup-protoc@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Add WASM target run: rustup target add wasm32-wasi - name: Install musl-tools diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 315968f62..8f8537dad 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,6 +48,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + - name: Install Protoc + uses: arduino/setup-protoc@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Install Rust uses: actions-rs/toolchain@v1 with: diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index cc0ee2ab9..19b95fd7a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -22,6 +22,11 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Install Protoc + uses: arduino/setup-protoc@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup toolchain run: rustup show - uses: Swatinem/rust-cache@v2 @@ -40,6 +45,10 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Install Protoc + uses: arduino/setup-protoc@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Setup toolchain run: rustup show - uses: Swatinem/rust-cache@v2 @@ -63,6 +72,10 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Install Protoc + uses: arduino/setup-protoc@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Setup toolchain run: rustup show - uses: Swatinem/rust-cache@v2 diff --git a/Cargo.lock b/Cargo.lock index 2e1439327..918d8a87b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -383,6 +383,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + +[[package]] name = "cache-padded" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1492,6 +1498,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" [[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] name = "itoa" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1837,6 +1852,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] +name = "multimap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" + +[[package]] name = "names" version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2153,6 +2174,16 @@ dependencies = [ ] [[package]] +name = "petgraph" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] name = "phf" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2298,6 +2329,16 @@ dependencies = [ ] [[package]] +name = "prettyplease" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" +dependencies = [ + "proc-macro2", + "syn 1.0.96", +] + +[[package]] name = "proc-macro-error" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2337,6 +2378,60 @@ dependencies = [ ] [[package]] +name = "prost" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" +dependencies = [ + "bytes", + "heck 0.4.0", + "itertools", + "lazy_static", + "log", + "multimap", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "regex", + "syn 1.0.96", + "tempfile", + "which", +] + +[[package]] +name = "prost-derive" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 1.0.96", +] + +[[package]] +name = "prost-types" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" +dependencies = [ + "prost", +] + +[[package]] name = "ptr_meta" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -4518,6 +4613,8 @@ dependencies = [ "notify-debouncer-full", "once_cell", "percent-encoding", + "prost", + "prost-build", "regex", "rmp-serde", "serde", diff --git a/default-plugins/fixture-plugin-for-tests/src/main.rs b/default-plugins/fixture-plugin-for-tests/src/main.rs index 074aa1a4d..fe8b034b9 100644 --- a/default-plugins/fixture-plugin-for-tests/src/main.rs +++ b/default-plugins/fixture-plugin-for-tests/src/main.rs @@ -22,13 +22,14 @@ impl<'de> ZellijWorker<'de> for TestWorker { fn on_message(&mut self, message: String, payload: String) { if message == "ping" { self.number_of_messages_received += 1; - post_message_to_plugin( - "pong".into(), - format!( + post_message_to_plugin(PluginMessage { + worker_name: None, + name: "pong".into(), + payload: format!( "{}, received {} messages", payload, self.number_of_messages_received ), - ); + }); } } } @@ -143,22 +144,30 @@ impl ZellijPlugin for State { start_or_reload_plugin(plugin_url) }, Key::Ctrl('g') => { - open_file(std::path::PathBuf::from("/path/to/my/file.rs").as_path()); + open_file(FileToOpen { + path: std::path::PathBuf::from("/path/to/my/file.rs"), + ..Default::default() + }); }, Key::Ctrl('h') => { - open_file_floating(std::path::PathBuf::from("/path/to/my/file.rs").as_path()); + open_file_floating(FileToOpen { + path: std::path::PathBuf::from("/path/to/my/file.rs"), + ..Default::default() + }); }, Key::Ctrl('i') => { - open_file_with_line( - std::path::PathBuf::from("/path/to/my/file.rs").as_path(), - 42, - ); + open_file(FileToOpen { + path: std::path::PathBuf::from("/path/to/my/file.rs"), + line_number: Some(42), + ..Default::default() + }); }, Key::Ctrl('j') => { - open_file_with_line_floating( - std::path::PathBuf::from("/path/to/my/file.rs").as_path(), - 42, - ); + open_file_floating(FileToOpen { + path: std::path::PathBuf::from("/path/to/my/file.rs"), + line_number: Some(42), + ..Default::default() + }); }, Key::Ctrl('k') => { open_terminal(std::path::PathBuf::from("/path/to/my/file.rs").as_path()); @@ -169,16 +178,18 @@ impl ZellijPlugin for State { ); }, Key::Ctrl('m') => { - open_command_pane( - std::path::PathBuf::from("/path/to/my/file.rs").as_path(), - vec!["arg1".to_owned(), "arg2".to_owned()], - ); + open_command_pane(CommandToRun { + path: std::path::PathBuf::from("/path/to/my/file.rs"), + args: vec!["arg1".to_owned(), "arg2".to_owned()], + ..Default::default() + }); }, Key::Ctrl('n') => { - open_command_pane_floating( - std::path::PathBuf::from("/path/to/my/file.rs").as_path(), - vec!["arg1".to_owned(), "arg2".to_owned()], - ); + open_command_pane_floating(CommandToRun { + path: std::path::PathBuf::from("/path/to/my/file.rs"), + args: vec!["arg1".to_owned(), "arg2".to_owned()], + ..Default::default() + }); }, Key::Ctrl('o') => { switch_tab_to(1); @@ -225,7 +236,11 @@ impl ZellijPlugin for State { }, Event::SystemClipboardFailure => { // this is just to trigger the worker message - post_message_to("test", "ping", "gimme_back_my_payload"); + post_message_to(PluginMessage { + worker_name: Some("test".into()), + name: "ping".into(), + payload: "gimme_back_my_payload".into(), + }); }, _ => {}, } diff --git a/default-plugins/strider/src/main.rs b/default-plugins/strider/src/main.rs index 35ff92ea7..e620930c0 100644 --- a/default-plugins/strider/src/main.rs +++ b/default-plugins/strider/src/main.rs @@ -31,16 +31,16 @@ impl ZellijPlugin for State { EventType::FileSystemUpdate, EventType::FileSystemDelete, ]); - post_message_to( - "file_name_search", - &serde_json::to_string(&MessageToSearch::ScanFolder).unwrap(), - "", - ); - post_message_to( - "file_contents_search", - &serde_json::to_string(&MessageToSearch::ScanFolder).unwrap(), - "", - ); + post_message_to(PluginMessage { + worker_name: Some("file_name_search".into()), + name: serde_json::to_string(&MessageToSearch::ScanFolder).unwrap(), + payload: "".into(), + }); + post_message_to(PluginMessage { + worker_name: Some("file_contents_search".into()), + name: serde_json::to_string(&MessageToSearch::ScanFolder).unwrap(), + payload: "".into(), + }); self.search_state.loading = true; set_timeout(0.5); // for displaying loading animation } @@ -191,48 +191,48 @@ impl ZellijPlugin for State { .iter() .map(|p| p.to_string_lossy().to_string()) .collect(); - post_message_to( - "file_name_search", - &serde_json::to_string(&MessageToSearch::FileSystemCreate).unwrap(), - &serde_json::to_string(&paths).unwrap(), - ); - post_message_to( - "file_contents_search", - &serde_json::to_string(&MessageToSearch::FileSystemCreate).unwrap(), - &serde_json::to_string(&paths).unwrap(), - ); + post_message_to(PluginMessage { + worker_name: Some("file_name_search".into()), + name: serde_json::to_string(&MessageToSearch::FileSystemCreate).unwrap(), + payload: serde_json::to_string(&paths).unwrap(), + }); + post_message_to(PluginMessage { + worker_name: Some("file_contents_search".into()), + name: serde_json::to_string(&MessageToSearch::FileSystemCreate).unwrap(), + payload: serde_json::to_string(&paths).unwrap(), + }); }, Event::FileSystemUpdate(paths) => { let paths: Vec<String> = paths .iter() .map(|p| p.to_string_lossy().to_string()) .collect(); - post_message_to( - "file_name_search", - &serde_json::to_string(&MessageToSearch::FileSystemUpdate).unwrap(), - &serde_json::to_string(&paths).unwrap(), - ); - post_message_to( - "file_contents_search", - &serde_json::to_string(&MessageToSearch::FileSystemUpdate).unwrap(), - &serde_json::to_string(&paths).unwrap(), - ); + post_message_to(PluginMessage { + worker_name: Some("file_name_search".into()), + name: serde_json::to_string(&MessageToSearch::FileSystemUpdate).unwrap(), + payload: serde_json::to_string(&paths).unwrap(), + }); + post_message_to(PluginMessage { + worker_name: Some("file_contents_search".into()), |