Crate bashrs

Crate bashrs 

Source
Expand description

§Rash - Rust to Shell Transpiler

Rash is a Rust-to-POSIX shell script transpiler that generates safe, deterministic, and verifiable shell scripts from a restricted Rust subset.

§Features

  • POSIX Compliance: Generated scripts work on sh, dash, bash, and ash
  • Safety: Injection attack prevention, proper quoting, verified output
  • Determinism: Same input always produces identical output
  • ShellCheck Integration: All output passes shellcheck validation

§Quick Start

use bashrs::{transpile, Config};

let rust_code = r#"
    fn main() {
        let greeting = "Hello, World!";
        echo(greeting);
    }

    fn echo(msg: &str) {}
"#;

let shell_script = transpile(rust_code, Config::default()).unwrap();
assert!(shell_script.contains("#!/bin/sh"));

§Main Functions

  • transpile: Convert Rust code to shell script
  • check: Validate Rust code without generating output

§Configuration

use bashrs::{Config, transpile};
use bashrs::models::{ShellDialect, VerificationLevel};

let config = Config {
    target: ShellDialect::Posix,
    verify: VerificationLevel::Strict,
    optimize: true,
    ..Config::default()
};

let rust_code = "fn main() { let x = 42; }";
let result = transpile(rust_code, config);
assert!(result.is_ok());

Re-exports§

pub use models::Config;
pub use models::Error;
pub use models::Result;

Modules§

ast
Abstract Syntax Tree (AST) Module
bash_parser
Bash-to-Rash Parser Module
bash_quality
Bash Quality Tools
bash_transpiler
Bash-to-Rash Transpiler
cli
compiler
Compiler module for bashrs
config
Shell configuration file management
container
emitter
Shell Code Emitter Module
formal
Formal verification module for the rash emitter
formatter
Pre-flight Formatter Implementation
ir
Intermediate Representation (IR) module
linter
bashrs Native Linter
make_parser
Makefile Parser and Purification
models
repl
services
stdlib
This module provides support for stdlib functions that are transpiled to POSIX shell runtime functions.
test_generator
Test Generation Module
validation
verifier

Functions§

check
Check if the given Rust code is valid for transpilation without generating output.
transpile
Transpile Rust source code to POSIX shell script.