Skip to content

Commit 57d04c8

Browse files
ojedafbq
authored andcommitted
kbuild: rust: avoid creating temporary files
`rustc` outputs by default the temporary files (i.e. the ones saved by `-Csave-temps`, such as `*.rcgu*` files) in the current working directory when `-o` and `--out-dir` are not given (even if `--emit=x=path` is given, i.e. it does not use those for temporaries). Since out-of-tree modules are compiled from the `linux` tree, `rustc` then tries to create them there, which may not be accessible. Thus pass `--out-dir` explicitly, even if it is just for the temporary files. Similarly, do so for Rust host programs too. Reported-by: Raphael Nestler <[email protected]> Closes: #1015 Reported-by: Andrea Righi <[email protected]> Tested-by: Raphael Nestler <[email protected]> # non-hostprogs Tested-by: Andrea Righi <[email protected]> # non-hostprogs Fixes: 295d839 ("kbuild: specify output names separately for each emission type from rustc") Cc: [email protected] Signed-off-by: Miguel Ojeda <[email protected]> Tested-by: Martin Rodriguez Reboredo <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 191c0a3 commit 57d04c8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

scripts/Makefile.build

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ $(obj)/%.lst: $(src)/%.c FORCE
264264

265265
rust_allowed_features := new_uninit
266266

267+
# `--out-dir` is required to avoid temporaries being created by `rustc` in the
268+
# current working directory, which may be not accessible in the out-of-tree
269+
# modules case.
267270
rust_common_cmd = \
268271
RUST_MODFILE=$(modfile) $(RUSTC_OR_CLIPPY) $(rust_flags) \
269272
-Zallow-features=$(rust_allowed_features) \
@@ -272,7 +275,7 @@ rust_common_cmd = \
272275
--extern alloc --extern kernel \
273276
--crate-type rlib -L $(objtree)/rust/ \
274277
--crate-name $(basename $(notdir $@)) \
275-
--emit=dep-info=$(depfile)
278+
--out-dir $(dir $@) --emit=dep-info=$(depfile)
276279

277280
# `--emit=obj`, `--emit=asm` and `--emit=llvm-ir` imply a single codegen unit
278281
# will be used. We explicitly request `-Ccodegen-units=1` in any case, and

scripts/Makefile.host

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ hostc_flags = -Wp,-MMD,$(depfile) \
8686
hostcxx_flags = -Wp,-MMD,$(depfile) \
8787
$(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
8888
$(HOSTCXXFLAGS_$(target-stem).o)
89-
hostrust_flags = --emit=dep-info=$(depfile) \
89+
90+
# `--out-dir` is required to avoid temporaries being created by `rustc` in the
91+
# current working directory, which may be not accessible in the out-of-tree
92+
# modules case.
93+
hostrust_flags = --out-dir $(dir $@) --emit=dep-info=$(depfile) \
9094
$(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
9195
$(HOSTRUSTFLAGS_$(target-stem))
9296

0 commit comments

Comments
 (0)