Where to learn about crate file format?


I’m looking into what sorts of information can be package into a compiled crate file, and I’m wondering if there’s some resource out there on the format used for the crate file? I’ve looked but haven’t found anything.


Is there something called “crate file”?

I think there are only package bundles that get uploaded to crates.io, and binaries that are machine language or other output formats asked for from the compiler. Are you talking about any of these, or something else?


It’s technically unspecified.


I just played around with cargo package and a dummy project and it looks like a *.crate file is just a regular tarball of your source code without anything ignored by your VCS.

You could probably reverse engineer the exact format by looking at cargo’s source code and with a little experimenting. It should go without saying that it’s probably not a good idea to rely on the crate format because it isn’t defined by the language spec (well, I don’t think it’s in The Rust Reference anyway). Instead you should prefer to go through the official interface (cargo package/publish).


If anyone is interested, here’s the relevant piece of code in Cargo: https://github.com/rust-lang/cargo/blob/534ce68621ce4feec0b7e8627cfd3b077d4f3900/src/cargo/ops/cargo_package.rs#L185. But yeah the layout of .crate file is unspecified.


Awesome, thanks folks! This is exactly what I need.


can confirm, true fact :ballot_box_with_check: