diff --git a/cargo-nextest/src/dispatch.rs b/cargo-nextest/src/dispatch.rs index aad404409be..f54406a3ef9 100644 --- a/cargo-nextest/src/dispatch.rs +++ b/cargo-nextest/src/dispatch.rs @@ -45,6 +45,7 @@ use std::{ collections::BTreeSet, env::VarError, io::{Cursor, Write}, + path::PathBuf, sync::Arc, }; use swrite::{swrite, SWrite}; @@ -1009,7 +1010,31 @@ impl BaseApp { None => { let target_triple = discover_target_triple(&cargo_configs, cargo_opts.target.as_deref()); - BuildPlatforms::new(target_triple)? + let mut args = vec!["--print", "sysroot"]; + if let Some(target_triple) = &target_triple { + args.extend(["--target", target_triple.platform.triple_str()]); + } + let output = duct::cmd(rustc_path().as_str(), args) + .stdout_capture() + .unchecked() + .run() + .ok() + .and_then(|output| { + if output.status.success() { + Some(Cursor::new(output.stdout)) + } else { + log::debug!( + "failed to execute sysroot discover command: {}", + output.status + ); + log::debug!("stdout:"); + log::debug!("{}", String::from_utf8_lossy(&output.stdout)); + log::debug!("stderr:"); + log::debug!("{}", String::from_utf8_lossy(&output.stderr)); + None + } + }); + BuildPlatforms::new(output, target_triple)? } }; @@ -2012,6 +2037,15 @@ fn warn_on_err(thing: &str, err: &(dyn std::error::Error)) { log::warn!("{}", s); } +fn rustc_path() -> Utf8PathBuf { + match std::env::var_os("RUSTC") { + Some(rustc_path) => PathBuf::from(rustc_path) + .try_into() + .expect("RUSTC env var is not valid UTF-8"), + None => Utf8PathBuf::from("rustc"), + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/fixtures/nextest-tests/Cargo.lock b/fixtures/nextest-tests/Cargo.lock index 789d4353e4c..3dff4e96d55 100644 --- a/fixtures/nextest-tests/Cargo.lock +++ b/fixtures/nextest-tests/Cargo.lock @@ -26,6 +26,10 @@ dependencies = [ "uuid", ] +[[package]] +name = "proc-macro-test" +version = "0.1.0" + [[package]] name = "uuid" version = "1.2.1" diff --git a/fixtures/nextest-tests/Cargo.toml b/fixtures/nextest-tests/Cargo.toml index 93394f96357..8e5a299923f 100644 --- a/fixtures/nextest-tests/Cargo.toml +++ b/fixtures/nextest-tests/Cargo.toml @@ -34,6 +34,7 @@ members = [ "derive", "dylib-test", "with-build-script", + "proc-macro-test" ] [dependencies] diff --git a/fixtures/nextest-tests/proc-macro-test/Cargo.toml b/fixtures/nextest-tests/proc-macro-test/Cargo.toml new file mode 100644 index 00000000000..4ba8c79e372 --- /dev/null +++ b/fixtures/nextest-tests/proc-macro-test/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "proc-macro-test" +version = "0.1.0" +edition = "2021" + +[lib] +proc-macro = true diff --git a/fixtures/nextest-tests/proc-macro-test/src/lib.rs b/fixtures/nextest-tests/proc-macro-test/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/fixtures/nextest-tests/proc-macro-test/src/lib.rs @@ -0,0 +1 @@ + diff --git a/integration-tests/tests/integration/fixtures.rs b/integration-tests/tests/integration/fixtures.rs index e3af588973e..76574971255 100644 --- a/integration-tests/tests/integration/fixtures.rs +++ b/integration-tests/tests/integration/fixtures.rs @@ -128,6 +128,7 @@ pub static EXPECTED_LIST: Lazy> = Lazy::new(|| { BuildPlatform::Target, vec![("tests::test_out_dir_present", false)], ), + TestInfo::new("proc-macro-test", BuildPlatform::Host, vec![]), ] }); @@ -379,7 +380,20 @@ pub fn check_list_binaries_output(stdout: &[u8]) { let result: BinaryListSummary = serde_json::from_slice(stdout).unwrap(); let test_suite = &*EXPECTED_LIST; - assert_eq!(test_suite.len(), result.rust_binaries.len()); + let mut expected_binary_ids = test_suite + .iter() + .map(|test_info| test_info.id.clone()) + .collect::>(); + expected_binary_ids.sort(); + let mut actual_binary_ids = result.rust_binaries.keys().collect::>(); + actual_binary_ids.sort(); + assert_eq!( + test_suite.len(), + result.rust_binaries.len(), + "expected rust binaries:\n{:?}\nactual rust binaries\n{:?}", + expected_binary_ids, + actual_binary_ids + ); for test in test_suite { let entry = result diff --git a/integration-tests/tests/integration/snapshots/integration__archive_includes.snap b/integration-tests/tests/integration/snapshots/integration__archive_includes.snap index 0d1bb2179fa..031c8ec4727 100644 --- a/integration-tests/tests/integration/snapshots/integration__archive_includes.snap +++ b/integration-tests/tests/integration/snapshots/integration__archive_includes.snap @@ -2,7 +2,7 @@ source: integration-tests/tests/integration/main.rs expression: output.stderr_as_str() --- - Archiving 16 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 7 extra paths to + Archiving 17 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 7 extra paths to Warning ignoring extra path `/excluded-dir` because it does not exist Warning ignoring extra path `/depth-0-dir` specified with depth 0 since it is a directory Warning ignoring extra path `/file_that_does_not_exist.txt` because it does not exist diff --git a/integration-tests/tests/integration/snapshots/integration__archive_includes_without_uds.snap b/integration-tests/tests/integration/snapshots/integration__archive_includes_without_uds.snap index 17fb0bb6b42..1207aced2c2 100644 --- a/integration-tests/tests/integration/snapshots/integration__archive_includes_without_uds.snap +++ b/integration-tests/tests/integration/snapshots/integration__archive_includes_without_uds.snap @@ -2,7 +2,7 @@ source: integration-tests/tests/integration/main.rs expression: output.stderr_as_str() --- - Archiving 16 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 7 extra paths to + Archiving 17 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 7 extra paths to Warning ignoring extra path `/excluded-dir` because it does not exist Warning ignoring extra path `/depth-0-dir` specified with depth 0 since it is a directory Warning ignoring extra path `/file_that_does_not_exist.txt` because it does not exist diff --git a/integration-tests/tests/integration/snapshots/integration__archive_missing_includes.snap b/integration-tests/tests/integration/snapshots/integration__archive_missing_includes.snap index 32b71d128af..216ad0a2bc3 100644 --- a/integration-tests/tests/integration/snapshots/integration__archive_missing_includes.snap +++ b/integration-tests/tests/integration/snapshots/integration__archive_missing_includes.snap @@ -2,7 +2,7 @@ source: integration-tests/tests/integration/main.rs expression: output.stderr_as_str() --- - Archiving 16 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 1 extra path to + Archiving 17 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 1 extra path to error: error creating archive `` Caused by: diff --git a/integration-tests/tests/integration/snapshots/integration__archive_no_includes.snap b/integration-tests/tests/integration/snapshots/integration__archive_no_includes.snap index 4eb2ace1975..5b7e571f30b 100644 --- a/integration-tests/tests/integration/snapshots/integration__archive_no_includes.snap +++ b/integration-tests/tests/integration/snapshots/integration__archive_no_includes.snap @@ -2,7 +2,7 @@ source: integration-tests/tests/integration/main.rs expression: output.stderr_as_str() --- - Archiving 16 binaries (including 2 non-test binaries), 2 build script output directories, and 2 linked paths to + Archiving 17 binaries (including 2 non-test binaries), 2 build script output directories, and 2 linked paths to Warning linked path `/debug/build//does-not-exist` not found, requested by: cdylib-link v0.1.0 (this is a bug in this crate that should be fixed) Archived files to in diff --git a/nextest-metadata/src/test_list.rs b/nextest-metadata/src/test_list.rs index de8f46f570b..0857b0f75a6 100644 --- a/nextest-metadata/src/test_list.rs +++ b/nextest-metadata/src/test_list.rs @@ -519,6 +519,12 @@ pub struct BuildPlatformsSummary { /// In the future, this will become a list of target triples once multiple `--target` arguments /// are supported. pub target: PlatformSummary, + + /// The sysroot for the target platform. + /// + /// Empty if fialed to discover. + #[serde(default)] + pub sysroot: Option, } /// Information about the kind of a Rust non-test binary. diff --git a/nextest-runner/src/config/test_helpers.rs b/nextest-runner/src/config/test_helpers.rs index 6c86ccd6e6f..293a7460d40 100644 --- a/nextest-runner/src/config/test_helpers.rs +++ b/nextest-runner/src/config/test_helpers.rs @@ -84,14 +84,18 @@ pub(super) fn binary_query<'a>( } pub(super) fn build_platforms() -> BuildPlatforms { - BuildPlatforms::new_with_host( - Platform::new("x86_64-unknown-linux-gnu", TargetFeatures::Unknown).unwrap(), - Some(TargetTriple { + BuildPlatforms { + host: Platform::new("x86_64-unknown-linux-gnu", TargetFeatures::Unknown).unwrap(), + target: Some(TargetTriple { platform: Platform::new("aarch64-apple-darwin", TargetFeatures::Unknown).unwrap(), source: TargetTripleSource::Env, location: TargetDefinitionLocation::Builtin, }), - ) + sysroot: Some( + Utf8PathBuf::from("/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu") + .into_boxed_path(), + ), + } } pub(super) fn test_group(name: &str) -> TestGroup { diff --git a/nextest-runner/src/list/binary_list.rs b/nextest-runner/src/list/binary_list.rs index 6664343ec1d..f44eb2e8617 100644 --- a/nextest-runner/src/list/binary_list.rs +++ b/nextest-runner/src/list/binary_list.rs @@ -398,6 +398,7 @@ mod tests { use indoc::indoc; use maplit::btreeset; use pretty_assertions::assert_eq; + use std::io::Cursor; use target_spec::{Platform, TargetFeatures}; #[test] @@ -426,7 +427,9 @@ mod tests { source: TargetTripleSource::CliOption, location: TargetDefinitionLocation::Builtin, }; - let build_platforms = BuildPlatforms::new(Some(fake_triple)).unwrap(); + let fake_sysroot = "/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu"; + let build_platforms = + BuildPlatforms::new(Some(Cursor::new(fake_sysroot)), Some(fake_triple)).unwrap(); let mut rust_build_meta = RustBuildMeta::new("/fake/target", build_platforms); rust_build_meta @@ -504,7 +507,8 @@ mod tests { "target": { "triple": "x86_64-unknown-linux-gnu", "target-features": "unknown" - } + }, + "sysroot": "/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu" } ], "target-platform": "x86_64-unknown-linux-gnu" diff --git a/nextest-runner/src/list/rust_build_meta.rs b/nextest-runner/src/list/rust_build_meta.rs index abe05829382..178e7930d5b 100644 --- a/nextest-runner/src/list/rust_build_meta.rs +++ b/nextest-runner/src/list/rust_build_meta.rs @@ -9,6 +9,7 @@ use crate::{ reuse_build::PathMapper, }; use camino::Utf8PathBuf; +use itertools::Itertools; use nextest_metadata::{RustBuildMetaSummary, RustNonTestBinarySummary}; use std::{ collections::{BTreeMap, BTreeSet}, @@ -95,6 +96,7 @@ impl RustBuildMeta { build_platforms: BuildPlatforms { host: Platform::current().unwrap(), target: None, + sysroot: None, }, } } @@ -109,6 +111,9 @@ impl RustBuildMeta { // FIXME/HELP WANTED: get the rustc sysroot library path here. // See https://github.com/nextest-rs/nextest/issues/267. + if self.build_platforms.sysroot.is_none() { + log::warn!("failed to detect the rustc sysroot, may fail to list or run tests"); + } // Cargo puts linked paths before base output directories. self.linked_paths .keys() @@ -127,6 +132,15 @@ impl RustBuildMeta { // This is the order paths are added in by Cargo. [with_deps, abs_base] })) + // Add the rustc path to the search paths to run procudure macro binaries. See + // details in https://github.com/nextest-rs/nextest/issues/1493. + .chain( + self.build_platforms + .sysroot + .as_ref() + .map(|sysroot| sysroot.to_path_buf().join("bin")), + ) + .unique() .collect() } } @@ -169,3 +183,54 @@ impl RustBuildMeta { } } } + +#[cfg(test)] +mod tests { + use super::*; + use std::{fs, io::Cursor}; + + #[test] + fn test_dylib_paths_should_include_rustc_dir() { + let rust_sysroot = Utf8PathBuf::from("/fake/rustc/sysroot"); + let rustc_dir = rust_sysroot.join("bin"); + + let rust_build_meta = RustBuildMeta { + build_platforms: BuildPlatforms::new(Some(Cursor::new(rust_sysroot.as_str())), None) + .expect("Should create BuildPlatforms with fake sysroot successfully"), + ..RustBuildMeta::empty() + }; + let dylib_paths = rust_build_meta.dylib_paths(); + + assert!( + dylib_paths.contains(&rustc_dir), + "{:?} should contain {}", + dylib_paths, + rustc_dir + ); + } + + #[test] + fn test_dylib_paths_should_not_contain_duplicate_paths() { + let tmpdir = camino_tempfile::tempdir().expect("should create temp dir successfully"); + let rust_sysroot = tmpdir.path().to_path_buf(); + let rustc_dir = rust_sysroot.join("bin"); + fs::create_dir(&rustc_dir) + .expect("should create bin directory in the tmp folder successfully"); + + let rust_build_meta = RustBuildMeta { + target_directory: rust_sysroot.clone(), + linked_paths: [(Utf8PathBuf::from("bin"), Default::default())].into(), + base_output_directories: [Utf8PathBuf::from("bin")].into(), + build_platforms: BuildPlatforms::new(Some(Cursor::new(rust_sysroot.as_str())), None) + .expect("Should create BuildPlatforms with fake sysroot successfully"), + ..RustBuildMeta::empty() + }; + let dylib_paths = rust_build_meta.dylib_paths(); + + assert!( + dylib_paths.clone().into_iter().all_unique(), + "{:?} should not contain duplicate paths", + dylib_paths + ); + } +} diff --git a/nextest-runner/src/list/test_list.rs b/nextest-runner/src/list/test_list.rs index 41692ee2e3c..b41913e3f12 100644 --- a/nextest-runner/src/list/test_list.rs +++ b/nextest-runner/src/list/test_list.rs @@ -968,7 +968,7 @@ mod tests { use nextest_filtering::FilteringExpr; use nextest_metadata::{FilterMatch, MismatchReason}; use pretty_assertions::assert_eq; - use std::iter; + use std::{io::Cursor, iter}; use target_spec::Platform; #[test] @@ -1033,7 +1033,9 @@ mod tests { source: TargetTripleSource::CliOption, location: TargetDefinitionLocation::Builtin, }; - let build_platforms = BuildPlatforms::new(Some(fake_triple)).unwrap(); + let fake_sysroot = "/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu"; + let build_platforms = + BuildPlatforms::new(Some(Cursor::new(fake_sysroot)), Some(fake_triple)).unwrap(); let fake_env = EnvironmentMap::empty(); let rust_build_meta = RustBuildMeta::new("/fake", build_platforms).map_paths(&PathMapper::noop()); @@ -1144,7 +1146,8 @@ mod tests { "target": { "triple": "aarch64-unknown-linux-gnu", "target-features": "unknown" - } + }, + "sysroot": "/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu" } ], "target-platform": "aarch64-unknown-linux-gnu" diff --git a/nextest-runner/src/platform.rs b/nextest-runner/src/platform.rs index 6cb1cd6d985..6560bfe7317 100644 --- a/nextest-runner/src/platform.rs +++ b/nextest-runner/src/platform.rs @@ -7,7 +7,9 @@ use crate::{ cargo_config::{CargoTargetArg, TargetTriple}, errors::{RustBuildMetaParseError, TargetTripleError, UnknownHostPlatform}, }; +use camino::{Utf8Path, Utf8PathBuf}; use nextest_metadata::{BuildPlatformsSummary, RustBuildMetaSummary}; +use std::io::{self, Cursor}; pub use target_spec::Platform; /// A representation of host and target platforms. @@ -21,22 +23,52 @@ pub struct BuildPlatforms { /// In the future, this will become a list of target triples once multiple `--target` arguments /// are supported. pub target: Option, + + /// The sysroot for the target platform. + /// + /// This is needed to run procedure macro binaries on Windows. See + /// [https://github.com/nextest-rs/nextest/issues/1493] for details. Empty if failed to detect. + pub sysroot: Option>, } impl BuildPlatforms { /// Creates a new `BuildPlatform`. /// /// Returns an error if the host platform could not be determined. - pub fn new(target: Option) -> Result { + pub fn new( + reader: Option, + target: Option, + ) -> Result { + let sysroot = reader.and_then(|mut reader| { + let mut line = Default::default(); + match reader.read_line(&mut line) { + Ok(_) => { + let original_line = line.as_str(); + let line = line.trim(); + if line.is_empty() { + log::debug!( + "empty input found when deciding the sysroot: {:#?}", + original_line + ); + return None; + } + Some(Utf8PathBuf::from(line).into_boxed_path()) + } + Err(e) => { + log::debug!( + "failed to read the input when deciding the sysroot: {:#?}", + e + ); + None + } + } + }); let host = Platform::current().map_err(|error| UnknownHostPlatform { error })?; - Ok(Self { host, target }) - } - - /// Creates a new `BuildPlatform` where the host is specified. - /// - /// This is intended for testing situations. Most users should call [`Self::new`] instead. - pub fn new_with_host(host: Platform, target: Option) -> Self { - Self { host, target } + Ok(Self { + host, + target, + sysroot, + }) } /// Returns the argument to pass into `cargo metadata --filter-platform `. @@ -61,7 +93,13 @@ impl BuildPlatforms { } else { self.host.to_summary() }; - BuildPlatformsSummary { target } + BuildPlatformsSummary { + target, + sysroot: self + .sysroot + .as_ref() + .map(|sysroot| sysroot.clone().into_path_buf()), + } } /// Creates a `RustBuildMeta` from a serializable summary. @@ -79,7 +117,100 @@ impl BuildPlatforms { // Compatibility with metadata generated by older versions of nextest. TargetTriple::deserialize_str(summary.target_platform.clone())? }; - BuildPlatforms::new(target_triple) + let sysroot = summary + .target_platforms + .first() + .cloned() + .and_then(|build_platforms| build_platforms.sysroot) + .map(String::from) + .map(Cursor::new); + BuildPlatforms::new(sysroot, target_triple) .map_err(|error| RustBuildMetaParseError::UnknownHostPlatform(error.error)) } } + +#[cfg(test)] +mod tests { + use super::*; + use indoc::indoc; + + #[test] + fn test_failed_to_read_sysroot() { + struct ReadMock; + impl io::Read for ReadMock { + fn read(&mut self, _: &mut [u8]) -> io::Result { + Err(io::Error::other("test error")) + } + } + let reader = io::BufReader::new(ReadMock); + let build_platforms = + BuildPlatforms::new(Some(reader), None).expect("should be Ok with read failure"); + assert_eq!(build_platforms.sysroot, None); + } + + #[test] + fn test_empty_input_sysroot() { + let build_platforms = + BuildPlatforms::new(Some(io::empty()), None).expect("should be Ok with empty input"); + assert_eq!(build_platforms.sysroot, None); + + let build_platforms = + BuildPlatforms::new(Some(Cursor::new("")), None).expect("should be Ok"); + assert_eq!(build_platforms.sysroot, None); + } + + #[test] + fn test_parse_input_sysroot() { + // single line + let fake_sysroot = "/fake/sysroot/22548"; + let build_platforms = BuildPlatforms::new(Some(Cursor::new(fake_sysroot)), None) + .expect("should be Ok with fake sysroot"); + assert_eq!( + build_platforms + .sysroot + .as_ref() + .map(|sysroot| sysroot.as_str()), + Some(fake_sysroot) + ); + + // multiple lines + let fake_sysroot: &str = indoc! {r#" + /fake/sysroot/1 + /fake/sysroot/2 + "#}; + let build_platforms = BuildPlatforms::new(Some(Cursor::new(fake_sysroot)), None) + .expect("should be Ok with mutlieple-line fake sysroot"); + assert_eq!( + build_platforms + .sysroot + .as_ref() + .map(|sysroot| sysroot.as_str()), + Some("/fake/sysroot/1") + ); + + // with leading/trailing whitespace + let fake_sysroot = "\t /fake/sysroot\t \n\r"; + let build_platforms = BuildPlatforms::new(Some(Cursor::new(fake_sysroot)), None) + .expect("should be Ok with fake sysroot"); + assert_eq!( + build_platforms + .sysroot + .as_ref() + .map(|sysroot| sysroot.as_str()), + Some("/fake/sysroot") + ); + + // empty content with whitespaces + let fake_sysroot = "\t \r\n"; + let build_platforms = BuildPlatforms::new(Some(Cursor::new(fake_sysroot)), None) + .expect("should be Ok with fake sysroot"); + assert_eq!(build_platforms.sysroot, None); + } + + #[test] + fn test_none_sysroot_input() { + let build_platforms = + BuildPlatforms::new(None::, None).expect("should be Ok without input"); + assert_eq!(build_platforms.sysroot, None); + } +} diff --git a/nextest-runner/src/reporter.rs b/nextest-runner/src/reporter.rs index 9afb258ea64..e1ee09b598d 100644 --- a/nextest-runner/src/reporter.rs +++ b/nextest-runner/src/reporter.rs @@ -1946,6 +1946,7 @@ mod tests { use crate::{ config::NextestConfig, platform::BuildPlatforms, reporter::structured::StructuredReporter, }; + use std::io::Empty; use test_strategy::proptest; // --- @@ -2216,7 +2217,7 @@ mod tests { let test_list = TestList::empty(); let config = NextestConfig::default_config("/fake/dir"); let profile = config.profile(NextestConfig::DEFAULT_PROFILE).unwrap(); - let build_platforms = BuildPlatforms::new(None).unwrap(); + let build_platforms = BuildPlatforms::new(None::, None).unwrap(); let mut buf: Vec = Vec::new(); let output = ReporterStderr::Buffer(&mut buf); diff --git a/nextest-runner/src/runner.rs b/nextest-runner/src/runner.rs index 62c0786602e..4fc5f94fd25 100644 --- a/nextest-runner/src/runner.rs +++ b/nextest-runner/src/runner.rs @@ -2371,6 +2371,7 @@ enum TerminateMode { mod tests { use super::*; use crate::{config::NextestConfig, platform::BuildPlatforms}; + use std::io::Empty; #[test] fn no_capture_settings() { @@ -2382,7 +2383,7 @@ mod tests { let test_list = TestList::empty(); let config = NextestConfig::default_config("/fake/dir"); let profile = config.profile(NextestConfig::DEFAULT_PROFILE).unwrap(); - let build_platforms = BuildPlatforms::new(None).unwrap(); + let build_platforms = BuildPlatforms::new(None::, None).unwrap(); let handler_kind = SignalHandlerKind::Noop; let profile = profile.apply_build_platforms(&build_platforms); let runner = builder diff --git a/nextest-runner/tests/integration/basic.rs b/nextest-runner/tests/integration/basic.rs index 09d0d027a46..da541f1ea6d 100644 --- a/nextest-runner/tests/integration/basic.rs +++ b/nextest-runner/tests/integration/basic.rs @@ -19,7 +19,10 @@ use nextest_runner::{ test_output::TestOutput, }; use pretty_assertions::assert_eq; -use std::{io::Cursor, time::Duration}; +use std::{ + io::{Cursor, Empty}, + time::Duration, +}; use test_case::test_case; #[test] @@ -27,7 +30,7 @@ fn test_list_binaries() -> Result<()> { set_env_vars(); let graph = &*PACKAGE_GRAPH; - let build_platforms = BuildPlatforms::new(None)?; + let build_platforms = BuildPlatforms::new(None::, None)?; let binary_list = BinaryList::from_messages( Cursor::new(&*FIXTURE_RAW_CARGO_TEST_OUTPUT), graph, @@ -104,7 +107,7 @@ fn test_run() -> Result<()> { let profile = config .profile(NextestConfig::DEFAULT_PROFILE) .expect("default config is valid"); - let build_platforms = BuildPlatforms::new(None).unwrap(); + let build_platforms = BuildPlatforms::new(None::, None).unwrap(); let profile = profile.apply_build_platforms(&build_platforms); let runner = TestRunnerBuilder::default() @@ -213,7 +216,7 @@ fn test_run_ignored() -> Result<()> { let profile = config .profile(NextestConfig::DEFAULT_PROFILE) .expect("default config is valid"); - let build_platforms = BuildPlatforms::new(None).unwrap(); + let build_platforms = BuildPlatforms::new(None::, None).unwrap(); let profile = profile.apply_build_platforms(&build_platforms); let runner = TestRunnerBuilder::default() @@ -411,7 +414,7 @@ fn test_retries(retries: Option) -> Result<()> { let profile = config .profile("with-retries") .expect("with-retries config is valid"); - let build_platforms = BuildPlatforms::new(None).unwrap(); + let build_platforms = BuildPlatforms::new(None::, None).unwrap(); let profile = profile.apply_build_platforms(&build_platforms); let profile_retries = profile.retries(); @@ -561,7 +564,7 @@ fn test_termination() -> Result<()> { let profile = config .profile("with-termination") .expect("with-termination config is valid"); - let build_platforms = BuildPlatforms::new(None).unwrap(); + let build_platforms = BuildPlatforms::new(None::, None).unwrap(); let profile = profile.apply_build_platforms(&build_platforms); let runner = TestRunnerBuilder::default() diff --git a/nextest-runner/tests/integration/fixtures.rs b/nextest-runner/tests/integration/fixtures.rs index ff480855c03..d28d6089e57 100644 --- a/nextest-runner/tests/integration/fixtures.rs +++ b/nextest-runner/tests/integration/fixtures.rs @@ -29,7 +29,7 @@ use once_cell::sync::Lazy; use std::{ collections::{BTreeMap, HashMap}, env, fmt, - io::Cursor, + io::{Cursor, Empty}, sync::Arc, }; @@ -175,6 +175,7 @@ pub(crate) static EXPECTED_TESTS: Lazy>> "with-build-script".into() => vec![ TestFixture { name: "tests::test_out_dir_present", status: FixtureStatus::Pass }, ], + "proc-macro-test".into() => vec![], } }, ); @@ -332,7 +333,7 @@ impl FixtureTargets { ) .unwrap(); let env = EnvironmentMap::new(&cargo_configs); - let build_platforms = BuildPlatforms::new(None).unwrap(); + let build_platforms = BuildPlatforms::new(None::, None).unwrap(); let binary_list = Arc::new( BinaryList::from_messages( Cursor::new(&*FIXTURE_RAW_CARGO_TEST_OUTPUT), diff --git a/nextest-runner/tests/integration/target_runner.rs b/nextest-runner/tests/integration/target_runner.rs index 11e7e3ca1d1..1ce89172411 100644 --- a/nextest-runner/tests/integration/target_runner.rs +++ b/nextest-runner/tests/integration/target_runner.rs @@ -14,7 +14,7 @@ use nextest_runner::{ target_runner::{PlatformRunner, TargetRunner}, test_filter::{RunIgnored, TestFilterBuilder}, }; -use std::env; +use std::{env, io::Cursor}; use target_spec::Platform; fn runner_for_target(triple: Option<&str>) -> Result<(BuildPlatforms, TargetRunner)> { @@ -25,8 +25,26 @@ fn runner_for_target(triple: Option<&str>) -> Result<(BuildPlatforms, TargetRunn Vec::new(), ) .unwrap(); + let output = { + let mut args = vec!["--print", "sysroot"]; + if let Some(triple) = triple { + args.extend(["--target", triple]); + } + duct::cmd("rustc", args) + .stdout_capture() + .unchecked() + .run() + .ok() + .and_then(|output| { + if output.status.success() { + Some(Cursor::new(output.stdout)) + } else { + None + } + }) + }; let triple = TargetTriple::find(&configs, triple)?; - let build_platforms = BuildPlatforms::new(triple)?; + let build_platforms = BuildPlatforms::new(output, triple)?; let target_runner = TargetRunner::new(&configs, &build_platforms)?; Ok((build_platforms, target_runner)) }