feat: decompose macros
feature as macros-decl
and macros-proc
#4804
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
As its name suggests, the
macros
feature enables the use of various macros in Tokio. Among the most beloved are the#[tokio::main]
and theselect!
macros.However, one major difference between attribute macros and declarative macros is that the former requires the
tokio-macros
crate, which is the home for various procedural macros.tokio/tokio/Cargo.toml
Line 48 in d8cad13
In turn, a dependency on the
tokio-macros
crate also pulls in the (relatively heavy)syn
andquote
crates.tokio/tokio-macros/Cargo.toml
Lines 24 to 27 in d8cad13
The main issue arises when attribute macros are not needed, but the user still wishes to use the declarative macros (i.e.
select!
,join!
, andtry_join!
). They are thus forced to enable themacros
feature, which undesirably pulls in the attribute macros from thetokio-macros
crate anyway.Solution
To avoid this issue, this PR decomposes the
macros
feature into two sub-features:macros-decl
andmacros-proc
.1 Themacros-decl
feature enables the declarative macros while themacros-proc
feature enables the procedural macros. To maintain backwards-compatibility, themacros
feature is now just an alias for["macros-decl", "macros-proc"]
.Most notably, the
macros-proc
feature enablesdep:tokio-macros
.2 The explicit decomposition allows the user to use the declarative macros without being forced to pull in the heavier attribute macros.3Please do let me know if there are any issues with my decomposition. In particular, I would love to resolve any compilation issues (if any) that arise due to outdated references to the old
macros
feature. Thanks! 🎉Footnotes
I'm open to changing the sub-feature names if anyone prefers otherwise. I figured that this was an appropriate naming convention since there is already precedent with
["io-std", "io-util"]
and["rt", "rt-multi-thread"]
. ↩In the actual PR, I did not use the
dep:
prefix to respect the MSRV. ↩It is worth noting, however, that the
syn
andquote
crates would have been pulled in by other crates, anyway. This is especially true for projects with many dependencies (most notablyserde_derive
). Nevertheless, it is still good to give the user extra control over the compilation of dependencies. ↩