Rust-for-Linux/linux

Build failed due to `rustc` temporaries in the out-of-tree case

ojeda opened this issue · 5 comments

ojeda commented

Reported by Raphael Nestler at: https://rust-for-linux.zulipchat.com/#narrow/stream/291565-Help/topic/Out.20of.20tree.20module.20for.20mainline.20kernel/near/367742473

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.

Passing --out-dir explicitly, even if it is just for the temporary files, should solve it.

I already answered on zulip, but maybe for reference here as well: The suggested patch

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 94d67252df4e..261e51c0af59 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -287,7 +287,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

Works for me. I integrated it in the package I maintain for ArchLinux: https://aur.archlinux.org/cgit/aur.git/tree/0001-Fix-Rust-out-of-tree-module-build.patch?h=linux-rust and tested it.

ojeda commented

Thanks @rnestler! I will submit it and add your Reported-by and Tested-by tags.

arighi commented

Thanks @rnestler. This also solves a problem in Ubuntu to build out-of-tree modules in Rust (since we provide all the Rust artifacts under /usr/src/linux-headers-$(uname -r)).

You can add my Tested-by: Andrea Righi <andrea.righi@canonical.com> if you want.

ojeda commented

Thanks @arighi, I will add it and send it today.