History

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.

Miguel Ojeda committed 3 years ago

Commit df01b7c1 parent 0817d252 files · +9 −2Browse files

Showing the changes to scripts (2 of 2 files). Show all

Unified · Split

2 files
  1. scripts/Makefile.build +4 −1
  2. scripts/Makefile.host +5 −1
scripts/Makefile.build+4−1
@@ -264,6 +264,9 @@ $(obj)/%.lst: $(src)/%.c FORCE · 263 unmodified lines
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 = \ · 2 unmodified lines
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+5−1
@@ -86,7 +86,11 @@ hostc_flags = -Wp,-MMD,$(depfile) \ · 85 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t