Skip to content
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

Suggested rust-analyzer config can't run rustfmt #107547

Closed
jyn514 opened this issue Feb 1, 2023 · 25 comments · Fixed by #107834
Closed

Suggested rust-analyzer config can't run rustfmt #107547

jyn514 opened this issue Feb 1, 2023 · 25 comments · Fixed by #107834
Assignees
Labels
C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@jyn514
Copy link
Member

jyn514 commented Feb 1, 2023

#107297 broke the rust-analyzer config we suggest in the dev-guide: https://rustc-dev-guide.rust-lang.org/building/suggested.html#configuring-rust-analyzer-for-rustc

    "rust-analyzer.rustfmt.overrideCommand": [
        "./build/host/stage0/bin/rustfmt",
        "--edition=2021"
    ],

since now rustfmt is in build/host/rustfmt/bin/rustfmt instead of build/host/stage0/bin/rustfmt.

Originally posted by @jyn514 in #107297 (comment)

@jyn514 jyn514 added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) C-bug Category: This is a bug. labels Feb 1, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 1, 2023
@zephaniahong
Copy link
Contributor

@rustbot claim

@zephaniahong
Copy link
Contributor

Hi! Just to clarify, the idea is to change to code to match the docs?

@albertlarsan68
Copy link
Member

I think the idea is changing the docs to match the new behavior.

@zephaniahong
Copy link
Contributor

For reference: rust-lang/rustc-dev-guide#1574

@jyn514
Copy link
Member Author

jyn514 commented Feb 1, 2023

I'd prefer to change the code so that we don't force all contributors to update their config.

@Mark-Simulacrum
Copy link
Member

I don't think we can put the binary back, or at least, that feels iffy - we'd be trying to overlap two different sysroots. rustfmt used to be statically linked to libstd and librustc_driver, but that's no longer the case.

@Mark-Simulacrum
Copy link
Member

I suppose we could try to create a symlink from the old path to the new one? That might work, not sure.

@albertlarsan68
Copy link
Member

Maybe add a proxy?
On Linux it might just be

#!/usr/bin/sh
exec ../rustdoc $* #FIXME make this syntax correct

@jyn514
Copy link
Member Author

jyn514 commented Feb 1, 2023

A symlink seems like a good solution to me.

@albertlarsan68
Copy link
Member

Does the symlink still finds the correct so?

@jyn514
Copy link
Member Author

jyn514 commented Feb 1, 2023

✨ try it and see ✨

@zephaniahong
Copy link
Contributor

I'll experiment adding a symlink.

@albertlarsan68
Copy link
Member

On Windows, creating a symlink does not find the needed DLLs.
Trying to execute the symlink pops two msgbox saying that it doesn't find the rustc_driver and std DLLs.
You would need to symlink also the DLLs.
On Linux, it does find the correct SOs.

@kadiwa4
Copy link
Contributor

kadiwa4 commented Feb 1, 2023

Symlinking also works on macOS.

@jyn514
Copy link
Member Author

jyn514 commented Feb 2, 2023

On Windows, creating a symlink does not find the needed DLLs. Trying to execute the symlink pops two msgbox saying that it doesn't find the rustc_driver and std DLLs. You would need to symlink also the DLLs. On Linux, it does find the correct SOs.

Ok, this is pretty messy. How about doing both:

  • Add the symlink, which will work with both the old and new config on Mac and Linux
  • Update the recommended config in the dev-guide, which will help contributors fix the error message on Windows

and from there we can work long-term to using the same toolchain for rustfmt and other tools, without having a time pressure.

@jyn514
Copy link
Member Author

jyn514 commented Feb 2, 2023

and from there we can work long-term to using the same toolchain for rustfmt and other tools, without having a time pressure.

cc rust-lang/rustfmt#4884, rust-lang/rustfmt#3900

@zephaniahong
Copy link
Contributor

May I get some guidance and the creation of the symlink? Do I use rust to create the symlink in src/bootstrap/download.rs after the rustfmt_path line or do I use a bash command? If I do use a bash command, is there a file I should be adding it to?

Thank you!

@jyn514
Copy link
Member Author

jyn514 commented Feb 2, 2023

@zephaniahong use

fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(&self, src: P, link: Q) -> io::Result<()> {

@zephaniahong
Copy link
Contributor

And just to confirm, I use that symlink function here?

let rustfmt_path = bin_root.join("bin").join(exe("rustfmt", host));
let rustfmt_stamp = bin_root.join(".rustfmt-stamp");

@jyn514
Copy link
Member Author

jyn514 commented Feb 2, 2023

yes

@bjorn3
Copy link
Member

bjorn3 commented Feb 2, 2023

I think it would be possible to move rustfmt back to the same sysroot as the bootstrap compiler by only taking libstd.so, librustc_middle.so and libLLVM.so from the nightly rustc component and not copying any other files like the rustc binary. Libstd.so and librustc_middle.so both contain a hash in their name unique for each rustc version. libLLVM.so should contain the rustc version, so that shouldn't conflict either.

@albertlarsan68
Copy link
Member

Doing the same with the DLLs on Windows could also work.

@est31
Copy link
Member

est31 commented Feb 5, 2023

related (different error with rustfmt, but caused by the same change): #107676

@jyn514
Copy link
Member Author

jyn514 commented Feb 8, 2023

Hi @zephaniahong, any progress on the symlink? happy to help out if you're running into trouble :)

@zephaniahong
Copy link
Contributor

Hey @jyn514 ! Thanks for reaching out! I'll be starting tomorrow and will reach out to you if/when I need help!
Apologies for the delay!

@bors bors closed this as completed in a8df4b1 Feb 9, 2023
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants