Windows10系统中从源码编译rustdesk

引子

记录笔者在 Windows 10 下编译 rustdesk 的过程及编译成功的经验分享。这里不讲它的好,也不说它多么牛逼,没有源码讲解、没有架构分析,只是出于一个萌新的好奇,一时的心动,就想动手来编译试试。 那么现在开始吧,都是建立在 rust 已经安装好的情况下。

准备

这里笔者将所有的源码都 clone 在 E:\work\gitwork 目录。

# 安装 vcpkg
git clone https://github.com/microsoft/vcpkg.git
.\vcpkg\bootstrap-vcpkg.bat

# 配置 VCPKG_ROOT 环境变量。vcpkg 编译后,会在源代码目录生成 vcpkg.exe 文件,指向那个目录就可以了
VCPKG_ROOT = E:\work\gitwork\vcpkg

# 安装编译相关依赖
vcpkg install libvpx:x64-windows-static libyuv:x64-windows-static opus:x64-windows-static

# 安装 llvm,下载地址
https://prereleases.llvm.org/win-snapshots/LLVM-12.0.0-6923b0a7-win64.exe

# clone rustdesk 源码
https://github.com/rustdesk/rustdesk.git

# 创建 target\debug 目录,下载 sciter.dll 放到 debug 目录下,下载地址
https://raw.githubusercontent.com/c-smile/sciter-sdk/master/bin.win/x64/sciter.dll

特别提醒:

  1. 在安装 vcpkg 的时候一定要记得配置环境变量。如果不配置可能出现 错误[1]。
  2. 在安装 llvm 的时候,一定要勾选环境变量配置,“Add LLVM to the system PATH for all users”,如果忘记选了,可以重新安装。如果不配置可能出现 错误[2]、错误[3]。
  3. 要提前将 sciter.dll 文件放到 target\debug 文件夹下,否则可能出现 错误[4]。

编译运行

# 到 rustdek 源码根目录,编译运行
cargo run

rustdesk

错误

[1]

error: failed to run custom build command for `magnum-opus v0.3.4-2 (https://github.com/open-trade/magnum-opus#ad083616)`

Caused by:
  process didn't exit successfully: `E:\work\gitwork\rustdesk\target\debug\build\magnum-opus-113a3842d93bb866\build-script-build` (exit code: 101)
  --- stdout
  cargo:info=x64-windows-static
  cargo:rustc-link-lib=static=opus
  cargo:rustc-link-search=E:\work\gitwork\vcpkg\installed\x64-windows-static\lib
  cargo:include=E:\work\gitwork\vcpkg\installed\x64-windows-static\include
  rerun-if-changed=C:\Users\win10\.cargo\git\checkouts\magnum-opus-7580b098b18e2bc5\ad08361\opus_ffi.h
  rerun-if-changed=E:\work\gitwork\vcpkg\installed\x64-windows-static\include

  --- stderr
  thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"', C:\Users\win10\.cargo\registry\src\mirrors.ustc.edu.cn-61ef6e0cd06fb9b8\bindgen-0.59.1\src/lib.rs:2117:31
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

[2]

error: failed to run custom build command for `magnum-opus v0.3.4-2 (https://github.com/open-trade/magnum-opus#ad083616)`

Caused by:
  process didn't exit successfully: `E:\work\gitwork\rustdesk\target\debug\build\magnum-opus-113a3842d93bb866\build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NotPresent', C:\Users\win10\.cargo\git\checkouts\magnum-opus-7580b098b18e2bc5\ad08361\build.rs:7:50
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

[3]

error: failed to run custom build command for `scrap v0.5.0 (E:\work\gitwork\rustdesk\libs\scrap)`

Caused by:
  process didn't exit successfully: `E:\work\gitwork\rustdesk\target\debug\build\scrap-6fb609a91970fd74\build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NotPresent', libs\scrap\build.rs:7:50
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

[4]

[2021-11-20T03:17:35Z INFO  rustdesk::server] server not started (will try to start): 系统找不到指定的文件。 (os error 2)
thread 'main' panicked at 'error: 'sciter.dll' was not found neither in PATH nor near the current executable.
  Please verify that Sciter SDK is installed and its binaries (from SDK/bin/64) are available in PATH.', C:\Users\win10\.cargo\git\checkouts\rust-sciter-06aa50f9c0fcf3d6\4cd10f9\src/lib.rs:215:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\rustdesk.exe` (exit code: 101)

本博客采用 知识共享署名-禁止演绎 4.0 国际许可协议 进行许可

本文标题:Windows10系统中从源码编译rustdesk

本文地址:https://jizhong.plus/post/2021/11/rustdesk-window10-build.html