Skip to content

Conversation

@taiki-e
Copy link
Owner

@taiki-e taiki-e commented Oct 3, 2025

Fixes #432

There is no support for nextest-archive because nextest itself doesn't seem to support it yet.

+ cargo nextest archive --archive-file a.tar.zst
warning: /home/runner/work/cargo-llvm-cov/cargo-llvm-cov/tests/fixtures/crates/build_dir/Cargo.toml: no edition set: defaulting to the 2015 edition while the latest is 2024
   Compiling build_dir v0.0.0 (/home/runner/work/cargo-llvm-cov/cargo-llvm-cov/tests/fixtures/crates/build_dir)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.11s
   Archiving 1 binary and 1 standard library to a.tar.zst
The application panicked (crashed).
Message:  binary paths must be within target directory: StripPrefixError(())
Location: /home/runner/work/nextest/nextest/nextest-runner/src/reuse_build/archiver.rs:344

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 8 frames hidden ⋮                               
   9: nextest_runner::reuse_build::archiver::archive_to_file::{{closure}}::hfe6386f37325607b
      at <unknown source file>:<unknown line>
  10: cargo_nextest::dispatch::BaseApp::exec_archive::hb0c18033879d0a05
      at <unknown source file>:<unknown line>
  11: cargo_nextest::dispatch::AppOpts::exec::h0a45ae9b7294b285
      at <unknown source file>:<unknown line>
  12: cargo_nextest::dispatch::CargoNextestApp::exec::h5d63f524fe109718
      at <unknown source file>:<unknown line>
  13: cargo_nextest::main::h75d34d2809558cd2
      at <unknown source file>:<unknown line>
  14: std::sys::backtrace::__rust_begin_short_backtrace::h5f4ef41318e24363
      at <unknown source file>:<unknown line>
  15: main<unknown>
      at <unknown source file>:<unknown line>
  16: __libc_start_main<unknown>
      at <unknown source file>:<unknown line>
  17: _start<unknown>
      at /home/runner/.local/lib/python3.10/site-packages/ziglang/lib/libc/glibc/sysdeps/x86_64/start-2.33.S:120

@taiki-e taiki-e changed the title Initial support for build-dir Initial support for Cargo build-dir Oct 3, 2025
@taiki-e taiki-e force-pushed the build-dir branch 2 times, most recently from 1d28ef5 to a2690a4 Compare October 3, 2025 14:54
@taiki-e
Copy link
Owner Author

taiki-e commented Oct 3, 2025

Ah, the scope of --target-dir's effect depends on whether build-dir is specified in the configuration, so this is blocked on taiki-e/cargo-config2#29.

However, when using environment variables, it will probably not be a blocker.

src/main.rs Outdated
// This is not the ideal way, but the way unstable book says it is cannot support them.
// https://doc.rust-lang.org/nightly/rustc/instrument-coverage.html#tips-for-listing-the-binaries-automatically
let mut target_dir = cx.ws.target_dir.clone();
let mut build_dir = cx.ws.metadata.build_directory().to_owned();
Copy link
Owner Author

Choose a reason for hiding this comment

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

This is likely inefficient as it triggers a rebuild, but unfortunately, build-dir lacks a flag like --target-dir and only has transparent environment variables, so it may be difficult to make it behave the same as target-dir here.

Comment on lines 858 to 864
if let Some(target) = &cx.args.target {
target_dir.push(target);
build_dir.push(target);
}

Choose a reason for hiding this comment

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

Just want to point out that the build-dir contents are considered internal to Cargo.

We are planning to restructure the build-dir layout in rust-lang/cargo#15947 which may break this logic in the future

Choose a reason for hiding this comment

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

Though given the nature of this tool we probably have no choice but to depend on the Cargo internals to get the correct files :/

Copy link
Owner Author

Choose a reason for hiding this comment

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

Though given the nature of this tool we probably have no choice but to depend on the Cargo internals to get the correct files :/

Yeah. This isn't only happening with Cargo; it can occur with other testing tools as well. (e.g., #299 (comment))

If changes occur, we'll address them. As for future changes, we can only hope that "upstream developers are smart enough and only change internal structures when it's actually reasonable to do so".

@taiki-e taiki-e force-pushed the build-dir branch 4 times, most recently from 6356a68 to f984df7 Compare October 4, 2025 02:09
@taiki-e taiki-e changed the title Initial support for Cargo build-dir Support Cargo build-dir Oct 4, 2025
@taiki-e taiki-e force-pushed the build-dir branch 6 times, most recently from c4efa6e to 6aa7b3d Compare October 4, 2025 05:23
@taiki-e taiki-e merged commit 33502f4 into main Oct 4, 2025
41 checks passed
@taiki-e taiki-e deleted the build-dir branch October 4, 2025 05:38
@taiki-e taiki-e mentioned this pull request Oct 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cargo build-dir support

2 participants