You _can_ put lipstick on a pig

Overview

lipstick 💄 🐷

You can put lipstick on a pig

What

lipstick compiles a subset of Rust's syntax into C. It's not a "Rust subset" though, since there's not borrow checker or lifetimes. It's simply a Rust-like syntax frontend for C.

Check it out in action in the playground.

Why

Because it's fun, duh.

Also, it might be a good teaching tool, so you can temporarily "turn off" the borrow checker. You can see how writing in unsafe system languages looks like, without actually having any C or C++ knowledge.

Usage

lipstick 0.3.0
Lipstick for C

Compile Rust-like syntax into C code

USAGE:
    lipstick [FLAGS] [OPTIONS] <INPUT> [-- <COMPILER FLAGS>...]

FLAGS:
    -C, --cc         Compile the output of lipstick by calling your C compiler
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -Z <FEATURE>                 Debugging flags [possible values: syn]
        --compiler <COMPILER>    Specifies which C compiler to invoke [default: cc]
    -o, --out <OUT>              The file to write the output to ("-" for stdout) [default: <INPUT>.c]

ARGS:
    <INPUT>                The file to be compiled to C
    <COMPILER FLAGS>...    Flags for the `cc` compiler

Example

Input

fn foo() -> &u32 {
  let x: u32 = 7;
  let y: &u32 = &x;
  y
}

Output

lipstick foo.rs
#include <stdint.h>
#ifndef u32
#define u32 uint32_t
#endif
u32 * foo() ;
u32 * foo() {
  u32 x = 7;
  u32 *y = &x;
  return y;
}

Reference

Primitive Types

u8-u64, i8-i64, isize, usize, bool and floats are translated equivalent C types. The never type ! can be used in return position.

Composite Types

You can define structs and unions, and use arrays with constant length. Order of definition does not matter. Function types can also be used.

References

References &x and the deref operator *x can be used freely, without pesky lifetimes bothering you.

Control Flow

if - else, while and loop work. Labeled loops and break/continue work. for loops can be used with literal ranges 0..n or 0..=n.

match expressions can be used and will get translated to switch statements but the only allowed patterns are literals or variables (except for an optional, final wildcard _), blocks are the only allowed bodies.

Expressions

Implicit returns in functions work.

#include directives

You can use include![my_header] or include![<sys/elf>] (note the lack of extension) to generate include directives.

Type Inference

For locally defined types, the -> operator is auto-inferred.

What Does not Work

  • No fancy restrict, const or volatile shenanigans.
  • No type inference, lifetimes, traits, generics, methods, impls, visibility modifiers, paths, tuples, patterns, attributes, etc.

TODO

  • Some form of use modules
  • Stdlib access
  • Preserve comments
  • char/string semantics
  • statics
  • Tuples?
  • Enums
  • Attributes for "annotations" (e.g. volatile)
  • Type inference?
  • Macros?
  • Map cc errors back to original source?
You might also like...
Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.
Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.

Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.

Display a random Shiba from your terminal whenever you feel the need to. Because why not?
Display a random Shiba from your terminal whenever you feel the need to. Because why not?

Shiba CLI Command-line interface (CLI) to display a random Shiba Inu whenever needed, by just running shiba on your terminal. How To Use • How Does It

🌌⭐cosmo is a wrapper for Git essentially, allowing you to compress multiple commands into one
🌌⭐cosmo is a wrapper for Git essentially, allowing you to compress multiple commands into one

❯ Cosmo Git tooling of the future New feature: Cosmo hooks! Click here for more info! ❯ 👀 Features Config files (with defaults!) Fast Easy to use Fri

koyo is a cli tool that lets you run commands as another user. It is similar to doas or sudo.

koyo is a cli tool that lets you run commands as another user. It is similar to doas or sudo.

FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config.
FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config.

Connect quickly to your services 🚀 FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config. Instal

Rust crate that allows you to display status & progress information in a terminal

status-line This crate allows you to display status & progress information in a terminal This crate handles the problem of displaying a small amount o

A CLI tool which can help you automatically kill process of your choice. Useful for freeing up memory and CPU usage!
A CLI tool which can help you automatically kill process of your choice. Useful for freeing up memory and CPU usage!

Quickiller There are always programs such as chrome that keep eating up your resources even when closed! The only way to prevent this is to kill all o

A fun rust terminal program so you can make Christmas trees!
A fun rust terminal program so you can make Christmas trees!

Xmastree 2021 A fun christmas tree where you can add ornaments! Then, you can export the file into either: a rust file a txt file About Taking a break

You'd never guess what this did.

FlashbangVST A plugin I made to test out making VSTs in Rust. This is possibly one of the best things I have ever made. If you make something using th

Shellfirm - Intercept any risky patterns (default or defined by you) and prompt you a small challenge for double verification

shellfirm Opppppsss you did it again? ?? ?? ?? Protect yourself from yourself! rm -rf * git reset --hard before saving? kubectl delete ns which going

elad 652 Dec 29, 2022
Dura - You shouldn't ever lose your work if you're using Git

Dura Dura is a background process that watches your Git repositories and commits your uncommitted changes without impacting HEAD, the current branch,

Tim Kellogg 4.1k Jan 8, 2023
zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets you're watching easily into watchlists for easy access on your terminal.

zigfi zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets

Aldrin Zigmund Cortez Velasco 18 Oct 24, 2022
This automatically patches the RoPro extension for you, allowing you to have pro_tier for free.

RoPro Patcher This automatically patches the RoPro extension for you, allowing you to have pro_tier for free. NOTE Chrome, Brave (and possibly other b

Stefan 10 Jan 1, 2023
Sero is a web server that allows you to easily host your static sites without pain. The idea was inspired by surge.sh but gives you full control.

sero Lightning-fast, static web publishing with zero configuration and full control ?? Table Of Contents ?? Table Of Contents ?? Tools ❓ About The Pro

Dmitry Miasnenko 6 Nov 13, 2023
(Rust) Coloring terminal so simple you already know how to do it !

Colored Coloring terminal so simple, you already know how to do it! "this is blue".blue(); "this is red".red(); "this is red on blue".red(

Thomas Wickham 1.2k Jan 4, 2023
A CLI tool that allow you to create a temporary new rust project using cargo with already installed dependencies

cargo-temp A CLI tool that allow you to create a new rust project in a temporary directory with already installed dependencies. Install Requires Rust

Yohan Boogaert 61 Oct 31, 2022
Fuzzy a general fuzzy finder that saves you time in rust!

Life is short, skim! Half of our life is spent on navigation: files, lines, commands… You need skim! It is a general fuzzy finder that saves you time.

Jinzhou Zhang 3.7k Jan 8, 2023
a simple program that you can scrap, is shit and really simple but is cool.

if you want to run it you need to have installed curl by default scrap youtube, but you can change it, also change the number of threads and run: carg

pai 7 Oct 15, 2021
A Rust CLI tool that helps you enforce Git policies through Git hooks both server and client side

GitPolicyEnforcer This is a command line utility written in Rust, that helps you utilize Git hooks, to enforce various policies. It currently supports

Vagelis Prokopiou 4 Aug 14, 2022