I am about to publish a small command-line utility and I separated the project into a library (someone can be interested in using it outside of the tool) and a small binary. I the language was C I would name the library "libabrdump" and the tool "abrdump" but I see that Rust avoids the "lib" prefix in libraries. An option would be to call the library "abrdump" and the application "abrdump-cli" but I'd like to be able to do:
$ cargo install abrdump
$ abrdump [options] ...
and that implies that the name for the executable crate should be "abrdump". Or am I missing something?
There is an "official" naming scheme for projects like this one?
If you want to make the tool available as a cargo subcommand, like 'cargo abrdump' , I think you have to name it 'cargo-abrdump' by convention. Because cargo discovers subcommands by looking for executables named cargo- in your $PATH.
No, I don't think making it a cargo subcommand is a good idea: it does not have anything to do with cargo or the Rust tooling ecosystem. I just want to be able to install it via cargo and invoke it using a short name ("abrdump").
If you follow the default layout of a Cargo project, you probably have a src/lib.rs file for your library and a src/main.rs file for your binary. The names of these two crates default to the package name (with dashes replaced by underscores for the library target). I wouldn't deviate from the default if you are unsure of what to do.
I am thinking about publishing. I'd like to have opinions about how to name the two crates (library and executable), with the constraint that I'd like to be able to invoke the binary with "abrdump" instead of something like "abrdump-cli" or "abrdump-tool".
Then the library crate will have to be published first as it is a dependency for the cli tool. You can use cargo search to check whether the name is available.
This shouldn't be needed if the crate name of the cli tool is 'abrdump' and the entry point is src/main.rs For naming the tool 'abrdump' and to be extra safe, you could add the following to the tools Cargo.toml, I am guessing you already have the path for the lib set up as you are successfully running it.
[[bin]]
name = "abrdump"
And there's literally the 'libc' crate out there (I get that it's just bindings but still) So I don't see why not name your library 'libabrdump' :'D
I don't think there is a default/official naming scheme for such a setup. You could however emulate the single-package binary + library crate default naming scheme, which is what I'd do, if I wouldn't want the -cli postfix in my binary. Say you have the package abrdump-cli with the binary and the abrdump package with the library. I'd rename the binary in the abrdump-cli package to abrdump. Users can then install it with cargo install abrdump-cli and use the abrdump command afterwards.
if you want to use a single package for both the library and binary, the cli tool can be conditional compiled (see required-features), and cli-only dependencies like clap can be optional. something like this: