@@ -44,17 +44,10 @@ rustc_sysroot := $(shell MAKEFLAGS= $(RUSTC) $(rust_flags) --print sysroot)
44
44
rustc_host_target := $(shell $(RUSTC ) --version --verbose | grep -F 'host: ' | cut -d' ' -f2)
45
45
RUST_LIB_SRC ?= $(rustc_sysroot ) /lib/rustlib/src/rust/library
46
46
47
- ifeq ($(quiet ) ,silent_)
48
- cargo_quiet =-q
47
+ ifneq ($(quiet ) ,)
49
48
rust_test_quiet =-q
50
49
rustdoc_test_quiet =--test-args -q
51
50
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
58
51
endif
59
52
60
53
core-cfgs = \
@@ -135,22 +128,21 @@ quiet_cmd_rustc_test_library = RUSTC TL $<
135
128
@$(objtree ) /include/generated/rustc_cfg $(rustc_target_flags ) \
136
129
--crate-type $(if $(rustc_test_library_proc ) ,proc-macro,rlib) \
137
130
--out-dir $(objtree ) /$(obj ) /test --cfg testlib \
138
- --sysroot $(objtree ) /$(obj ) /test/sysroot \
139
131
-L$(objtree ) /$(obj ) /test \
140
132
--crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@ ) ) $<
141
133
142
- rusttestlib-build_error : $(src ) /build_error.rs rusttest-prepare FORCE
134
+ rusttestlib-build_error : $(src ) /build_error.rs FORCE
143
135
+$(call if_changed,rustc_test_library)
144
136
145
137
rusttestlib-macros : private rustc_target_flags = --extern proc_macro
146
138
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
148
140
+$(call if_changed,rustc_test_library)
149
141
150
- rusttestlib-bindings : $(src ) /bindings/lib.rs rusttest-prepare FORCE
142
+ rusttestlib-bindings : $(src ) /bindings/lib.rs FORCE
151
143
+$(call if_changed,rustc_test_library)
152
144
153
- rusttestlib-uapi : $(src ) /uapi/lib.rs rusttest-prepare FORCE
145
+ rusttestlib-uapi : $(src ) /uapi/lib.rs FORCE
154
146
+$(call if_changed,rustc_test_library)
155
147
156
148
quiet_cmd_rustdoc_test = RUSTDOC T $<
@@ -159,7 +151,7 @@ quiet_cmd_rustdoc_test = RUSTDOC T $<
159
151
$(RUSTDOC ) --test $(rust_common_flags ) \
160
152
@$(objtree ) /include/generated/rustc_cfg \
161
153
$(rustc_target_flags ) $(rustdoc_test_target_flags ) \
162
- --sysroot $( objtree ) / $( obj ) /test/sysroot $(rustdoc_test_quiet ) \
154
+ $(rustdoc_test_quiet ) \
163
155
-L$(objtree ) /$(obj ) /test --output $(rustdoc_output ) \
164
156
--crate-name $(subst rusttest-,,$@ ) $<
165
157
@@ -192,68 +184,22 @@ quiet_cmd_rustc_test = RUSTC T $<
192
184
$(RUSTC ) --test $(rust_common_flags ) \
193
185
@$(objtree ) /include/generated/rustc_cfg \
194
186
$(rustc_target_flags ) --out-dir $(objtree ) /$(obj ) /test \
195
- --sysroot $(objtree ) /$(obj ) /test/sysroot \
196
187
-L$(objtree ) /$(obj ) /test \
197
188
--crate-name $(subst rusttest-,,$@ ) $< ; \
198
189
$(objtree ) /$(obj ) /test/$(subst rusttest-,,$@ ) $(rust_test_quiet ) \
199
190
$(rustc_test_run_flags )
200
191
201
192
rusttest : rusttest-macros rusttest-kernel
202
193
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
-
248
194
rusttest-macros : private rustc_target_flags = --extern proc_macro
249
195
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
251
197
+$(call if_changed,rustc_test)
252
198
+$(call if_changed,rustdoc_test)
253
199
254
200
rusttest-kernel : private rustc_target_flags = --extern alloc \
255
201
--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 \
257
203
rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \
258
204
rusttestlib-uapi FORCE
259
205
+$(call if_changed,rustc_test)
0 commit comments