Files
kucherenko__jscpd/rust/README.md
apk afea9b1cc6 feat(release): publish jscpd platform wheels to PyPI
Closes #1037.

Adds rust/scripts/build-pypi-wheels.py, which repacks the eight
jscpd-<platform>.tar.gz release tarballs into platform wheels: the same
binary under <pkg>.data/scripts/ as both `jscpd` and `cpd`, one wheel
per target, stdlib only, no maturin and no recompilation. glibc wheels
take their manylinux floor from the GLIBC_x.y symbols in the binary
(manylinux_2_34 today), musl builds are static so they tag as
musllinux_1_2, macOS and Windows use the Rust minimums. Semver
pre-releases map to PEP 440 (5.3.0-beta.1 -> 5.3.0b1); other labels
fail rather than guess.

release.yml gains a rust-publish-pypi job after the npm publish: it
takes the binary artifacts from this run, refills any missing target
from the published npm platform package (resumed releases, or a version
already on npm), builds the wheels, pip-installs the matching one and
checks `jscpd --version` and `cpd --version`, then uploads with PyPI
trusted publishing (environment `pypi`, no token, skip-existing). The
detect job treats a version missing from PyPI as pending, so the wheels
for the current release publish on the next push to master without a
new release commit. The GitHub release lists the PyPI package and waits
on the upload the same way it waits on crates.io and npm.

Docs: PyPI in the README install table and packages table, rust/README
and docs/rust.md install sections, and a `language: python` pre-commit
option in docs/ci-and-hooks.md so the hook no longer needs Node.js.

Claude-Session: https://claude.ai/code/session_01WztdFKZAwW9b51iJe9zhtV
2026-09-10 13:56:08 +02:00

5.3 KiB

jscpd — Rust engine

Copy/paste detector for programming source code. A self-contained binary that finds duplicated blocks across 224 language formats, writes reports in 15 formats and can fail CI when duplication grows.

Published as jscpd on npm (installs the jscpd command), cpd on npm (installs the cpd command), and jscpd on crates.io (installs both). Full documentation: jscpd.dev and docs/rust.md.

Install

npm

# installs the jscpd command
npm install -g jscpd

# installs only the cpd command
npm install -g cpd

Prebuilt binaries for 8 platforms (macOS arm64/x64, Linux arm64/x64 with glibc or musl, Windows arm64/x64) — no Node.js runtime required.

crates.io

cargo install jscpd
# or, without compiling (prebuilt release binaries via cargo-binstall):
cargo binstall jscpd

Installs both jscpd and cpd binaries.

PyPI

Platform wheels carrying the same prebuilt binary, for Python toolchains and pre-commit hooks that should not need Node.js:

pip install jscpd          # or: pipx install jscpd / uv tool install jscpd
uvx jscpd /path/to/code    # run without installing

Installs both jscpd and cpd commands.

Nix

# Run without installing
nix run github:kucherenko/jscpd -- /path/to/code

# Install permanently
nix profile install github:kucherenko/jscpd

Homebrew

brew install jscpd

From source

git clone https://github.com/kucherenko/jscpd.git
cd jscpd/rust
cargo build --release
# binaries at target/release/jscpd and target/release/cpd

Quick Start

jscpd .
jscpd ./src ./lib
jscpd . --blame --reporters console-full
jscpd . --reporters json,html
jscpd . --threshold 10
jscpd --baseline-from-ref origin/main --fail-on-new-clones .
jscpd --mcp .
jscpd --list

Architecture

jscpd/cpd (CLI binary)
 ├── cpd-core      — Detection algorithm (Rabin-Karp rolling hash)
 ├── cpd-tokenizer — Language tokenization (224 formats)
 ├── cpd-finder    — File walking, orchestration, baseline, git blame
 └── cpd-reporter  — Output formatting (15 reporters)
Crate Purpose
jscpd CLI binary and entry point (crates/cpd)
cpd-core Detection algorithm, rolling hash, models
cpd-tokenizer Language tokenization (224 formats); pure, no I/O
cpd-finder File walking, orchestration, git blame
cpd-reporter Output formatting (15 reporters)

Current versions are in each crate's Cargo.toml; scripts/sync-version.mjs keeps them and the npm packages in step. The workspace layout, npm launcher packages and platform packages are described in docs/packages.md.

Programmatic Usage (Rust)

use cpd_finder::orchestrate::{RunConfig, run};

let config = RunConfig {
    paths: vec!["./src".into()],
    min_tokens: 50,
    ..Default::default()
};

let result = run(&config).unwrap();
println!("Found {} clones", result.clones.len());
println!("Analyzed {} files", result.statistics.total.sources);

See docs/api.md and examples/rust-cpd-finder.

Building and testing

Requires Rust 1.96+ (the MSRV declared in Cargo.toml, enforced by the msrv job in CI). Development uses the exact toolchain pinned in rust-toolchain.toml.

cargo build --release
cargo nextest run --workspace        # or: cargo test --workspace
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --all --check

# End-to-end run over the multi-format corpus (what CI's smoke job does)
./target/release/jscpd ../fixtures --reporters console,json --output ../smoke-report --min-tokens 50

After changing the format table in crates/cpd-tokenizer/src/formats.rs, regenerate the root FORMATS.md with node scripts/gen-formats-md.mjs.

Benchmarks

Compared against other copy/paste detectors (jscpd-rs, Duplo, Fallow, Simian, PMD CPD) on the repository's fixtures/ corpus — timing, detection counts, cross-format detection and AI-token efficiency — in benchmark/BENCHMARK.md. Re-run with benchmark/benchmark.sh.

Documentation

Coming from jscpd v4?

The CLI flags, .jscpd.json config and reporters are the same; see the migration table for the few differences. jscpd v4 (TypeScript engine, Node.js API, LevelDB/Redis stores) is maintained on the master-v4 branch and published as jscpd@4.

License

MIT