Crates.io | crp |
lib.rs | crp |
version | 0.2.2 |
created_at | 2025-09-14 12:21:01.66048+00 |
updated_at | 2025-09-15 17:15:20.935089+00 |
description | Utility to shorten and streamline workspace member execution |
homepage | |
repository | https://codeberg.org/petervaro/crp |
max_upload_size | |
id | 1838682 |
size | 48,017 |
crp
In a large Cargo workspace a lot of automation is likely to be expressed in the
form of Rust scripts. Some of the great advantages of this is that these are
written in the same language as the rest of the code base, can reuse any
entities of it, and work particularly well across multiple operating systems and
architectures. The downside is that they need to be compiled on each invocation
from scratch to make sure the executed program is the latest—or at least
checked whether anything has changed in it or its dependencies. Thus, these are
invoked with cargo run
, explicitly specifying the package to be executed and
all of its arguments passed down.
That might require a lot of typing and longer commands than necessary. And that
is precisely what crp
solves, it shortens the command and makes it more
convenient to use and to remember.
crp
takes the first argument and passes that down to a cargo run
invocation
as the --package
. The rest of the arguments are passed down as options to the
running package itself.
# This `crp` invocation:
$ crp <package> <arguments>...
# Is the same as:
$ cargo run --package <package> -- <arguments>...
The simplest and most flexible way to install crp
is with cargo
:
$ cargo install crp
N.B. Installing
crp
like this leads to the leanest and fastest execution, however, further configuration options are available at build time which alter its behaviour. These are detailed in the following sections.
If there's a common prefix and/or suffix in your project(s), crp
can take care
of adding those before or after the passed down package name, allowing further
shortening of the command. This can be particularly useful when combined with
per directory customisation with the likes of direnv
.
To enable any of these abilities, crp
should be compiled with specific
features as listed below:
Feature | Environment Variables | Functionality |
---|---|---|
prefix-handling |
CRP_PACKAGE_PREFIX |
Prefix to be added before the package name |
suffix-handling |
CRP_PACKAGE_SUFFIX |
Suffix to be added after the package name |
$ cargo install crp --features prefix-handling,suffix-handling
In an imaginary workspace where all tasks are prefixed with script-
, the
fictional script-upload
task can be invoked as such:
$ export CRP_PACKAGE_PREFIX='script-'
# This `crp` invocation:
$ crp upload --timeout 10s
# Is the same as:
$ cargo run --package script-upload -- --timeout 10s
When crp
installed with any of the affix handling enabled, it is capable of
handling an optional short flag, -e
(stands for 'without environment'), which
allows ignoring the CRP_*
environment variables.
In an imaginary workspace where both download
and download-task
crates are
available the following invocations can be made:
export CRP_PACKAGE_SUFFIX='-task'
# This `crp` invocation:
$ crp download --url https://example.com
# Is the same as:
$ cargo run --package download-task -- --url https://example.com
# And this `crp` invocation:
$ crp -e download --url https://example.com
# Is the same as:
$ cargo run --package download -- --url https://example.com
crp
?c
argo r
un p
ackage, which is (somewhat) self-explanatory.cargo-xtask
: It is not an extension to Cargo, but a pattern. As
such, it has the advantage that no installation is required, it works out of
the box with cargo
. In a way, crp
is an additional layer to xtask
, but
instead of cargo xtask
the invocation becomes crp xtask
and therefore no
extra aliasing is required.
That being said, the two has different purposes, xtask
unifies the task
execution into a single entry-point, whereas crp
simplifies the invocation
of running a particular package of a workspace, therefore, the two are not
mutually exclusive, nor they are alternatives to one another.
Copyright ©2025 Peter Varo
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses.