-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Read version of rustc that compiled proc macro #6822
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
Conversation
crates/proc_macro_api/src/lib.rs
Outdated
snappy_decoder | ||
.read_exact(&mut bytes_before_version) | ||
.unwrap(); | ||
let length = bytes_before_version[12]; // what? can't use -1 indexing? |
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.
This should probably also check that the metadata version is 5.
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.
Or rather, it should be checked before decompression.
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.
You mean, the last byte 5
in 8 bytes sequence r u s t 0 0 0 5
?
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.
Yes
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.
I think this is resolved by the condition check if header != EXPECTED_HEADER {...}
that I added in later commit? @bjorn3
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.
I think this is resolved by the condition check if header != EXPECTED_HEADER {...} that I added in later commit?
Yes, I think so .
There were some changes in this crate ( |
If I keep add commit to this branch on my laptop then push them to my fork on github, do those change get automatically updated here? |
Yes |
noice! |
See #6393 (comment) if some rebasing tips, but it's fine if you don't feel like trying that. |
👀 |
I see. Is it ok to use |
It's ok, but you'll need to use a bunch of |
r? @jonas-schievink :) |
@jsomedon hey, do you need help with the rebase? |
My bad for disappearing without words.. I caught the flu so I was mostly taking rest these days instead of wrestling with rust code. Probably shouldn't skip sleeping 😓 I haven't look much onto what I need for rebasing but I guess I should cherry pick some commits just like you did in the comment you linked? |
Yes, you can cherry-pick the first one. No worries, just shout if you need help. |
@bjorn3 do you think this is worth the complexity over reading the output of |
🤷 |
I think it is – running |
I just pushed commits to resolve issues mentioned in code review. Will work on the rebasing task. |
crates/proc_macro_api/src/lib.rs
Outdated
// * [some more bytes that we don really care but still there] :-) | ||
// Check this issue for more about the bytes layout: | ||
// https://github.com/rust-analyzer/rust-analyzer/issues/6174 | ||
fn read_version(&self, dylib_path: &Path) -> io::Result<String> { |
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 actually getting called somewhere?
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.
Not yet, I think. We need to call it before loading the library, around ProcMacroLibraryLibloading::open
or above.
But we still need to figure out what version to expect.
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.
No, but there is this discussion.
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.
Well, it would still be nice to wire it up. I just didn't want to scare you off right from the start 😬
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.
Well, it would still be nice to wire it up. I just didn't want to scare you off right from the start grimacing
I see, sure thing. 😄
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.
That won't quite work for beta and stable, as those don't show the date at which the branch forked from master (and thus abi compatibility) but the date at which they were built.
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.
Oh, right. We need three version strings, then?
I hate this.
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.
(confused and scratching my head)
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.
So how do I get the version that I am comparing with for stable and beta? And is there universal way of doing this for all three including nightly?
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.
We have some discussion in zulip that only stable is fine for now.
So I think the last ABI change was rust-lang/rust#74653, which means the earliest |
|
Just updated my local repo and github fork, then rebased my fix branch(jsomedon:check_version), then |
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.
Sorry for the delay. We want to push forward this PR for #7328 now.
I think current form is okay now (we could refactoring later on), and the miss piece of this PR is actually call read_version
from ProcMacroLibraryLibloading::open
and logging warning if the version is invalid.
If you are busy, I could co-author this PR if you want.
crates/proc_macro_api/src/lib.rs
Outdated
// * [some more bytes that we don really care but still there] :-) | ||
// Check this issue for more about the bytes layout: | ||
// https://github.com/rust-analyzer/rust-analyzer/issues/6174 | ||
fn read_version(&self, dylib_path: &Path) -> io::Result<String> { |
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.
We have some discussion in zulip that only stable is fine for now.
crates/proc_macro_api/src/lib.rs
Outdated
snappy_decoder | ||
.read_exact(&mut bytes_before_version) | ||
.unwrap(); | ||
let length = bytes_before_version[12]; // what? can't use -1 indexing? |
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.
I think this is resolved by the condition check if header != EXPECTED_HEADER {...} that I added in later commit?
Yes, I think so .
Yeah, sure. 😅 |
With Jay Somedon <[email protected]>
Signed-off-by: Jay Somedon <[email protected]>
* check metadata version * use memmap * use Result instead of unwrap with Jay Somedon <[email protected]>
Co-authored-by: Jonas Schievink <[email protected]>
Co-authored-by: Jonas Schievink <[email protected]>
Co-authored-by: Laurențiu Nicola <[email protected]>
There is a typo in the commit message: *built |
LGTM @edwin0cheng is this waiting for anything else? |
bors r+ |
@jsomedon Thanks for the PR ! |
Never mind, I ended up on an old toolchain. I guess that's another thing to check for :-(. |
8716: Replace `memmap` with `memmap2` in `proc_macro_api` r=edwin0cheng a=memoryruins #7522 did the same for `proc_macro_srv` before this usage of `memmap` was introduced to `proc_macro_api` in #6822 . Something like [`cargo-deny`](https://github.com/EmbarkStudios/cargo-deny-action) could help prevent specific crates (and versions, licenses, etc) from being introduced into the crate tree, but that's unrelated to this pull request. Co-authored-by: memoryruins <[email protected]>
Signed-off-by: Jay Somedon [email protected]
This PR is to fix #6174.
I basically
read_version
andread_section
(used byread_version
)snap
andobject
to be used by those two methodsI just noticed that some part of code were auto-reformatted by rust-analyzer on file save. Does it matter?