-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Allow rust-project.json to specify sysroot workspace #19096
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
There is still some work to do here, but I wanted to get feedback on the overall approach before moving forward and making the corresponding changes in Buck's rust-project. We can also delete stitched sysroot here if we change Cargo to be the fallback. |
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.
Seems reasonable to me, I assume (should we rid of the stitched variant), setting sysroot
, sysroot_src
and sysroot_project
as None
would imply not to load a sysroot? Or should we have a separate flag to opt-into not loading. Maybe just sysroot_src
and sysroot_project
being None
should opt-out (as a sysroot
dir is still useful for tools). I don't know the use-cases of alternate build systems too well here
@@ -566,7 +573,9 @@ impl ProjectWorkspace { | |||
Some(PackageRoot { is_local: false, include, exclude }) | |||
}) | |||
.collect(), | |||
SysrootWorkspace::Stitched(_) | SysrootWorkspace::Empty => vec![], | |||
SysrootWorkspace::Json(_) |
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.
Do we not need to handle this as well?
@@ -65,6 +65,7 @@ pub struct ProjectJson { | |||
pub(crate) sysroot: Option<AbsPathBuf>, | |||
/// e.g. `path/to/sysroot/lib/rustlib/src/rust/library` | |||
pub(crate) sysroot_src: Option<AbsPathBuf>, | |||
pub(crate) sysroot_project: Option<ProjectJsonData>, |
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.
Shouldn't this be Option<ProjectJson>?
@@ -65,6 +65,7 @@ pub struct ProjectJson { | |||
pub(crate) sysroot: Option<AbsPathBuf>, | |||
/// e.g. `path/to/sysroot/lib/rustlib/src/rust/library` | |||
pub(crate) sysroot_src: Option<AbsPathBuf>, | |||
pub(crate) sysroot_project: Option<ProjectJsonData>, |
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.
Comment above would be nice
053f2bd
to
597b00d
Compare
I've added another commit that deletes stitched sysroot. The current behavior is...
I'm not aware of a use case for explicitly opting out of the sysroot entirely. Is there a way to do that for cargo projects? If not, I don't think we need it for json projects either. |
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.
Will need a rebase over my latest changes which likely conflict a fair bit, sorry. I don't think cargo projects ever want to specify not having a sysroot rust source so removing that should be fine. I do now wonder though whether rust-project.json even wants a sysroot source field at all, or if instead we want to expose the lang origin thing for its specified crate data. That is have it embed the sysroot into its crate graph itself and tag the relevant crates accordingly?
@davidbarsky regarding my comment there, specifically
I believe that is something you've been thinking about this week basically (in the space of cargo metadata, but here it applies more directly wrt to the json format) |
Yeah, I have been thinking about this because I was trying to see if there's a way to unify the paths for handling a I also chatted with @darichey and @capickett this week, where I learned that Buck can use a Buckified |
crates/project-model/src/sysroot.rs
Outdated
SysrootWorkspace::Json(project_json) => project_json | ||
.crates() | ||
.filter_map(|(_, krate)| krate.display_name.clone()) | ||
.any(|name| name.canonical_name().as_str() == "core-0.0.0"), // FIXME: this is buck-specific and should be handled there instead |
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.
A bit iffy about this, we might want to disable the check for json sysroots for now?
I just realized that I actually don't know what a "stitched workspace" refers to: I can't really find it in my limited scrollback! |
Summary: rust-analyzer wants to drop support for their "stitched sysroot" (where it will assume the structure of the sysroot) in favor of relying on the build tool to tell it the sysroot layout. Since we have a buckified sysroot, that can be buck, and we can include a nested JsonProject for the sysroot. Corresponding rust-analyzer change: rust-lang/rust-analyzer#19096 Reviewed By: davidbarsky Differential Revision: D69328620 fbshipit-source-id: ee0b461b2e144bfefd30970d6f6ce35ae89e8ee1
597b00d
to
b5a4350
Compare
Oh I thought I replied to this by mail, sorry. Stitched just means we manually picked the crates in the sysroot from a known list. That logic predates the sysroot now shipping a proper cargo workspace (which is why we can drop support for it now, its been long enough) |
b5a4350
to
16024dd
Compare
Corresponding buck2 changes: I've tested this with those changes and the sysroot loads properly. |
16024dd
to
0a456cf
Compare
@@ -225,18 +223,6 @@ fn rust_project_cfg_groups() { | |||
check_crate_graph(crate_graph, expect_file!["../test_data/output/rust_project_cfg_groups.txt"]); | |||
} | |||
|
|||
#[test] |
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 deleted this test because it's really testing a behavior of the stitched sysroot.
0a456cf
to
18a678e
Compare
Thanks! |
Following up on #18590 (comment) and #18788 to add a
sysroot_project
key to rust-project.json which allows specifying a nested rust-project for the sysroot. This gives control over the sysroot layout to the rust-project generator (e.g., Buck). At work, we can build the sysroot with Buck, so this change allows us to make use of that instead of the stitched sysroot. Most users of Buck and Bazel will still want to use Cargo for the sysroot.