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

Ask rust_toolchain for rustc_src in rust_analyzer.bzl #733

Merged
merged 1 commit into from
May 12, 2021

Conversation

hlopko
Copy link
Member

@hlopko hlopko commented May 11, 2021

In this PR we remove hardcoded assumption about where rust-analyzer support code looks for rustc sources, and instead read that information from the rust_toolchain.rustc_src. We also handle the case when rustc sources are actually in the main repository, so there is no need to use the __EXEC_ROOT__/ prefix for its path.

@hlopko
Copy link
Member Author

hlopko commented May 11, 2021

CC @djmarcin

@hlopko hlopko force-pushed the fix_rust_analyzer_sysroot branch from 04080c2 to 9b957cb Compare May 11, 2021 12:30
@hlopko hlopko requested a review from illicitonion May 11, 2021 12:30
@hlopko hlopko force-pushed the fix_rust_analyzer_sysroot branch 2 times, most recently from 443894a to 9d3902c Compare May 11, 2021 12:39
Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Seems reasonable :)

@hlopko hlopko force-pushed the fix_rust_analyzer_sysroot branch from 9d3902c to 221b641 Compare May 11, 2021 13:06
@hlopko
Copy link
Member Author

hlopko commented May 11, 2021

@illicitonion only until you'll see I just added rustc srcs back after your PR :))

Now more seriously we'll need some way of including rustc sources for some targets on the CI. I can see how an env var could be used for that, what do you think?

@hlopko hlopko force-pushed the fix_rust_analyzer_sysroot branch from 221b641 to d4116da Compare May 11, 2021 13:08
@illicitonion
Copy link
Collaborator

@illicitonion only until you'll see I just added rustc srcs back after your PR :))

Now more seriously we'll need some way of including rustc sources for some targets on the CI. I can see how an env var could be used for that, what do you think?

Personally I'm fine with rules_rust always fetching the rustc srcs, as long as it doesn't force consumers of rules_rust to also always fetch them...

@UebelAndre
Copy link
Collaborator

Personally I'm fine with rules_rust always fetching the rustc srcs, as long as it doesn't force consumers of rules_rust to also always fetch them...

I would love to only fetch Rust srcs when needed (which is locally). I don't think there's a reason to fetch them in CI (of projects using rules_rust) so would like to have a mechanism for controlling this. I think there's a lot of value in rust_analyzer so I think it's fine to default to downloading the sources and allow for an 'opt-out' flag.

@hlopko hlopko force-pushed the fix_rust_analyzer_sysroot branch 2 times, most recently from 25f034d to a95ffc5 Compare May 11, 2021 18:04
@hlopko
Copy link
Member Author

hlopko commented May 11, 2021

Personally I'm fine with rules_rust always fetching the rustc srcs, as long as it doesn't force consumers of rules_rust to also always fetch them...

Oh I'm glad to hear that, that simplifies a lot and makes a perfect sense to me.

I would love to only fetch Rust srcs when needed (which is locally). I don't think there's a reason to fetch them in CI (of projects using rules_rust) so would like to have a mechanism for controlling this. I think there's a lot of value in rust_analyzer so I think it's fine to default to downloading the sources and allow for an 'opt-out' flag.

If I understand you correctly you're saying that users of rules_rust should not downloads rustc sources by default, both locally and on the CI, but there should be a way to download sources for people wanting to use rust analyzer (and that there is rarely a need to download rustc sources on their CI). I fully agree with these points.

What this PR does is only downloading rustc sources for local development of rules_rust, and also for CI of rules_rust (because we need test coverage on the CI for the rust analyzer support).

So it seems to me we're in full synergy? :)

@UebelAndre
Copy link
Collaborator

What this PR does is only downloading rustc sources for local development of rules_rust, and also for CI of rules_rust (because we need test coverage on the CI for the rust analyzer support).

What about local development of another project which uses rules_rust but is not actually the rules? What does that workflow look like?

@hlopko
Copy link
Member Author

hlopko commented May 11, 2021

That project has to write its own WORKSPACE file and in it specify which rust toolchains to use (and therefore whether and how to download rustc sources). WORKSPACE files are not used when the repository is an external repo, they are only used when the repository is the main one.

@UebelAndre
Copy link
Collaborator

That project has to write its own WORKSPACE file and in it specify which rust toolchains to use (and therefore whether and how to download rustc sources). WORKSPACE files are not used when the repository is an external repo, they are only used when the repository is the main one.

Yeah, so the thing I'm saying is the new include_rust_srcs flag is not a flexible enough solution. I don't know of any use of the rust sources outside of local development. So as I write the WORKSPACE file for my project, I'll set include_rust_srcs = True and forever incur the cost of fetching those. Again, this is fine locally because I plan to use those for rust_analyzer but it's a cost to CI where each build now downloads these sources that are otherwise useless. I should be able to specify in a .bazelrc whether or not I want to set include_rust_srcs = True so local developers can have functional rust_analyzer and CI can efficiently build and test code.

@UebelAndre
Copy link
Collaborator

#541 is a good example of what I'm thinking. Where something settable in a .bazelrc file can toggle this behavior.

@hlopko hlopko force-pushed the fix_rust_analyzer_sysroot branch from a95ffc5 to 804a002 Compare May 12, 2021 06:22
@hlopko
Copy link
Member Author

hlopko commented May 12, 2021

Ah I understand now. Yeah, having an environment variable to include sources that you set locally, or a variable to not include sources, that you set on the CI, sound like a standard solution for this problem. It's an issue a bit orthogonal to this PR, let's address it in a separate PR (do you want to give it a try? :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants