herolib_rust/README.md
2025-08-06 03:27:49 +02:00

4.3 KiB
Raw Permalink Blame History

Herocode Herolib Rust Repository

Overview

This repository contains the Herocode Herolib Rust library and a collection of scripts, examples, and utilities for building, testing, and publishing the SAL (System Abstraction Layer) crates. The repository includes:

  • Rust crates for various system components (e.g., os, process, text, git, vault, kubernetes, etc.).
  • Rhai scripts and test suites for each crate.
  • Utility scripts to automate common development tasks.

Scripts

The repository provides three primary helper scripts located in the repository root:

Script Description Typical Usage
scripts/publish-all.sh Publishes all SAL crates to crates.io in the correct dependency order. Handles version bumping, dependency updates, dryrun mode, and ratelimiting. ./scripts/publish-all.sh [--dry-run] [--wait <seconds>] [--version <ver>]
build_herodo.sh Builds the herodo binary from the herodo package and optionally runs a specified Rhai script. ./build_herodo.sh [script_name]
run_rhai_tests.sh Executes all Rhai test suites across the repository, logging results and providing a summary. ./run_rhai_tests.sh

Below are detailed usage instructions for each script.


1. scripts/publish-all.sh

Purpose

  • Publishes each SAL crate in the correct dependency order.
  • Updates crate versions (if --version is supplied).
  • Updates path dependencies to version dependencies before publishing.
  • Supports dryrun mode to preview actions without publishing.
  • Handles ratelimiting between crate publishes.

Options

Option Description
--dry-run Shows what would be published without actually publishing.
--wait <seconds> Wait time between publishes (default: 15s).
--version <ver> Set a new version for all crates (updates Cargo.toml files).
-h, --help Show help message.

Example Usage

# Dry run  no crates will be published
./scripts/publish-all.sh --dry-run

# Publish with a custom wait time and version bump
./scripts/publish-all.sh --wait 30 --version 1.2.3

# Normal publish (no dryrun)
./scripts/publish-all.sh

Notes

  • Must be run from the repository root (where Cargo.toml lives).
  • Requires cargo and a loggedin cargo session (cargo login).
  • The script automatically updates dependencies in each crates Cargo.toml to use the new version before publishing.

2. build_herodo.sh

Purpose

  • Builds the herodo binary from the herodo package.
  • Copies the binary to a systemwide location (/usr/local/bin) if run as root, otherwise to ~/hero/bin.
  • Optionally runs a specified Rhai script after building.

Usage

# Build only
./build_herodo.sh

# Build and run a specific Rhai script (e.g., `example`):
./build_herodo.sh example

Details

  • The script changes to its own directory, builds the herodo crate (cargo build), and copies the binary.
  • If a script name is provided, it looks for the script in:
    • src/rhaiexamples/<name>.rhai
    • src/herodo/scripts/<name>.rhai
  • If the script is not found, the script exits with an error.

3. run_rhai_tests.sh

Purpose

  • Runs all Rhai test suites across the repository.
  • Supports both the legacy rhai_tests directory and the newer */tests/rhai layout.
  • Logs output to run_rhai_tests.log and prints a summary.

Usage

# Run all tests
./run_rhai_tests.sh

Output

  • Colored console output for readability.
  • Log file (run_rhai_tests.log) contains full output for later review.
  • Summary includes total modules, passed, and failed counts.
  • Exit code 0 if all tests pass, 1 otherwise.

General Development Workflow

  1. Build: Use build_herodo.sh to compile the herodo binary.
  2. Test: Run run_rhai_tests.sh to ensure all Rhai scripts pass.
  3. Publish: When ready to release, use scripts/publish-all.sh (with --dry-run first to verify).

Prerequisites

  • Rust toolchain (cargo, rustc) installed.
  • Rhai interpreter (herodo) built and available.
  • Git for version control.
  • Cargo login for publishing to crates.io.

License

See LICENSE for details.


Happy coding!