覆盖依赖项的构建脚本 [英] Override build script for a dependency

查看:41
本文介绍了覆盖依赖项的构建脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 Rust crate,它对一些包装本机库的 *-sys crate 具有传递依赖关系.*-sys crates 使用 build.rs 使用 cmake 构建本机库,这在我的环境中不受支持.

I am building a Rust crate that has transitive dependencies on a few *-sys crates wrapping native libraries. The *-sys crates use build.rs to build the native libraries with cmake, which is not supported in my environment.

我已经在我的项目树的其他地方预建了这些本地库.我想覆盖构建脚本 不运行,而是使用现有的本机库.

I already have those native libraries prebuilt elsewhere in my project tree. I would like to override the build scripts to not run, and use the existing native libraries instead.

如果清单包含 links 键,则 Cargo 支持覆盖使用自定义库指定的构建脚本.此功能的目的是防止完全运行有问题的构建脚本,而是提前提供元数据.

If a manifest contains a links key, then Cargo supports overriding the build script specified with a custom library. The purpose of this functionality is to prevent running the build script in question altogether and instead supply the metadata ahead of time.

要覆盖构建脚本,请将以下配置放置在任何可接受的 Cargo 配置位置.

To override a build script, place the following configuration in any acceptable Cargo configuration location.

[target.x86_64-unknown-linux-gnu.foo]
rustc-link-search = ["/path/to/foo"]
rustc-link-lib = ["foo"]
root = "/path/to/foo"
key = "value"

来源:货物参考>构建脚本

我根据该文档的初步猜测是,我只需要在声明依赖项时添加 rustc-link-lib,但这似乎不起作用.

My initial guess based on that documentation is that I would just need to add rustc-link-lib when declaring the dependency, but this doesn't seem to work.

[package]
# ...

[dependencies]
# ...
harfbuzz-sys = { version = "0.3", rustc-link-lib = ["harfbuzz"] }
# ...

Cargo 仍然尝试调用 build.rs 并失败.

Cargo still tries to invoke build.rs and fails.

是否有正确的方法可以覆盖 harfbuzz-sysbuild.rs 在我的项目中的所有传递依赖项?

Is there a correct way to override harfbuzz-sys's build.rs for all of its transitive dependents in my project?

推荐答案

您需要将覆盖信息放入 货物配置文件.例如对于 harfbuzz-sys,您可以将其放入工作区中的 .cargo/config 中:

You need to put the override information into one of the Cargo configuration files. For example for harfbuzz-sys, you could put this into .cargo/config inside your workspace:

[target.machine-vendor-os.harfbuzz]
rustc-link-search = ["/path/to/staging/usr/lib"]
rustc-link-lib = ["harfbuzz"]

注意第一行:

  • machine-vendor-os must be the same as the value that you give to cargo with the --target option.
  • harfbuzz must be the same as the links key defined in your dependency's Cargo.toml.

在第二行,/path/to/staging/usr/lib 是预编译依赖项在构建系统上的路径.

And on the second line, /path/to/staging/usr/lib is the path where your pre-compiled dependency is located on the build system.

这篇关于覆盖依赖项的构建脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆