kbuild: rust: avoid creating temporary files
Subsystems (3)
Miguel Ojeda
maintainerPATCH 1/1 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.
--- scripts/Makefile.build | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/Makefile.build +4 -1
@@ -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
Signature · 1 line
2.41.0
Quoted 11 lines · Miguel Ojeda
rustcoutputs by default the temporary files (i.e. the ones saved by-Csave-temps, such as*.rcgu*files) in the current working directory when-oand--out-dirare not given (even if--emit=x=pathis given, i.e. it does not use those for temporaries).Since out-of-tree modules are compiled from the
linuxtree,rustcthen tries to create them there, which may not be accessible.Thus pass
--out-direxplicitly, even if it is just for the temporary files.
Quoted 7 lines
Reported-by Raphael Nestler <[email protected]>Reported-by Andrea Righi <[email protected]>Tested-by Raphael Nestler <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Miguel Ojeda <[email protected]>
Seems reasonable to me.
Quoted 32 lines
--- scripts/Makefile.build | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)scripts/Makefile.build +4
-1@@ -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, andbase-commit:
06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5Signature · 1 line
2.41.0
Quoted 18 lines · Miguel Ojeda
rustcoutputs by default the temporary files (i.e. the ones saved by-Csave-temps, such as*.rcgu*files) in the current working directory when-oand--out-dirare not given (even if--emit=x=pathis given, i.e. it does not use those for temporaries).Since out-of-tree modules are compiled from the
linuxtree,rustcthen tries to create them there, which may not be accessible.Thus pass
--out-direxplicitly, even if it is just for the temporary files.Reported-by Raphael Nestler <[email protected]>Reported-by Andrea Righi <[email protected]>Tested-by Raphael Nestler <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Miguel Ojeda <[email protected]>
Quoted 2 lines
---
[...]
Quoted 12 lines · Miguel Ojeda
rustcoutputs by default the temporary files (i.e. the ones saved by-Csave-temps, such as*.rcgu*files) in the current working directory when-oand--out-dirare not given (even if--emit=x=pathis given, i.e. it does not use those for temporaries).Since out-of-tree modules are compiled from the
linuxtree,rustcthen tries to create them there, which may not be accessible.Thus pass
--out-direxplicitly, even if it is just for the temporary files.
Quoted 8 lines
Reported-by Raphael Nestler <[email protected]>Reported-by Andrea Righi <[email protected]>Tested-by Raphael Nestler <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Miguel Ojeda <[email protected]>---
Applied to linux-kbuild/fixes. Thanks.
I believe this is a fix, so I will include it
in my next pull request.
Quoted 31 lines
scripts/Makefile.build | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)scripts/Makefile.build +4
-1@@ -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, andbase-commit:
06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5--
2.41.0
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 5 lines · Masahiro Yamada
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
Quoted 11 lines · Miguel Ojeda
Quoted 5 lines · Masahiro Yamada
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 <[email protected]> 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?
Quoted 3 lines
I guess it can be also considered a feature (e.g. "supporting more setups"), but having the temporaries created where they were was unintentional.
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 10 lines · Masahiro Yamada
Maybe, the following was a breakage.
commit
295d8398c67e314d99bb070f38883f83fe94a97aAuthor: Masahiro Yamada <[email protected]> Date: Sat Jan 7 18:18:15 2023 +0900kbuild: specify output names separately for each emission type from rustc
Before that,
rust_common_cmdhad --out-dir.
That's right, good catch!
Quoted 2 lines
BTW, do we also need to fix
scripts/Makefile.hostin case the external moduleMakefilecreates 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-bys 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]
scripts/Makefile.host +1 -1
@@ -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))
Quoted 21 lines · Miguel Ojeda
Quoted 10 lines · Masahiro Yamada
Maybe, the following was a breakage.
commit
295d8398c67e314d99bb070f38883f83fe94a97aAuthor: Masahiro Yamada <[email protected]> Date: Sat Jan 7 18:18:15 2023 +0900kbuild: specify output names separately for each emission type from rustc
Before that,
rust_common_cmdhad --out-dir.That's right, good catch!
Quoted 2 lines
BTW, do we also need to fix
scripts/Makefile.hostin case the external moduleMakefilecreates host programs?Indeed, we need it too. [1] would fix it (tested it with a trivial out-of-tree Rust hostprog).
Quoted 8 lines
Do you want me to send it separately? i.e. to avoid losing the
Tested-bys 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
emission type from rustc")
Quoted 19 lines
Thanks!
Cheers,
Miguel[1]
scripts/Makefile.host +1
-1@@ -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))
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 34 lines · Masahiro Yamada
Quoted 21 lines · Miguel Ojeda
Quoted 10 lines · Masahiro Yamada
Maybe, the following was a breakage.
commit
295d8398c67e314d99bb070f38883f83fe94a97aAuthor: Masahiro Yamada <[email protected]> Date: Sat Jan 7 18:18:15 2023 +0900kbuild: specify output names separately for each emission type from rustc
Before that,
rust_common_cmdhad --out-dir.That's right, good catch!
Quoted 2 lines
BTW, do we also need to fix
scripts/Makefile.hostin case the external moduleMakefilecreates host programs?Indeed, we need it too. [1] would fix it (tested it with a trivial out-of-tree Rust hostprog).
Quoted 8 lines
Do you want me to send it separately? i.e. to avoid losing the
Tested-bys 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.
Quoted 6 lines
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 eachemission type from rustc")
I dropped v1 for now,
expecting to get v2 soon.
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 6 lines · Masahiro Yamada
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 eachemission type from rustc")
Both done [1] -- I marked the Tested-bys with "# non-hostprogs" to avoid losing the tags.
Thanks!
[1] https://lore.kernel.org/rust-for-linux/[email protected]/
Cheers,
Miguel