Uploading binary packages (not libraries) to crates.io

I've been trying to upload my bfc, compiler project to crates.io, so it can be installed with cargo install bfc.

I'm a little confused by the process. I have a src/main.rs (my project is not a library), but running cargo publish complains:

error: api errors: wildcard (`*`) dependency constraints are not allowed on crates.io. See http://doc.crates.io/faq.html#can-libraries-use--as-a-version-for-their-dependencies for more information

I also don't understand why cargo publish rebuilds my code. Every time I run cargo publish, my project, and all its dependencies, are recompiled! Why is that?

Whilst I've found the RFC for cargo install, Page Moved does not explain why cargo thinks my package is a library, and the crates.io publishing docs don't seem to mention cargo install.

Are there canonical docs somewhere? What am I missing? Cargo usually works wonderfully, so I think I may be doing something silly somewhere.

That error means that you cannot have wildcard dependencies in your Cargo.toml:

[dependencies]
llvm-sys = "*"
...

You have to specify the version (range) explicitly.
See also: Page Moved

The docs suggested to me that this only applies to libraries. Have I misunderstood?

As far as I know, it applies to all packages, not just libraries. It could be a brainfart on the part of the writer, owing to very nearly everything on crates.io being a library.

Both of these measures are there to make it more likely that the package is buildable (and hopefully working) when it's uploaded and into the future.

I think that's a misunderstanding.
Wildcards are forbidden for libraries, but this does not imply they are allowed for executables. At least I couldn't find any docs that explicitly state that this only applies to libraries.

The FAQ from the error message also states that:

Starting January 22nd, 2016, crates.io will begin rejecting packages with wildcard dependency constraints.

(emphasis is mine)
Packages means both, libraries and executables.

But even if wildcards would be allowed, specifying sensible version constraints is still a good idea.

Thanks for your responses!

I've opened a PR to improve the crates.io docs and filed an issue for the repeated compilation problem. :slight_smile:

1 Like