How to declare feature flags for package installing from git in Cargo.toml?

I am trying to install a forked version of a package, originally it looks like this:

sqlx = { version = "0.5.9", features = [ "postgres", "migrate", "macros", "runtime-actix-rustls", "chrono" ] }

And I change it to this now:

sqlx = { version = "0.5.9", git = "https://github.com/demurgos/sqlx.git", branch = "issue-1477", features = [ "postgres", "migrate", "macros", "runtime-actix-rustls", "chrono" ] }

But it gives me this:

error: one of the features ['runtime-actix-native-tls', 'runtime-async-std-native-tls', 'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', 'runtime-tokio-rustls'] must be enabled
  --> /home/hugosum/.cache/cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-rt-0.5.9/src/lib.rs:9:1
   |
9  | / compile_error!(
10 | |     "one of the features ['runtime-actix-native-tls', 'runtime-async-std-native-tls', \
11 | |      'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', \
12 | |      'runtime-tokio-rustls'] must be enabled"
13 | | );
   | |__^

error: could not compile `sqlx-rt` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed

Is there an alternative syntax for declaring feature flags for package installed from git? Why am I bumping into this issue?

Try removing the version = "0.5.9" bit.

sqlx = { git = "https://github.com/demurgos/sqlx.git", branch = "issue-1477", features = [ "postgres", "migrate", "macros", "runtime-actix-rustls", "chrono" ] }

I have dont that, still it doesn't work. But with this dependency I can build ok in a fresh project. No idea what went wrong.

Do you have any other dependencies which might be pulling in sqlx without setting the correct feature flags?

The error message from above comes from sqlx-rt v0.5.9 on crates.io, not a git checkout.

1 Like

Right this is helpful, thanks! It is affected by my another package in Cargo.toml, ormx

sqlx = { git = "https://github.com/demurgos/sqlx.git", branch = "issue-1477", features = [ "postgres", "migrate", "macros", "runtime-actix-rustls", "chrono" ] }
# ormx = { version = "0.10.0", features = [ "postgres" ] }

Commenting that out would work fine. I thought like other package manager, Cargo would provide the dependency of an package automatically for me, but seems like this one is its peer dependency.

But it is providing the package's dependency for you.

It's just that your app's dependency tree looks something like this:

So you've got two copies of sqlx in your dependency tree.

By adding the git dependency to your crate's Cargo.toml it will only affect which version of sqlx your crate depends on - it won't magically go through your entire dependency tree updating all sqlx references to use that version because there's a high chance it'll break something.

If you want to override sqlx for your entire dependency tree, you might want to use one of the techniques from the Overriding Dependencies chapter of The Cargo Book.

There is no such thing as "peer dependencies" in Rust, either you depend on a crate or you don't.

2 Likes

Yes thanks! I ended up overriding it like this and everything is working ok!

[patch.crates-io]
sqlx = { git = "https://github.com/demurgos/sqlx.git", branch = "issue-1477", features = [ "postgres", "migrate", "macros", "runtime-actix-rustls", "chrono" ] }

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.