Skip to content

Commit 2834c4c

Browse files
committed
rustc: document the jobserver
Explicitly document that the jobserver may be used by `rustc`, as well as recommend the `+` indicator for integration of `rustc` into GNU Make. In particular, show the warning to increase the chances that this document is found when searching for solutions online. In addition, add a note about the issue with GNU Make 4.3 since it is important that users realize they should do this even if they do not expect parallelism from `rustc`. Finally, show how to workaround the issue of `$(shell ...)` calls in recursive Make (which e.g. was needed for the Linux kernel). The GNU Make 4.4 case under `--jobserver-style=pipe` is not added since it got fixed after Rust 1.76.0 already (i.e. `rustc` will not warn if it finds the negative file descriptors). From: rust-lang#120515 Cc: @petrochenkov @belovdv @weihanglo @bjorn3 Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 57da90e commit 2834c4c

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- [What is rustc?](what-is-rustc.md)
44
- [Command-line Arguments](command-line-arguments.md)
55
- [Codegen Options](codegen-options/index.md)
6+
- [Jobserver](jobserver.md)
67
- [Lints](lints/index.md)
78
- [Lint Levels](lints/levels.md)
89
- [Lint Groups](lints/groups.md)

src/doc/rustc/src/jobserver.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Jobserver
2+
3+
Internally, `rustc` may take advantage of parallelism. `rustc` will coordinate
4+
with the build system calling it if a [GNU Make jobserver] is passed in the
5+
`MAKEFLAGS` environment variable.
6+
7+
Starting with Rust 1.76.0, `rustc` will warn if a jobserver appears to be
8+
available but is not accessible, e.g.:
9+
10+
```console
11+
$ echo 'fn main() {}' | MAKEFLAGS=--jobserver-auth=3,4 rustc -
12+
warning: failed to connect to jobserver from environment variable `MAKEFLAGS="--jobserver-auth=3,4"`: cannot open file descriptor 3 from the jobserver environment variable value: Bad file descriptor (os error 9)
13+
|
14+
= note: the build environment is likely misconfigured
15+
```
16+
17+
## Calling `rustc` from GNU Make
18+
19+
When calling `rustc` from GNU Make, it is recommended that all `rustc`
20+
invocations are marked as recursive in the `Makefile` (by prefixing the command
21+
line with the `+` indicator), so that GNU Make enables the jobserver for them.
22+
For instance:
23+
24+
<!-- ignore-tidy-tab -->
25+
26+
```make
27+
x:
28+
+@echo 'fn main() {}' | rustc -
29+
```
30+
31+
In particular, GNU Make 4.3 (a widely used version as of 2024) passes a simple
32+
pipe jobserver in `MAKEFLAGS` even when it was not made available for the child
33+
process, which in turn means `rustc` will warn about it. For instance, if the
34+
`+` indicator is removed from the example above and GNU Make is called with e.g.
35+
`make -j2`, then the warning will trigger.
36+
37+
For calls to `rustc` inside `$(shell ...)` inside a recursive Make, one can
38+
disable the jobserver manually, e.g.:
39+
40+
```make
41+
S := $(shell MAKEFLAGS= rustc --print sysroot)
42+
43+
x:
44+
@$(MAKE) y
45+
46+
y:
47+
@echo $(S)
48+
```
49+
50+
[GNU Make jobserver]: https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.html

0 commit comments

Comments
 (0)