Table of Contents
Fetching ...

Towards a Transpiler for C/C++ to Safer Rust

Dhiren Tripuramallu, Swapnil Singh, Shrirang Deshmukh, Srinivas Pinisetty, Shinde Arjun Shivaji, Raja Balusamy, Ajaganna Bandeppa

TL;DR

The paper addresses the challenge of safely migrating C/C++ codebases to Rust for performance-critical systems. It adopts a two-pronged approach: (i) manual transpilation to understand Rust equivalents for C/C++ constructs and (ii) the development of a transpilation mapping table to guide future automation. Through a focused study on the Tizen gperf module, it evaluates existing automatic transpilers (notably CRust) and analyzes their limitations, finding that current tools offer only partial or unsafe translations for large OO codebases. The results demonstrate that manual transpilation yields improved memory safety with competitive performance, and it lays the groundwork for an automated C++ to Rust transpiler, highlighting areas where tools fall short, such as class handling and header resolution. Overall, the work underscores Rust's potential for safe, high-performance system programming and charts a path toward scalable migration tooling.

Abstract

Rust is a multi-paradigm programming language developed by Mozilla that focuses on performance and safety. Rust code is arguably known best for its speed and memory safety, a property essential while developing embedded systems. Thus, it becomes one of the alternatives when developing operating systems for embedded devices. How to convert an existing C++ code base to Rust is also gaining greater attention. In this work, we focus on the process of transpiling C++ code to a Rust codebase in a robust and safe manner. The manual transpilation process is carried out to understand the different constructs of the Rust language and how they correspond to C++ constructs. Based on the learning from the manual transpilation, a transpilation table is created to aid in future transpilation efforts and to develop an automated transpiler. We also studied the existing automated transpilers and identified the problems and inefficiencies they involved. The results of the transpilation process were closely monitored and evaluated, showing improved memory safety without compromising performance and reliability of the resulting codebase. The study concludes with a comprehensive analysis of the findings, an evaluation of the implications for future research, and recommendations for the same in this area.

Towards a Transpiler for C/C++ to Safer Rust

TL;DR

The paper addresses the challenge of safely migrating C/C++ codebases to Rust for performance-critical systems. It adopts a two-pronged approach: (i) manual transpilation to understand Rust equivalents for C/C++ constructs and (ii) the development of a transpilation mapping table to guide future automation. Through a focused study on the Tizen gperf module, it evaluates existing automatic transpilers (notably CRust) and analyzes their limitations, finding that current tools offer only partial or unsafe translations for large OO codebases. The results demonstrate that manual transpilation yields improved memory safety with competitive performance, and it lays the groundwork for an automated C++ to Rust transpiler, highlighting areas where tools fall short, such as class handling and header resolution. Overall, the work underscores Rust's potential for safe, high-performance system programming and charts a path toward scalable migration tooling.

Abstract

Rust is a multi-paradigm programming language developed by Mozilla that focuses on performance and safety. Rust code is arguably known best for its speed and memory safety, a property essential while developing embedded systems. Thus, it becomes one of the alternatives when developing operating systems for embedded devices. How to convert an existing C++ code base to Rust is also gaining greater attention. In this work, we focus on the process of transpiling C++ code to a Rust codebase in a robust and safe manner. The manual transpilation process is carried out to understand the different constructs of the Rust language and how they correspond to C++ constructs. Based on the learning from the manual transpilation, a transpilation table is created to aid in future transpilation efforts and to develop an automated transpiler. We also studied the existing automated transpilers and identified the problems and inefficiencies they involved. The results of the transpilation process were closely monitored and evaluated, showing improved memory safety without compromising performance and reliability of the resulting codebase. The study concludes with a comprehensive analysis of the findings, an evaluation of the implications for future research, and recommendations for the same in this area.
Paper Structure (32 sections, 9 figures, 1 table)

This paper contains 32 sections, 9 figures, 1 table.

Figures (9)

  • Figure 1: Example of ownership in Rust
  • Figure 2: Example of ownership using functions in Rust
  • Figure 3: Code excerpt from the transpilation
  • Figure 4: Crate import example
  • Figure 7: Global Variables in Rust
  • ...and 4 more figures