Rust on Windows CMake 问题

Rust on Windows CMake issue

我已经在我的 PC (Windows 10 Pro) 上使用 rustup-init.exe 安装了 Rust,然后安装了 Microsoft Visual C++ Build Tools 2017 和用于 CMake 选项的 Visual C++ 工具。

简单的例子没有问题:

fn main() {
   println!("Hello world!");
}

我执行了 cargo run 命令,结果我得到了预期的 Hello world!


但是现在我想去看看Azul GUI framework

main.rs

extern crate azul;

fn main() {
   println!("Hello world!");
}

Cargo.toml

[package]
name = "my_first_azul_app"
version = "0.1.0"
authors = ["Author"]
edition = "2018"

[dependencies]
azul = { git = "https://github.com/maps4print/azul" }

当我执行cargo run命令时发生错误:

...

error: failed to run custom build command for `harfbuzz-sys v0.3.0 (https://github.com/maps4print/azul-dependencies?rev=c1548977fb62399f39aa642d2e7e24a24a25246e#c1548977)`
process didn't exit successfully: `C:\Users\admin\Documents\Rust\Projects\my_first_azul_app\target\debug\build\harfbuzz-sys-37196527d1c78dd0\build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=HARFBUZZ_SYS_NO_PKG_CONFIG
running: "cmake" "C:\Users\admin\.cargo\git\checkouts\azul-dependencies-70bb1f94316762f9\c154897\harfbuzz-sys-0.3.0\harfbuzz" "-G" "Visual Studio 15 2017 Win64" "-Thost=x64" "-DCMAKE_INSTALL_PREFIX=C:\Users\admin\Documents\Rust\Projects\my_first_azul_app\target\debug\build\harfbuzz-sys-9193f770b45e8642\out" "-DCMAKE_C_FLAGS= /nologo /MD" "-DCMAKE_C_FLAGS_DEBUG= /nologo /MD" "-DCMAKE_CXX_FLAGS= /nologo /MD" "-DCMAKE_CXX_FLAGS_DEBUG= /nologo /MD" "-DCMAKE_BUILD_TYPE=Debug"

--- stderr
thread 'main' panicked at '
failed to execute command: cannot find the file specified. (os error 2)
is `cmake` not installed?

...

如何解决 CMake 和 Rust 的这个问题?我应该指定 CMake 路径吗?

我通过将 CMake bin 添加到 PATH 变量中解决了这个问题。刚刚在最近安装的 Visual Studio Build Tools 目录中搜索 cmake.exe 文件或 CMake 文件夹并找到 cmake.exe

对我来说是C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin

这样我就不必单独安装 CMake。

我还在 Visual Studio 构建工具的安装过程中添加了 Windows 10 SDK 复选框。

现在构建我的项目时没有错误。我希望这对某人有所帮助。