Cargo should release Make jobserver token when it's waiting for file lock
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 15.5k
- Forks
- 3k
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 51
Description
Consider the following Makefile:
default: first second third
.PHONY: first second
first second:
+cargo build -p $@ --verbose
third:
echo start $@
sleep 1
echo end $@
And the directory containing the Makefile contains the following Cargo.toml:
[workspace]
members = [
"first",
"second",
]
first and second are just created with cargo new, with an additional build.rs each that contains the following:
use std::{thread, time};
fn main() {
thread::sleep(time::Duration::from_secs(2));
}
Now, run the build with make -j2.
The timeline of what happens looks like the following:
- 0s: make executes the two cargo commands.
- 0s: first cargo command invokes rustc for build.rs and runs build_script_build ; second cargo command prints "Blocking waiting for file lock on build directory"
- 2s: first cargo finishes running build_script_build, builds the rest of the first crate
- 2s: second cargo command invokes rustc for build.rs and runs build_script_build
- 2s: make executes
echo start thirdthensleep 2 - 4s: second cargo finishes running build_script_build, builds the rest of the second crate
- 4s: make executes
echo end third.
Obviously, this is all synthetic, and cargo releasing the make jobserver token as proposed in the summary would not change the outcome in this example, being that the build would still take 4 seconds. But what it would allow is for make to start running the third target earlier, and that could make a hell of a difference.
The real world manifestation is https://bugzilla.mozilla.org/show_bug.cgi?id=1533988 which is caused by the Firefox build system invoking three cargo commands in the same workspace, two of which are "Blocking waiting for file lock on build directory", and the one that does work is actually likely to not be using all the cores available because of how a lot of the dependency chain of the crates built is linear. So the two cargos doing nothing are preventing more C++ compiler processes working while the first cargo works.
Cc: @alexcrichton
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided Makefile, Cargo.toml, and build.rs files by running make -j2. Then trace Cargo's handling of the Make jobserver while it waits for the build-directory file lock. Done means a waiting Cargo process releases its jobserver token so make can start the third target earlier without changing the build result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100