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

Add $manifest_path substitution for cargo override commands #13528

Closed
wants to merge 1 commit into from

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Nov 2, 2022

We now allow using $manifest_path in the overrideCommands for build scripts and checkOnSave if their invocation strategy is per-workspace, which will be replaced by the path to the corresponding workspace's Cargo.toml or rust-project.json

Comment on lines +165 to +170
/// The Cargo.toml or rust-project.json file of the project.
project_file: AbsPathBuf,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naive question: while i think it's reasonable to make this required to start with, do you think this can be expended to not be a file and instead load this rust-project.json over some process that dynamically creates this?

(idk if this question is better addressed in a dedicated issue.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean, but for flychecking to occur, we already need to have a project structure which implies that there is at least one rust-project.json or Cargo.toml loaded

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...I think I mixed up what this PR was doing, I'm sorry about that! Bit tired.

Anyways: while I get that rust-project.json does need to be loaded for flycheck (and any analysis from rust-analyzer), I'm wondering if it needs to be loaded from file, as opposed to be read in via stdout or UDS, or anything along those lines.

Copy link
Member Author

@Veykril Veykril Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I assume this is in regards to project loading, otherwise I am not sure I understand) not necessarily, I could imagine an lsp extension for fetching the project structure maybe?

@Veykril Veykril added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 3, 2022
@bors
Copy link
Collaborator

bors commented Dec 16, 2022

☔ The latest upstream changes (presumably #13785) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung
Copy link
Member

How does this close #10793? We still have the problem that errors are printed with paths relative to the package manifest, not the working directory.

@Veykril
Copy link
Member Author

Veykril commented Aug 21, 2023

I don't quite recall the issue and this PR that well (I was planning on looking into it next week). But I think the rough idea was that this could work around the issue somehow? Or maybe it was only related to some of the comment in the linked issue.

Actually, I think the idea was that if the command uses the $manifest_path var, r-a could infer that the diagnostics will be relative to the manifest directory, not the working directory? Might be wrong but, again I'll have to check next week and read up on the past discussions.

@RalfJung
Copy link
Member

I wrote a summary of the current situation as I understand it at #10793 (comment)

@Veykril Veykril self-assigned this Aug 21, 2023
@HKalbasi HKalbasi added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 20, 2023
@bors
Copy link
Collaborator

bors commented Jan 2, 2024

☔ The latest upstream changes (presumably #16062) made this pull request unmergeable. Please resolve the merge conflicts.

@Veykril Veykril added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 3, 2024
@Veykril
Copy link
Member Author

Veykril commented Jan 10, 2024

I'll close this. I don't think we should add this to the cargo runners. Anything fancy like this most likely has a more complicated/different build system than cargo and should instead rely on the project-json format which might support this in the end. (this includes the rustc workspace which should switch to that format)

@Veykril Veykril closed this Jan 10, 2024
@RalfJung
Copy link
Member

RalfJung commented Jan 10, 2024 via email

@Veykril
Copy link
Member Author

Veykril commented Jan 10, 2024

https://rust-analyzer.github.io/manual.html#non-cargo-based-projects I can write up some thought regarding that wrt what x.py should do for that later

Related, #16135

@RalfJung
Copy link
Member

Hm, having to set the sysroot dir by hand makes it pretty much impossible to just ship such a project file and use it unaltered?

Also, rustc basically uses cargo. Having to duplicate all dependency information for RA would be a huge waste of effort IMO.

So I don't see a practical way for rustc (or Miri) to use that format, unfortunately.

@RalfJung
Copy link
Member

But anyway, my real issue is #10793, not this PR. I am not sure if this substitution would even help that issue.

@Veykril
Copy link
Member Author

Veykril commented Jan 11, 2024

Also, rustc basically uses cargo. Having to duplicate all dependency information for RA would be a huge waste of effort IMO.

It does not. In terms of check diagnostic output sure, but aside from that the workspace does not resemble a cargo workspace. It barely works in r-a right now with the hacks we have in place to make it somewhat work in the first place. Just open one of the library crates and you'll see a bunch of incorrect diagnostics. Proc-macros stop working if you add certain excluded workspaces like the cg_clif backend and a bunch of other things. That's the main reason why I want rust-lang/rust to move to rust-project.json.

Hm, having to set the sysroot dir by hand makes it pretty much impossible to just ship such a project file and use it unaltered?

In general a project would have a command or similar to produce the file for users, it is unfortunate to require a setup step to use r-a but in rust-lang/rust's case at least, that is already kind of required with x.py setup anyways.

But anyway, my real issue is #10793, not this PR. I am not sure if this substitution would even help that issue.

Probably not, that still requires fixing from cargo's side imo.

@RalfJung
Copy link
Member

RalfJung commented Jan 11, 2024

All dependency management in rustc is done via cargo. So in that sense rustc is using cargo. Having a copy of that dependency information somewhere else will inevitably result in that copy getting out-of-sync, and keeping it up-to-date will add yet more roadblocks to contributing to rustc.

@Veykril
Copy link
Member Author

Veykril commented Jan 11, 2024

Yet plain cargo commands do not work. Bootstrap solely putting cargo commands together that work out is nice and all, but r-a has assumptions about normal cargo workspaces that break due to how the repo works. For one the sysroot is very special in the workspace and to properly support r-a to work in the library folders (which are at the same time the sysroot of the workspace) is already so complicated that half the things break in r-a.

There might be a way to fix this in a simple way, but if there is I don't know how. I've tried many times, every time fixing one thing in the rust-lang/rust workspace at the cost of breaking something else. So frankly speaking I gave up on trying. And ideally r-a wouldn't have to special case anything for the rust-lang workspace, but for that to be the case the workspace either needs to become more like a plain cargo workspace or switch to rust-project.json (as all non-plain cargo build systems need to).

@RalfJung
Copy link
Member

Maybe there's a middle-ground where bootstrap can describe to RA what is special about this workspace. But giving up entirely and duplicating everything about how these crates need to be build is not a good solution either, IMO. I understand your frustration, but now you're swinging too far in the other direction I would say.

Anyway as we said above this PR is not on the critical path to improving the RA experience for rustc. rust-lang/cargo#9887 is the blocker here.

@davidbarsky
Copy link
Contributor

Speaking as a person who spends a lot of time with Buck and Rust: while Cargo is a great build system/package manager, I've noticed that Cargo doesn't scale particularly well to more complex builds (which is fair! a general purpose build system is hard). I don't think Lukas is swinging too hard in the opposite direction, honestly. Some of the issues that rustc is running into here would be substantially easier to resolve with a rust-project.json-based workflow. It might be an unfamiliar path, but I'd be happy to talk about my experiences in other contexts.

(iirc, a colleague of mine replaced x.py with buck2 as an experiment and rust-analyzer worked.)

@lnicola
Copy link
Member

lnicola commented Jan 11, 2024

The Rust for Linux project has a Makefile target that creates a rust-analyzer.json. I can imagine x.py being able to generate one.

@RalfJung
Copy link
Member

Sounds like something that should be discussed with t-compiler or with the bootstrap subteam.

@Veykril
Copy link
Member Author

Veykril commented Jan 11, 2024

There are multiple things relevant for this, I'll try writing down some notes regarding the problems the current rustc workspace has. But the gist is just because bootstrap makes use only of cargo for dependency resolution and assembling the actual workspace with a multitude of cargo commands does not make rust-lang/rust a cargo workspace and given bootstrap in rust-lang/rustc rust-project,json is should work out pretty well as a general solution in my eyes.

@Veykril Veykril deleted the cargo-subs branch September 9, 2024 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants