* [PATCH v2] kbuild: rust: avoid creating temporary files
@ 2023-07-23 14:21 Miguel Ojeda
2023-07-23 14:34 ` Martin Rodriguez Reboredo
2023-07-25 5:00 ` Masahiro Yamada
0 siblings, 2 replies; 3+ messages in thread
From: Miguel Ojeda @ 2023-07-23 14:21 UTC (permalink / raw)
To: Masahiro Yamada, Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor
Cc: Nathan Chancellor, Nick Desaulniers, Nicolas Schier, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Alice Ryhl,
Andreas Hindborg, linux-kbuild, rust-for-linux, linux-kernel,
patches, Raphael Nestler, Andrea Righi, stable
`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 <raphael.nestler@gmail.com>
Closes: https://github.com/Rust-for-Linux/linux/issues/1015
Reported-by: Andrea Righi <andrea.righi@canonical.com>
Tested-by: Raphael Nestler <raphael.nestler@gmail.com> # non-hostprogs
Tested-by: Andrea Righi <andrea.righi@canonical.com> # non-hostprogs
Fixes: 295d8398c67e ("kbuild: specify output names separately for each emission type from rustc")
Cc: stable@vger.kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
v2:
- Add fix for host programs too (Masahiro).
scripts/Makefile.build | 5 ++++-
scripts/Makefile.host | 6 +++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 6413342a03f4..82e3fb19fdaf 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -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) \
@@ -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
diff --git a/scripts/Makefile.host b/scripts/Makefile.host
index 7aea9005e497..8f7f842b54f9 100644
--- a/scripts/Makefile.host
+++ b/scripts/Makefile.host
@@ -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))
base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
--
2.41.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] kbuild: rust: avoid creating temporary files
2023-07-23 14:21 [PATCH v2] kbuild: rust: avoid creating temporary files Miguel Ojeda
@ 2023-07-23 14:34 ` Martin Rodriguez Reboredo
2023-07-25 5:00 ` Masahiro Yamada
1 sibling, 0 replies; 3+ messages in thread
From: Martin Rodriguez Reboredo @ 2023-07-23 14:34 UTC (permalink / raw)
To: Miguel Ojeda, Masahiro Yamada, Wedson Almeida Filho, Alex Gaynor
Cc: Nathan Chancellor, Nick Desaulniers, Nicolas Schier, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Alice Ryhl,
Andreas Hindborg, linux-kbuild, rust-for-linux, linux-kernel,
patches, Raphael Nestler, Andrea Righi, stable
On 7/23/23 11:21, Miguel Ojeda wrote:
> `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 <raphael.nestler@gmail.com>
> Closes: https://github.com/Rust-for-Linux/linux/issues/1015
> Reported-by: Andrea Righi <andrea.righi@canonical.com>
> Tested-by: Raphael Nestler <raphael.nestler@gmail.com> # non-hostprogs
> Tested-by: Andrea Righi <andrea.righi@canonical.com> # non-hostprogs
> Fixes: 295d8398c67e ("kbuild: specify output names separately for each emission type from rustc")
> Cc: stable@vger.kernel.org
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
> ---
> [...]
Tested-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] kbuild: rust: avoid creating temporary files
2023-07-23 14:21 [PATCH v2] kbuild: rust: avoid creating temporary files Miguel Ojeda
2023-07-23 14:34 ` Martin Rodriguez Reboredo
@ 2023-07-25 5:00 ` Masahiro Yamada
1 sibling, 0 replies; 3+ messages in thread
From: Masahiro Yamada @ 2023-07-25 5:00 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Wedson Almeida Filho, Alex Gaynor, Nathan Chancellor,
Nick Desaulniers, Nicolas Schier, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Andreas Hindborg,
linux-kbuild, rust-for-linux, linux-kernel, patches,
Raphael Nestler, Andrea Righi, stable
On Sun, Jul 23, 2023 at 11:21 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> `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 <raphael.nestler@gmail.com>
> Closes: https://github.com/Rust-for-Linux/linux/issues/1015
> Reported-by: Andrea Righi <andrea.righi@canonical.com>
> Tested-by: Raphael Nestler <raphael.nestler@gmail.com> # non-hostprogs
> Tested-by: Andrea Righi <andrea.righi@canonical.com> # non-hostprogs
> Fixes: 295d8398c67e ("kbuild: specify output names separately for each emission type from rustc")
> Cc: stable@vger.kernel.org
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
> ---
> v2:
> - Add fix for host programs too (Masahiro).
This is now available in the mainline.
df01b7cfcef08bf3fdcac2909d0e1910781d6bfd
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-25 5:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-23 14:21 [PATCH v2] kbuild: rust: avoid creating temporary files Miguel Ojeda
2023-07-23 14:34 ` Martin Rodriguez Reboredo
2023-07-25 5:00 ` Masahiro Yamada
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).