Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

sapir/gcc-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

173,757 Commits

Repository files navigation

Rust frontend for GCC

This is currently at a very early stage. At the time of writing, it can compile trivial functions, like:

fn my_function(x: i32) -> i32 { x }

But most language features don't work yet.

How does it work?

The gcc/rust directory contains a frontend with some boilerplate that links to a Rust crate in gcc/rust/gcc_rust. The Rust code runs rustc up to the MIR stage, then generates a GENERIC tree (a GCC IR) and passes it back to the C code. Access to GCC's internal APIs (especially macros) is handled by C wrapper functions in gcc/rust/rust1.cc.

Build instructions

(Be warned, these are currently rather rough.)

mkdir gcc
cd gcc
git clone --depth 50 -b rust https://github.com/sapir/gcc-rust/ gcc-src
RUST_TOOLCHAIN=$(cat gcc-src/gcc/rust/gcc-rust/rust-toolchain)
rustup toolchain add "$RUST_TOOLCHAIN"
rustup component add --toolchain="$RUST_TOOLCHAIN" rustc-dev
mkdir gcc-build
cd gcc-build
../gcc-src/configure \
 --prefix=$(pwd)/../gcc-install \
 --enable-languages=c,c++,rust \
 --disable-multilib \
 --disable-bootstrap
make
make install
cd ..
gcc-install/bin/gcc whatever.rs -o whatever.so -shared

Running tests

python3 -m pip install pytest
git clone https://github.com/sapir/gcc-rust-tests/
GCC_RUST="$(pwd)/gcc-install/bin/gcc" python3 gcc-rust-tests/test.py

About

a (WIP) Rust frontend for gcc / a gcc backend for rustc

Resources

License

GPL-2.0 and 2 other licenses found

Licenses found

GPL-2.0
COPYING
LGPL-2.1
COPYING.LIB
Unknown
COPYING.RUNTIME

Stars

Watchers

Forks

Packages

Contributors

Languages

  • C 45.6%
  • Ada 15.6%
  • C++ 14.8%
  • Go 7.0%
  • D 6.0%
  • GCC Machine Description 3.7%
  • Other 7.3%

AltStyle によって変換されたページ (->オリジナル) /