Skip to content

Commit

Permalink
feat(wasm-support): add wasm support (#351)
Browse files Browse the repository at this point in the history
Hi @Eugeny,

As mentioned in the previous pull request, it seems like you would
prefer a complete PR for the entire integration. Hence, I have merged
the previous two pull requests into one, containing the full
integration. Please take a look!

### Key Changes:
1. Introduced the `russh-util` crate, and sealed the runtime with
conditional compilation: **Tokio** for non-WASM, and **wasm-bindgen**
for WASM.
2. Sealed the time functionality in `russh-util`: using **std::time**
for non-WASM, and **chrono** for WASM.
3. Updated `cryptovec`, encapsulating the differences for `memset`,
`memcpy`, `mlock`, and `munlock` into separate files, gated behind
feature flags.
4. Conditionally excluded the `server` module from compiling for WASM.
If anyone needs it in the future, they can follow a similar approach to
the one I used.
5. Restructured the `known_hosts` module and gated it behind a
compilation flag, as the WASM environment typically lacks a file system.
6. Made various minor changes to the project structure to improve
maintainability.
7. Added `server`-specific `cfg` and `cfg_attr` attributes to handle
platform differences in usage.

Let me know if any further modifications are needed!

---------

Co-authored-by: Eugene <inbox@null.page>
  • Loading branch information
irvingoujAtDevolution and Eugeny authored Sep 23, 2024
1 parent 459544a commit d03df31
Show file tree
Hide file tree
Showing 28 changed files with 1,137 additions and 704 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ jobs:
with:
package: russh

Build-WASM:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install target
run: rustup target add wasm32-wasip1

- name: Build (all features enabled)
run: cargo build --verbose --target wasm32-wasip1 -p russh

Formatting:
runs-on: ubuntu-latest

Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["russh-keys", "russh", "russh-config", "cryptovec", "pageant"]
members = ["russh-keys", "russh", "russh-config", "cryptovec", "pageant", "russh-util"]
resolver = "2"

[patch.crates-io]
russh = { path = "russh" }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ This is a fork of [Thrussh](https://nest.pijul.com/pijul/thrussh) by Pierre-Éti
### Panics

* When the Rust allocator fails to allocate memory during a CryptoVec being resized.
* When `mlock`/`munlock` fails to protect sensitive data in memory.

### Unsafe code

Expand Down
3 changes: 3 additions & 0 deletions cryptovec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ libc = "0.2"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = {version = "0.3", features = ["basetsd", "minwindef", "memoryapi"]}

[dev-dependencies]
wasm-bindgen-test = "0.3"
Loading

0 comments on commit d03df31

Please sign in to comment.