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

fix: preserve jobserver file descriptors on rustc invocation to get TargetInfo #12447

Merged
merged 1 commit into from
Aug 8, 2023

Conversation

belovdv
Copy link
Contributor

@belovdv belovdv commented Aug 4, 2023

Then cargo asks rustc for TargetInfo, cargo passes environment variables that describe jobserver file descriptors, but doesn't actually passed them, because jobserver-rs sets FD_CLOEXEC by default and expects users to explicitly call Client::configure to pass them further. Rustc respects make jobserver, so this causes error - env vars refers to nonexistent file descriptors, which is ignored now.

This PR makes cargo compatible with rust-lang/rust#113730, which attempts to catch such situations.

@rustbot
Copy link
Collaborator

rustbot commented Aug 4, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @epage (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added A-cfg-expr Area: Platform cfg expressions S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 4, 2023
@petrochenkov
Copy link
Contributor

petrochenkov commented Aug 4, 2023

What cargo does when it wants to really run rustc (for compilation, with jobserver passed through properly) - changes CLOEXEC flags to false? Creates jobserver-rs client in some other way?

Maybe it makes sense to do the same thing here for consistency, even if this rustc run is tiny.

@bjorn3
Copy link
Member

bjorn3 commented Aug 4, 2023

The jobserver crate has a method which forwards the jobserver to a given Command.

@belovdv
Copy link
Contributor Author

belovdv commented Aug 4, 2023

Method Client::configure takes Command, while TargetInfo::new uses ProcessBuilder, so removing env vars seems to be simpler solution.

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Thanks for working on jobserver so far!

The intent of this pull request is not immediately clear to me. What does this try to resolve in practice? People in the future may be confused and wonderwhy these envs were removed. I know there are links to discussions, but without a summary it's not easy to follow. Besides, assumed this quite important, I believe a test is pretty much wanted. Thus, I'd like to see something beyond code:

  • A clear PR description of why this is bad and how it affects other programs.
  • Why the solution is desired (remove envs) but not others (e.g. inherit jobserver).
  • A test that verifies the “wrong” behavior, and one follow-up commit fixes it.

@belovdv
Copy link
Contributor Author

belovdv commented Aug 4, 2023

I've updated PR description.

how it affects other programs

This PR affects only rustc invocation, so I'm not sure, what do you mean.

Why the solution is desired but not others

I don't know, if this solution is better. It shouldn't change anything, since now jobserver isn't used and it won't be used with this PR. Also, according to @bjorn3 "That rustc call doesn't use jobserver", so passing jobserver won't change anything, so it's may be better to use simplest solution.

A test that verifies the “wrong” behavior

My local test is makefile, called make -j 2, which contains + RUSTC=dummy cargo build, there dummy - some binary, that responds to dummy -vV, and checks that make variables (if any) points to existing file descriptors.

One option to write such test is to use some wrapper over rustc, which would verify that passed jobserver-related env vars from cargo don't refer to nonexistent file descriptors, but imho it would be enough to have such check in rustc, which my PR to rustc is intended to add.

@petrochenkov
Copy link
Contributor

The intent of this pull request is not immediately clear to me. What does this try to resolve in practice?

At high level:

(Even if the check in rust-lang/rust#113730 is later made optional or relaxed due to incompatibilities in third-party tools that we cannot fix, with cargo we can indeed fix it so it's better to make it compatible.)

I'd personally follow #12447 (comment) and Client::configure this rustc run even if it's tiny, just for consistency.

@weihanglo
Copy link
Member

To fix CI, rebase onto master. See #12450

@belovdv
Copy link
Contributor Author

belovdv commented Aug 6, 2023

Branch rebased, thanks.

ProcessBuilder calls Client::configure, if inherit_jobserver provided one. Does this solution suit better (so I should update PR name and description)?

About test - should I add one, or it'd be enough to have check in rustc?

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Thanks! Looks a bit more reasonable to me in terms of consistency.

While updating PR title and description, could you also add a comment of a line or two to explain why Cargo inherits jobserver here?

@belovdv belovdv changed the title fix: remove jobserver-related env vars on rustc invocation to get TargetInfo fix: preserve jobserver file descriptors on rustc invocation to get TargetInfo Aug 8, 2023
@weihanglo
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 8, 2023

📌 Commit 1e12538 has been approved by weihanglo

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 8, 2023
@bors
Copy link
Collaborator

bors commented Aug 8, 2023

⌛ Testing commit 1e12538 with merge a07a12a...

@bors
Copy link
Collaborator

bors commented Aug 8, 2023

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing a07a12a to master...

@bors bors merged commit a07a12a into rust-lang:master Aug 8, 2023
18 checks passed
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 13, 2023
Update cargo

21 commits in d78bbf4bde3c6b95caca7512f537c6f9721426ff..7e9de3f4ec3708f500bec142317895b96131e47c
2023-08-03 12:58:25 +0000 to 2023-08-13 00:47:32 +0000
- feat: remove `--keep-going` from `cargo test/bench` (rust-lang/cargo#12478)
- chore: window-sys should be a platform-specific dependency (rust-lang/cargo#12483)
- docs: make the env var source of rerun-if-env-changed clearer (rust-lang/cargo#12482)
- doc: note the backward compatible `.cargo/credential` file exists (rust-lang/cargo#12479)
- Fix elided lifetime in associated const (rust-lang/cargo#12475)
- prompt the use of `--nocapture` flag if `cargo test` process is terminated via a signal. (rust-lang/cargo#12463)
- cargo-credential: reset stdin & stdout to the Console (rust-lang/cargo#12469)
- Fix cargo remove incorrectly removing used patches (rust-lang/cargo#12454)
- chore(gh): Expand update window (rust-lang/cargo#12466)
- Fix panic when enabling http.debug for certain strings (rust-lang/cargo#12468)
- fix(cli): Make `--help` easier to browse (rust-lang/cargo#11905)
- fix: preserve jobserver file descriptors on rustc invocation to get `TargetInfo` (rust-lang/cargo#12447)
- refactor: migrate to `tracing` (rust-lang/cargo#12458)
- docs: add example for cargo-credential (rust-lang/cargo#12461)
- Bail out an error when using cargo:: in custom build script (rust-lang/cargo#12332)
- Fix printing multiple warning messages for unused fields in [registries] table (rust-lang/cargo#12439)
- Update windows dependencies (rust-lang/cargo#12453)
- Rustfmt a let-else statement (rust-lang/cargo#12451)
- Add allow(internal_features) (rust-lang/cargo#12450)
- Update pretty_env_logger to 0.5 (rust-lang/cargo#12445)
- Remove build metadata from libgit2-sys dependency (rust-lang/cargo#12444)

r? `@ghost`
@ehuss ehuss added this to the 1.73.0 milestone Aug 22, 2023
bors added a commit that referenced this pull request Nov 10, 2023
fix: preserve jobserver file descriptors on rustc invocation in `fix_exec_rustc`

Similar to #12447

Command `cargo fix` invokes `cargo rustc`. It sends environment variable which points to closed file descriptors.

This PR makes cargo compatible with rust-lang/rust#113730.

It should be enough to have tests in rustc. It seems to be good to have more centralized way to pass jobserver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cfg-expr Area: Platform cfg expressions S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants