# ๐ ๏ธ Rust Project Utility Scripts
This directory contains cross-platform **developer utility scripts** shared across all Rust projects.
They provide unified build checks, quality assurance, and resource verification tools.
> ๐ฆ Intended for use as a private Git submodule, e.g.:
>
> ```bash
> git submodule add git@github.com:umpire274/rust_dev_scripts.git dev_tools
> ```
---
## ๐ Adding This Repository as a Git Submodule
This utility toolkit is intended to be embedded inside other Rust projects as a **Git submodule**, typically under a
folder such as `dev_tools/`.
Follow the steps below to correctly add, initialize, update, or remove this submodule.
### โ Add the submodule to your project
From the root of your target repository:
```bash
git submodule add git@github.com:umpire274/rust_dev_scripts.git dev_tools
git submodule update --init --recursive
```
or using HTTPS:
```bash
git submodule add https://github.com/umpire274/rust_dev_scripts.git dev_tools
git submodule update --init --recursive
```
This will:
* Create the `dev_tools/` directory
* Register the submodule in `.gitmodules`
* Check out the latest commit of the shared scripts
Then commit the changes:
```bash
git add .gitmodules dev_tools/
git commit -m "Add rust_dev_scripts submodule under dev_tools/"
git push
```
---
### ๐ Initialize or update the submodule
When cloning a repository that already contains this submodule:
```bash
git submodule update --init --recursive
```
To update the submodule to the commit recorded in the main repository:
```bash
git submodule update --recursive
```
To update the submodule to the latest commit on its default branch:
```bash
git submodule update --remote --merge
```
---
### โฌ๏ธ Pulling the latest version of the submodule
If you want your main project to use the latest commit of `rust_dev_scripts`:
```bash
cd dev_tools
git pull origin main
cd ..
git add dev_tools
git commit -m "Update dev_tools submodule"
git push
```
---
### ๐๏ธ Removing the submodule (clean removal)
To fully remove the submodule from your project:
```bash
git submodule deinit -f dev_tools
git rm -f dev_tools
rm -rf .git/modules/dev_tools
git commit -m "Remove dev_tools submodule"
git push
```
---
## ๐ Recommended Folder Structure
```
your_project/
โโ src/
โโ target/
โโ dev_tools/
โ โโ scripts/
โ โโ build_check.ps1
โ โโ build_check.sh
โ โโ check_icon.ps1
โ โโ check_icon.sh
โ โโ generate_ico.ps1
โ โโ generate_ico.sh
โ โโ generate_icons.ps1
โ โโ generate_icons.sh
โ โโ magick_tools.ps1
โ โโ magick_tools.sh
โโ .gitmodules
```
---
## ๐ง Tip
Always use the shared build-check pipeline before pushing changes:
```bash
./dev_tools/scripts/build_check.sh --release
```
or on Windows:
```powershell
.\dev_tools\scripts\build_check.ps1 --release
```
---
# ๐ Available Scripts
| **build_check.ps1** | Windows (PowerShell) | Full build + QA pipeline for Rust projects |
| **build_check.sh** | Linux / macOS | Full build + QA pipeline (POSIX-compliant) |
| **check_icon.ps1** | Windows | Verifies if an `.exe` file contains embedded icon resources |
| **check_icon.sh** | Linux / macOS | Checks embedded icons in ELF or Mach-O binaries |
| **generate_icons.ps1** | Windows | Generates multi-resolution PNG icons (16 โ 1024 px) |
| **generate_icons.sh** | Linux / macOS | Same functionality as the PowerShell version |
| **generate_ico.ps1** | Windows | Builds multi-layer `.ico` files from PNG sources |
| **generate_ico.sh** | Linux / macOS | POSIX version of the ICO generator |
| **magick_tools.ps1** | Windows | ImageMagick wrapper for common operations |
| **magick_tools.sh** | Linux / macOS | POSIX version of the ImageMagick wrapper |
---
# ๐ Build Pipeline Scripts (`build_check.*`)
These scripts execute a standardized series of Rust project quality checks:
| ๐งน **cargo clean** | Cleans previous build artifacts (optional) |
| ๐๏ธ **cargo build** | Builds the project in debug or release mode |
| โจ **cargo fmt (auto-fix)** | Runs `cargo fmt --check`; auto-fixes formatting and re-checks |
| ๐ **cargo clippy** | Lints the code; warnings are treated as errors |
| ๐งช **cargo test** | Runs all tests (optional) |
---
## โจ Auto-Fix Formatting
Both build scripts now include enhanced formatting logic:
### ๐ Automatic correction flow
1. Run `cargo fmt --all -- --check`
2. If formatting is correct โ continue
3. If formatting fails โ automatically run `cargo fmt --all`
4. Run the check again
5. If formatting is still incorrect โ pipeline stops with an error
### โ๏ธ Advantages
* Ensures consistent formatting across all repos
* Prevents CI failures due to trivial fmt issues
* Reduces friction for contributors
* Keeps code review clean and standardized
---
## ๐ Common CLI Options
| `--release` | Build and test in release mode |
| `--skip-tests` | Skip running the test suite |
| `--quiet` | Suppress detailed command output |
| `--verbose` | Enable verbose Cargo logging (-vv) |
| `--no-clean` | Skip the initial clean step |
| `--only-build` | Build the project and skip QA steps |
| `--time` | Display total pipeline execution time |
| `--target` | Compile for a custom Rust target triple |
---
## ๐งช Examples
### ๐ช Windows (PowerShell)
```powershell
# Full pipeline
.\build_check.ps1
# Release mode, no clean, skip tests
.\build_check.ps1 --release --skip-tests --no-clean
```
### ๐ง Linux / macOS
```bash
./build_check.sh
./build_check.sh --release --skip-tests --no-clean --quiet
```
---
## ๐ข Exit Codes
| 0 | All steps completed successfully |
| 1 | At least one step failed |
**Note:** The formatting step now performs **automatic fixing**.
It only fails if the code remains incorrectly formatted *after* the auto-fix procedure.
---
# ๐ผ๏ธ Icon Verification Scripts (`check_icon.*`)
These scripts verify whether a compiled binary includes embedded icon resources.
| check_icon.ps1 | Checks Windows `.exe` metadata for embedded icons |
| check_icon.sh | Uses `file`, `otool`, or `rcedit` to inspect ELF/Mach-O binaries |
---
# ๐๏ธ ICO Multi-Size Generator (`generate_ico.*`)
Cross-platform scripts for creating Windows `.ico` files with multiple resolutions.
Options and usage examples are identical across platforms (POSIX / PowerShell).
---
# ๐ผ๏ธ PNG Multi-Size Icon Generator (`generate_icons.*