Skip to content

Fix cargo oxide debug executable discovery - #330

Merged
nihalpasham merged 3 commits into
NVIDIA:mainfrom
mohamedsamirx:fix-debug-cargo-artifact-path
Jul 4, 2026
Merged

nihalpasham merged 3 commits into
NVIDIA:mainfrom
mohamedsamirx:fix-debug-cargo-artifact-path

Conversation

@mohamedsamirx

@mohamedsamirx mohamedsamirx commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make cargo oxide debug launch the executable Cargo actually built instead of guessing a path under target/release. The same artifact-selection helper is also used by the run and sanitizer paths.

Before: Cargo builds one package/target -> cargo-oxide may launch another path
After:  Cargo metadata selects packages -> Cargo JSON selects the exact executable

This also adds debug --bin / --features support and resolves cuda-gdb through the configured CUDA toolkit.

What changed

Executable selection

  • Read Cargo metadata to determine the current package or workspace default members.
  • Keep each emitted executable's Cargo package_id and target name.
  • Honor package.default-run and an explicit --bin only when Cargo emitted that exact artifact.
  • Allow a unique --bin to disambiguate multiple default members.
  • Ignore library-only members and executable artifacts from dependencies or other packages.
  • Treat zero or multiple matching artifacts as an error instead of silently choosing another program.
  • Choose from Cargo's emitted artifacts rather than metadata target declarations, so bins disabled by required-features are handled correctly.

Backend build isolation

  • Build rustc_codegen_cuda explicitly for Cargo's host tuple in its own absolute target directory.
  • Remove inherited application CARGO_BUILD_TARGET settings from the backend build.
  • Read the exact backend dylib path from Cargo's JSON output.
  • Reject missing or ambiguous backend artifacts; there is no fallback to a stale guessed target/debug path.
  • Make cargo oxide doctor report the corresponding host-triple path.

CLI and documentation

  • Add cargo oxide debug --bin <name> and --features <features>.
  • Use the configured CUDA toolkit when locating cuda-gdb.
  • Document the new debug behavior in the cargo-oxide README and book.

Safety and failure behavior

The selection rule is deliberately strict:

selected Cargo packages
        -> emitted bin artifacts
        -> --bin / default-run filter
        -> exactly one executable, or a clear error

This prevents a successful build from causing cuda-oxide to debug a stale binary, a build-tool artifact, or a different workspace member.

Testing

  • cargo fmt --all -- --check
  • cargo test -p cargo-oxide (72 tests)
  • cargo clippy -p cargo-oxide --all-targets -- -D warnings
  • cargo check --workspace --locked
  • git diff --check
  • Real backend setup with an invalid inherited CARGO_BUILD_TARGET and a separate application CARGO_TARGET_DIR
  • cargo oxide doctor resolves the host-triple backend path
  • GPU execution (not required for this host-tooling change)

Regression coverage includes configured target directories, custom bin names, virtual and non-virtual workspace defaults, multiple default members, default-run, library-only members, dependency artifacts, duplicate bin names, missing requested targets, required-features, and stale backend-path rejection.

@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks @mohamedsamirx - using cargo’s reported executable path makes sense, and the normal single-package cases work.

A couple of things to fix before this can merge:

  • Keep each artifact’s package_id and select only the executable belonging to cargo’s chosen package and target. If default-run or --bin names a target cargo did not build, return an error instead of silently debugging another binary.
  • Use cargo metadata to honor a virtual workspace’s default member and that package’s default-run.
  • Ignore executable artifacts from binary dependencies. They are build tools, not the program the user requested.
  • Isolate the rustc-codegen backend build from the application’s CARGO_TARGET_DIR, or obtain the backend path from cargo’s artifact output. A fresh custom target directory currently makes cargo-oxide look in the wrong place.

Please add one regression test for each case. The existing artifact-path and toolkit-lookup work can stay as it is.

@nihalpasham nihalpasham added bug Something isn't working QoL-improvement Quality-of-life improvement; not a correctness fix cargo-oxide The `cargo oxide` subcommand and build automation build-related Build scripts, toolchain discovery, or compilation setup documentation Improvements or additions to documentation tests Adds or improves test coverage labels Jul 3, 2026
Reuse Cargo compiler-artifact JSON parsing for debug builds so the debugger launches the executable Cargo actually produced instead of guessing target/release/<example>.

Add debug --bin/--features parity with run and sanitize, and resolve cuda-gdb through configured CUDA toolkit roots.

Signed-off-by: Mohamed Samir <[email protected]>
@mohamedsamirx
mohamedsamirx force-pushed the fix-debug-cargo-artifact-path branch from dee19c8 to af5820f Compare July 3, 2026 15:10
@mohamedsamirx

Copy link
Copy Markdown
Contributor Author

Thanks @nihalpasham, addressed in the latest push.

What changed:

  • Kept package_id with each Cargo executable artifact and now select only the artifact matching Cargo’s selected package and target.
  • Use cargo metadata to resolve the package being debugged, including virtual workspace default-members and the selected package’s default-run.
  • Return an error when --bin or default-run names a target that Cargo did not build, instead of falling back to another executable.
  • Ignore executable artifacts from other packages, including binary/build-tool dependencies.
  • Isolated the rustc-codegen backend build from the application target directory by forcing the backend build to its own local target dir.

Added regression coverage for each requested case:

  • virtual workspace default member + package default-run
  • requested --bin target not built
  • default-run target not built
  • executable artifacts from another package
  • backend build isolation from CARGO_TARGET_DIR

Validation:

cargo fmt --check
cargo test -p cargo-oxide
cargo clippy -p cargo-oxide -- -D warnings
git diff --check origin/main..HEAD

@nihalpasham

Copy link
Copy Markdown
Collaborator

The update version looks good. I added a quick follow-up for a few workspace and host-target edge cases we found during adversarial testing. The final branch now follows cargo's

  • selected packages and emitted artifacts, rejects missing or ambiguous targets, and obtains the backend from Cargo's exact host build output.

@nihalpasham
nihalpasham merged commit 932183a into NVIDIA:main Jul 4, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup cargo-oxide The `cargo oxide` subcommand and build automation documentation Improvements or additions to documentation QoL-improvement Quality-of-life improvement; not a correctness fix tests Adds or improves test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants