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
1 change: 1 addition & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ jobs:
- name: Build and Test
env:
RUSTFLAGS: -D warnings
CARGO_UNSTABLE_BUILD_DIR_NEW_LAYOUT: true
run: cargo run --manifest-path ci/Cargo.toml build-and-test
1 change: 1 addition & 0 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ jobs:
- name: Build and Test
env:
RUSTFLAGS: -D warnings
CARGO_UNSTABLE_BUILD_DIR_NEW_LAYOUT: true
run: cargo run --manifest-path ci/Cargo.toml build-and-test
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ jobs:
- name: Build and Test
env:
RUSTFLAGS: -D warnings
CARGO_UNSTABLE_BUILD_DIR_NEW_LAYOUT: true
run: cargo run --manifest-path ci/Cargo.toml build-and-test
19 changes: 17 additions & 2 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,8 +1130,23 @@ fn rustfmt() -> PathBuf {
let mut me = env::current_exe().expect("failed to get current executable");
// Chop of the test name.
me.pop();
// Chop off `deps`.
me.pop();

// Handle Cargo's old and new filesystem layouts
// * v1: `target/<profile>/deps/test-bin-[HASH][EXE]`
// * v2: `target/<profile>/build/<pkgname>/[HASH]/out/test-bin-[HASH][EXE]`
if me.ends_with("deps") {
// Chop off `deps`.
me.pop();
} else if me.ends_with("out") {
// Chop off `out`.
me.pop();
// Chop off `<hash>`.
me.pop();
// Chop off `<pkgname>`.
me.pop();
// Chop off `build`.
me.pop();
}

me.push("rustfmt");
assert!(
Expand Down
9 changes: 9 additions & 0 deletions tests/cargo-fmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ use rustfmt_config_proc_macro::rustfmt_only_ci_test;
fn cargo_fmt(args: &[&str]) -> (String, String) {
let mut bin_dir = env::current_exe().unwrap();
bin_dir.pop(); // chop off test exe name

// Handle Cargo's old and new filesystem layouts
// * v1: `target/<profile>/deps/test-bin-[HASH][EXE]`
// * v2: `target/<profile>/build/<pkgname>/[HASH]/out/test-bin-[HASH][EXE]`
if bin_dir.ends_with("deps") {
Copy link
Copy Markdown
Contributor

@ytmimi ytmimi Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to add the same comment here about the v1 and v2 build dirs:

    // Handle Cargo's old and new filesystem layouts
    // * v1: `target/<profile>/deps/test-bin-[HASH][EXE]`
    // * v2: `target/<profile>/build/<pkgname>/[HASH]/out/test-bin-[HASH][EXE]`

View changes since the review

bin_dir.pop();
} else if bin_dir.ends_with("out") {
bin_dir.pop(); // chop off `out`
bin_dir.pop(); // chop off `<hash>`
bin_dir.pop(); // chop off `<pkgname>`
bin_dir.pop(); // chop off `build`
}
let cmd = bin_dir.join(format!("cargo-fmt{}", env::consts::EXE_SUFFIX));

Expand Down