cral

Crates.iocral
lib.rscral
version0.2.0
created_at2026-01-24 08:25:18.088269+00
updated_at2026-01-24 09:55:59.480136+00
descriptionC code gen.
homepage
repositoryhttps://github.com/ZJZCORE/cral/
max_upload_size
id2066399
size19,748
(ZJZCORE)

documentation

README

cral

This crate can generate c code from ASTs.

This crate's design and functionality inspired by the crustal crate.

Usage

This crate is publish to crates.io.

Add this crate to your project using Cargo:

cargo add cral

Alternatively, add the following to your Cargo.toml dependencies section:

[dependencies]
cral = "0.0.0" # Replace with actual version

Examples

Example 1 : HelloWorld

use cral::prelude::*;
let f = File::new([
    Decl::include("stdio.h", true),
    Decl::fn_decl(Type::void(), "main", [], Block::new([
        Stmt::Expr(Expr::call(
            Expr::name("printf"),
            [Expr::literal_str("HelloWorld")],
        ))
    ]))
]);
f.save("main.c").unwrap();

Generated main.c file content:

#include<stdio.h>
void main() {
    printf("HelloWorld");
}


Commit count: 3

cargo fmt