Updated macOS build instructions

Signed-off-by: Nadahar <Nadahar@users.noreply.github.com>
This commit is contained in:
Nadahar 2024-04-07 01:02:08 +02:00
parent f4a275a6ea
commit ebbe9b002a
No known key found for this signature in database
GPG Key ID: 101C00449760763B

View File

@ -3,17 +3,119 @@ title: macOS
weight: 21
---
There are multiple ways to do this, this guide assumes that `Xcode`, `Git` and `Homebrew` are already installed.
The biggest challenge is probably to find versions of all the tools that work together, especially since parts of the toolchain like Xcode and LLVM are dictated by your macOS version. The versions used in this guide probably aren't what you should use. As a start to figure what versions to use is to look in the [GitHub build workflow](https://github.com/rustdesk/rustdesk/blob/master/.github/workflows/flutter-build.yml) for the RustDesk version you want to build (choose the tag for which to see the file in the upper left of the page), but that won't necessarily work because the macOS tools that comes with the GitHub runner might not be the same versions as those on your local system.
#### Exports
`export` is used to set various environmental variables. When you run `export`, that variable is set for the current terminal session only, and these must therefore be repeated for every new terminal window you want to use to build RustDesk, now and in the future. Generally, it's preferable to add all `export`s to a script that is executed automatically for every terminal that is opened, for example `~/.bash_profile`. The full `export` commands listed here can simply be appended to the file, but must also be run in the current terminal because the file isn't read until a *new* terminal is opened.
### Install the tools we're going to use from Homebrew
```bash
brew install python3 create-dmg nasm cmake ggc wget ninja pkg-config wget rustup
```
cd
Some of the installations might fail because some of the target folders don't exist on our system. In that case, create the folder, set owner and permissions and run the `brew` command again. Example if `/usr/local/include` doesn't exist:
```bash
sudo mkdir /usr/local/include
sudo chown <username>:admin /usr/local/include
sudo chmod 775 /usr/local/include
```
### Install vcpkg
Vcpkg is used to manage the C/C++ dependencies used by RustDesk. Decide where you want the installation and run the following from the folder in which you want the `vcpkg` folder to reside. In this example `/Users/<username>/repos/` is used as the location, and the tag `2023.04.15` is used as the version.
```bash
git clone https://github.com/microsoft/vcpkg
cd vcpkg
git checkout 2023.04.15
./bootstrap-vcpkg.sh
brew install nasm yasm
./bootstrap-vcpkg.sh -disableMetrics
./vcpkg install libvpx libyuv opus aom
git clone https://github.com/rustdesk/rustdesk
cd rustdesk
export VCPKG_ROOT=$HOME/vcpkg
wget https://github.com/c-smile/sciter-sdk/raw/master/bin.osx/libsciter.dylib
cargo run
export VCPKG_ROOT=~/repos/vcpkg
```
### Install and configure Rust
We use `rustup` to manage Rust, which was already installed above using Homebrew. But, it still needs to be configured. Follow the instructions and make sure both `rustup` and `rustc` are on the `PATH`. In this example we use Rust version `1.75.0`, but you might need to use a different version. You can install and manage multiple versions of Rust with `rustup`.
```bash
rustup-init
rustup default 1.75.0
rustup component add rustfmt
```
For an overview over installed and default Rust toolchains, run `rustup show`.
### Download the RustDesk source files
Decide where you want the RustDesk source files and run the following from the folder in which you want the `rustdesk` folder to reside. In this example `/Users/<username>/repos/` is used as the location.
```bash
git clone https://github.com/rustdesk/rustdesk
cd rustdesk/libs/portable/
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt
```
If `python3` or `pip` is unknown, add them to the `PATH` with something like (use your actual folder names):
```bash
export PATH=~/Library/Python/3.9/bin:$PATH
```
Once that's done (remember to also edit `~/.bash_profile`), run the failed command(s) again.
### Install user interface components
RustDesk can be built both using [Sciter](https://sciter.com/) and [Flutter](https://flutter.dev/). Both of these need additional components, so follow the steps for the relevant version, or both.
#### Sciter
From the `rustdesk` folder, run:
```bash
wget https://github.com/c-smile/sciter-sdk/raw/master/bin.osx/libsciter.dylib
```
#### Flutter
[FVM](https://fvm.app/) lets you manage which version of Flutter is used, and is probably the easiest way to be able to easily try different Flutter versions.
```bash
brew tap leoafarias/fvm
brew install fvm cocoapods
```
Install and use, for example Flutter `3.16.9`, with:
```bash
fvm global 3.16.9
```
FVM is meant to use a more complex setup where it can provide different Flutter versions for different projects, but that's beyond the scope of this guide. Instead, simply add the location of the default Flutter provided by FVM to your `PATH` manually, which means that you must use `fvm global` to switch Flutter version:
```bash
export PATH=$HOME/fvm/default/bin:$PATH
```
Once that is done, you should disable telemetry and check if everything is OK:
```bash
flutter --disable-analytics
dart --disable-analytics
flutter doctor -v
```
It doesn't matter if some of the checks fail, they usually will, what's important is that the check for the environment you intend to use is OK, namely "Xcode". If there are problems reported, address them before moving forward.
Once Flutter is up and running, it's time to install the "bridge" that binds Rust and Flutter together. Here is another one of the versions that much work together with everything else, in this example we use `1.80.1`:
```bash
cargo install flutter_rust_bridge_codegen --version "1.80.1" --features "uuid"
```
### Build
Build from the `rustdesk` folder. Build the Sciter version with:
```bash
python3 ./build.py
```
Build the Flutter version with:
```bash
flutter_rust_bridge_codegen --rust-input ./src/flutter_ffi.rs --dart-output ./flutter/lib/generated_bridge.dart --c-output ./flutter/macos/Runner/bridge_generated.h
python3 ./build.py --flutter
```
If everything goes well, you should now have a `dmg`file ready to install in your `rustdesk` folder.