简体   繁体   English

如何让Cargo执行构建脚本并同时使用特定于目标的链接器?

[英]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'

Update: 更新:

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. 因此,无法链接构建脚本并且构建失败。

Solution: 解:

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.

相关问题 如何使运行Cargo build脚本可选? - How can I make running a Cargo build script optional? 特定于目标的变量作为 Makefile 中的先决条件 - Target-specific Variables as Prerequisites in a Makefile 我如何制作仅在对特定目录进行更改时才能使用Codeship构建的脚本? - How can I make a script that will build w/ Codeship only when changes are made to a specific directory? 如何在gnu make中使用目标特定变量 - how to use target specific variable in gnu make 使用Rust Cargo进行构建的不同目标名称 - Different target names using Rust Cargo for build 我可以在构建脚本中使用内联 Powershell 吗? - Can I use Inline Powershell in Build Script? 如何从构建脚本(build.rs)访问当前的货物配置文件(调试/发布,...) - How to access current cargo profile (debug/release, …) from the build script (build.rs) 如何在统一的游戏玩家和游戏构建中设置相同的时间刻度(?)? - How can i set the same time scale (?) in in-unity game player and game build? 如何指定将在scons中构建多个目标的单个目标? - How can I specify a single target that will build multiple targets in scons? 我可以在 Codeship 的构建脚本中使用 git 标签作为版本吗 - Can i use the git tag as a version in the build script in Codeship
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM