Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cargo, workspace and temporary local dependency

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.

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:

  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.
    

    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.

    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.

My questions:

  1. How it should be done?
  2. How to get rid of this warning?
like image 814
adahn Avatar asked Nov 09 '22 05:11

adahn


1 Answers

To close the topic; This discussion resolves the issue: 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.

like image 167
adahn Avatar answered Jan 04 '23 03:01

adahn