Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ jobs:
run: cargo local-nt run --profile ci
- name: Test with latest nextest release
run: cargo nextest run --profile ci
env:
# TODO: should remove once https://github.com/nextest-rs/nextest/pull/1499 is in the
# latest release
RUSTUP_WINDOWS_PATH_ADD_BIN: 1
- name: Test without double-spawning
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-14' }}
env:
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions cargo-nextest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ swrite.workspace = true
thiserror = "1.0.60"
nextest-workspace-hack.workspace = true

[dev-dependencies]
camino-tempfile = "1.1.1"

[features]
default = ["default-no-update", "self-update"]
experimental-tokio-console = ["nextest-runner/experimental-tokio-console"]
Expand Down
33 changes: 24 additions & 9 deletions cargo-nextest/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use nextest_runner::{
VersionOnlyConfig,
},
double_spawn::DoubleSpawnInfo,
errors::{UnknownHostPlatform, WriteTestListError},
errors::WriteTestListError,
list::{
BinaryList, OutputFormat, RustTestArtifact, SerializableFormat, TestExecuteContext,
TestList,
},
partition::PartitionerBuilder,
platform::BuildPlatforms,
platform::{BuildPlatforms, BuildPlatformsTarget},
redact::Redactor,
reporter::{structured, FinalStatusLevel, StatusLevel, TestOutputDisplay, TestReporterBuilder},
reuse_build::{archive_to_file, ArchiveReporter, PathMapper, ReuseBuildInfo},
Expand All @@ -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 @@ -971,6 +972,7 @@ impl From<FinalStatusLevelOpt> for FinalStatusLevel {
#[derive(Debug)]
struct BaseApp {
output: OutputContext,
// TODO: support multiple --target options
build_platforms: BuildPlatforms,
cargo_metadata_json: Arc<String>,
package_graph: Arc<PackageGraph>,
Expand Down Expand Up @@ -1006,7 +1008,22 @@ impl BaseApp {
// Next, read the build platforms.
let build_platforms = match reuse_build.binaries_metadata() {
Some(kind) => kind.binary_list.rust_build_meta.build_platforms.clone(),
None => discover_build_platforms(&cargo_configs, cargo_opts.target.as_deref())?,
None => {
let mut build_platforms = BuildPlatforms::new()?;
if let Some(output) = RustcCli::print_host_libdir().read() {
build_platforms.set_host_libdir_from_rustc_output(Cursor::new(output));
}
if let Some(triple) =
discover_target_triple(&cargo_configs, cargo_opts.target.as_deref())
{
let mut target = BuildPlatformsTarget::new(triple.clone());
if let Some(output) = RustcCli::print_target_libdir(&triple).read() {
target.set_libdir_from_rustc_output(Cursor::new(output));
}
build_platforms.target = Some(target);
}
build_platforms
}
};

// Read the Cargo metadata.
Expand Down Expand Up @@ -1927,11 +1944,11 @@ fn acquire_graph_data(
Ok(json)
}

fn discover_build_platforms(
fn discover_target_triple(
cargo_configs: &CargoConfigs,
target_cli_option: Option<&str>,
) -> Result<BuildPlatforms, UnknownHostPlatform> {
let target_triple = match TargetTriple::find(cargo_configs, target_cli_option) {
) -> Option<TargetTriple> {
match TargetTriple::find(cargo_configs, target_cli_option) {
Ok(Some(triple)) => {
log::debug!(
"using target triple `{}` defined by `{}`; {}",
Expand All @@ -1950,9 +1967,7 @@ fn discover_build_platforms(
warn_on_err("target triple", &err);
None
}
};

BuildPlatforms::new(target_triple)
}
}

fn runner_for_target(
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.39.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
23 changes: 22 additions & 1 deletion integration-tests/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
//! `NEXTEST_BIN_EXE_cargo-nextest-dup`.

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

mod fixtures;
mod temp_project;
Expand Down Expand Up @@ -818,3 +819,23 @@ 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_triple = host_platform.triple_str();
let output = CargoNextestCli::new()
.args(["list", "--target", host_triple, "--message-format", "json"])
.output();
let result: TestListSummary = serde_json::from_slice(&output.stdout).unwrap();
let build_platforms = &result
.rust_build_meta
.platforms
.expect("should have the platforms field");
assert_eq!(build_platforms.host.platform, host_platform.to_summary());
assert_eq!(build_platforms.targets[0].platform.triple, host_triple);
assert_eq!(
build_platforms.targets[0].libdir,
build_platforms.host.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>
49 changes: 48 additions & 1 deletion nextest-metadata/src/test_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ pub enum RustBinaryIdNameAndKind<'a> {
}

/// Rust metadata used for builds and test runs.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default)]
#[serde(rename_all = "kebab-case")]
pub struct RustBuildMetaSummary {
/// The target directory for Rust artifacts.
Expand All @@ -483,7 +483,13 @@ pub struct RustBuildMetaSummary {
/// Linked paths, relative to the target directory.
pub linked_paths: BTreeSet<Utf8PathBuf>,

/// The build platforms used while compiling the Rust artifacts.
#[serde(default)]
pub platforms: Option<BuildPlatformsSummary>,

/// The target platforms used while compiling the Rust artifacts.
///
/// Deprecated in favor of [`Self::platforms`]; use that if non-empty.
#[serde(default)]
pub target_platforms: Vec<PlatformSummary>,

Expand All @@ -510,6 +516,45 @@ pub struct RustNonTestBinarySummary {
pub path: Utf8PathBuf,
}

/// Serialized representation of the host platform.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct HostPlatformSummary {
/// The host platform, if specified.
pub platform: PlatformSummary,

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

/// Serialized representation of the target platform.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct TargetPlatformSummary {
/// The target platform, if specified.
pub platform: PlatformSummary,

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

/// Serialized representation of the host and the target platform.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct BuildPlatformsSummary {
/// The target platform used while compiling the Rust artifacts.
pub host: HostPlatformSummary,

/// The host platform used while compiling the Rust artifacts.
pub targets: Vec<TargetPlatformSummary>,
}

/// Information about the kind of a Rust non-test binary.
///
/// This is part of [`RustNonTestBinarySummary`], and is used to determine runtime environment
Expand Down Expand Up @@ -705,6 +750,7 @@ mod tests {
linked_paths: BTreeSet::new(),
target_platform: None,
target_platforms: vec![],
platforms: None,
}; "no target platform")]
#[test_case(r#"{
"target-directory": "/foo",
Expand All @@ -720,6 +766,7 @@ mod tests {
linked_paths: BTreeSet::new(),
target_platform: Some("x86_64-unknown-linux-gnu".to_owned()),
target_platforms: vec![],
platforms: None,
}; "single target platform specified")]
fn test_deserialize_old_rust_build_meta(input: &str, expected: RustBuildMetaSummary) {
let build_meta: RustBuildMetaSummary =
Expand Down
2 changes: 1 addition & 1 deletion nextest-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ cfg-if = "1.0.0"
chrono = "0.4.38"
debug-ignore.workspace = true
display-error-chain = "0.2.0"
duct = "0.13.7"
either = "1.11.0"
futures = "0.3.30"
guppy = "0.17.5"
Expand Down Expand Up @@ -130,7 +131,6 @@ self_update = { version = "0.39.0", optional = true }

[dev-dependencies]
color-eyre = { version = "0.6.3", default-features = false }
duct = "0.13.7"
indoc = "2.0.5"
insta = { version = "1.39.0", default-features = false }
maplit = "1.0.2"
Expand Down
12 changes: 12 additions & 0 deletions nextest-runner/src/cargo_config/target_triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ pub struct TargetTriple {
}

impl TargetTriple {
/// Create an x86_64-unknown-linux-gnu [`TargetTriple`]. Useful for testing.
///
/// # Panics
///
/// Panics if the underlying implementation fail to parse the `"x86_64-unknown-linux-gnu"`
/// triple string.
pub fn x86_64_unknown_linux_gnu() -> Self {
TargetTriple::deserialize_str(Some("x86_64-unknown-linux-gnu".to_owned()))
.expect("creating TargetTriple from linux gnu triple string should succeed")
.expect("the output of deserialize_str shouldn't be None")
}

/// Converts a `PlatformSummary` that was output by `TargetTriple::serialize` back to a target triple.
/// This target triple is assumed to originate from a build-metadata config.
pub fn deserialize(
Expand Down
4 changes: 2 additions & 2 deletions nextest-runner/src/config/overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ impl CompiledOverride<PreBuildPlatform> {
let target_eval = build_platforms
.target
.as_ref()
.map_or(host_test_eval, |triple| {
self.data.target_spec.eval(&triple.platform)
.map_or(host_test_eval, |target| {
self.data.target_spec.eval(&target.triple.platform)
});

CompiledOverride {
Expand Down
4 changes: 2 additions & 2 deletions nextest-runner/src/config/scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ impl CompiledProfileScripts<PreBuildPlatform> {
let target_eval = build_platforms
.target
.as_ref()
.map_or(host_test_eval, |triple| {
self.data.target_spec.eval(&triple.platform)
.map_or(host_test_eval, |target| {
self.data.target_spec.eval(&target.triple.platform)
});

CompiledProfileScripts {
Expand Down
Loading