货物、工作空间和临时本地依赖 [英] Cargo, workspace and temporary local dependency

查看:51
本文介绍了货物、工作空间和临时本地依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个货物工作区中有两个项目 my_project 和 my_inner_project.它们都依赖于 gfx(以及 gfx_core 和 gfx_device_gl).我在 gfx_device_core 中发现了一个错误,所以我已经对它进行了分叉、克隆、本地修补,并希望在提交之前对其进行测试.

I have two projects my_project and my_inner_project in one cargo workspace. They both depend on gfx (and gfx_core and 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.

项目结构:

-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

现在我想让货物在 my_project 构建期间使用 gfx 的本地副本:

Now I want cargo to use local copy of gfx during my_project build:

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

  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. So it refuses to build project, complaining that gfx* is part of the workspace, but it is not below workspace root. AFAIK, there is currently no way to change this implicit "everything is in workspace" behavior.
  2. Second approach ([replace]): This approach leads to the same behavior as described above. Path specified inside [replace] is also added implicitly into workspace.
  3. Third approach (local path overrides): I've added gfx to paths in .cargo/config. 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. This also don't work in stable rust 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.

和错误:

error: failed to find lock source of gfx_core

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

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.

该错误在 rust nightly 中得到了修复,所以我已经安装了它并且终于能够使用我的本地 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.

因此,在相对基本的任务上挣扎了一天之后,我有了一个解决方案,该解决方案仅在夜间有效,并承诺在功能版本中无效.

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.

我的问题:

  1. 应该怎么做?
  2. 如何消除此警告?

推荐答案

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

To close the topic; This discussion resolves the issue: https://github.com/rust-lang/cargo/issues/3192

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

Now, paths pointing outside workspace directory are not implicitly included into workspace. Moreover there is exclude key in workspace configuration.

这篇关于货物、工作空间和临时本地依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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