• Stars
    star
    381
  • Rank 110,161 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C/C++ to Rust transpiler

CRUST

Build

C/C++ to Rust Transpiler

C++ is a system programming language widely used in development of operating systems, firmwares, device drivers and in application development. Major drawback with C++ or any other system programming language is memory safety, null pointers and dangling pointers, which are very dangerous if not handled properly by the programmer. The programming language Rust is system programming language which provides the safe and secure programming with highly enforced compiler restrictions with zero cost abstraction.


This tool is intended to translate existing C++ code base into Rust with less effort. May require manual lookup or minute edit to the translated code.


Usage

First, make sure you are setup for Rust development. Check out http://www.rust-lang.org for more information. The installation sets up the Rust compiler and Cargo package management system. Also, it adds rustc and cargo commands to your PATH variable.

Now that you're setup for rust. Open any suitable terminal and cd into the crust directory

Run cargo build to compile the entire project and download some dependencies.

Now, you may test out CRUST using some of the examples in the example folder as follows: cargo run

The program asks for the C/C++ file to be converted to Rust (Enter the path relative to the current location):

Enter the C/C++ file to be converted to Rust : examples/prog.cpp

Next, enter the translation mode, Strict or Loose (default is Loose). Strict mode assumes all variables to be immutable and Loose mode makes all variables mutable.

It also asks whether the program should be converted into a cargo project. It essentially sets up the program into a project with package management. Check out http://doc.crates.io/ for more information.

Enter the translation mode [(S/s)trict/(L/l)oose] : l
Do you want to create a cargo project :[Y/N] n

Now, it completes the translation and shows where the translated file is stored

Input file size : 177bytes
Tokenizing.......       :DONE
Invoking Parser ........        :DONE
Rust equivalent of source of `examples/prog.cpp` is generated successfully, View the rust code in file : ./examples/pro
g.rs

Alternatively, you may generate an executable similar to C executable as follows:

cargo build --release

This generates an executable, /target/release/crust which can be moved anywhere and run anytime using: ./crust

While executing this binary, the following options are available:

Options:
    -s, --strict        Strict mode (immutable)
    -p, --project-name  Cargo project name
    -h, --help          show this help message

Note that if the strict options are not applied, it implies loose mode.

Same options are available using the cargo run -- command. Options to CRUST must be entered after the --, while options to cargo must be entered before the --. It's just easier to use the executable.


I will

  1. convert the given C/C++ file with basic language construct into Rust.
  2. preserve the comments,
  3. run the formatter on the generated code.
  4. Convert to rust shorthand notion for return values.
  5. document section where i failed to convert leaving out the original code as is.

I (haven't implemented the parser for all features of C/C++), so I cant

  1. convert the included header files yet.
  2. convert function pointers yet.
  3. analyse the types and choose an efficient type.

More Repositories

1

lignum

A distributed message queue.
Go
119
star
2

Stack-VM

Simple Stack based virtual machine
Rust
19
star
3

genesis

An Attempt to learn Operating System development
C
7
star
4

go-service-layout

A template for designing go service
Go
5
star
5

life

Go
4
star
6

stack-langc

StackVM langauge (postfix expression) compiler.
Rust
4
star
7

crust-repl

A repl into crust transpiler, allows you to type out simple language construct and get the equivalent C/C++ construct.
Rust
4
star
8

yaab

a simple buffer implementation for any type (like bytes.Buffer)
Go
3
star
9

SimplyEdit

a terminal-based editor, an attempt at write editor inspired from VI
C
2
star
10

extlog

Extension golang `log` package to emit JSON streams.
Go
2
star
11

goshort

url shortener service implemented based on hexagonal architecture following YT
Go
2
star
12

apk-patch-server

Android APK repo and APK delta generation server
Java
2
star
13

boot_program

program to run on the bare metal host.
Assembly
2
star
14

Bluetooth_RC_Controller

Arduino
1
star
15

gmod

A tool to generate the go project with go mod initialised
Rust
1
star
16

go-ds

bunch of data structure and algorithm implementation in go
Go
1
star
17

crust_of_rust

collection of programs with covering rust concepts and tools
Rust
1
star
18

institution_mngmnt_system

C++ application to manage student attendance and marks.
C++
1
star
19

MediaPlayer

Simple audio/video player.
Java
1
star
20

boot_shell

a simple shell in bootloader.
Assembly
1
star
21

linux_commands.rs

Rust
1
star
22

vipersss

Go
1
star
23

codenotes

This repository contains curated notes on programming.
1
star
24

grpc-interceptors

Go
1
star
25

bench_disk_io.go

Go
1
star
26

lazydb-learningdb

attempt build sqlite like db using cstack/db_tutorial
C
1
star
27

programmer

clojure programmer to write program for basic arithmetic operation
Clojure
1
star
28

dotfiles

Repo to host my dotfiles like vim config.
Vim Script
1
star
29

ImageExtractor

scrape the given site for images and download them to a given directory.
Python
1
star
30

LetsTalk

socket-io based application (an exercise)
JavaScript
1
star
31

monkeylang

Implementing interpreter in Go
Go
1
star