You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Cargo.toml中正确配置工作区开发依赖?

工作区dev-dependencies的正确配置方式

你在工作区根目录的Cargo.toml(虚拟清单)中配置了:

[workspace.dev-dependencies]
serial_test = "2.0.0"

子项目的Cargo.toml则配置:

[dev-dependencies]
serial_test.workspace = true

但运行时出现以下错误:

Caused by:
  error inheriting `serial_test` from workspace root manifest's `workspace.dependencies.serial_test`

Caused by:
  `dependency.serial_test` was not found in `workspace.dependencies`

这种workspace = true的继承方式在普通dependencies段中可以正常工作,但在dev-dependencies场景下需要调整配置逻辑。

问题原因

Cargo的工作区依赖继承规则明确:子项目中通过workspace = true声明要继承的依赖,必须定义在工作区根的[workspace.dependencies]段落中,[workspace.dev-dependencies]并不能被子项目通过这种方式继承。

正确配置步骤

  1. 修改工作区根Cargo.toml:将依赖移至[workspace.dependencies]段:
[workspace.dependencies]
serial_test = "2.0.0"
  1. 子项目Cargo.toml保持原有配置:在[dev-dependencies]中继承该依赖即可:
[dev-dependencies]
serial_test.workspace = true

或者使用完整写法:

[dev-dependencies]
serial_test = { workspace = true }

这样配置后,子项目就能正确将工作区定义的serial_test作为开发依赖使用,同时遵循工作区的版本统一管理。

内容的提问来源于stack exchange,提问作者junglie85

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 07:59:53