Skip to content

Commit 5a1db80

Browse files
committed
Add Desktop Native getting started
1 parent 573020a commit 5a1db80

3 files changed

Lines changed: 121 additions & 20 deletions

File tree

‎custom-words.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Mailcatcher
4747
minio
4848
MVVM
4949
NGRX
50+
Napi
51+
napi
5052
OIDCS
5153
Omnisharp
5254
onboarded
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Desktop Native
2+
3+
Desktop Native (DN) is a Rust project that represents all of the native operating system logic used
4+
in the Desktop client.
5+
6+
The DN code is effectively a library that is exposed to Electron via
7+
[napi-rs](https://napi.rs/docs/introduction/getting-started). See [Napi](#napi) for more
8+
information.
9+
10+
## Dependencies
11+
12+
1. [Rust](https://www.rust-lang.org/tools/install)
13+
2. The nightly toolchain: `rustup toolchain install nightly`
14+
3. Cargo binaries for pre-commit hooks
15+
- [cargo-sort](https://crates.io/crates/cargo-sort)
16+
- [cargo-udeps](https://crates.io/crates/cargo-udeps)
17+
- [cargo-deny](https://crates.io/crates/cargo-deny)
18+
19+
## Compiling
20+
21+
To ensure the code will compile, a faster check than building binaries is to use `check`.
22+
23+
```
24+
cargo check
25+
```
26+
27+
The binary target can be built as well, however there is marginal gain from that since the
28+
compilation as part of running the Desktop electron app will be building the executable code.
29+
30+
```
31+
cargo build
32+
```
33+
34+
## Checks
35+
36+
The following checks are run in CI and also as pre-commit hooks. They can also be run manually.
37+
38+
```
39+
cargo +nightly fmt --check
40+
```
41+
42+
```
43+
cargo +nightly clippy --all-features --all-targets --tests -- -D warnings
44+
```
45+
46+
## Automated testing
47+
48+
Tests are invoked in CI and can be ran manually with the below commands.
49+
50+
### Examples
51+
52+
Execute the unit and integration tests:
53+
54+
```
55+
cargo test
56+
```
57+
58+
Execute the only unit tests:
59+
60+
```
61+
cargo test --lib
62+
```
63+
64+
## Cross compiling
65+
66+
Since the Desktop client supports multiple platforms, much of the code is compile-time gated with
67+
`cfg` flags. [Cross](https://crates.io/crates/cross) can be useful to check compilation of
68+
non-native OS specific code.
69+
70+
```
71+
cargo install cross --git https://github.com/cross-rs/cross
72+
```
73+
74+
### Examples
75+
76+
Check compilation for Linux:
77+
78+
```
79+
cross check --target x86_64-unknown-linux-gnu
80+
```
81+
82+
Run `clippy` for Intel Macs:
83+
84+
```
85+
cross clippy --target x86_64-apple-darwin --all-features --tests
86+
```
87+
88+
Run unit tests for Windows:
89+
90+
```
91+
cross test --lib --target x86_64-pc-windows-gnu
92+
```
93+
94+
Run integration tests for Apple Silicon Macs:
95+
96+
```
97+
cross --target aarch64-apple-darwin
98+
```
99+
100+
## Napi
101+
102+
`napi-rs` provides an abstraction layer by wrapping the C API that Node.js exposes, in safe Rust
103+
bindings. This enables development without having to manually write unsafe FFI.
104+
105+
Most feature crates in the DN workspace have a Napi layer in the project's
106+
[napi](https://github.com/bitwarden/clients/tree/main/apps/desktop/desktop_native/napi/src) crate
107+
source. This Napi layer is compiled as part of the normal build processes, and `napi` is a standard
108+
crate dependency in the project's workspace.
109+
110+
::::note
111+
112+
In order to actually generate the bindings,
113+
[building the Desktop client](../index.mdx#build-native-module) in the parent directory is
114+
necessary.
115+
116+
::::

‎docs/getting-started/clients/desktop/index.mdx‎

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,20 @@ import TabItem from "@theme/TabItem";
99

1010
## Requirements
1111

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

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

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

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

2722
</TabItem>
2823
<TabItem value="mac" label="macOS">
2924

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

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

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

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

7457
```bash
7558
cd apps/desktop/desktop_native/napi

0 commit comments

Comments
 (0)