Skip to content

Commit

Permalink
kbuild: rust: avoid creating temporary files
Browse files Browse the repository at this point in the history
`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: Rust-for-Linux/linux#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]>
Signed-off-by: Masahiro Yamada <[email protected]>
  • Loading branch information
ojeda authored and masahir0y committed Jul 23, 2023
1 parent 0817d25 commit df01b7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion scripts/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ $(obj)/%.lst: $(src)/%.c FORCE

rust_allowed_features := new_uninit

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

# `--emit=obj`, `--emit=asm` and `--emit=llvm-ir` imply a single codegen unit
# will be used. We explicitly request `-Ccodegen-units=1` in any case, and
Expand Down
6 changes: 5 additions & 1 deletion scripts/Makefile.host
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ hostc_flags = -Wp,-MMD,$(depfile) \
hostcxx_flags = -Wp,-MMD,$(depfile) \
$(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
$(HOSTCXXFLAGS_$(target-stem).o)
hostrust_flags = --emit=dep-info=$(depfile) \

# `--out-dir` is required to avoid temporaries being created by `rustc` in the
# current working directory, which may be not accessible in the out-of-tree
# modules case.
hostrust_flags = --out-dir $(dir $@) --emit=dep-info=$(depfile) \
$(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
$(HOSTRUSTFLAGS_$(target-stem))

Expand Down

0 comments on commit df01b7c

Please sign in to comment.