features添加quinn后,无法在windows上交叉编译为linux二进制
1225754321 opened this issue · 4 comments
1225754321 commented
Describe the bug
features选择quinn后,无法在windows上交叉编译为linux二进制
查看Cargo.lock发现是因为quinn-proto使用的ring库版本为0.16.20
其他库调用的是ring为0.17.8就可以正常编译
To Reproduce
Steps to reproduce the behavior:
- 使用windows机器
- 创建一个普通的salvo项目,features添加quinn
- .cargo/config.toml配置如下
[target.x86_64-unknown-linux-musl]
linker = "rust-lld"
rustflags = ["-C", "linker-flavor=ld.lld"] - 在项目目录执行
cargo build -r --target x86_64-unknown-linux-musl
- 编译报错
Compiling slab v0.4.9
The following warnings were emitted during compilation:
warning: ring@0.17.8: Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is `musl-gcc` installed? (see https://github.com/rust-lang/cc-rs#compile-time-requirements for help)
warning: ring@0.17.8: Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is `musl-gcc` installed? (see https://github.com/rust-lang/cc-rs#compile-time-requirements for help)
error: failed to run custom build command for `ring v0.17.8`
Caused by:
process didn't exit successfully: `D:\git\urlmock\target\release\build\ring-7a3d44b58d2184a0\build-script-build` (exit code: 1)
--- stdout
cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_8_
OPT_LEVEL = Some("3")
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-pc-windows-msvc")
cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-musl
CC_x86_64-unknown-linux-musl = None
cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_musl
CC_x86_64_unknown_linux_musl = None
cargo:rerun-if-env-changed=TARGET_CC
TARGET_CC = None
cargo:rerun-if-env-changed=CC
CC = None
RUSTC_LINKER = Some("rust-lld")
cargo:rerun-if-env-changed=CROSS_COMPILE
CROSS_COMPILE = None
cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
cargo:warning=Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is `musl-gcc` installed? (see https://github.com/rust-lang/cc-rs#compile-time-requirements for help)
cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-musl
CFLAGS_x86_64-unknown-linux-musl = None
cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_musl
CFLAGS_x86_64_unknown_linux_musl = None
cargo:rerun-if-env-changed=TARGET_CFLAGS
TARGET_CFLAGS = None
cargo:rerun-if-env-changed=CFLAGS
CFLAGS = None
cargo:warning=Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is `musl-gcc` installed? (see https://github.com/rust-lang/cc-rs#compile-time-requirements for help)
--- stderr
error occurred: Failed to find tool. Is `musl-gcc` installed? (see https://github.com/rust-lang/cc-rs#compile-time-requirements for help)
Expected behavior
正常编译
Screenshots
无
Desktop (please complete the following information):
- OS: windows10/1809
Additional context
无
chrislearn commented
直接用 github 的 main 分支试试,应该已经升级过了,只是没有发布新版本。
1225754321 commented
好的,万分感谢
1225754321 commented
改用main分支后还是有一样的问题
salvo = { git = "https://github.com/salvo-rs/salvo.git", branch = "main", features = [
"serve-static",
"quinn",
"logging",
] }
The following warnings were emitted during compilation:
warning: ring@0.17.8: Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is `musl-gcc` installed? (see https://github.com/rust-lang/cc-rs#compile-time-requirements for help)
warning: ring@0.17.8: Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is `musl-gcc` installed? (see https://github.com/rust-lang/cc-rs#compile-time-requirements for help)
error: failed to run custom build command for `ring v0.17.8`
Caused by:
process didn't exit successfully: `D:\git\urlmock\target\release\build\ring-7a3d44b58d2184a0\build-script-build` (exit code: 1)
--- stdout
cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_8_
OPT_LEVEL = Some("3")
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-pc-windows-msvc")
cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-musl
CC_x86_64-unknown-linux-musl = None
cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_musl
CC_x86_64_unknown_linux_musl = None
cargo:rerun-if-env-changed=TARGET_CC
TARGET_CC = None
cargo:rerun-if-env-changed=CC
CC = None
RUSTC_LINKER = Some("rust-lld")
cargo:rerun-if-env-changed=CROSS_COMPILE
CROSS_COMPILE = None
cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
cargo:warning=Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is `musl-gcc` installed? (see https://github.com/rust-lang/cc-rs#compile-time-requirements for help)
cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-musl
CFLAGS_x86_64-unknown-linux-musl = None
cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_musl
CFLAGS_x86_64_unknown_linux_musl = None
cargo:rerun-if-env-changed=TARGET_CFLAGS
TARGET_CFLAGS = None
cargo:rerun-if-env-changed=CFLAGS
CFLAGS = None
cargo:warning=Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is `musl-gcc` installed? (see https://github.com/rust-lang/cc-rs#compile-time-requirements for help)
--- stderr
error occurred: Failed to find tool. Is `musl-gcc` installed? (see https://github.com/rust-lang/cc-rs#compile-time-requirements for help)
warning: build failed, waiting for other jobs to finish...
1225754321 commented
打包相关:
暂时无法在win下直接使用`cargo build -r --target x86_64-unknown-linux-musl`, 进行交叉编译
这里提供两个方案:
1. 直接到linux环境进行编译为linux二进制
2. 使用zig进行交叉编译,步骤如下
1. 安装zig
1. 安装Scoop
1. 打开Windows Powershell
2. 在PowerShell命令控制台执行: `iex (new-object net.webclient).downloadstring('https://get.scoop.sh')`
2. 使用scoop安装zig: 在PowerShell命令控制台执行: `scoop install zig`
2. 安装cargo-zigbuild
1. `cargo install cargo-zigbuild`
3. 使用zigbuild进行编译
1. 注意需要调整`.cargo/config.toml`
1. ```toml
[target.x86_64-unknown-linux-musl]
linker = "rust-lld"
rustflags = ["-C", "linker-flavor=ld.lld"]
```
改为
```toml
[target.x86_64-unknown-linux-musl]
```
2. 执行编译命令: `cargo zigbuild -r --target x86_64-unknown-linux-musl`
4. 成功编译