-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
How to catch proc-macro output in rust-analyzer #12494
Comments
I don't know if there is a way to catch the output of a proc macro. If there isn't you could write the output to a known file like
That is not allowed. You aren't allowed to modify the source directory from a build script or proc macro. In fact cargo will prevent you from publishing a crate that modifies the source directory. In the future the source directory for crates.io dependencies may even be made read-only. If you have a build script too, you could try putting the data in the directory pointed to by the |
Well, my crate is published https://docs.rs/symbols/ so, or cargo check is flawed or I've found a workaround since my crate isn't published as a proc-macro, but instead as a proc-macro utility (you've to use it inside your proc-macro). The strange thing is that only under VSCode rust-analyzer plugin it seems to fail without giving any errors (that are definitively managed inside my code), launching directly |
Your crate can be published, but users of proc macros that use your crate can't be.
I wouldn't expect so. |
Even moving cache files to |
With settings.json like {
"rust-analyzer.trace.server": "verbose",
"rust-analyzer.server.extraEnv": null
} it started printing out on tab "Rust Analyzer Language Server" lines starting with Settings were made yesterday and didn't worked until today's machine reboot, there must something wrong with settings reload.... I'll try to reproduce on Mac M1 machine... |
I'm unable to reproduce the log on Mac M1, on a Linux VM on the same machine works fine, looking at "Rust Analyzer Language Server Trace" on Mac M1 machine I see an unresolved-proc-macro block for every proc-macro, even for tokio::test
|
Do you happen to use a recent nightly version of rustc on your mac? If so #12489 is probably the cause. A fix has landed on the main branch and will land on stable next monday. |
I've installed a nightly toolchain only yesterday to be able to use |
Just tested on both stable v0.3.1091 and beta v0.4.1092 on Mac M1 machine, no changes, the problem is still there. |
Previously it would unconditionally show a weak warning for non-expanded macros. In https://github.com/rust-lang/rust-analyzer/pull/12514/files#diff-c27fa7dbaca8beeb94cb30bb4c62e88e1b4650436520054f678afdbfa1688ec8R31 it was changed to show weak warnings only when proc macros aren't enabled in the first place and otherwise show an error. |
Serde's proc-macros not resolving already indicates some problem that r-a has with your setup, I assume the |
Could you set |
I think I have no custom env vars at all |
Question is why this is happening 🤔 |
In my little experience, my eyes falls on |
Following that last log, I've checked vscode and rust-analyzer architecture, and they were both Intel (even if I was sure to have downloaded Silicon version), uninstalled, re-downloaded and reinstalled everything. |
Indeed. Rosetta 2 doesn't support dynamic linking across multiple architectures. If the main executable is compiled for x86_64, all dynamic libraries have to be compiled for it too. The only exception is for system libraries as those come bundled with trampolines for Rosetta 2 to translate between the x86_64 and arm64 abi's. A bit of a moonshot, but what if we bundle both x86_64 and arm64 rust-analyzer binaries in the same extension for macOS? Then rust-analyzer could check the target arch of the proc macro and start the proc macro server for the right target arch. If size is a concern, the arm64 binary for an x86_64 extension could contain just the proc macro server and skip the rest of rust-analyzer. It would also be possible to check if vscode is running under rosetta 2 and launch the arm64 instead of x86_64 version of rust-analyzer if both are bundled. That would break the case where both vscode and rustc are running under rosetta 2 though, but I expect that to be much less common. |
The original problem is working now as far as I understand, and the intel emulation problem will probably be addressed with #12579, so I think we can close this? |
A macro I've written seems to not work under rust-analyzer VSCode plugin on a Mac M1 machine, code builds fine but rust-analyzer doesn't shows macro-generated methods, while on my linux box it does.
My macro creates a cache file in std::env::current_dir() to light up build times, and I'm suspecting that's the main problem.
Trying to debug the hard way, I've put some log messages inside my macro to see if inside rust-analyzer something strange happens, but I can't find those messages, even with
"rust-analyzer.trace.server": "verbose"
.Is there a "standard" way to log from proc-macros in a way that rust-analyzer shows it?
The text was updated successfully, but these errors were encountered: