-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Check rustc version before loading a proc-macro #6174
Comments
Hi, can I take this issue if no one's working on this? I am kinda new to the community but I want to start contributing. :-) |
It's yours :-) |
Might not be really related to this issue but I have several questions about proc macro feature in general:
And regarding the actual bug in this issue: I think I wrapped my mind over how this proc macro thing works in rust analyzer but I only took a peek to the rustc code mentioned by @bjorn3. So looks like the
|
To prevent bugs and version incompatibilities from brining down rust-analyzer as a whole.
If you are using nightly, you can directly call into
You need to check the rustc version that compiled the proc macro to see if it is compatible with the
Yes
Makes sense
|
The only feasible way I can come up with is: look for bytes Also I just built and took a look at the |
You can use the |
I went through decompressing, and kinda stuck at figuring out how decoding actually works once I jumped forward the 8(the METADATA_HEADER)+4(the crate root position) bytes offset. I expect to see logic like how many bytes to read and how to decode a string from them being defined somewhere, but couldn't find such thing. The only thing that looks related remotely is this decode method crate fn get_rustc_version(&self) -> String {
Lazy::<String>::from_position(NonZeroUsize::new(METADATA_HEADER.len() + 4).unwrap())
// ^ this line above should give me a `Lazy<String>` value
.decode(self)
// so decode should be `fn (self, some_other_arg)`-> String?
// but the `define` from the link above is `fn (some_non_self) -> Result<Self, String> `
// I was asking fellas in discord channel if functions with such two signature match with
// some advanced syntax that I never heard about, but that doesn't seem to be the case..
} EDIT: |
Not sure if it helps, but that section looks like this:
For some reason the header is included twice and the version string isn't where I'd expect. There's also a Also, this seems like a really round-about way to check the version. We compile the proc macros ourselves by running |
ha, it looks like you didn't even decompress it and it can still show enough information.. |
Here it is after decompression:
|
bjorn3 replied me a while ago on zulip, and I am posting his message here in case someone interested wants to know:
|
What command was used for this? Very nice textual layout! |
I think it's
|
I thought I went through the decompression, but realized that I was working with the, un-decompressed section all the time... Basically, I got the ".rsutc" section using I see that my original section bytes contain the snappy magic word as well, so I should be able to somehow decompres it but have no idea where did I get it wrong. I see that's @lnicola actually decompressed it, wonder how did you do that? |
You need to skip the first 8 bytes:
The compressed data starts at |
Just finished checking verision from 1.How do I check what |
Does this mean the crate's version I've been trying to parse out is not the one we are interested?? |
I'm not sure. I don't think ABI changes are backwards compatible, so we might want to either:
Ideally we'd support at least nightly, beta and stable.
It's not that we are not interested in it, but AFAICT it's pretty much the same one that |
Sounds like we are talking about implementing a whole new feature, not just a simple bug fix. Not sure how planning and decision making go through in this project, I guess a new contributor like me might not get to say much.. nevertheless, I imagine a typical user would definitely like to see rust analyzer supporting as many versions as possible. That being said, I will go by whatever version support you guys think is reasonable to implement at this point. |
There's more discussion in #6448. To close this I suppose we could add a method somewhere that would return the version string from a proc macro shared library. Actually using it would be a different issue (to avoid scope creep in a new contributor's work). |
I think that's exactly what I have implemented so far. To double check, the version string in the compressed part of the crate's .rustc section, right? |
(yeah on my laptop it prints 0 too) |
Okay then I will add a And before that I will try to figure out how to make a pull request first 😅 |
Hexyl should use a different color for |
The
.rustc
section contains the rustc version in a very stable format. It is used to report the original rustc version when attempting to use a crate compiled with a different rustc version. You will first need to use snap to decompress the section, then you can look atget_rustc_version
to see how to decode it.METADATA_HEADER
is defined at https://github.com/rust-lang/rust/blob/382848989f91fa2c25390f0d5c1e8b1ae94f47df/compiler/rustc_metadata/src/rmeta/mod.rs#L54The text was updated successfully, but these errors were encountered: