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;
pub use transpiler::Transpiler;

Modules§

ast
Abstract syntax tree types and validation
bash_parser
Bash script parsing and AST generation Bash-to-Rash Parser Module
bash_quality
Bash quality tools (test generation, coverage, formatting, scoring) Bash Quality Tools
bash_transpiler
Bash script transpilation and purification Bash-to-Rash Transpiler
build_rs
build.rs integration with auto-discovery
cli
Command-line interface for bashrs
compiler
Rust compiler integration for transpilation Compiler module for bashrs
config
Shell configuration file management and analysis Shell configuration file management
container
Container and sandbox support
emitter
Shell script code emission
formal
Formal verification and proof generation Formal verification module for the rash emitter
formatter
Shell script formatting Pre-flight Formatter Implementation
ir
Intermediate representation for transpilation Intermediate Representation (IR) module
linter
Shell script linting with ShellCheck-equivalent rules bashrs Native Linter
make_parser
Makefile parsing and purification
models
Configuration types and error handling
repl
Interactive REPL with integrated debugger
services
Parser and compiler services
stdlib
Standard library function mappings
test_generator
Test case generation from shell scripts Test Generation Module
tracing
Tracing infrastructure for diagnostics and debugging
transpiler
Builder API for programmatic transpilation
types
Type system with taint tracking for injection safety Type system for bashrs
validation
AST and output validation
verifier
Output verification and shellcheck integration

Functions§

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