Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Mailcatcher
minio
MVVM
NGRX
Napi
napi
OIDCS
Omnisharp
onboarded
Expand Down
116 changes: 116 additions & 0 deletions docs/getting-started/clients/desktop/desktop-native/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Desktop Native

Desktop Native (DN) is a Rust project that represents all of the native operating system logic used
in the Desktop client.

The DN code is effectively a library that is exposed to Electron via
[napi-rs](https://napi.rs/docs/introduction/getting-started). See [Napi](#napi) for more
information.

## Dependencies

1. [Rust](https://www.rust-lang.org/tools/install)
2. The nightly toolchain: `rustup toolchain install nightly`
3. Cargo binaries for pre-commit hooks
- [cargo-sort](https://crates.io/crates/cargo-sort)
- [cargo-udeps](https://crates.io/crates/cargo-udeps)
- [cargo-deny](https://crates.io/crates/cargo-deny)

## Compiling

To ensure the code will compile, a faster check than building binaries is to use `check`.

```
cargo check
```

The binary target can be built as well, however there is marginal gain from that since the
compilation as part of running the Desktop electron app will be building the executable code.

```
cargo build
```

## Checks

The following checks are run in CI and also as pre-commit hooks. They can also be run manually.

```
cargo +nightly fmt --check
```

```
cargo +nightly clippy --all-features --all-targets --tests -- -D warnings
```

## Automated testing

Tests are invoked in CI and can be ran manually with the below commands.

### Examples

Execute the unit and integration tests:

```
cargo test
```

Execute the only unit tests:

```
cargo test --lib
```

## Cross compiling

Since the Desktop client supports multiple platforms, much of the code is compile-time gated with
`cfg` flags. [Cross](https://crates.io/crates/cross) can be useful to check compilation of
non-native OS specific code.

```
cargo install cross --git https://github.com/cross-rs/cross
```

### Examples

Check compilation for Linux:

```
cross check --target x86_64-unknown-linux-gnu
```

Run `clippy` for Intel Macs:

```
cross clippy --target x86_64-apple-darwin --all-features --tests
```

Run unit tests for Windows:

```
cross test --lib --target x86_64-pc-windows-gnu
```

Run integration tests for Apple Silicon Macs:

```
cross --target aarch64-apple-darwin
```

## Napi

`napi-rs` provides an abstraction layer by wrapping the C API that Node.js exposes, in safe Rust
bindings. This enables development without having to manually write unsafe FFI.

Most feature crates in the DN workspace have a Napi layer in the project's
[napi](https://github.com/bitwarden/clients/tree/main/apps/desktop/desktop_native/napi/src) crate
source. This Napi layer is compiled as part of the normal build processes, and `napi` is a standard
crate dependency in the project's workspace.

::::note

In order to actually generate the bindings,
[building the Desktop client](../index.mdx#build-native-module) in the parent directory is
necessary.

::::
23 changes: 3 additions & 20 deletions docs/getting-started/clients/desktop/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,20 @@ import TabItem from "@theme/TabItem";

## Requirements

Before you start, you must complete the [Clients repository setup instructions](../index.md).
Before you start, you must complete the [Clients repository setup instructions](../index.md), as
well as install the [Desktop Native dependencies](./desktop-native/index.mdx#Dependencies).

<Tabs groupId="os">
<TabItem value="win" label="Windows" default>

These are available as additional dependencies in the Visual Studio Installer.

- Visual C++ Build tools
- [Rust](https://www.rust-lang.org/tools/install)
1. The nightly toolchain: `rustup toolchain install nightly`
2. Cargo binaries for pre-commit hooks
- [cargo-sort](https://crates.io/crates/cargo-sort)
- [cargo-udeps](https://crates.io/crates/cargo-udeps)
- [cargo-deny](https://crates.io/crates/cargo-deny)

</TabItem>
<TabItem value="mac" label="macOS">

- Xcode Command Line Tools
- [Rust](https://www.rust-lang.org/tools/install)
1. The nightly toolchain: `rustup toolchain install nightly`
2. Cargo binaries for pre-commit hooks
- [cargo-sort](https://crates.io/crates/cargo-sort)
- [cargo-udeps](https://crates.io/crates/cargo-udeps)
- [cargo-deny](https://crates.io/crates/cargo-deny)

</TabItem>
<TabItem value="lin" label="Linux">
Expand All @@ -42,12 +31,6 @@ These are available as additional dependencies in the Visual Studio Installer.
- `build-essential`
- `libsecret-1-dev`
- `libglib2.0-dev`
- [Rust](https://www.rust-lang.org/tools/install)
1. The nightly toolchain: `rustup toolchain install nightly`
2. Cargo binaries for pre-commit hooks
- [cargo-sort](https://crates.io/crates/cargo-sort)
- [cargo-udeps](https://crates.io/crates/cargo-udeps)
- [cargo-deny](https://crates.io/crates/cargo-deny)

</TabItem>
</Tabs>
Expand All @@ -69,7 +52,7 @@ For complete Nx documentation and all available commands, see

The desktop application relies on a native module written in rust, which needs to be compiled
separately. This is baked in to the build process for `npm run electron`, but you can also compile
it manually.
it manually. See [Desktop Native](./desktop-native/index.mdx) for more information.

```bash
cd apps/desktop/desktop_native/napi
Expand Down
Loading