How do you declare serde as a git dependency?

I wanted to test out a change in serde against crates that depend on it. I want to build the dependent crates locally with their Cargo.toml dependencies pointing at either my local fork on disk, or even a remote git url with my changes, but even with zero code changes the crates fail to compile.

For example, when I update log's dependencies on serde to use a git url like this:

[dependencies]
cfg-if = "1.0"
# replaced with git url
#serde = { version = "1.0", optional = true, default-features = false }
serde = { git = "https://github.com/serde-rs/serde.git", tag = "v1.0.0", optional = true, default-features = false }
sval = { version = "=1.0.0-alpha.5", optional = true, default-features = false }
value-bag = { version = "=1.0.0-alpha.9", optional = true, default-features = false }

[dev-dependencies]
rustversion = "1.0"
# replaced with git url
#serde = { version = "1.0", features = ["derive"] }
serde = { git = "https://github.com/serde-rs/serde.git", tag = "v1.0.0", features = ["derive"]  }
serde_test = "1.0"
sval = { version = "=1.0.0-alpha.5", features = ["derive"] }
value-bag = { version = "=1.0.0-alpha.9", features = ["test"] }

the build appears to fail to build the crate with the Serialize trait:

error[E0277]: the trait bound `T: serde::ser::Serialize` is not satisfied
   --> src/kv/value.rs:203:45
    |
203 |             inner: ValueBag::capture_serde1(value),
    |                    ------------------------ ^^^^^ the trait `serde::ser::Serialize` is not implemented for `T`
    |                    |
    |                    required by a bound introduced by this call
    |
note: required by a bound in `value_bag::internal::serde::v1::<impl ValueBag<'v>>::capture_serde1`
   --> /Users/conraddean/.cargo/registry/src/github.com-1ecc6299db9ec823/value-bag-1.0.0-alpha.9/src/internal/serde/v1.rs:22:12
    |
22  |         T: serde1_lib::Serialize + 'static,
    |            ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `value_bag::internal::serde::v1::<impl ValueBag<'v>>::capture_serde1`
help: consider further restricting this bound
    |
200 |         T: self::serde::Serialize + 'static + serde::ser::Serialize,
    |                                             +++++++++++++++++++++++

error[E0277]: the trait bound `T: serde::ser::Serialize` is not satisfied
   --> src/kv/value.rs:245:42
    |
245 |             inner: ValueBag::from_serde1(value),
    |                    --------------------- ^^^^^ the trait `serde::ser::Serialize` is not implemented for `T`
    |                    |
    |                    required by a bound introduced by this call
    |
note: required by a bound in `value_bag::internal::serde::v1::<impl ValueBag<'v>>::from_serde1`
   --> /Users/conraddean/.cargo/registry/src/github.com-1ecc6299db9ec823/value-bag-1.0.0-alpha.9/src/internal/serde/v1.rs:32:12
    |
32  |         T: serde1_lib::Serialize,
    |            ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `value_bag::internal::serde::v1::<impl ValueBag<'v>>::from_serde1`
help: consider further restricting this bound
    |
242 |         T: self::serde::Serialize + serde::ser::Serialize,
    |                                   +++++++++++++++++++++++

error[E0599]: no method named `serialize` found for struct `ValueBag` in the current scope
   --> src/kv/value.rs:420:20
    |
420 |         self.inner.serialize(s)
    |                    ^^^^^^^^^ method not found in `ValueBag<'v>`
    |
   ::: /Users/conraddean/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.138/src/ser/mod.rs:247:8
    |
247 |     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    |        --------- the method is available for `ValueBag<'v>` here
    |
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
3   | use serde::ser::Serialize;
    |

Maybe you just cannot use file paths nor git urls to specify serde as a dependency? How do I set up dependencies so that I can test out modifications to serde locally in crates that depend on it?

For this you could use a patch in Cargo.toml.
What that does is override the given dependency in your crate as well as in all dependencies.

3 Likes

That works, thank you!

I doubt that serde would be special. I think the problem is that you are also depending on serde_test, which presumably pulls in the "real" serde as its own dependency.

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.