rust: Suppress searching builtin sysroot
authorMatthew Maurer <mmaurer@google.com>
Tue, 31 Oct 2023 20:10:14 +0000 (20:10 +0000)
committerMiguel Ojeda <ojeda@kernel.org>
Thu, 14 Dec 2023 19:14:01 +0000 (20:14 +0100)
By default, if Rust is passed `--target=foo` rather than a target.json
file, it will infer a default sysroot if that component is installed. As
the proposed aarch64 support [1] uses `aarch64-unknown-none` rather than a
target.json file, this is needed [2] to prevent rustc from being confused
between the custom kernel sysroot and the pre-installed one.

[ Miguel: Applied Boqun's extra case (for `rusttest`) and reworded to add
  links to the arm64 patch series discussion. In addition, fixed the
  `rustdoc` target too (which requires a conditional since `cmd_rustdoc`
  is also used for host crates like `macros`). ]

Signed-off-by: Matthew Maurer <mmaurer@google.com>
Tested-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/rust-for-linux/20231020155056.3495121-1-Jamie.Cunliffe@arm.com/
Link: https://lore.kernel.org/rust-for-linux/CAGSQo01pOixiPXkW867h4vPUaAjtKtHGKhkV-rpifJvKxAf4Ww@mail.gmail.com/
Link: https://lore.kernel.org/r/20231031201752.1189213-1-mmaurer@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/Makefile
scripts/Makefile.build

index 2912c5e075cb6c0451665511bbc7cdf7a575cb97..5a3e3140e234869c1ea9acacfbc1cbe9c74e6b78 100644 (file)
@@ -78,6 +78,7 @@ quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
                $(rustc_target_flags) -L$(objtree)/$(obj) \
                --output $(rustdoc_output) \
                --crate-name $(subst rustdoc-,,$@) \
+               $(if $(rustdoc_host),,--sysroot=/dev/null) \
                @$(objtree)/include/generated/rustc_cfg $<
 
 # The `html_logo_url` and `html_favicon_url` forms of the `doc` attribute
@@ -178,6 +179,7 @@ quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<
                --extern build_error --extern macros \
                --extern bindings --extern uapi \
                --no-run --crate-name kernel -Zunstable-options \
+               --sysroot=/dev/null \
                --test-builder $(objtree)/scripts/rustdoc_test_builder \
                $< $(rustdoc_test_kernel_quiet); \
        $(objtree)/scripts/rustdoc_test_gen
@@ -404,6 +406,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
                --emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
                --crate-type rlib -L$(objtree)/$(obj) \
                --crate-name $(patsubst %.o,%,$(notdir $@)) $< \
+               --sysroot=/dev/null \
        $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@)
 
 rust-analyzer:
index 9a3063735e711b6d21f46b98ac1e704c6318ba48..dae447a1ad30c4a30d48f4741e7a5dfd81622ced 100644 (file)
@@ -275,6 +275,7 @@ rust_common_cmd = \
        --extern alloc --extern kernel \
        --crate-type rlib -L $(objtree)/rust/ \
        --crate-name $(basename $(notdir $@)) \
+       --sysroot=/dev/null \
        --out-dir $(dir $@) --emit=dep-info=$(depfile)
 
 # `--emit=obj`, `--emit=asm` and `--emit=llvm-ir` imply a single codegen unit