[英]How can I make Cargo execute a build script and use a target-specific linker at the same time?
I'm adjusting the build process of a library written in Rust. 我正在调整用Rust编写的库的构建过程。 The goal is to have it compile on Windows with MSVCC.
目标是在Windows上使用MSVCC进行编译。 Due to some specific dependencies, I have to make sure that the correct MSVCC linker is being used, so I've set up a project-specific configuration file for Cargo with:
由于某些特定的依赖关系,我必须确保使用正确的MSVCC链接器,因此我为Cargo设置了一个特定于项目的配置文件:
[target.x86_64-pc-windows-msvc]
linker = "C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/link.exe"
When I run cargo build
now, my build-script build.rs
is no longer executed. 当我现在运行
cargo build
,我的构建脚本build.rs
不再执行。 Since the script provides the paths for important libraries, the building process eventually fails. 由于脚本为重要库提供了路径,因此构建过程最终会失败。
To reproduce the problem under Windows 10 (64-bit) with Visual Studio 12, create a project as follows: 要使用Visual Studio 12在Windows 10(64位)下重现该问题,请按如下方式创建项目:
| build.rs
| Cargo.toml
|
+---.cargo
| config
|
\---src
main.rs
./build.rs: ./build.rs:
use std::env;
fn main() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
panic!("Building!");
}
./Cargo.toml: ./Cargo.toml:
[package]
name = "some_binary"
version = "0.1.0"
build = "build.rs"
.cargo/config: .cargo /配置:
[target.x86_64-pc-windows-msvc]
linker = "C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/link.exe"
src/main.rs: SRC / main.rs:
fn main() {
println!("Hello, world!");
}
When you call cargo build
, linking should fail with 当您调用
cargo build
,链接应该失败
LINK : fatal error LNK1181: cannot open input file 'advapi32.lib'
链接:致命错误LNK1181:无法打开输入文件'advapi32.lib'
Currently, the stable version of Rust fails at including the proper libraries (namely the Windows SDK) when the VS linker is specified explictly. 目前,当明确指定VS链接器时,Rust的稳定版本无法包含适当的库(即Windows SDK)。 Consequently, the build-script could not be linked and building failed.
因此,无法链接构建脚本并且构建失败。
Recent changes in the nightly have solved this problem. 最近的夜间变化解决了这个问题。 Just switch to the nightly or wait until it is merged to the stable version.
只需切换到每晚或等到合并到稳定版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.