简体   繁体   English

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

[英]Cargo, workspace and temporary local dependency

I have two projects my_project and my_inner_project in one cargo workspace. 我在一个货物工作区中有两个项目my_project和my_inner_project。 They both depend on gfx (and gfx_core and gfx_device_gl). 它们都依赖于gfx(以及gfx_core和gfx_device_gl)。 I've found a bug in gfx_device_core, so I've forked it, cloned, patched locally and want to test it before commit. 我在gfx_device_core中发现了一个错误,因此我已经对其进行了分叉,克隆,本地修补,并希望在提交之前对其进行测试。

Projects structure: 项目结构:

-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

Now I want cargo to use local copy of gfx during my_project build: 现在,我希望货物在my_project构建期间使用gfx的本地副本:

  1. First approach (local path in Cargo.toml): I've changed source of all gfx packages to local path in Cargo.tomls of both my projects.\\ Unfortunately, cargo implicitly assumes (which is a bit insane for me), that all dependencies pointed by "path" are part of workspace, yet workspace member must lay below workspace root in file system. 第一种方法(Cargo.toml中的本地路径):我将所有gfx包的源都更改为两个项目的Cargo.tomls中的本地路径。\\不幸的是,货物隐含地假设(这对我来说有点疯狂) “路径”所指向的依赖项是工作空间的一部分,但是工作空间成员必须位于文件系统中的工作空间根目录之下。 So it refuses to build project, complaining that gfx* is part of the workspace, but it is not below workspace root. 因此它拒绝构建项目,抱怨gfx *是工作空间的一部分,但它不在工作空间根目录下。 AFAIK, there is currently no way to change this implicit "everything is in workspace" behavior. AFAIK,当前无法更改此隐式“一切都在工作区”行为。
  2. Second approach ([replace]): This approach leads to the same behavior as described above. 第二种方法([替换]):这种方法导致与上述相同的行为。 Path specified inside [replace] is also added implicitly into workspace. [replace]内部指定的路径也隐式添加到工作空间中。
  3. Third approach (local path overrides): I've added gfx to paths in .cargo/config. 第三种方法(覆盖本地路径):我在.cargo / config中的路径中添加了gfx。 It was also necessary to change source of gfx package in my .tomls from crate.io, to git repository, because version in overriden package and version referrenced in .toml must match. 也有必要将我的.tomls中的gfx软件包的源从crate.io更改为git仓库,因为被覆盖的软件包中的版本和.toml中引用的版本必须匹配。 This also don't work in stable rust 1.13. 这在稳定的锈蚀1.13中也不起作用。 I get warning: 我得到警告:

     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. 

    And error: 错误:

     error: failed to find lock source of gfx_core 

    My local copy of gfx and repository pointed in Cargo.toml inside my projects are identical, so I don't understand why this warning is emited. 我在项目内的Cargo.toml中指向的gfx和存储库的本地副本是相同的,因此我不明白为什么会发出此警告。

    The error is fixed in rust nightly, so I've installed it and finally was able to compile project with my local gfx copy. 该错误已在每晚的rust中修复,因此我已经安装了该错误,最终能够使用本地gfx副本编译项目。

So after a day of struggling with relatively basic task, I have a solution, which works only in nightly and promises it will not work in feature releases. 因此,经过一天相对艰苦的基本工作之后,我有了一个解决方案,该解决方案仅在夜间运行,并承诺在功能发布中将不起作用。

My questions: 我的问题:

  1. How it should be done? 应该怎么做?
  2. How to get rid of this warning? 如何摆脱这个警告?

To close the topic; 结束话题; This discussion resolves the issue: https://github.com/rust-lang/cargo/issues/3192 该讨论解决了该问题: https : //github.com/rust-lang/cargo/issues/3192

Now, paths pointing outside workspace directory are not implicitly included into workspace. 现在,指向工作空间目录外部的路径不会隐式包含在工作空间中。 Moreover there is exclude key in workspace configuration. 此外,工作空间配置中没有exclude键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM