rust-lang / rust-lang/cargo

Allow building helper binaries for tests

Open
#4,356 4 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-cargo-targets C-enhancement Command-test S-needs-design
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

I've written a few crates that do process manipulation, and when writing tests I find myself needing a helper binary to run and manipulate. Three quick examples are read-process-memory, spawn-ptrace, and spawn-task-port.

I currently just put those helper binaries in src/bin so they get built as programs, but they're not intended for end-user consumption and don't need to be built except for test usage. It would be nicer if cargo had a way to build helper binaries for tests, like perhaps .rs files under tests/bin could be treated as such? Helper binaries should be considered a dependency of running tests, so they should be rebuilt as necessary before tests are run, but could be built in parallel with the tests themselves.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing helper-binary examples in src/bin/test.rs from read-process-memory, spawn-ptrace, and rust-spawn-task-port. Determine how Cargo could discover and build test-only binaries, including rebuilding them before tests and allowing parallel execution; done means this workflow is supported without treating helpers as end-user binaries.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.