Skip to content

Commit

Permalink
Add rustc folder to dynamic linker search path
Browse files Browse the repository at this point in the history
... so that we can run cargo-nextest with proc-macro projects on
Windows.

This commit also adds integration tests for running cargo-nextest for
proc-macro projects.
  • Loading branch information
06393993 committed May 18, 2024
1 parent d23ea6c commit 24b0f99
Show file tree
Hide file tree
Showing 18 changed files with 364 additions and 29 deletions.
11 changes: 10 additions & 1 deletion cargo-nextest/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use nextest_runner::{
target_runner::{PlatformRunner, TargetRunner},
test_filter::{RunIgnored, TestFilterBuilder},
write_str::WriteStr,
RustcCli,
};
use once_cell::sync::OnceCell;
use owo_colors::{OwoColorize, Stream, Style};
Expand Down Expand Up @@ -1009,10 +1010,18 @@ impl BaseApp {
Some(kind) => kind.binary_list.rust_build_meta.build_platforms.clone(),
None => {
let mut build_platform_builder = BuildPlatformBuilder::default();
if let Some(output) = RustcCli::print_host_libdir().read() {
build_platform_builder.set_host_libdir(Cursor::new(output));
}
if let Some(target_triple) =

Check warning on line 1016 in cargo-nextest/src/dispatch.rs

View check run for this annotation

Codecov / codecov/patch

cargo-nextest/src/dispatch.rs#L1016

Added line #L1016 was not covered by tests
discover_target_triple(&cargo_configs, cargo_opts.target.as_deref())
{
build_platform_builder.set_target(target_triple).add();
let mut target_builder =
build_platform_builder.set_target(target_triple.clone());
if let Some(output) = RustcCli::print_target_libdir(&target_triple).read() {
target_builder.set_libdir(Cursor::new(output));
}
target_builder.add();

Check warning on line 1024 in cargo-nextest/src/dispatch.rs

View check run for this annotation

Codecov / codecov/patch

cargo-nextest/src/dispatch.rs#L1019-L1024

Added lines #L1019 - L1024 were not covered by tests
}
build_platform_builder.build()?
}
Expand Down
4 changes: 4 additions & 0 deletions fixtures/nextest-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fixtures/nextest-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ members = [
"derive",
"dylib-test",
"with-build-script",
"proc-macro-test"
]

[dependencies]
Expand Down
7 changes: 7 additions & 0 deletions fixtures/nextest-tests/proc-macro-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "proc-macro-test"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true
Empty file.
16 changes: 15 additions & 1 deletion integration-tests/tests/integration/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub static EXPECTED_LIST: Lazy<Vec<TestInfo>> = Lazy::new(|| {
BuildPlatform::Target,
vec![("tests::test_out_dir_present", false)],
),
TestInfo::new("proc-macro-test", BuildPlatform::Host, vec![]),
]
});

Expand Down Expand Up @@ -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::<Vec<_>>();
expected_binary_ids.sort();
let mut actual_binary_ids = result.rust_binaries.keys().collect::<Vec<_>>();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <archive-file>
Archiving 17 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 7 extra paths to <archive-file>
Warning ignoring extra path `<target-dir>/excluded-dir` because it does not exist
Warning ignoring extra path `<target-dir>/depth-0-dir` specified with depth 0 since it is a directory
Warning ignoring extra path `<target-dir>/file_that_does_not_exist.txt` because it does not exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <archive-file>
Archiving 17 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 7 extra paths to <archive-file>
Warning ignoring extra path `<target-dir>/excluded-dir` because it does not exist
Warning ignoring extra path `<target-dir>/depth-0-dir` specified with depth 0 since it is a directory
Warning ignoring extra path `<target-dir>/file_that_does_not_exist.txt` because it does not exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <archive-file>
Archiving 17 binaries (including 2 non-test binaries), 2 build script output directories, 2 linked paths, and 1 extra path to <archive-file>
error: error creating archive `<archive-file>`

Caused by:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <archive-file>
Archiving 17 binaries (including 2 non-test binaries), 2 build script output directories, and 2 linked paths to <archive-file>
Warning linked path `<target-dir>/debug/build/<cdylib-link-hash>/does-not-exist` not found, requested by: cdylib-link v0.1.0
(this is a bug in this crate that should be fixed)
Archived <file-count> files to <archive-file> in <duration>
12 changes: 12 additions & 0 deletions nextest-metadata/src/test_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,18 @@ pub struct RustNonTestBinarySummary {
pub struct BuildPlatformSummary {
/// The target platform, if specified.
pub target: PlatformSummary,

/// The libdir for the host platform.
///
/// Empty if failed to discover.
#[serde(default)]
pub host_libdir: Option<Utf8PathBuf>,

/// The libdir for the target platform.
///
/// Empty if failed to discover.
#[serde(default)]
pub target_libdir: Option<Utf8PathBuf>,
}

/// Information about the kind of a Rust non-test binary.
Expand Down
6 changes: 6 additions & 0 deletions nextest-runner/src/config/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ pub(super) fn binary_query<'a>(
pub(super) fn build_platforms() -> NextestBuildPlatform {
NextestBuildPlatform {
host: Platform::new("x86_64-unknown-linux-gnu", TargetFeatures::Unknown).unwrap(),
host_libdir: Some(
Utf8PathBuf::from("/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib")
),
target: Some(BuildPlatformTarget {
triple: TargetTriple {
platform: Platform::new("aarch64-apple-darwin", TargetFeatures::Unknown).unwrap(),
source: TargetTripleSource::Env,
location: TargetDefinitionLocation::Builtin,
},
libdir: Some(
Utf8PathBuf::from("/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-apple-darwin/lib")
),
}),
}
}
Expand Down
11 changes: 9 additions & 2 deletions nextest-runner/src/list/binary_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ mod tests {
use indoc::indoc;
use maplit::btreeset;
use pretty_assertions::assert_eq;
use std::io::Cursor;
use target_spec::{Platform, TargetFeatures};

#[test]
Expand Down Expand Up @@ -427,8 +428,12 @@ mod tests {
source: TargetTripleSource::CliOption,
location: TargetDefinitionLocation::Builtin,
};
let fake_libdir = "/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib";
let mut build_platform_builder = BuildPlatformBuilder::default();
build_platform_builder.set_target(fake_triple).add();
let mut build_platform_target_builder = build_platform_builder.set_target(fake_triple);
build_platform_target_builder.set_libdir(Cursor::new(fake_libdir));
build_platform_target_builder.add();
build_platform_builder.set_host_libdir(Cursor::new(fake_libdir));
let build_platforms = build_platform_builder.build().unwrap();

let mut rust_build_meta = RustBuildMeta::new("/fake/target", build_platforms);
Expand Down Expand Up @@ -507,7 +512,9 @@ mod tests {
"target": {
"triple": "x86_64-unknown-linux-gnu",
"target-features": "unknown"
}
},
"host-libdir": "/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib",
"target-libdir": "/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib"
}
],
"target-platforms": [
Expand Down
Loading

0 comments on commit 24b0f99

Please sign in to comment.