-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
Externalize derive macro implementation #2765
Conversation
4a3641c
to
0925e7d
Compare
Just released my code for versioning here if you want to take a look at what this PR allows ^^ btw, if you have time, I'd love to hear your opinion the project |
May I ask for your review @dtolnay ? |
@@ -0,0 +1 @@ | |||
../serde_derive/src/implementation/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a symbolic link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup it was, just like for serde_derive_internals
See: https://github.com/serde-rs/serde/blob/master/serde_derive_internals/src
The issues raised in #2021 are not really resolved by this. I think this is a feature needed commonly enough that we could probably quickly figure out a small robust rust language feature to allow you to call proc macros from other proc macros. I think that would be better in general |
Going to close this as I don't see it landing in this form any time soon. |
I also thought of a simple feature gate, but AFAIK [lib]
proc-macro = true cannot be set via by feature gate, at least not last time I checked, but it would be really nice to get that ! Do you have other ideas I could explore ? |
For now you can create a git repo with this repo as a submodule and create your crate that way. It'll be on you to update then, but that was already true. The main problem with those approaches is keeping in sync with the serde version for the internal API that the derives use |
I don't know what would be needed on the rustc side to support invoking proc macros from other proc macros, but it doesn't seem insurmountable if the lang team agrees this is desirable |
Haha, I honestly didn't even thought about submodules, thanks for the idea!
Yup but that's a burden for libraries developers not for (Not trying to get the PR opened again, just genuinely trying to understand, I probably am missing a point 😄)
Don't know either, hopefully I can find the issues/RFC back and link this PR or ask questions about it 🙃 |
Oh yea I meant problems for you if you go with the submodule approach and potentially users of your crate. Though it may be automatable in a cronjob to generate and publish the crate whenever a new serde_derive is released |
Oh, I thought you were saying that for serde and the PR itself, yup it could become a pain for me and others if serde changes too much. I didn't saw it as an issue for me as in #1137 dtolnay said that if an extension of serde becomes a popular/viable solution it could get merged directly in serde and was hoping I could one day get that chance 🙃. Thanks for the explanations and your time 👍 |
Hi,
I'm currently trying to make a crate built on top of serde to try to implement a relatively naive idea for struture versioning regarding #1137 as a POC (and hopefully a suitable solution).
For ease of use (both as the developper and user of the crate) I'd like my crate to be able to benefit from serde's derive implementation that is thankfully in a separate function that could be exported.
This would allow my crate (and other ones of the same kind) to be 100% compatible with all of serde derive's attribute and features by manually running the derive function and modifying the AST with
quote
andsyn
.This would allow crate developers to inject their features direclty on the
Serialize
orDeserialize
implementation outputed byserde_derive
, kinda like what I'm doing:original file being:
This is, I think, kinda related to #2021.
To do so I pretty much replicated the
serde_derive_internals
situation.If this change is ok to you (if its not I can simply use my fork for the time being), I'd like to have your opinion on how you want me to fix the current clippy issues (the lib file currently being the same as for
serde_derive_internals
)Simply add a bunch of
#[allow()]
on thelib.rs
, try my best to fix every one of them, alternative ?Notes
English isn't my primary language, I'm sorry if I made mistakes, if anything sounds bad or if I'm hard to understand 😓.