History

kbuild: mark `rustc` (and others) invocations as recursive

`rustc` (like Cargo) may take advantage of the jobserver at any time (e.g. for backend parallelism, or eventually frontend too). In the kernel, we call `rustc` with `-Ccodegen-units=1` (and `-Zthreads` is 1 so far), so we do not expect parallelism. However, in the upcoming Rust 1.76.0, a warning is emitted by `rustc` [1] when it cannot connect to the jobserver it was passed (in many cases, but not all: compiling and `--print sysroot` do, but `--version` does not). And given GNU Make always passes the jobserver in the environment variable (even when a line is deemed non-recursive), `rustc` will end up complaining about it (in particular in Make 4.3 where there is only the simple pipe jobserver style). One solution is to remove the jobserver from `MAKEFLAGS`. However, we can mark the lines with calls to `rustc` (and Cargo) as recursive, which looks simpler. This is being documented as a recommendation in `rustc` [2] and allows us to be ready for the time we may use parallelism inside `rustc` (potentially now, if a user passes `-Zthreads`). Thus do so. Similarly, do the same for `rustdoc` and `cargo` calls. Finally, there is one case that the solution does not cover, which is the `$(shell ...)` call we have. Thus, for that one, set an empty `MAKEFLAGS` environment variable.

Miguel Ojeda committed 2 years ago

Commit ecab4111 parent e9441714 files · +31 −31Browse files

Unified · Split

4 files
  1. Makefile +2 −2
  2. rust/Makefile +24 −24
  3. scripts/Makefile.build +4 −4
  4. scripts/Makefile.host +1 −1
Makefile+2−2
@@ -1197,7 +1197,7 @@ prepare0: archprepare · 1196 unmodified lines
1197# All the preparing..1197# All the preparing..
1198prepare: prepare01198prepare: prepare0
1199ifdef CONFIG_RUST1199ifdef CONFIG_RUST
1200 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh1200 +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh
1201 $(Q)$(MAKE) $(build)=rust1201 $(Q)$(MAKE) $(build)=rust
1202endif1202endif
1203 1203
@@ -1707,7 +1707,7 @@ $(DOC_TARGETS): · 503 unmodified lines
1707# "Is Rust available?" target1707# "Is Rust available?" target
1708PHONY += rustavailable1708PHONY += rustavailable
1709rustavailable:1709rustavailable:
1710 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh && echo "Rust is available!"1710 +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh && echo "Rust is available!"
1711 1711
1712# Documentation target1712# Documentation target
1713#1713#
rust/Makefile+24−24
@@ -40,7 +40,7 @@ obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.o · 39 unmodified lines
40ifdef CONFIG_RUST40ifdef CONFIG_RUST
41 41
42# `$(rust_flags)` is passed in case the user added `--sysroot`.42# `$(rust_flags)` is passed in case the user added `--sysroot`.
43rustc_sysroot := $(shell $(RUSTC) $(rust_flags) --print sysroot)43rustc_sysroot := $(shell MAKEFLAGS= $(RUSTC) $(rust_flags) --print sysroot)
44rustc_host_target := $(shell $(RUSTC) --version --verbose | grep -F 'host: ' | cut -d' ' -f2)44rustc_host_target := $(shell $(RUSTC) --version --verbose | grep -F 'host: ' | cut -d' ' -f2)
45RUST_LIB_SRC ?= $(rustc_sysroot)/lib/rustlib/src/rust/library45RUST_LIB_SRC ?= $(rustc_sysroot)/lib/rustlib/src/rust/library
46 46
@@ -108,14 +108,14 @@ rustdoc-macros: private rustdoc_host = yes · 61 unmodified lines
108rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \108rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
109 --extern proc_macro109 --extern proc_macro
110rustdoc-macros: $(src)/macros/lib.rs FORCE110rustdoc-macros: $(src)/macros/lib.rs FORCE
111 $(call if_changed,rustdoc)111 +$(call if_changed,rustdoc)
112 112
113rustdoc-core: private rustc_target_flags = $(core-cfgs)113rustdoc-core: private rustc_target_flags = $(core-cfgs)
114rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE114rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
115 $(call if_changed,rustdoc)115 +$(call if_changed,rustdoc)
116 116
117rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE117rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE
118 $(call if_changed,rustdoc)118 +$(call if_changed,rustdoc)
119 119
120# We need to allow `rustdoc::broken_intra_doc_links` because some120# We need to allow `rustdoc::broken_intra_doc_links` because some
121# `no_global_oom_handling` functions refer to non-`no_global_oom_handling`121# `no_global_oom_handling` functions refer to non-`no_global_oom_handling`
@@ -124,7 +124,7 @@ rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE · 2 unmodified lines
124rustdoc-alloc: private rustc_target_flags = $(alloc-cfgs) \124rustdoc-alloc: private rustc_target_flags = $(alloc-cfgs) \
125 -Arustdoc::broken_intra_doc_links125 -Arustdoc::broken_intra_doc_links
126rustdoc-alloc: $(src)/alloc/lib.rs rustdoc-core rustdoc-compiler_builtins FORCE126rustdoc-alloc: $(src)/alloc/lib.rs rustdoc-core rustdoc-compiler_builtins FORCE
127 $(call if_changed,rustdoc)127 +$(call if_changed,rustdoc)
128 128
129rustdoc-kernel: private rustc_target_flags = --extern alloc \129rustdoc-kernel: private rustc_target_flags = --extern alloc \
130 --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \130 --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \
@@ -132,7 +132,7 @@ rustdoc-kernel: private rustc_target_flags = --extern alloc \ · 1 unmodified line
132rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-macros \132rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-macros \
133 rustdoc-compiler_builtins rustdoc-alloc $(obj)/libmacros.so \133 rustdoc-compiler_builtins rustdoc-alloc $(obj)/libmacros.so \
134 $(obj)/bindings.o FORCE134 $(obj)/bindings.o FORCE
135 $(call if_changed,rustdoc)135 +$(call if_changed,rustdoc)
136 136
137quiet_cmd_rustc_test_library = RUSTC TL $<137quiet_cmd_rustc_test_library = RUSTC TL $<
138 cmd_rustc_test_library = \138 cmd_rustc_test_library = \
@@ -146,18 +146,18 @@ quiet_cmd_rustc_test_library = RUSTC TL $< · 7 unmodified lines
146 --crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@)) $<146 --crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@)) $<
147 147
148rusttestlib-build_error: $(src)/build_error.rs rusttest-prepare FORCE148rusttestlib-build_error: $(src)/build_error.rs rusttest-prepare FORCE
149 $(call if_changed,rustc_test_library)149 +$(call if_changed,rustc_test_library)
150 150
151rusttestlib-macros: private rustc_target_flags = --extern proc_macro151rusttestlib-macros: private rustc_target_flags = --extern proc_macro
152rusttestlib-macros: private rustc_test_library_proc = yes152rusttestlib-macros: private rustc_test_library_proc = yes
153rusttestlib-macros: $(src)/macros/lib.rs rusttest-prepare FORCE153rusttestlib-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
154 $(call if_changed,rustc_test_library)154 +$(call if_changed,rustc_test_library)
155 155
156rusttestlib-bindings: $(src)/bindings/lib.rs rusttest-prepare FORCE156rusttestlib-bindings: $(src)/bindings/lib.rs rusttest-prepare FORCE
157 $(call if_changed,rustc_test_library)157 +$(call if_changed,rustc_test_library)
158 158
159rusttestlib-uapi: $(src)/uapi/lib.rs rusttest-prepare FORCE159rusttestlib-uapi: $(src)/uapi/lib.rs rusttest-prepare FORCE
160 $(call if_changed,rustc_test_library)160 +$(call if_changed,rustc_test_library)
161 161
162quiet_cmd_rustdoc_test = RUSTDOC T $<162quiet_cmd_rustdoc_test = RUSTDOC T $<
163 cmd_rustdoc_test = \163 cmd_rustdoc_test = \
@@ -189,7 +189,7 @@ quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $< · 25 unmodified lines
189 $(src)/kernel/lib.rs $(obj)/kernel.o \189 $(src)/kernel/lib.rs $(obj)/kernel.o \
190 $(objtree)/scripts/rustdoc_test_builder \190 $(objtree)/scripts/rustdoc_test_builder \
191 $(objtree)/scripts/rustdoc_test_gen FORCE191 $(objtree)/scripts/rustdoc_test_gen FORCE
192 $(call if_changed,rustdoc_test_kernel)192 +$(call if_changed,rustdoc_test_kernel)
193 193
194# We cannot use `-Zpanic-abort-tests` because some tests are dynamic,194# We cannot use `-Zpanic-abort-tests` because some tests are dynamic,
195# so for the moment we skip `-Cpanic=abort`.195# so for the moment we skip `-Cpanic=abort`.
@@ -254,21 +254,21 @@ quiet_cmd_rustsysroot = RUSTSYSROOT · 58 unmodified lines
254 $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib254 $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib
255 255
256rusttest-prepare: FORCE256rusttest-prepare: FORCE
257 $(call if_changed,rustsysroot)257 +$(call if_changed,rustsysroot)
258 258
259rusttest-macros: private rustc_target_flags = --extern proc_macro259rusttest-macros: private rustc_target_flags = --extern proc_macro
260rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro260rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
261rusttest-macros: $(src)/macros/lib.rs rusttest-prepare FORCE261rusttest-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
262 $(call if_changed,rustc_test)262 +$(call if_changed,rustc_test)
263 $(call if_changed,rustdoc_test)263 +$(call if_changed,rustdoc_test)
264 264
265rusttest-kernel: private rustc_target_flags = --extern alloc \265rusttest-kernel: private rustc_target_flags = --extern alloc \
266 --extern build_error --extern macros --extern bindings --extern uapi266 --extern build_error --extern macros --extern bindings --extern uapi
267rusttest-kernel: $(src)/kernel/lib.rs rusttest-prepare \267rusttest-kernel: $(src)/kernel/lib.rs rusttest-prepare \
268 rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \268 rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \
269 rusttestlib-uapi FORCE269 rusttestlib-uapi FORCE
270 $(call if_changed,rustc_test)270 +$(call if_changed,rustc_test)
271 $(call if_changed,rustc_test_library)271 +$(call if_changed,rustc_test_library)
272 272
273ifdef CONFIG_CC_IS_CLANG273ifdef CONFIG_CC_IS_CLANG
274bindgen_c_flags = $(c_flags)274bindgen_c_flags = $(c_flags)
@@ -396,7 +396,7 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@ · 121 unmodified lines
396# Therefore, to get `libmacros.so` automatically recompiled when the compiler396# Therefore, to get `libmacros.so` automatically recompiled when the compiler
397# version changes, we add `core.o` as a dependency (even if it is not needed).397# version changes, we add `core.o` as a dependency (even if it is not needed).
398$(obj)/libmacros.so: $(src)/macros/lib.rs $(obj)/core.o FORCE398$(obj)/libmacros.so: $(src)/macros/lib.rs $(obj)/core.o FORCE
399 $(call if_changed_dep,rustc_procmacro)399 +$(call if_changed_dep,rustc_procmacro)
400 400
401quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@401quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
402 cmd_rustc_library = \402 cmd_rustc_library = \
@@ -435,36 +435,36 @@ $(obj)/core.o: private skip_flags = -Dunreachable_pub · 32 unmodified lines
435$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))435$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
436$(obj)/core.o: private rustc_target_flags = $(core-cfgs)436$(obj)/core.o: private rustc_target_flags = $(core-cfgs)
437$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs scripts/target.json FORCE437$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs scripts/target.json FORCE
438 $(call if_changed_dep,rustc_library)438 +$(call if_changed_dep,rustc_library)
439 439
440$(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'440$(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
441$(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE441$(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
442 $(call if_changed_dep,rustc_library)442 +$(call if_changed_dep,rustc_library)
443 443
444$(obj)/alloc.o: private skip_clippy = 1444$(obj)/alloc.o: private skip_clippy = 1
445$(obj)/alloc.o: private skip_flags = -Dunreachable_pub445$(obj)/alloc.o: private skip_flags = -Dunreachable_pub
446$(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)446$(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)
447$(obj)/alloc.o: $(src)/alloc/lib.rs $(obj)/compiler_builtins.o FORCE447$(obj)/alloc.o: $(src)/alloc/lib.rs $(obj)/compiler_builtins.o FORCE
448 $(call if_changed_dep,rustc_library)448 +$(call if_changed_dep,rustc_library)
449 449
450$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE450$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
451 $(call if_changed_dep,rustc_library)451 +$(call if_changed_dep,rustc_library)
452 452
453$(obj)/bindings.o: $(src)/bindings/lib.rs \453$(obj)/bindings.o: $(src)/bindings/lib.rs \
454 $(obj)/compiler_builtins.o \454 $(obj)/compiler_builtins.o \
455 $(obj)/bindings/bindings_generated.rs \455 $(obj)/bindings/bindings_generated.rs \
456 $(obj)/bindings/bindings_helpers_generated.rs FORCE456 $(obj)/bindings/bindings_helpers_generated.rs FORCE
457 $(call if_changed_dep,rustc_library)457 +$(call if_changed_dep,rustc_library)
458 458
459$(obj)/uapi.o: $(src)/uapi/lib.rs \459$(obj)/uapi.o: $(src)/uapi/lib.rs \
460 $(obj)/compiler_builtins.o \460 $(obj)/compiler_builtins.o \
461 $(obj)/uapi/uapi_generated.rs FORCE461 $(obj)/uapi/uapi_generated.rs FORCE
462 $(call if_changed_dep,rustc_library)462 +$(call if_changed_dep,rustc_library)
463 463
464$(obj)/kernel.o: private rustc_target_flags = --extern alloc \464$(obj)/kernel.o: private rustc_target_flags = --extern alloc \
465 --extern build_error --extern macros --extern bindings --extern uapi465 --extern build_error --extern macros --extern bindings --extern uapi
466$(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \466$(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \
467 $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE467 $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE
468 $(call if_changed_dep,rustc_library)468 +$(call if_changed_dep,rustc_library)
469 469
470endif # CONFIG_RUST470endif # CONFIG_RUST
scripts/Makefile.build+4−4
@@ -290,7 +290,7 @@ quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ · 289 unmodified lines
290 cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $<290 cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $<
291 291
292$(obj)/%.o: $(src)/%.rs FORCE292$(obj)/%.o: $(src)/%.rs FORCE
293 $(call if_changed_dep,rustc_o_rs)293 +$(call if_changed_dep,rustc_o_rs)
294 294
295quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@295quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
296 cmd_rustc_rsi_rs = \296 cmd_rustc_rsi_rs = \
@@ -298,19 +298,19 @@ quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ · 1 unmodified line
298 command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@298 command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@
299 299
300$(obj)/%.rsi: $(src)/%.rs FORCE300$(obj)/%.rsi: $(src)/%.rs FORCE
301 $(call if_changed_dep,rustc_rsi_rs)301 +$(call if_changed_dep,rustc_rsi_rs)
302 302
303quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@303quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
304 cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $<304 cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $<
305 305
306$(obj)/%.s: $(src)/%.rs FORCE306$(obj)/%.s: $(src)/%.rs FORCE
307 $(call if_changed_dep,rustc_s_rs)307 +$(call if_changed_dep,rustc_s_rs)
308 308
309quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@309quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
310 cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $<310 cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $<
311 311
312$(obj)/%.ll: $(src)/%.rs FORCE312$(obj)/%.ll: $(src)/%.rs FORCE
313 $(call if_changed_dep,rustc_ll_rs)313 +$(call if_changed_dep,rustc_ll_rs)
314 314
315# Compile assembler sources (.S)315# Compile assembler sources (.S)
316# ---------------------------------------------------------------------------316# ---------------------------------------------------------------------------
scripts/Makefile.host+1−1
@@ -156,7 +156,7 @@ quiet_cmd_host-rust = HOSTRUSTC $@ · 155 unmodified lines
156 cmd_host-rust = \156 cmd_host-rust = \
157 $(HOSTRUSTC) $(hostrust_flags) --emit=link=$@ $<157 $(HOSTRUSTC) $(hostrust_flags) --emit=link=$@ $<
158$(host-rust): $(obj)/%: $(src)/%.rs FORCE158$(host-rust): $(obj)/%: $(src)/%.rs FORCE
159 $(call if_changed_dep,host-rust)159 +$(call if_changed_dep,host-rust)
160 160
161targets += $(host-csingle) $(host-cmulti) $(host-cobjs) \161targets += $(host-csingle) $(host-cmulti) $(host-cobjs) \
162 $(host-cxxmulti) $(host-cxxobjs) $(host-rust)162 $(host-cxxmulti) $(host-cxxobjs) $(host-rust)