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 6628491
Show file tree
Hide file tree
Showing 21 changed files with 381 additions and 30 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

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) =
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();
}
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.
1 change: 1 addition & 0 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ once_cell = "1.19.0"
regex = "1.10.4"
serde_json = "1.0.117"
insta = { version = "1.38.0", default-features = false }
target-spec = { version = "3.1.0", features = ["custom", "summaries"] }
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
16 changes: 15 additions & 1 deletion integration-tests/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
//! `NEXTEST_BIN_EXE_cargo-nextest-dup`.

use camino::{Utf8Path, Utf8PathBuf};
use nextest_metadata::{BuildPlatform, NextestExitCode};
use nextest_metadata::{BuildPlatform, NextestExitCode, TestListSummary};
use target_spec::Platform;
use std::{fs::File, io::Write};

mod fixtures;
Expand Down Expand Up @@ -818,3 +819,16 @@ fn test_setup_script_error() {
Some(NextestExitCode::SETUP_SCRIPT_FAILED)
);
}

#[test]
fn test_target_arg() {
let host_platform = Platform::current().expect("should detect the host target successfully");
let host_target = host_platform.triple_str();
let output = CargoNextestCli::new()
.args(["list", "--target", host_target, "--message-format", "json"])
.output();
let result: TestListSummary = serde_json::from_slice(&output.stdout).unwrap();
let build_platform = &result.rust_build_meta.target_platforms_v2[0];
assert_eq!(build_platform.target.triple, host_target);
assert_eq!(build_platform.host_libdir, build_platform.target_libdir);
}
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 6628491

Please sign in to comment.