#cargo #script #cargo-toml #cargo-build #make #building #rssc

yanked cargo-rssc

rssc - Rust scripts for crates building

0.3.42 Aug 12, 2021
0.3.41 Aug 12, 2021

#21 in #make

MIT license

23KB
401 lines

cargo-rssc

cargo rssc - Rust scripts for crates building

Try it

Inside your main rust project directory (the one with Cargo.toml) run:

cargo install cargo-rssc
cargo rssc new

Open in new editor the new directory scripts_rssc in your main rust project and view/edit the rust code of the helper rust project.
Then try in the main rust project:

cargo rssc build
cargo rssc release
cargo rssc docs

Motivation

Cargo is a great tool for building rust projects. It has all the basics: cargo build, cargo build --release, cargo fmt, cargo test, cargo doc,...
But sometimes we need to do more things like copying some files, publish to ftp or enter long commands. These are tasks that must be automated.
There are many different build systems and task runners there: make, cmake, shell scripts, cargo-make, cargo-script, cargo-run-script, runner, python scripts, powershell scripts, cmd prompt scripts, ...
Sadly there is no standard in the rust community for now. I wanted something similar to build.rs, so I can write my "scripts" in pure rust. I don't want to learn another meta language with weird syntax and difficult to debug. So I will make something really simple, easy, rusty and extensible.

rssc - Rust scripts for crates building

Rust is a compiled language. It is not really a scripting or interpreted language. But the compilation of small projects is really fast and can be ignored. Subsequent calls will use the already built binary and so the speed will be even faster.

scripts_rssc helper project

In the root of the main rust project it will create a new directory scripts_rssc with a new helper rust project. It should not interfere with the main rust project. This folder will then go into git commits and pushed to remote repositories as part of the main project. It has its own .gitignore to avoid committing its target directory.
The scripts_rssc helper project contains user defined tasks in rust code. This helper project should be opened in a new editor starting from the scripts_rssc folder. It does not share dependencies with the main project. It is completely separate.

cargo rssc subcommand

The binary crate cargo-rssc is added to cargo as a new subcommand cargo rssc.
It reads the CLI arguments and runs the scripts_rssc binary with them. If needed it will compile scripts_rssc first.
The code-flow of the source code of cargo-rssc is simple, fully commented and straightforward to audit in this open-source crate.
After my first publish to crates.io I discovered that the position of the argument changes if it is used as:
cargo-rssc new - new is 1st arg
or
cargo rssc new - new is 2nd arg

templates

Inside the cargo-rssc project there are 2 folders with rust sub-projects as templates. I can open a new editor for these folders and build this crates indipendently. So it is easy to debug and develop. But I cannot publish these folders and files. I can publish only the source code inside the rust project.
Before publish I must copy the text of these files inside the modules template_basic and template_with_lib. It is not difficult now that rust has raw strings.

template_basic

The command

cargo rssc new

will copy the template_basic into scripts_rssc folder.
This has no dependencies and is really simple to understand how it works.
Explore it and add your own tasks or rust code.
Then in the main project run your task like:

cargo rssc build

Your code will be compiled and executed.

template_with_lib

This is a work in progress.
The goal is to create a cargo_rssc_lib with many functions that are commonly used when building rust projects.

cargo crev reviews and advisory

It is recommended to always use cargo-crev
to verify the trustworthiness of each of your dependencies.
Please, spread this info.
On the web use this url to read crate reviews. Example:
https://web.crev.dev/rust-reviews/crate/num-traits/

Dependencies

~200KB