cargo-cp-artifact

raw JSON →
0.1.9 verified Fri May 01 auth: no javascript maintenance

Small CLI utility for copying Rust compiler artifacts (binaries, cdylibs, dylibs) produced by cargo to a specified output file. Current stable version 0.1.9, released as part of the Neon bindings ecosystem. Parses cargo's JSON metadata output (via --message-format=json) to reliably locate artifacts regardless of build profile or target. Differentiators: works with npm script integration via --npm flag, supports multiple artifact mappings, and wraps arbitrary commands as a child process. Not actively maintained; last release in 2023.

error Error: No matching artifacts found for pattern
cause Crate name or artifact kind does not match any artifact emitted by cargo.
fix
Verify crate name in Cargo.toml and artifact kind (cdylib, bin, etc.). Use cargo build --release --message-format=json to see available artifacts.
error Error: The argument '--artifact' requires 3 arguments but only 2 were provided
cause Missing the third argument (output file) for --artifact.
fix
Provide three values: artifact-kind crate-name output-file, e.g., --artifact cdylib my-crate lib/index.node
error Error: unknown artifact kind 'staticlib'
cause Unsupported artifact kind specified.
fix
Use one of: bin, cdylib, dylib (or abbreviations b, c, d).
gotcha The -- separator is required between cargo-cp-artifact arguments and the wrapped command. Omitting it causes unexpected behavior.
fix Use -- before the wrapped command, e.g., cargo-cp-artifact -a cdylib my-crate lib/index.node -- cargo build --message-format=json-render-diagnostics
gotcha Artifact kind must match exactly: 'bin', 'cdylib', or 'dylib'. Alternatives like 'staticlib' will not be recognized.
fix Use only 'bin', 'cdylib', or 'dylib' (or abbreviations 'b', 'c', 'd').
gotcha The crate name must match the Cargo.toml package name, not the directory name or the package name with hyphens. Hyphens in Cargo names are automatically converted to underscores in artifact names.
fix Use the exact Cargo.toml [package] name. For npm integration, ensure npm_package_name matches or use --npm flag with proper env variable.
npm install cargo-cp-artifact
yarn add cargo-cp-artifact
pnpm add cargo-cp-artifact

Installs cargo-cp-artifact globally and uses it to copy a Rust cdylib to a .node file after building with cargo.

npm install -g cargo-cp-artifact

# In a Rust project that produces a cdylib named 'my_crate'
mkdir -p lib
cargo-cp-artifact -a cdylib my_crate lib/index.node -- cargo build --release --message-format=json-render-diagnostics

# Verify artifact was copied
ls -la lib/index.node