Unsolved import crate but in cargo,toml already

I tried to cargo build this repo (https://github.com/TrafficTse/curv-abridged), but it kept reporting "Unsolved import num_bigint" as shown below, although it has already been included in the file cargo.toml by num-bigint = { version = "0.4", features = ["serde"], optional = true }. May I ask why? I don't think the difference in the hyphen and the underline matters since I also tried and still failed.

That package is broken. They should use a feature that has the num_bigint dependency and then feature-gate everything that has use num_bigint under that feature.


Put differently, if you don’t actually want the num_bigint dependency to be optional, the optional = true needs to be removed.

It it’s supposed to be optional, then the code that uses it needs to become conditionally compiled using #[cfg(…)] attributes. (See also the cargo book. Also I cannot find good tutorials, maybe someone knows some; otherwise try to look and understand how other crates to it.)

Edit: For example, for comparison, you could look into the original repository that this (chain of) fork(s) is based on, and that one applies such a cfg in the code.

1 Like

The cargo documentation states

By default, this optional dependency implicitly defines a feature that looks like this:

gif = ["dep:gif"]

So there is already a feature called num-bigint, and it does compile with cargo build --features num-bigint. It would just need a few #[cfg(feature = "num-bigint")] to correct. Maybe you can open an issue or even make a PR?


Ah, that makes sense. Thx a lot. I roughly know how to use #cfg(...)].

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.