Skip to content

unify bootstrap and shim binaries - #95164

Closed
fee1-dead wants to merge 2 commits into
rust-lang:masterfrom
fee1-dead-contrib:unify-shim-bins
Closed

unify bootstrap and shim binaries#95164
fee1-dead wants to merge 2 commits into
rust-lang:masterfrom
fee1-dead-contrib:unify-shim-bins

Conversation

@fee1-dead

Copy link
Copy Markdown
Member

they are now dispatched based on the binary name it is called with.
target/debug/rust{c, doc} are now hard linked to bootstrap.

This fixes#95141, cc @jyn514.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 21, 2022
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@jyn514jyn514 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is awesome ❤️

Comment threadsrc/bootstrap/bin/main.rs Outdated
Comment threadsrc/bootstrap/Cargo.toml Outdated
Comment threadsrc/bootstrap/bin/main.rs Outdated
Comment threadsrc/bootstrap/bin/main.rs Outdated
Comment threadsrc/bootstrap/lib.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe use Build::copy instead? It hardlinks and falls back to copying if it fails. Some systems may not support hardlinks.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Build::copy defeats the point, it means the new files won't be updated on changes.

I don't know a good solution here :/ maybe we could do test somewhere of whether the fs supports file links and copy unconditionally if so?

@fee1-deadfee1-deadMar 23, 2022

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

it means the new files won't be updated on changes

Not sure what you meant. The current implementation is as follows:

/// Copies a file from `src` to `dst`pubfncopy(&self,src:&Path,dst:&Path){ifself.config.dry_run{return;}self.verbose_than(1,&format!("Copy {:?} to {:?}", src, dst));if src == dst {return;}let _ = fs::remove_file(&dst);let metadata = t!(src.symlink_metadata());if metadata.file_type().is_symlink(){let link = t!(fs::read_link(src));t!(symlink_file(link, dst));}elseifletOk(()) = fs::hard_link(src, dst){// Attempt to "easy copy" by creating a hard link// (symlinks don't work on windows), but if that fails// just fall back to a slow `copy` operation.}else{ifletErr(e) = fs::copy(src, dst){panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)}t!(fs::set_permissions(dst, metadata.permissions()));let atime = FileTime::from_last_access_time(&metadata);let mtime = FileTime::from_last_modification_time(&metadata);t!(filetime::set_file_times(dst, atime, mtime));}}

Which is akin to an unconditional hard_link.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, because if you hit the fs::copy path, then the next time bootstrap is executed "rustc".exists() will return true and it will never recopy the binary. Which defeats the whole point of this change.

@fee1-deadfee1-deadMar 23, 2022

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

That is true, I will just remove the check for rustc.exists() because it was triggering a filesystem error because the dest file already existed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, I suppose that works too. The hard link should be very cheap compared to everything else bootstrap does 👍

@Mark-SimulacrumMark-Simulacrum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we name the "primary" (i.e., the one produced by rustc) binary something less difficult to refer to? Maybe rustbuild-binary-dispatch-shim?

Please also squash the commits as you make changes, no need for "review changes" commits.

Comment threadsrc/bootstrap/bin/main.rs Outdated
Comment threadsrc/bootstrap/bin/main.rs Outdated
Comment threadsrc/bootstrap/bin/rustc.rs Outdated
Comment threadsrc/bootstrap/lib.rs Outdated
Comment threadsrc/bootstrap/lib.rs Outdated
@Mark-SimulacrumMark-Simulacrum 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 Apr 6, 2022
@fee1-dead
fee1-deadforce-pushed the unify-shim-bins branch 2 times, most recently from a6aa04c to 578826aCompareApril 7, 2022 04:56
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors

bors commented Apr 10, 2022

Copy link
Copy Markdown
Collaborator

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

@Mark-SimulacrumMark-Simulacrum added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 30, 2022
they are now dispatched based on the binary name it is called with.
`target/debug/rust{c, doc}` are now hard linked to `bootstrap`.
@fee1-dead

Copy link
Copy Markdown
MemberAuthor

Umm, I took a look and it looks like it already tries to remove the destination before copying: https://cs.github.com/rust-lang/rust/blob/fee75fbe11b1fad5d93c723234178b2a329a3c03/src/bootstrap/lib.rs#L1418

@fee1-deadfee1-dead 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 May 10, 2022
@bjorn3

Copy link
Copy Markdown
Member

Windows doesn't allow deleting files that are currently open by default. I believe FILE_DISPOSITION_POSIX_SEMANTICS allows deleting open files though.

@fee1-dead

Copy link
Copy Markdown
MemberAuthor

So I tried to use posix_delete on windows with the latest commit. Should we see whether that will work?

@Mark-Simulacrum

Copy link
Copy Markdown
Member

I'm not sure that function is publicly exposed, but we can try. @bors r+

@bors

bors commented May 11, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit 64a8af9 has been approved by Mark-Simulacrum

@borsbors 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 May 11, 2022
@bors

bors commented May 11, 2022

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 64a8af9 with merge c0220834cf72ccea19c0454ad82db04e18ea67a7...

@bors

bors commented May 11, 2022

Copy link
Copy Markdown
Collaborator

💔 Test failed - checks-actions

@borsbors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 11, 2022
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-msvc-tools failed! Check out the build log: (web)(plain)

Click to see the possible cause of the failure (guessed by this bot)
 Compiling xz2 v0.1.6
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:36
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:67
--> src\bootstrap\lib.rs:1430:67
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0624]: associated function `posix_delete` is private
--> src\bootstrap\lib.rs:1431:30
|
1431 | let _ = file.posix_delete();
Some errors have detailed explanations: E0603, E0624.
For more information about an error, try `rustc --explain E0603`.
error: could not compile `bootstrap` due to 3 previous errors
---
Compiling bootstrap v0.0.0 (D:\a\rust\rust\src\bootstrap)
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:36
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:67
--> src\bootstrap\lib.rs:1430:67
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0624]: associated function `posix_delete` is private
--> src\bootstrap\lib.rs:1431:30
|
1431 | let _ = file.posix_delete();
Some errors have detailed explanations: E0603, E0624.
For more information about an error, try `rustc --explain E0603`.
error: could not compile `bootstrap` due to 3 previous errors
---
Compiling bootstrap v0.0.0 (D:\a\rust\rust\src\bootstrap)
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:36
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:67
--> src\bootstrap\lib.rs:1430:67
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0624]: associated function `posix_delete` is private
--> src\bootstrap\lib.rs:1431:30
|
1431 | let _ = file.posix_delete();
Some errors have detailed explanations: E0603, E0624.
For more information about an error, try `rustc --explain E0603`.
error: could not compile `bootstrap` due to 3 previous errors
---
Compiling bootstrap v0.0.0 (D:\a\rust\rust\src\bootstrap)
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:36
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:67
--> src\bootstrap\lib.rs:1430:67
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0624]: associated function `posix_delete` is private
--> src\bootstrap\lib.rs:1431:30
|
1431 | let _ = file.posix_delete();
Some errors have detailed explanations: E0603, E0624.
For more information about an error, try `rustc --explain E0603`.
error: could not compile `bootstrap` due to 3 previous errors
---
Compiling bootstrap v0.0.0 (D:\a\rust\rust\src\bootstrap)
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:36
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:67
--> src\bootstrap\lib.rs:1430:67
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0624]: associated function `posix_delete` is private
--> src\bootstrap\lib.rs:1431:30
|
1431 | let _ = file.posix_delete();
Some errors have detailed explanations: E0603, E0624.
For more information about an error, try `rustc --explain E0603`.
error: could not compile `bootstrap` due to 3 previous errors

@bors

bors commented May 14, 2022

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 64a8af9 with merge 83698375db8b68e4b56f5a650443f96accc44471...

@bors

bors commented May 14, 2022

Copy link
Copy Markdown
Collaborator

💔 Test failed - checks-actions

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job i686-msvc-1 failed! Check out the build log: (web)(plain)

Click to see the possible cause of the failure (guessed by this bot)
 Compiling xz2 v0.1.6
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:36
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:67
--> src\bootstrap\lib.rs:1430:67
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0624]: associated function `posix_delete` is private
--> src\bootstrap\lib.rs:1431:30
|
1431 | let _ = file.posix_delete();
Some errors have detailed explanations: E0603, E0624.
For more information about an error, try `rustc --explain E0603`.
error: could not compile `bootstrap` due to 3 previous errors
---
Compiling bootstrap v0.0.0 (D:\a\rust\rust\src\bootstrap)
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:36
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:67
--> src\bootstrap\lib.rs:1430:67
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0624]: associated function `posix_delete` is private
--> src\bootstrap\lib.rs:1431:30
|
1431 | let _ = file.posix_delete();
Some errors have detailed explanations: E0603, E0624.
For more information about an error, try `rustc --explain E0603`.
error: could not compile `bootstrap` due to 3 previous errors
---
Compiling bootstrap v0.0.0 (D:\a\rust\rust\src\bootstrap)
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:36
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:67
--> src\bootstrap\lib.rs:1430:67
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0624]: associated function `posix_delete` is private
--> src\bootstrap\lib.rs:1431:30
|
1431 | let _ = file.posix_delete();
Some errors have detailed explanations: E0603, E0624.
For more information about an error, try `rustc --explain E0603`.
error: could not compile `bootstrap` due to 3 previous errors
---
Compiling bootstrap v0.0.0 (D:\a\rust\rust\src\bootstrap)
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:36
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:67
--> src\bootstrap\lib.rs:1430:67
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0624]: associated function `posix_delete` is private
--> src\bootstrap\lib.rs:1431:30
|
1431 | let _ = file.posix_delete();
Some errors have detailed explanations: E0603, E0624.
For more information about an error, try `rustc --explain E0603`.
error: could not compile `bootstrap` due to 3 previous errors
---
Compiling bootstrap v0.0.0 (D:\a\rust\rust\src\bootstrap)
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:36
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0603]: module `sys` is private
--> src\bootstrap\lib.rs:1430:67
--> src\bootstrap\lib.rs:1430:67
|
1430 | if let Ok(file) = std::sys::fs::File::open(dst, &std::sys::fs::OpenOptions::new()) {
| ^^^ private module
note: the module `sys` is defined here
error[E0624]: associated function `posix_delete` is private
--> src\bootstrap\lib.rs:1431:30
|
1431 | let _ = file.posix_delete();
Some errors have detailed explanations: E0603, E0624.
For more information about an error, try `rustc --explain E0603`.
error: could not compile `bootstrap` due to 3 previous errors

@Mark-SimulacrumMark-Simulacrum 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 May 14, 2022
@apirainoapiraino added the T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. label May 23, 2022
@jyn514

Copy link
Copy Markdown
Member

This should no longer be necessary with the new plan, since no one will run cargo run locally (they'll either download it from CI or build all binaries from source through x.py): #95141 (comment)

Sorry to spend so much of your time on this.

@fee1-dead

Copy link
Copy Markdown
MemberAuthor

I did take a look at rustup, and it looks like they retry the deletion with timeout instead of invoking the functions once. Maybe that will resolve the issue (perhaps due to concurrency?) But if this is not needed anymore I'm happy to leave it.

@fee1-dead
fee1-dead deleted the unify-shim-bins branch March 25, 2023 09:02
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.T-infraRelevant to the infrastructure team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo run doesn't rebuild bootstrap binaries

8 participants

@fee1-dead@rust-highfive@rust-log-analyzer@bors@Mark-Simulacrum@jyn514@bjorn3@apiraino