Skip to content

feat: add Cargo/Rust crate patching support behind feature flag#31

Merged
mikolalysenko merged 1 commit intomainfrom
feat/cargo-ecosystem-support
Mar 4, 2026
Merged

feat: add Cargo/Rust crate patching support behind feature flag#31
mikolalysenko merged 1 commit intomainfrom
feat/cargo-ecosystem-support

Conversation

@mikolalysenko
Copy link
Contributor

Summary

  • Adds Cargo/Rust ecosystem support behind a cargo feature flag, enabling patching of crates in $CARGO_HOME/registry/src/ and vendor/ directories
  • Refactors duplicated ecosystem dispatch logic across 4 CLI commands (apply, rollback, scan, get) into a centralized ecosystem_dispatch module, reducing ~190 lines of boilerplate
  • Introduces an Ecosystem enum that replaces string-based ecosystem identification, making future ecosystem additions mechanical

Key changes

Core (socket-patch-core):

  • Ecosystem enum in crawlers/types.rs with from_purl(), cli_name(), display_name(), purl_prefix(), all()
  • CargoCrawler in crawlers/cargo_crawler.rs — supports registry layout (<name>-<version>/) and vendor layout (<name>/), with line-based Cargo.toml parser and directory-name fallback for version.workspace = true
  • Cargo PURL functions in utils/purl.rs (is_cargo_purl, parse_cargo_purl, build_cargo_purl)

CLI (socket-patch-cli):

  • ecosystem_dispatch.rspartition_purls(), find_packages_for_purls(), find_packages_for_rollback(), crawl_all_ecosystems()
  • All 4 commands refactored to use dispatch helpers instead of manual per-ecosystem code

Feature flag: --features cargo on both crates; without it, all existing behavior is unchanged.

Test plan

  • cargo test --workspace — 233 tests pass (no regressions, no feature flag)
  • cargo test --workspace --features cargo — 253 tests pass (20 new cargo-specific tests)
  • cargo build --release — clean build without feature
  • cargo build --release --features cargo — clean build with feature
  • e2e tests verify scan discovers crates in both registry and vendor layouts
  • CI should run both cargo test --workspace and cargo test --workspace --features cargo

🤖 Generated with Claude Code

Introduces Cargo ecosystem support gated behind a `cargo` feature flag,
and refactors the duplicated ecosystem dispatch logic across CLI commands
into a centralized module.

- Add `Ecosystem` enum to replace string-based ecosystem dispatch
- Add `CargoCrawler` supporting registry and vendor layouts
- Add `ecosystem_dispatch.rs` with shared partition/crawl helpers
- Refactor apply, rollback, scan, get commands to use dispatch helpers
- Add cargo PURL functions (parse, build, is_cargo_purl)
- Add 20 new tests (253 total with feature, 233 without)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mikolalysenko mikolalysenko merged commit a2b946c into main Mar 4, 2026
5 of 7 checks passed
@mikolalysenko mikolalysenko deleted the feat/cargo-ecosystem-support branch March 4, 2026 21:03
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.

1 participant