Skip to content

Commit e2ca0b0

Browse files
committed
Add rustc libdir folders to dynamic linker search path
... so that we can run cargo-nextest with proc-macro projects on Windows. This commit also adds integration tests that run cargo-nextest with a proc-macro project.
1 parent 6486c32 commit e2ca0b0

21 files changed

+369
-33
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cargo-nextest/src/dispatch.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use nextest_runner::{
3737
target_runner::{PlatformRunner, TargetRunner},
3838
test_filter::{RunIgnored, TestFilterBuilder},
3939
write_str::WriteStr,
40+
RustcCli,
4041
};
4142
use once_cell::sync::OnceCell;
4243
use owo_colors::{OwoColorize, Stream, Style};
@@ -1009,10 +1010,17 @@ impl BaseApp {
10091010
Some(kind) => kind.binary_list.rust_build_meta.build_platforms.clone(),
10101011
None => {
10111012
let mut build_platforms = BuildPlatforms::new()?;
1013+
if let Some(output) = RustcCli::print_host_libdir().read() {
1014+
build_platforms.set_host_libdir_from_rustc_output(Cursor::new(output));
1015+
}
10121016
if let Some(triple) =
10131017
discover_target_triple(&cargo_configs, cargo_opts.target.as_deref())
10141018
{
1015-
build_platforms.target = Some(BuildPlatformsTarget { triple });
1019+
let mut target = BuildPlatformsTarget::new(triple.clone());
1020+
if let Some(output) = RustcCli::print_target_libdir(&triple).read() {
1021+
target.set_libdir_from_rustc_output(Cursor::new(output));
1022+
}
1023+
build_platforms.target = Some(target);
10161024
}
10171025
build_platforms
10181026
}

fixtures/nextest-tests/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/nextest-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ members = [
3434
"derive",
3535
"dylib-test",
3636
"with-build-script",
37+
"proc-macro-test"
3738
]
3839

3940
[dependencies]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "proc-macro-test"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
proc-macro = true

fixtures/nextest-tests/proc-macro-test/src/lib.rs

Whitespace-only changes.

integration-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ once_cell = "1.19.0"
3636
regex = "1.10.4"
3737
serde_json = "1.0.117"
3838
insta = { version = "1.39.0", default-features = false }
39+
target-spec = { version = "3.1.0", features = ["custom", "summaries"] }

integration-tests/tests/integration/fixtures.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub static EXPECTED_LIST: Lazy<Vec<TestInfo>> = Lazy::new(|| {
128128
BuildPlatform::Target,
129129
vec![("tests::test_out_dir_present", false)],
130130
),
131+
TestInfo::new("proc-macro-test", BuildPlatform::Host, vec![]),
131132
]
132133
});
133134

@@ -379,7 +380,20 @@ pub fn check_list_binaries_output(stdout: &[u8]) {
379380
let result: BinaryListSummary = serde_json::from_slice(stdout).unwrap();
380381

381382
let test_suite = &*EXPECTED_LIST;
382-
assert_eq!(test_suite.len(), result.rust_binaries.len());
383+
let mut expected_binary_ids = test_suite
384+
.iter()
385+
.map(|test_info| test_info.id.clone())
386+
.collect::<Vec<_>>();
387+
expected_binary_ids.sort();
388+
let mut actual_binary_ids = result.rust_binaries.keys().collect::<Vec<_>>();
389+
actual_binary_ids.sort();
390+
assert_eq!(
391+
test_suite.len(),
392+
result.rust_binaries.len(),
393+
"expected rust binaries:\n{:?}\nactual rust binaries\n{:?}",
394+
expected_binary_ids,
395+
actual_binary_ids
396+
);
383397

384398
for test in test_suite {
385399
let entry = result

integration-tests/tests/integration/main.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
//! `NEXTEST_BIN_EXE_cargo-nextest-dup`.
2424
2525
use camino::{Utf8Path, Utf8PathBuf};
26-
use nextest_metadata::{BuildPlatform, NextestExitCode};
26+
use nextest_metadata::{BuildPlatform, NextestExitCode, TestListSummary};
2727
use std::{fs::File, io::Write};
28+
use target_spec::Platform;
2829

2930
mod fixtures;
3031
mod temp_project;
@@ -818,3 +819,16 @@ fn test_setup_script_error() {
818819
Some(NextestExitCode::SETUP_SCRIPT_FAILED)
819820
);
820821
}
822+
823+
#[test]
824+
fn test_target_arg() {
825+
let host_platform = Platform::current().expect("should detect the host target successfully");
826+
let host_target = host_platform.triple_str();
827+
let output = CargoNextestCli::new()
828+
.args(["list", "--target", host_target, "--message-format", "json"])
829+
.output();
830+
let result: TestListSummary = serde_json::from_slice(&output.stdout).unwrap();
831+
let build_platforms = &result.rust_build_meta.target_platforms_v2[0];
832+
assert_eq!(build_platforms.target.triple, host_target);
833+
assert_eq!(build_platforms.host_libdir, build_platforms.target_libdir);
834+
}

integration-tests/tests/integration/snapshots/integration__archive_includes.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: integration-tests/tests/integration/main.rs
33
expression: output.stderr_as_str()
44
---
5-
Archiving 16 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 7 extra paths to <archive-file>
5+
Archiving 17 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 7 extra paths to <archive-file>
66
Warning ignoring extra path `<target-dir>/excluded-dir` because it does not exist
77
Warning ignoring extra path `<target-dir>/depth-0-dir` specified with depth 0 since it is a directory
88
Warning ignoring extra path `<target-dir>/file_that_does_not_exist.txt` because it does not exist

integration-tests/tests/integration/snapshots/integration__archive_includes_without_uds.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: integration-tests/tests/integration/main.rs
33
expression: output.stderr_as_str()
44
---
5-
Archiving 16 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 7 extra paths to <archive-file>
5+
Archiving 17 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 7 extra paths to <archive-file>
66
Warning ignoring extra path `<target-dir>/excluded-dir` because it does not exist
77
Warning ignoring extra path `<target-dir>/depth-0-dir` specified with depth 0 since it is a directory
88
Warning ignoring extra path `<target-dir>/file_that_does_not_exist.txt` because it does not exist

integration-tests/tests/integration/snapshots/integration__archive_missing_includes.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: integration-tests/tests/integration/main.rs
33
expression: output.stderr_as_str()
44
---
5-
Archiving 16 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 1 extra path to <archive-file>
5+
Archiving 17 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 1 extra path to <archive-file>
66
error: error creating archive `<archive-file>`
77

88
Caused by:

integration-tests/tests/integration/snapshots/integration__archive_no_includes.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: integration-tests/tests/integration/main.rs
33
expression: output.stderr_as_str()
44
---
5-
Archiving 16 binaries (including 2 non-test binaries), 2 build script output directories, and 2 linked paths to <archive-file>
5+
Archiving 17 binaries (including 2 non-test binaries), 2 build script output directories, and 2 linked paths to <archive-file>
66
Warning linked path `<target-dir>/debug/build/<cdylib-link-hash>/does-not-exist` not found, requested by: cdylib-link v0.1.0
77
(this is a bug in this crate that should be fixed)
88
Archived <file-count> files to <archive-file> in <duration>

nextest-metadata/src/test_list.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,18 @@ pub struct RustNonTestBinarySummary {
522522
pub struct BuildPlatformsSummary {
523523
/// The target platform, if specified.
524524
pub target: PlatformSummary,
525+
526+
/// The libdir for the host platform.
527+
///
528+
/// Empty if failed to discover.
529+
#[serde(default)]
530+
pub host_libdir: Option<Utf8PathBuf>,
531+
532+
/// The libdir for the target platform.
533+
///
534+
/// Empty if failed to discover.
535+
#[serde(default)]
536+
pub target_libdir: Option<Utf8PathBuf>,
525537
}
526538

527539
/// Information about the kind of a Rust non-test binary.

nextest-runner/src/config/test_helpers.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,18 @@ pub(super) fn binary_query<'a>(
8686
pub(super) fn build_platforms() -> BuildPlatforms {
8787
BuildPlatforms {
8888
host: Platform::new("x86_64-unknown-linux-gnu", TargetFeatures::Unknown).unwrap(),
89+
host_libdir: Some(
90+
Utf8PathBuf::from("/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib")
91+
),
8992
target: Some(BuildPlatformsTarget {
9093
triple: TargetTriple {
9194
platform: Platform::new("aarch64-apple-darwin", TargetFeatures::Unknown).unwrap(),
9295
source: TargetTripleSource::Env,
9396
location: TargetDefinitionLocation::Builtin,
9497
},
98+
libdir: Some(
99+
Utf8PathBuf::from("/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-apple-darwin/lib")
100+
),
95101
}),
96102
}
97103
}

nextest-runner/src/list/binary_list.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,12 @@ mod tests {
427427
source: TargetTripleSource::CliOption,
428428
location: TargetDefinitionLocation::Builtin,
429429
};
430+
let fake_libdir = "/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib";
430431
let mut build_platforms = BuildPlatforms::new().unwrap();
432+
build_platforms.host_libdir = Some(Utf8PathBuf::from(fake_libdir));
431433
build_platforms.target = Some(BuildPlatformsTarget {
432434
triple: fake_triple,
435+
libdir: Some(Utf8PathBuf::from(fake_libdir)),
433436
});
434437
let build_platforms = build_platforms;
435438

@@ -509,7 +512,9 @@ mod tests {
509512
"target": {
510513
"triple": "x86_64-unknown-linux-gnu",
511514
"target-features": "unknown"
512-
}
515+
},
516+
"host-libdir": "/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib",
517+
"target-libdir": "/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib"
513518
}
514519
],
515520
"target-platforms": [

0 commit comments

Comments
 (0)