Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the associated proc macro pattern #291

Merged
merged 1 commit into from
Aug 29, 2023
Merged

Conversation

jswrenn
Copy link
Collaborator

@jswrenn jswrenn commented Aug 28, 2023

The "associated proc macro pattern" is a trick for ensuring that zerocopy and zerocopy-derive have equal verions, even when the optional derive feature of zerocopy isn't used.

The derive feature of zerocopy provides a convenient way for end-users to depend on zerocopy-derive that ensures that zerocopy and zerocopy-derive have exactly equal versions. Unfortunately, using this feature creates a dependency between these two crates that prevents them from being built in parallel. A compile-time-conscious user of zerocopy can avoid this by depending on both of these crates explicitly, but this places the onus on them to ensure that their versions are exactly equal.

The "associated proc macro pattern" is a trick for ensuring that zerocopy and zerocopy-derive have equal verions, even when the optional derive feature of zerocopy isn't used. With it, an end-user of zerocopy can write:

[dependencies]
zerocopy = "MAJOR.MINOR"
zerocopy-derive = "MAJOR.MINOR"

...and cargo will ensure that the actual versions that are used are exactly equal.

For more information, see: https://github.com/matklad/macro-dep-test

Copy link
Member

@joshlf joshlf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Can we leave a suggestion in the crate doc comment to suggest that this is an option? We'll also want to maybe open an issue to track making this a more strongly-worded suggestion once this technique has baked in the ecosystem and folks agree it's the way to go.

Copy link
Member

@joshlf joshlf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the approach of putting a newline after the feature name play nicely with markdown (for the readme) and cargo doc (for lib.rs)?

README.md Outdated
crate. These derives are re-exported from `zerocopy`, so it is not
necessary to depend on `zerocopy-derive` directly.

However, you may experience better compile times if you explicitly depend
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "...if you don't use the derive feature and instead explicitly depend..." to make it clear that this is instead of the feature, not in addition to it?

Also, maybe s/explicitly/directly/?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I opted for slightly more concise wording, but the effect should be the same.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like these changes actually got pushed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh. I totally typed them in README.md instead of lib.rs, and then gleefully overwrote README.md with generate-readme.sh.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed!

@joshlf
Copy link
Member

joshlf commented Aug 29, 2023

Oh and one other thing: could you also bump the version numbers to 0.7.1 in this PR? I'll release that once this merges so folks can take advantage of it.

@jswrenn
Copy link
Collaborator Author

jswrenn commented Aug 29, 2023

Does the approach of putting a newline after the feature name play nicely with markdown (for the readme) and cargo doc (for lib.rs)?

Mostly. Unfortunately, cargo readme appears to be stripping out the trailing triple-space from those lines, so Github's rendering doesn't have a newline after each feature heading, but the rustdoc does. I don't think this is an issue. Github is also a little more generous with spacing between list items, so the extra newline isn't as important for visually delineating cargo features. Both renderings look good to my eye.

Oh and one other thing: could you also bump the version numbers to 0.7.1 in this PR? I'll release that once this merges so folks can take advantage of it.

Done.

@jswrenn jswrenn force-pushed the assoc-proc-macro-pattern branch 2 times, most recently from 07f5ea0 to 0e2f636 Compare August 29, 2023 14:44
The "associated proc macro pattern" is a trick for ensuring that
`zerocopy` and `zerocopy-derive` have equal verions, even when
the optional `derive` feature of `zerocopy` isn't used.

The `derive` feature of `zerocopy` provides a convenient way for
end-users to depend on `zerocopy-derive` that ensures that `zerocopy`
and `zerocopy-derive` have exactly equal versions. Unfortunately,
using this feature creates a dependency between these two crates that
prevents them from being built in parallel. A compile-time-conscious
user of `zerocopy` can avoid this by depending on both of these crates
explicitly, but this places the onus on them to ensure that their
versions are exactly equal.

The "associated proc macro pattern" is a trick for ensuring that
`zerocopy` and `zerocopy-derive` have equal verions, even when
the optional `derive` feature of `zerocopy` isn't used. With it,
an end-user of zerocopy can write:

    [dependencies]
    zerocopy = "MAJOR.MINOR"
    zerocopy-derive = "MAJOR.MINOR"

...and cargo will ensure that the actual versions that are used
are exactly equal.

For more information, see: https://github.com/matklad/macro-dep-test
@joshlf joshlf merged commit b8610f8 into main Aug 29, 2023
149 checks passed
@joshlf joshlf deleted the assoc-proc-macro-pattern branch August 29, 2023 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants