From 18a897320b4a1892348d3cdf52d25bc29457edc2 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 13 Sep 2019 15:11:52 +0200 Subject: [PATCH 1/2] Only build libtest when libstd is built --- src/cargo/ops/cargo_compile.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index e872d9409a7..9c2aa3f1f81 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -398,7 +398,10 @@ pub fn compile_ws<'a>( .iter() .any(|unit| unit.mode.is_rustc_test() && unit.target.harness()) { - crates.push("test".to_string()); + // Only build libtest when libstd is built (libtest depends on libstd) + if crates.iter().any(|c| c == "std") { + crates.push("test".to_string()); + } } standard_lib::generate_std_roots(&bcx, &crates, std_resolve.as_ref().unwrap())? } else { From 6b4fd44ea6e832fd4dda7e7738099f215c7383b1 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 13 Sep 2019 15:11:13 +0200 Subject: [PATCH 2/2] Add a test for -Zbuild-std with custom test frameworks --- tests/testsuite/standard_lib.rs | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/testsuite/standard_lib.rs b/tests/testsuite/standard_lib.rs index 4fa1d0edc5a..0ca7856d979 100644 --- a/tests/testsuite/standard_lib.rs +++ b/tests/testsuite/standard_lib.rs @@ -37,6 +37,7 @@ fn std_lib() { hashbrown(); libc(); test(); + custom_test_framework(); target_proc_macro(); bench(); doc(); @@ -186,6 +187,47 @@ fn test() { .run(); } +fn custom_test_framework() { + let p = project() + .file( + "src/lib.rs", + r#" + #![no_std] + #![cfg_attr(test, no_main)] + #![feature(custom_test_frameworks)] + #![test_runner(crate::test_runner)] + + pub fn test_runner(_tests: &[&dyn Fn()]) {} + + #[panic_handler] + fn panic(_info: &core::panic::PanicInfo) -> ! { + loop {} + } + "#, + ) + .file( + "target.json", + r#" + { + "llvm-target": "x86_64-unknown-none-gnu", + "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", + "arch": "x86_64", + "target-endian": "little", + "target-pointer-width": "64", + "target-c-int-width": "32", + "os": "none", + "linker-flavor": "ld.lld", + "linker": "rust-lld", + "executables": true, + "panic-strategy": "abort" + } + "#, + ) + .build(); + + cargo_build_std(&p, "test --target target.json --no-run -v", "core").run(); +} + fn target_proc_macro() { let p = project() .file(