Feature dependency problem

Using gtk-rs sourceview crate.
use sourceview::{ File, View, };
gave compile errors saying ‘File’ not in root. From hint in documentation at
https://gtk-rs.org/docs/sourceview/struct.File.html
I changed Cargo.toml [dependencies] from
sourceview = "0.5.0"
to
sourceview = { version = "0.5.0", features = ["v3_14"] }
and now get errors saying
failed to select a version for 'sourceview'. ... required by package 'foo v0.1.0 (/projects/foo)' versions that meet the requirements '^0.5.0' are: 0.5.0 the package 'foo' depends on 'sourceview', with features: 'v3_14' but 'sourceview' does not have these features.
Not sure how to proceed, grateful for assistance.

The source code is indeed guarded by #[cfg(feature = "v3_14")], but that feature is missing from the manifest:


You should report the issue!

@cuviper: Thanks; I have raised an issue [https://github.com/gtk-rs/sourceview/issues].

Is there any way to temporarily work around it? I’ve tried editing the manifest in ~/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.5.0 but it made no difference; possibly the info is cached somewhere: I don’t know much about the workings of cargo. :frowning:

You can checkout the sourceview repo at the version you need, make your modifications, and then point to it by overriding the dependency:
https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#overriding-dependencies

1 Like

OK, now find I need to use version 0.6.0 of ‘sourceview’. Trying to compile my project gives this error:

error: failed to select a version for 'sourceview'. ... required by package 'foo v0.1.0 (.../rust/gtk/foo)' versions that meet the requirements '= 0.6.0' are: 0.6.0 the package 'foo' depends on 'sourceview', with features: 'v3_14' but 'sourceview' does not have these features. failed to select a version for 'sourceview' which could resolve this conflict
However, ‘sourceview’ 0.6.0 does now have that feature, AFAICS.

If I clone the crate:
$ git clone https://github.com/gtk-rs/sourceview.git
and point my Cargo.toml at it:
sourceview = { version = "0.6.0", features = ["v3_14"], path = "../sourceview" }
I then get this:
error: failed to select a version for 'gdk-pixbuf-sys'. ... required by package 'sourceview v0.6.0 (.../rust/gtk/sourceview)' ... which is depended on by 'foo v0.1.0 (../rust/gtk/foo)' versions that meet the requirements '*' are: 0.8.0 the package 'gdk-pixbuf-sys' links to the native library 'gdk_pixbuf', but it conflicts with a previous package which links to 'gdk_pixbuf' as well: package 'gdk-pixbuf-sys v0.8.0' ... which is depended on by 'gtk v0.6.0' ... which is depended on by 'foo v0.1.0 (.../rust/gtk/foo)' failed to select a version for 'gdk-pixbuf-sys' which could resolve this conflict

Have also tried adding
[patch.crates-io] sourceview = { path = "../sourceview" }
to Cargo.toml, but it still gives the same error.

Somewhat confused! :confused:

You’re looking at master.

The sourceview repository has tagged commits for each release. git checkout 0.6.0 and you’ll see that the feature is missing.

error: failed to select a version for 'gdk-pixbuf-sys'. ... required by package 'sourceview v0.6.0 (.../rust/gtk/sourceview)' ... which is depended on by 'foo v0.1.0 (../rust/gtk/foo)' versions that meet the requirements '*' are:

I’m not entirely sure what’s going on there precisely, but somehow two different revisions of gdk-pixbuf-sys are getting pulled into the dependency tree. Looking at the sourceview crate I see lots of plain git dependencies:

...
[dependencies.pango]
git = "https://github.com/gtk-rs/pango"

[dependencies.gtk]
git = "https://github.com/gtk-rs/gtk"

[dependencies.gdk]
git = "https://github.com/gtk-rs/gdk"

[dependencies.cairo-rs]
git = "https://github.com/gtk-rs/cairo"
...

…I cannot fathom why the author did this (git dependencies without tag or rev are a disaster with regards to versioning, and I’m genuinely surprised that cargo publish even allows them!). I’m not saying this must be what’s causing this issue, but it is awfully suspicious.