npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cargo-cp-artifact

v0.1.9

Published

Copies compiler artifacts emitted by rustc by parsing Cargo metadata

Downloads

977,325

Readme

cargo-cp-artifact

cargo-cp-artifact is a small command line utility for parsing cargo metadata output and copying a compiler artifact to a desired location.

Installation

npm install -g cargo-cp-artifact

Usage

cargo-cp-artifact --artifact artifact-kind crate-name output-file -- wrapped-command

cargo-cp-artifact accepts a list of crate name and artifact kind to output file mappings and a command to wrap.cargo-cp-artifact will read stdout of the wrapped command and parse it as cargo metadata. Compiler artifacts that match arguments provided will be copied to the target destination.

When wrapping a cargo command, it is necessary to include a json format to --message-format.

Arguments

Multiple arguments are allowed to copy multiple build artifacts.

--artifact

Alias: -a

Followed by three arguments: artifact-kind crate-name output-file

--npm

Alias: -n

Followed by two arguments: artifact-kind output-file

The crate name will be read from the npm_package_name environment variable. If the package name includes a namespace (@namespace/package), the namespace will be removed when matching the crate name (package).

Artifact Kind

Valid artifact kinds are bin, cdylib, and dylib. They may be abbreviated as b, c, and d respectively.

For example, -ac is the equivalent of --artifact cdylib.

Examples

Wrapping cargo

cargo-cp-artifact -a cdylib my-crate lib/index.node -- cargo build --message-format=json-render-diagnostics

Parsing a file

cargo-cp-artifact -a cdylib my-crate lib/index.node -- cat build-output.txt

npm script

package.json

{
    "name": "my-crate",
    "scripts": {
        "build": "cargo-cp-artifact -nc lib/index.node -- cargo build --message-format=json-render-diagnostics"
    }
}
npm run build

# Additional arguments may be passed
npm run build -- --feature=serde

Why does this exist?

At the time of writing, cargo does not include a configuration for outputting a library or binary to a specified location. An --out-dir option exists on nightly, but does not allow specifying the name of the file.

It's surprisingly difficult to reliably find the location of a cargo compiler artifact. It is impacted by many parameters, including:

  • Build profile
  • Target, default or specified
  • Crate name and name transforms

However, cargo can emit metadata on stdout while continuing to provide human readable diagnostics on stderr. The metadata may be parsed to more easily and reliably find the location of compiler artifacts.

cargo-cp-artifact chooses to wrap a command as a child process instead of reading stdin for two reasons:

  1. Removes the need for -o pipefile when integrating with build tooling which may need to be platform agnostic.
  2. Allows additional arguments to be provided when used in an npm script.