货物、工作空间和临时本地依赖项

Cargo, workspace and temporary local dependency

我在一个 cargo workspace 中有两个项目 my_project 和 my_inner_project。它们都依赖于 gfx(以及 gfx_core 和 gfx_device_gl)。 我在 gfx_device_core 中发现了一个错误,所以我在本地进行了分叉、克隆、修补,并想在提交之前对其进行测试。

项目结构:

-my_project
--my_inner_project
---Cargo.toml
--Cargo.toml
-gfx
--src
---core
----Cargo.toml  #package gfx_core
---backend
----gl
-----Cargo.toml #package gfx_device_gl
---render
----Cargo.toml  #package gfx
--Cargo.toml

现在我希望 cargo 在 my_project 构建期间使用 gfx 的本地副本:

  1. 第一种方法(Cargo.toml 中的本地路径):我已将我两个项目的 Cargo.toml 中所有 gfx 包的源更改为本地路径。\ 不幸的是,cargo 隐含地假设(这对我来说有点疯狂),"path" 指向的所有依赖项都是工作空间的一部分,但工作空间成员必须位于文件系统中的工作空间根目录下。所以它拒绝构建项目,抱怨 gfx* 是工作区的一部分,但它不在工作区根目录下。据我所知,目前没有办法改变这种隐含的 "everything is in workspace" 行为。
  2. 第二种方法([替换]):这种方法导致与上述相同的行为。 [replace] 中指定的路径也被隐式添加到工作区中。
  3. 第三种方法(本地路径覆盖):我已将 gfx 添加到 .cargo/config 中的路径。还需要将我的 .tomls 中 gfx 包的来源从 crate.io 更改为 git 存储库,因为覆盖包中的版本和 .toml 中引用的版本必须匹配。这在稳定的 Rust 1.13 中也不起作用。我收到警告:

    warning: path override for crate `gfx_device_gl` has altered the original list of dependencies; the dependency on `gfx_core` was either added or modified to not match the previously resolved version
    
    This is currently allowed but is known to produce buggy behavior with spurious recompiles and changes to the crate graph. Path overrides unfortunately were never intended to support this feature, so for now this message is just a warning. In the future, however, this message will become a hard error.
    
    To change the dependency graph via an override it's recommended to use the `[replace]` feature of Cargo instead of the path override feature. This is documented online at the url below for more information.
    

    错误:

    error: failed to find lock source of gfx_core
    

    我的项目中 Cargo.toml 中指向的 gfx 和存储库的本地副本是相同的,所以我不明白为什么会发出此警告。

    错误在 rust nightly 中修复,所以我安装了它并最终能够使用我本地的 gfx 副本编译项目。

所以在与相对基本的任务斗争了一天之后,我有了一个解决方案,它只适用于每晚,并保证它不会在功能发布中工作。

我的问题:

  1. 应该怎么做?
  2. 如何摆脱这个警告?

关闭话题;这个讨论解决了这个问题: https://github.com/rust-lang/cargo/issues/3192

现在,指向工作区目录外部的路径不会隐式包含在工作区中。此外,工作区配置中有 exclude 键。