我如何仅获取和编译Dev依赖性?

发布于 2025-01-24 09:33:56 字数 691 浏览 2 评论 0原文

RUST cargo.toml规范文件允许开发依赖关系节,例如[dev-depentencies]

cargo.toml

[dev-dependencies]
tempdir = "0.3"

获取和编译这些开发依赖性的命令是什么?

需要明确的是,我想获取并仅编译[DEV依赖性]链接问题不同之处在于,它指的是获取和编译 all 依赖关系,然后构建应用程序。

The Rust Cargo.toml specification file allows for development dependencies section, e.g. [dev-dependencies]

Cargo.toml:

[dev-dependencies]
tempdir = "0.3"

What is the command to fetch and compile those development dependencies?

To be clear, I want to fetch and compile only the [dev-dependencies]. The Linked question differs in that it regards fetching and compiling all dependencies and then building the application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦归所梦 2025-01-31 09:33:56

我没有足够的声誉,所以我只是回答。

如您的链接所声明和 nofollow noreferrer“> >,不可能从Dev依赖性中“构建”二进制文件。

有时需要具有测试依赖项(或示例,
或仅基准)。此类依赖项被添加到cargo.toml中
[DEV依赖性]节

是偷偷摸摸的,可能是您可以在#[CFG(test)]下放置一些功能并运行货物测试,以便可以实现您的目标。

一种更合适的方法,使用货物使用功能标志在cargo.toml和cargo命令中进行选择性构建。您可以查看货物命令以切换功能在这里 and “ nofollow noreferrer”>可选依赖性

I do not have enough reputation so I just answer.

As declare by your link and rust-by-example, it is impossible to "build" a binary from dev-dependencies.

Sometimes there is a need to have dependencies for tests (or examples,
or benchmarks) only. Such dependencies are added to Cargo.toml in the
[dev-dependencies] section

To be sneaky, may be you can put some function under #[cfg(test)] and run cargo test so that your goal can be achieved.

A more appropriate way to selectively build by cargo using the feature flag, in cargo.toml and cargo command. You can take a look at the cargo command to toggle feature here and optional dependencies which help control categorizing of features.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文