* Re: [PATCH] kbuild: rust: avoid creating temporary files
2023-07-18 5:52 [PATCH] kbuild: rust: avoid creating temporary files Miguel Ojeda
@ 2023-07-18 16:43 ` Nathan Chancellor
2023-07-19 17:44 ` Martin Rodriguez Reboredo
2023-07-20 17:17 ` Masahiro Yamada
2 siblings, 0 replies; 10+ messages in thread
From: Nathan Chancellor @ 2023-07-18 16:43 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Masahiro Yamada, Wedson Almeida Filho, Alex Gaynor,
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 Tue, Jul 18, 2023 at 07:52:35AM +0200, 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.
>
> 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>
> Tested-by: Andrea Righi <andrea.righi@canonical.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Seems reasonable to me.
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> ---
> scripts/Makefile.build | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> 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
>
> base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
> --
> 2.41.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kbuild: rust: avoid creating temporary files
2023-07-18 5:52 [PATCH] kbuild: rust: avoid creating temporary files Miguel Ojeda
2023-07-18 16:43 ` Nathan Chancellor
@ 2023-07-19 17:44 ` Martin Rodriguez Reboredo
2023-07-20 17:17 ` Masahiro Yamada
2 siblings, 0 replies; 10+ messages in thread
From: Martin Rodriguez Reboredo @ 2023-07-19 17:44 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/18/23 02:52, 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.
>
> 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>
> Tested-by: Andrea Righi <andrea.righi@canonical.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
> ---
> [...]
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kbuild: rust: avoid creating temporary files
2023-07-18 5:52 [PATCH] kbuild: rust: avoid creating temporary files Miguel Ojeda
2023-07-18 16:43 ` Nathan Chancellor
2023-07-19 17:44 ` Martin Rodriguez Reboredo
@ 2023-07-20 17:17 ` Masahiro Yamada
2023-07-20 17:29 ` Miguel Ojeda
2 siblings, 1 reply; 10+ messages in thread
From: Masahiro Yamada @ 2023-07-20 17:17 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 Tue, Jul 18, 2023 at 2:52 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.
>
> 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>
> Tested-by: Andrea Righi <andrea.righi@canonical.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
> ---
Applied to linux-kbuild/fixes. Thanks.
I believe this is a fix, so I will include it
in my next pull request.
> scripts/Makefile.build | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> 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
>
> base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
> --
> 2.41.0
>
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kbuild: rust: avoid creating temporary files
2023-07-20 17:17 ` Masahiro Yamada
@ 2023-07-20 17:29 ` Miguel Ojeda
2023-07-20 18:34 ` Masahiro Yamada
0 siblings, 1 reply; 10+ messages in thread
From: Miguel Ojeda @ 2023-07-20 17:29 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Miguel Ojeda, 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 Thu, Jul 20, 2023 at 7:18 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Applied to linux-kbuild/fixes. Thanks.
>
> I believe this is a fix, so I will include it
> in my next pull request.
Thanks Masahiro! Yeah, it can be considered a fix. By the way, in case you want:
Fixes: 2f7ab1267dc9 ("Kbuild: add Rust support")
I guess it can be also considered a feature (e.g. "supporting more
setups"), but having the temporaries created where they were was
unintentional.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kbuild: rust: avoid creating temporary files
2023-07-20 17:29 ` Miguel Ojeda
@ 2023-07-20 18:34 ` Masahiro Yamada
2023-07-22 15:51 ` Miguel Ojeda
0 siblings, 1 reply; 10+ messages in thread
From: Masahiro Yamada @ 2023-07-20 18:34 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Miguel Ojeda, 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 Fri, Jul 21, 2023 at 2:30 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, Jul 20, 2023 at 7:18 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > Applied to linux-kbuild/fixes. Thanks.
> >
> > I believe this is a fix, so I will include it
> > in my next pull request.
>
> Thanks Masahiro! Yeah, it can be considered a fix. By the way, in case you want:
>
> Fixes: 2f7ab1267dc9 ("Kbuild: add Rust support")
Maybe, the following was a breakage.
commit 295d8398c67e314d99bb070f38883f83fe94a97a
Author: Masahiro Yamada <masahiroy@kernel.org>
Date: Sat Jan 7 18:18:15 2023 +0900
kbuild: specify output names separately for each emission type from rustc
Before that, rust_common_cmd had --out-dir.
BTW, do we also need to fix scripts/Makefile.host
in case the external module Makefile creates host programs?
> I guess it can be also considered a feature (e.g. "supporting more
> setups"), but having the temporaries created where they were was
> unintentional.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kbuild: rust: avoid creating temporary files
2023-07-20 18:34 ` Masahiro Yamada
@ 2023-07-22 15:51 ` Miguel Ojeda
2023-07-23 5:05 ` Masahiro Yamada
0 siblings, 1 reply; 10+ messages in thread
From: Miguel Ojeda @ 2023-07-22 15:51 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Miguel Ojeda, 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 Thu, Jul 20, 2023 at 8:35 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Maybe, the following was a breakage.
>
> commit 295d8398c67e314d99bb070f38883f83fe94a97a
> Author: Masahiro Yamada <masahiroy@kernel.org>
> Date: Sat Jan 7 18:18:15 2023 +0900
>
> kbuild: specify output names separately for each emission type from rustc
>
> Before that, rust_common_cmd had --out-dir.
That's right, good catch!
> BTW, do we also need to fix scripts/Makefile.host
> in case the external module Makefile creates host programs?
Indeed, we need it too. [1] would fix it (tested it with a trivial
out-of-tree Rust hostprog).
Do you want me to send it separately? i.e. to avoid losing the
`Tested-by`s etc. that we already got for this one, which is the
important one since that actually has users.
The hostprogs fix is not really critical for stable, since it is
unlikely there are users at all (we just got the first in-tree real
user in the Rust+KUnit integration coming into 6.6), but I guess it
does not hurt for the same reason.
Thanks!
Cheers,
Miguel
[1]
diff --git a/scripts/Makefile.host b/scripts/Makefile.host
index 7aea9005e497..54adf2e2ec51 100644
--- a/scripts/Makefile.host
+++ b/scripts/Makefile.host
@@ -86,7 +86,7 @@ hostc_flags = -Wp,-MMD,$(depfile) \
hostcxx_flags = -Wp,-MMD,$(depfile) \
$(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
$(HOSTCXXFLAGS_$(target-stem).o)
-hostrust_flags = --emit=dep-info=$(depfile) \
+hostrust_flags = --out-dir $(dir $@) --emit=dep-info=$(depfile) \
$(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
$(HOSTRUSTFLAGS_$(target-stem))
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] kbuild: rust: avoid creating temporary files
2023-07-22 15:51 ` Miguel Ojeda
@ 2023-07-23 5:05 ` Masahiro Yamada
2023-07-23 13:35 ` Masahiro Yamada
2023-07-23 14:27 ` Miguel Ojeda
0 siblings, 2 replies; 10+ messages in thread
From: Masahiro Yamada @ 2023-07-23 5:05 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Miguel Ojeda, 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 12:52 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, Jul 20, 2023 at 8:35 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > Maybe, the following was a breakage.
> >
> > commit 295d8398c67e314d99bb070f38883f83fe94a97a
> > Author: Masahiro Yamada <masahiroy@kernel.org>
> > Date: Sat Jan 7 18:18:15 2023 +0900
> >
> > kbuild: specify output names separately for each emission type from rustc
> >
> > Before that, rust_common_cmd had --out-dir.
>
> That's right, good catch!
>
> > BTW, do we also need to fix scripts/Makefile.host
> > in case the external module Makefile creates host programs?
>
> Indeed, we need it too. [1] would fix it (tested it with a trivial
> out-of-tree Rust hostprog).
>
> Do you want me to send it separately? i.e. to avoid losing the
> `Tested-by`s etc. that we already got for this one, which is the
> important one since that actually has users.
>
> The hostprogs fix is not really critical for stable, since it is
> unlikely there are users at all (we just got the first in-tree real
> user in the Rust+KUnit integration coming into 6.6), but I guess it
> does not hurt for the same reason.
Can you send v2 with the following squashed?
I think it makes sense to fix both if we add
Fixes: 295d8398c67e ("kbuild: specify output names separately for each
emission type from rustc")
> Thanks!
>
> Cheers,
> Miguel
>
> [1]
>
> diff --git a/scripts/Makefile.host b/scripts/Makefile.host
> index 7aea9005e497..54adf2e2ec51 100644
> --- a/scripts/Makefile.host
> +++ b/scripts/Makefile.host
> @@ -86,7 +86,7 @@ hostc_flags = -Wp,-MMD,$(depfile) \
> hostcxx_flags = -Wp,-MMD,$(depfile) \
> $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
> $(HOSTCXXFLAGS_$(target-stem).o)
> -hostrust_flags = --emit=dep-info=$(depfile) \
> +hostrust_flags = --out-dir $(dir $@) --emit=dep-info=$(depfile) \
> $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
> $(HOSTRUSTFLAGS_$(target-stem))
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kbuild: rust: avoid creating temporary files
2023-07-23 5:05 ` Masahiro Yamada
@ 2023-07-23 13:35 ` Masahiro Yamada
2023-07-23 14:27 ` Miguel Ojeda
1 sibling, 0 replies; 10+ messages in thread
From: Masahiro Yamada @ 2023-07-23 13:35 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Miguel Ojeda, 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 2:05 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Sun, Jul 23, 2023 at 12:52 AM Miguel Ojeda
> <miguel.ojeda.sandonis@gmail.com> wrote:
> >
> > On Thu, Jul 20, 2023 at 8:35 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
> > >
> > > Maybe, the following was a breakage.
> > >
> > > commit 295d8398c67e314d99bb070f38883f83fe94a97a
> > > Author: Masahiro Yamada <masahiroy@kernel.org>
> > > Date: Sat Jan 7 18:18:15 2023 +0900
> > >
> > > kbuild: specify output names separately for each emission type from rustc
> > >
> > > Before that, rust_common_cmd had --out-dir.
> >
> > That's right, good catch!
> >
> > > BTW, do we also need to fix scripts/Makefile.host
> > > in case the external module Makefile creates host programs?
> >
> > Indeed, we need it too. [1] would fix it (tested it with a trivial
> > out-of-tree Rust hostprog).
> >
> > Do you want me to send it separately? i.e. to avoid losing the
> > `Tested-by`s etc. that we already got for this one, which is the
> > important one since that actually has users.
> >
> > The hostprogs fix is not really critical for stable, since it is
> > unlikely there are users at all (we just got the first in-tree real
> > user in the Rust+KUnit integration coming into 6.6), but I guess it
> > does not hurt for the same reason.
>
>
> Can you send v2 with the following squashed?
>
>
> I think it makes sense to fix both if we add
> Fixes: 295d8398c67e ("kbuild: specify output names separately for each
> emission type from rustc")
I dropped v1 for now,
expecting to get v2 soon.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] kbuild: rust: avoid creating temporary files
2023-07-23 5:05 ` Masahiro Yamada
2023-07-23 13:35 ` Masahiro Yamada
@ 2023-07-23 14:27 ` Miguel Ojeda
1 sibling, 0 replies; 10+ messages in thread
From: Miguel Ojeda @ 2023-07-23 14:27 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Miguel Ojeda, 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 7:06 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Can you send v2 with the following squashed?
>
> I think it makes sense to fix both if we add
> Fixes: 295d8398c67e ("kbuild: specify output names separately for each
> emission type from rustc")
Both done [1] -- I marked the `Tested-by`s with "# non-hostprogs" to avoid
losing the tags.
Thanks!
[1] https://lore.kernel.org/rust-for-linux/20230723142128.194339-1-ojeda@kernel.org/
Cheers,
Miguel
^ permalink raw reply [flat|nested] 10+ messages in thread