Bevy的Windows环境设置
2022-05-29 22:45:23

Bevy的环境具有特殊的依赖,不正确配置编译将会有各种奇葩的报错。

0. 编译环境

OS:Windows11 Microsoft Windows [版本 10.0.22000.675]
Rust版本:rustup nightly
Bevy版本:0.7

 

1. 安装依赖的Windows c编译器和开发SDK

Bevy必须使用VS2019版本的c编译器,其他版本会出问题,你可以通过vs2019安装,也可以通过MSbuild2019安装

VS2019

关键安装2个组件:

  1. c编译器:MSVC v142 - VS 2019 C++ x64/x86生成工具

  2. SDK:自己操作系统对应SDK,比如我的是 Windows 11 SDK(10.0.22000.0)

 

 

2.  安装Rust Night版本,配置cargo代理

https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

2.0 安装GNU Windows编译器

如果不想费事安装Visual Studio或者MSBuild工具,可以使用Linux的GNU工具链,其实就是安装一个rust版的mingw。

rustup toolchain install stable-x86_64-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu

2.1 安装rustup night版本

rustup install nightly
rustup default nightly
rustc --version

2.2 cargo 镜像配置

C:Usersxxx.cargoconfig 文件

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'tuna'

# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

# rustcc社区
[source.rustcc]
registry = "git://crates.rustcc.cn/crates.io-index"

2.3 编译加速

cargo install -f cargo-binutils
rustup component add llvm-tools-preview

3.  bevy工程配置

3.1 工程root目录/.cargo/config.toml

[target.x86_64-pc-windows-msvc]
#linker = "rust-lld.exe"
rustflags = ["-Zshare-generics=off"]

注意 linker是注释掉的 要不然会有报错

code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN

Building the tutorial code with bevy/dynamic on Windows 10 raises error · Issue #2006 · bevyengine/bevy · GitHub

3.2 工程依赖配置

工程root目录/target/Cargo.toml

[package]
name = "bevy_startup"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.7.0", features = ["dynamic"] }

 

本文摘自 :https://www.cnblogs.com/


更多科技新闻 ......