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.
Common errors
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).
Warnings
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.
Install
npm install cargo-cp-artifact yarn add cargo-cp-artifact pnpm add cargo-cp-artifact Imports
- cli tool wrong
npm install cargo-cp-artifact (local install)correctnpm install -g cargo-cp-artifact - npx usage wrong
npx cargo-cp-artifact -a cdylib my-crate lib/index.node cargo build (missing -- separator)correctnpx cargo-cp-artifact -a cdylib my-crate lib/index.node -- cargo build --message-format=json-render-diagnostics - npm script usage wrong
"build": "cargo-cp-artifact -a cdylib %npm_package_name% lib/index.node -- cargo build"correct"build": "cargo-cp-artifact -nc lib/index.node -- cargo build --message-format=json-render-diagnostics"
Quickstart
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