2

Many libraries that contain procedural macros consist of two crates: a proc-macro crate implementing the actual macro and a normal "main" crate that reexports or wraps the proc macro. This is done because proc-macro crates cannot publicly export anything other than proc macros. Assuming the main crate is called foo, the macro crate is usually called foo-derive or foo-macros.

This brings up a couple of questions about how to version the proc-macro crate. Of course, the main crate follows semantic versioning. But should the macro crate follow it as well? I don't want people to use the macro crate directly, but only through the main crate. I clearly stated that in the proc-macro crate's description. I want to treat the macro crate as an implementation detail.

In that case, can I shouldn't need to follow semantic versioning, right? The main crate would then just require one exact version via foo-macro = "=0.0.4".

Is this fine? Or can something break with this approach? Are there some established best practices in the community?

Lukas Kalbertodt
  • 79,749
  • 26
  • 255
  • 305
  • Why not use the same version in both crates, even if the proc-macro doesn't change? No thinking involved, cannot go wrong. – rodrigo Sep 26 '20 at 16:14
  • @rodrigo I might want to make breaking changegs to the proc-macro API. Again, I want to treat it as some internal code and of course it would be fine to just change the API of internal helper methods. It just so happens that I am forced to put that internal code into a separate crate. – Lukas Kalbertodt Sep 26 '20 at 16:42
  • You don't have to follow semver, it's just a nice thing to do. If you make it clear that the crate isn't intended to be used directly, I really don't see a problem with making breaking changes like this. Internal/private crates are not uncommon. – mcarton Sep 26 '20 at 17:39
  • If your tooling can handle it, I would just use a build/sequence number on the macro crate, but I am a no-nothing when it comes to rust and associated tooling. – jwdonahue Oct 07 '20 at 20:02

0 Answers0