Skip to content

Commit 4c3a73a

Browse files
ojedafbq
authored andcommitted
kbuild: rust: remove now-unneeded rusttest custom sysroot handling
Since we dropped our custom `alloc` in commit 9d0441b ("rust: alloc: remove our fork of the `alloc` crate"), there is no need anymore to keep the custom sysroot hack. Thus delete it, which makes the target way simpler and faster too. This also means we are not using Cargo for anything at the moment, and that no download is required anymore, so update the main `Makefile` and the documentation accordingly. Signed-off-by: Miguel Ojeda <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 03734b2 commit 4c3a73a

File tree

4 files changed

+11
-81
lines changed

4 files changed

+11
-81
lines changed

Documentation/rust/quick-start.rst

-14
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,6 @@ can be installed manually::
164164
The standalone installers also come with ``clippy``.
165165

166166

167-
cargo
168-
*****
169-
170-
``cargo`` is the Rust native build system. It is currently required to run
171-
the tests since it is used to build a custom standard library that contains
172-
the facilities provided by the custom ``alloc`` in the kernel. The tests can
173-
be run using the ``rusttest`` Make target.
174-
175-
If ``rustup`` is being used, all the profiles already install the tool,
176-
thus nothing needs to be done.
177-
178-
The standalone installers also come with ``cargo``.
179-
180-
181167
rustdoc
182168
*******
183169

Documentation/rust/testing.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ Additionally, there are the ``#[test]`` tests. These can be run using the
131131

132132
make LLVM=1 rusttest
133133

134-
This requires the kernel ``.config`` and downloads external repositories. It
135-
runs the ``#[test]`` tests on the host (currently) and thus is fairly limited in
136-
what these tests can test.
134+
This requires the kernel ``.config``. It runs the ``#[test]`` tests on the host
135+
(currently) and thus is fairly limited in what these tests can test.
137136

138137
The Kselftests
139138
--------------

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ RUSTDOC = rustdoc
507507
RUSTFMT = rustfmt
508508
CLIPPY_DRIVER = clippy-driver
509509
BINDGEN = bindgen
510-
CARGO = cargo
511510
PAHOLE = pahole
512511
RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids
513512
LEX = flex
@@ -601,7 +600,7 @@ endif
601600
export RUSTC_BOOTSTRAP := 1
602601

603602
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIG
604-
export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN CARGO
603+
export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN
605604
export HOSTRUSTC KBUILD_HOSTRUSTFLAGS
606605
export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
607606
export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX

rust/Makefile

+8-62
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,10 @@ rustc_sysroot := $(shell MAKEFLAGS= $(RUSTC) $(rust_flags) --print sysroot)
4444
rustc_host_target := $(shell $(RUSTC) --version --verbose | grep -F 'host: ' | cut -d' ' -f2)
4545
RUST_LIB_SRC ?= $(rustc_sysroot)/lib/rustlib/src/rust/library
4646

47-
ifeq ($(quiet),silent_)
48-
cargo_quiet=-q
47+
ifneq ($(quiet),)
4948
rust_test_quiet=-q
5049
rustdoc_test_quiet=--test-args -q
5150
rustdoc_test_kernel_quiet=>/dev/null
52-
else ifeq ($(quiet),quiet_)
53-
rust_test_quiet=-q
54-
rustdoc_test_quiet=--test-args -q
55-
rustdoc_test_kernel_quiet=>/dev/null
56-
else
57-
cargo_quiet=--verbose
5851
endif
5952

6053
core-cfgs = \
@@ -135,22 +128,21 @@ quiet_cmd_rustc_test_library = RUSTC TL $<
135128
@$(objtree)/include/generated/rustc_cfg $(rustc_target_flags) \
136129
--crate-type $(if $(rustc_test_library_proc),proc-macro,rlib) \
137130
--out-dir $(objtree)/$(obj)/test --cfg testlib \
138-
--sysroot $(objtree)/$(obj)/test/sysroot \
139131
-L$(objtree)/$(obj)/test \
140132
--crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@)) $<
141133

142-
rusttestlib-build_error: $(src)/build_error.rs rusttest-prepare FORCE
134+
rusttestlib-build_error: $(src)/build_error.rs FORCE
143135
+$(call if_changed,rustc_test_library)
144136

145137
rusttestlib-macros: private rustc_target_flags = --extern proc_macro
146138
rusttestlib-macros: private rustc_test_library_proc = yes
147-
rusttestlib-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
139+
rusttestlib-macros: $(src)/macros/lib.rs FORCE
148140
+$(call if_changed,rustc_test_library)
149141

150-
rusttestlib-bindings: $(src)/bindings/lib.rs rusttest-prepare FORCE
142+
rusttestlib-bindings: $(src)/bindings/lib.rs FORCE
151143
+$(call if_changed,rustc_test_library)
152144

153-
rusttestlib-uapi: $(src)/uapi/lib.rs rusttest-prepare FORCE
145+
rusttestlib-uapi: $(src)/uapi/lib.rs FORCE
154146
+$(call if_changed,rustc_test_library)
155147

156148
quiet_cmd_rustdoc_test = RUSTDOC T $<
@@ -159,7 +151,7 @@ quiet_cmd_rustdoc_test = RUSTDOC T $<
159151
$(RUSTDOC) --test $(rust_common_flags) \
160152
@$(objtree)/include/generated/rustc_cfg \
161153
$(rustc_target_flags) $(rustdoc_test_target_flags) \
162-
--sysroot $(objtree)/$(obj)/test/sysroot $(rustdoc_test_quiet) \
154+
$(rustdoc_test_quiet) \
163155
-L$(objtree)/$(obj)/test --output $(rustdoc_output) \
164156
--crate-name $(subst rusttest-,,$@) $<
165157

@@ -192,68 +184,22 @@ quiet_cmd_rustc_test = RUSTC T $<
192184
$(RUSTC) --test $(rust_common_flags) \
193185
@$(objtree)/include/generated/rustc_cfg \
194186
$(rustc_target_flags) --out-dir $(objtree)/$(obj)/test \
195-
--sysroot $(objtree)/$(obj)/test/sysroot \
196187
-L$(objtree)/$(obj)/test \
197188
--crate-name $(subst rusttest-,,$@) $<; \
198189
$(objtree)/$(obj)/test/$(subst rusttest-,,$@) $(rust_test_quiet) \
199190
$(rustc_test_run_flags)
200191

201192
rusttest: rusttest-macros rusttest-kernel
202193

203-
# This prepares a custom sysroot with our custom `alloc` instead of
204-
# the standard one.
205-
#
206-
# This requires several hacks:
207-
# - Unlike `core` and `alloc`, `std` depends on more than a dozen crates,
208-
# including third-party crates that need to be downloaded, plus custom
209-
# `build.rs` steps. Thus hardcoding things here is not maintainable.
210-
# - `cargo` knows how to build the standard library, but it is an unstable
211-
# feature so far (`-Zbuild-std`).
212-
# - `cargo` only considers the use case of building the standard library
213-
# to use it in a given package. Thus we need to create a dummy package
214-
# and pick the generated libraries from there.
215-
# - The usual ways of modifying the dependency graph in `cargo` do not seem
216-
# to apply for the `-Zbuild-std` steps, thus we have to mislead it
217-
# by modifying the sources in the sysroot.
218-
# - To avoid messing with the user's Rust installation, we create a clone
219-
# of the sysroot. However, `cargo` ignores `RUSTFLAGS` in the `-Zbuild-std`
220-
# steps, thus we use a wrapper binary passed via `RUSTC` to pass the flag.
221-
#
222-
# In the future, we hope to avoid the whole ordeal by either:
223-
# - Making the `test` crate not depend on `std` (either improving upstream
224-
# or having our own custom crate).
225-
# - Making the tests run in kernel space (requires the previous point).
226-
# - Making `std` and friends be more like a "normal" crate, so that
227-
# `-Zbuild-std` and related hacks are not needed.
228-
quiet_cmd_rustsysroot = RUSTSYSROOT
229-
cmd_rustsysroot = \
230-
rm -rf $(objtree)/$(obj)/test; \
231-
mkdir -p $(objtree)/$(obj)/test; \
232-
cp -a $(rustc_sysroot) $(objtree)/$(obj)/test/sysroot; \
233-
echo '\#!/bin/sh' > $(objtree)/$(obj)/test/rustc_sysroot; \
234-
echo "$(RUSTC) --sysroot=$(abspath $(objtree)/$(obj)/test/sysroot) \"\$$@\"" \
235-
>> $(objtree)/$(obj)/test/rustc_sysroot; \
236-
chmod u+x $(objtree)/$(obj)/test/rustc_sysroot; \
237-
$(CARGO) -q new $(objtree)/$(obj)/test/dummy; \
238-
RUSTC=$(objtree)/$(obj)/test/rustc_sysroot $(CARGO) $(cargo_quiet) \
239-
test -Zbuild-std --target $(rustc_host_target) \
240-
--manifest-path $(objtree)/$(obj)/test/dummy/Cargo.toml; \
241-
rm $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib/*; \
242-
cp $(objtree)/$(obj)/test/dummy/target/$(rustc_host_target)/debug/deps/* \
243-
$(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib
244-
245-
rusttest-prepare: FORCE
246-
+$(call if_changed,rustsysroot)
247-
248194
rusttest-macros: private rustc_target_flags = --extern proc_macro
249195
rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
250-
rusttest-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
196+
rusttest-macros: $(src)/macros/lib.rs FORCE
251197
+$(call if_changed,rustc_test)
252198
+$(call if_changed,rustdoc_test)
253199

254200
rusttest-kernel: private rustc_target_flags = --extern alloc \
255201
--extern build_error --extern macros --extern bindings --extern uapi
256-
rusttest-kernel: $(src)/kernel/lib.rs rusttest-prepare \
202+
rusttest-kernel: $(src)/kernel/lib.rs \
257203
rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \
258204
rusttestlib-uapi FORCE
259205
+$(call if_changed,rustc_test)

0 commit comments

Comments
 (0)