Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 39 additions & 9 deletions tests/end_to_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,22 +657,38 @@ fn a_target_or_features_bring_in_the_code_behind_their_cfg_and_each_keeps_its_in
let console = "module-cycle gated::console::handle,gated::console::modes";
let export = "module-cycle gated::export::csv,gated::export::rows";
let metrics = "module-cycle gated::metrics::counter,gated::metrics::sink";
assert_eq!(keys(&workspace), [metrics]);
let host_has_console = cfg!(any(windows, target_arch = "aarch64"));
let mut host_default = vec![metrics];
if host_has_console {
host_default.push(console);
}
host_default.sort();
assert_eq!(keys(&workspace), host_default);
// The Windows standard library need not be installed: rust-analyzer
// reads its source.
let windows = ["--target", "x86_64-pc-windows-msvc"];
assert_eq!(configured_keys(&workspace, &windows), [console, metrics]);
let mut with_export = vec![export, metrics];
let mut all_features = vec![export, metrics];
let mut no_default_features = Vec::new();
if host_has_console {
with_export.push(console);
all_features.push(console);
no_default_features.push(console);
}
with_export.sort();
all_features.sort();
assert_eq!(
configured_keys(&workspace, &["--features", "export"]),
[export, metrics]
with_export
);
assert_eq!(
configured_keys(&workspace, &["--all-features"]),
[export, metrics]
all_features
);
assert_eq!(
configured_keys(&workspace, &["--no-default-features"]),
Vec::<String>::new()
no_default_features
);

let fresh = run(&workspace, &["-F", "export", "--no-default-features"]);
Expand All @@ -682,13 +698,17 @@ fn a_target_or_features_bring_in_the_code_behind_their_cfg_and_each_keeps_its_in
)));
assert!(fresh.stdout.contains("2 modules in `gated::export`"));
assert!(!fresh.stdout.contains("gated::metrics"));
assert_eq!(fresh.stdout.contains("gated::console"), host_has_console);
// Back to each: its index is still there, however its flags are written.
for (flags, code) in [
(&[][..], 1),
(&windows, 1),
(&["--features=export"], 1),
(&["--all-features"], 1),
(&["--no-default-features"], 0),
(
&["--no-default-features"],
if host_has_console { 1 } else { 0 },
),
] {
let again = run(&workspace, flags);
assert!(!again.stderr.contains("indexing"), "{flags:?}");
Expand All @@ -712,9 +732,19 @@ fn cargo_s_own_configuration_chooses_the_target_and_cfgs_too_and_each_keeps_its_
};
let console = "2 modules in `gated::console`";
let windows = ["--target", "x86_64-pc-windows-msvc"];
// Keep this distinct from the native target even on Apple Silicon macOS,
// where aarch64-apple-darwin is already Cargo's default target.
let configured_target = if cfg!(all(target_arch = "aarch64", target_os = "macos")) {
"aarch64-pc-windows-msvc"
} else {
"aarch64-apple-darwin"
};
let plain = run(&workspace, &[]);
assert!(plain.stderr.contains("indexing workspace..."));
assert!(!plain.stdout.contains(console));
assert_eq!(
plain.stdout.contains(console),
cfg!(any(windows, target_arch = "aarch64"))
);
assert!(run(&workspace, &windows).stdout.contains(console));

// Each brings in `console`, indexing once: the next run finds its index.
Expand All @@ -729,13 +759,13 @@ fn cargo_s_own_configuration_chooses_the_target_and_cfgs_too_and_each_keeps_its_
assert!(report.stdout.contains(console), "{variables:?}");
}
};
build_target("x86_64-pc-windows-msvc");
build_target(configured_target);
indexes_once(&[]);
std::fs::remove_file(config.join("config.toml")).unwrap();
indexes_once(&[("RUSTFLAGS", "--cfg windows")]);
indexes_once(&[("RUSTFLAGS", "--cfg rustflags_console")]);

// `--target` overrides `build.target`, as on cargo's command line.
build_target("aarch64-apple-darwin");
build_target(configured_target);
let flagged = run(&workspace, &windows);
assert!(!flagged.stderr.contains("indexing"));
assert!(flagged.stdout.contains(console));
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/gated/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Code that only some configurations build. Each module holds two modules
//! that use each other: a module cycle, reported when the module is indexed.

#[cfg(windows)]
#[cfg(any(windows, target_arch = "aarch64", rustflags_console))]
pub mod console;
#[cfg(feature = "export")]
pub mod export;
Expand Down
Loading