Fix cargo bench deadlock by isolating build script target directories#4
Merged
Fix cargo bench deadlock by isolating build script target directories#4
Conversation
- Eliminate file lock contention by using isolated temp directories - Extract shared build logic to prevent duplication (~200 lines) - Add aggressive error handling with clear failure diagnostics - Use CARGO_TARGET_DIR isolation instead of shared target/ directory - Fix .so file paths to use correct sbf-solana-solana/release location - Add cu_bench feature scaffolding for compute unit benchmarking - Consolidate build_anchor_program and build_pinocchio_program logic This resolves indefinite hanging in `cargo bench` caused by flock contention between main cargo process and build script subprocesses. The refactored build system is more robust, maintainable, and enables reliable benchmarking for compute unit measurement workflows.
- Move build_solana_program_internal from lib.rs to build_internal.rs - Add cargo clean step before building to ensure fresh artifacts - Update function calls in anchor and pinocchio modules to use new path - Gate build_internal module with appropriate feature flags - Remove redundant documentation reference in anchor build function - Improve file extension checking with is_some_and for clarity This refactoring improves code organization by separating build utilities from the main library interface while enhancing build reliability.
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.
Perfect branch name! Here's a PR title and description:
PR Title:
PR Description:
Problem
cargo benchwas hanging indefinitely during compilation, blocking development of compute unit benchmarking workflows. The issue manifested as a silent hang with no error output, making it difficult to diagnose.Root Cause
Through process sampling and system call tracing, we discovered the hang was caused by file lock (
flock) contention:target/directorycargo build-sbfsubprocessestarget/structureSolution
Isolated Build Directories: Use
CARGO_TARGET_DIRenvironment variable to build programs in isolated temp directories, preventing lock contention entirely.Refactored Build Logic: Extracted ~200 lines of duplicated code into a shared
build_solana_program_internal()helper that handles:OUT_DIRparsingKey Changes:
CARGO_TARGET_DIR/target/string splitting fromOUT_DIRsbf-solana-solana/release/locationImpact
✅ Eliminates cargo bench deadlock - Builds complete reliably without hanging
✅ Enables compute unit benchmarking - Unblocks CU measurement and optimization workflows
✅ Improved maintainability - Consolidated build logic, easier to debug and extend
✅ Better error handling - Clear diagnostics instead of mysterious
include_bytes!failuresTesting
cargo build --workspacecompletes successfullycargo bench cu_bench_spl_transfer --features cu_benchruns without hangingThis change provides a solid foundation for building intelligent transaction composition tools based on reliable compute unit measurements.