@@ -44,17 +44,10 @@ rustc_sysroot := $(shell MAKEFLAGS= $(RUSTC) $(rust_flags) --print sysroot)
4444rustc_host_target := $(shell $(RUSTC ) --version --verbose | grep -F 'host: ' | cut -d' ' -f2)
4545RUST_LIB_SRC ?= $(rustc_sysroot ) /lib/rustlib/src/rust/library
4646
47- ifeq ($(quiet ) ,silent_)
48- cargo_quiet =-q
47+ ifneq ($(quiet ) ,)
4948rust_test_quiet =-q
5049rustdoc_test_quiet =--test-args -q
5150rustdoc_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
5851endif
5952
6053core-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
145137rusttestlib-macros : private rustc_target_flags = --extern proc_macro
146138rusttestlib-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
156148quiet_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
201192rusttest : 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-
248194rusttest-macros : private rustc_target_flags = --extern proc_macro
249195rusttest-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
254200rusttest-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