fix: Support cargo build --tests by skipping test artifacts#239
Open
jssblck wants to merge 15 commits into
Open
fix: Support cargo build --tests by skipping test artifacts#239jssblck wants to merge 15 commits into
jssblck wants to merge 15 commits into
Conversation
Co-authored-by: Jessica Black <jess@attunehq.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash when running hurry cargo build --tests by adding support for test artifacts in the build plan processing logic. The fix treats test binaries as first-party code (similar to regular binaries) and skips them during caching operations, while still processing their third-party dependencies.
Key changes:
- Extended the skip condition in
workspace.rsto handleTargetKind::Testartifacts alongsideTargetKind::Bin - Updated the associated comment to reflect that both binaries and tests are first-party code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #196.
This PR fixes a crash when running
hurry cargo build --testsby explicitly handling and skippingTargetKind::Testartifacts in the build plan.Context
The crash occurred because
hurryencountered an unhandledTargetKind::Testwhen analyzing the build plan. These artifacts represent the final test binaries (first-party code), which we do not want to cache.By simply skipping these test artifacts (treating them like
TargetKind::Bin), we allowhurryto proceed and correctly process and cache the third-party dependencies that these tests rely on.Validation
We confirmed that dependencies appear as separate
TargetKind::Libinvocations in the build plan, while the test binary itself isTargetKind::Test.Build Plan Snippet:
(Generated with
RUSTC_BOOTSTRAP=1 cargo build --tests --build-plan -Z unstable-options){ "package_name": "serde", "target_kind": ["lib"] }, { "package_name": "hurry", "target_kind": ["test"] }Data Flow
The following diagram demonstrates how
hurryprocesses the build plan, skipping the test binary but capturing its dependencies:graph TD subgraph Cargo["Cargo Build Plan Generation"] A["Run: cargo build --tests --build-plan"] --> B{Build Plan Invocations} B --> C["Invocation 1: serde (Lib)"] B --> D["Invocation 2: tokio (Lib)"] B --> E["Invocation 3: my-app (Test Binary)"] end subgraph Hurry["Hurry Processing Loop (workspace.rs)"] F[Start Loop over Invocations] --> G{Check TargetKind} G -- "TargetKind::Lib / RLib" --> H[Process Dependency] H --> I[Create UnitPlan] I --> J[Cache/Restore Enabled] G -- "TargetKind::Bin" --> K["Skip (First-Party)"] K --> L[Continue Loop] G -- "TargetKind::Test" --> M["Skip (First-Party)"] M --> N[Continue Loop] G -- "Other" --> O["Error / Handle"] end C --> G D --> G E --> G style J fill:#bbf,stroke:#333,stroke-width:2px style M fill:#bfb,stroke:#333,stroke-width:2px style K fill:#bfb,stroke:#333,stroke-width:2pxAreas of Interest
packages/hurry/src/cargo/workspace.rs- AddedTargetKind::Testto the skip condition in theunits()method. This ensures test binaries are treated as first-party code (likeTargetKind::Bin) and ignored, preventing the "unsupported target kind" error.Testing
hurry cargo build --tests --hurry-skip-restore(or with valid credentials) to verify that the build completes successfully without crashing.Verification Output
$ cargo run --bin hurry -- cargo build --hurry-skip-restore --tests ... Finished `dev` profile [unoptimized + debuginfo] target(s) in 5.44s Exit code: 0Code Map
packages/hurry/src/cargo/workspace.rs:511- Updatedunits()to skipTargetKind::Test.🤖 Generated with Antigravity