2021-01-12 14:48:32 +01:00
![C/C++ CI ](https://github.com/Rust-GCC/gccrs/workflows/C/C++%20CI/badge.svg )
2021-04-05 15:27:42 +02:00
[![GCC Bootstrap Build ](https://github.com/Rust-GCC/gccrs/actions/workflows/bootstrap.yml/badge.svg )](https://github.com/Rust-GCC/gccrs/actions/workflows/bootstrap.yml)
2021-08-11 12:46:16 +02:00
[![Build Docker image ](https://github.com/Rust-GCC/gccrs/actions/workflows/docker.yml/badge.svg )](https://github.com/Rust-GCC/gccrs/actions/workflows/docker.yml)
2020-11-30 16:09:38 +01:00
![Docker Pulls ](https://img.shields.io/docker/pulls/philberty/gccrs )
2020-12-16 12:18:07 +01:00
[![project chat ](https://img.shields.io/badge/zulip-join_chat-brightgreen.svg )](https://gcc-rust.zulipchat.com/)
2021-04-13 13:25:43 +02:00
[![Bors enabled ](https://bors.tech/images/badge_small.svg )](https://app.bors.tech/repositories/32890)
2020-04-13 17:17:11 +02:00
# GCC Rust
2020-12-23 15:39:58 +01:00
![GCC Rust ](logo.png?raw=true "GCC rust Logo" )
2020-04-13 17:17:11 +02:00
2021-03-15 06:20:38 +01:00
Please note, the compiler is in a very early stage and not usable yet for compiling real Rust programs.
2021-01-22 15:44:32 +01:00
2021-01-11 05:34:23 +01:00
gccrs is a full alternative implementation of the Rust language ontop of GCC with the goal
2020-12-23 16:00:47 +01:00
to become fully upstream with the GNU toolchain.
The origin of this project was a community effort several years ago where Rust was still at version 0.9;
the language was subject to so much change that it became difficult for a community effort to play catch up.
2021-01-11 05:34:23 +01:00
Now that the language is stable, it is an excellent time to create alternative compilers. The developers of
2020-12-23 16:00:47 +01:00
the project are keen “Rustaceans” with a desire to give back to the Rust community and to learn what GCC is capable
of when it comes to a modern language.
2020-04-13 17:17:11 +02:00
2021-01-20 22:51:30 +01:00
## FAQ
Please find the answers to frequently asked questions over on: https://github.com/Rust-GCC/gccrs/wiki/Frequently-Asked-Questions
2021-01-11 05:34:23 +01:00
## Development Environment
2020-04-13 17:17:11 +02:00
2021-03-27 21:03:58 +01:00
### Building
2021-01-11 05:34:23 +01:00
Fetch dependencies for Ubuntu:
2020-04-13 17:17:11 +02:00
```bash
2020-12-16 12:14:59 +01:00
$ apt install build-essential libgmp3-dev libmpfr-dev libmpc-dev flex bison autogen gcc-multilib dejagnu
2020-04-13 17:17:11 +02:00
```
2020-11-29 21:38:51 +01:00
Clone the repository
2020-04-13 17:17:11 +02:00
```bash
2020-11-29 21:38:51 +01:00
$ git clone git@github.com:Rust-GCC/gccrs.git
2020-04-13 17:17:11 +02:00
```
2021-06-18 13:41:41 +02:00
#### Linux
2021-03-27 21:03:58 +01:00
It is important to remember that GNU toolchain projects are designed to be built outside of their source directory
2021-01-11 05:34:23 +01:00
which is why a build directory is created.
2020-04-13 17:17:11 +02:00
```bash
$ mkdir gccrs-build
$ cd gccrs-build
2020-12-04 17:30:03 +01:00
$ ../gccrs/configure --prefix=$HOME/gccrs-install --disable-bootstrap --enable-multilib --enable-languages=rust
2020-04-13 17:17:11 +02:00
$ make
```
2021-06-18 13:41:41 +02:00
#### MacOS
The path of header dir and sysroot should be specified when you configure the project.
```bash
$ mkdir mac-build
$ cd mac-build
$ ../gccrs/configure --prefix=$HOME/gccrs-install --disable-bootstrap --enable-multilib --enable-languages=rust --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
$ make
```
#### Running GCC Rust
2020-12-07 10:34:53 +01:00
Running the compiler itself without make install we can simply invoke the compiler proper:
2020-04-13 17:17:11 +02:00
2021-01-11 05:34:23 +01:00
```bash
2021-06-03 23:57:34 +02:00
$ ./gcc/rust1 test.rs -frust-debug -frust-dump-parse -Warray-bounds -dumpbase test.rs -mtune=generic -march=x86-64 -O0 -version -fdump-tree-gimple -o test.s -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64
2020-04-13 17:17:11 +02:00
```
2020-11-29 21:38:51 +01:00
2021-02-26 19:58:58 +01:00
To invoke the compiler driver (gccrs) we need to:
2020-11-29 21:38:51 +01:00
2021-01-11 05:34:23 +01:00
```bash
2020-11-29 21:38:51 +01:00
$ make install
```
2021-03-27 21:03:58 +01:00
Then invoke the compiler from the installation directory:
2020-11-29 21:38:51 +01:00
2021-01-11 05:34:23 +01:00
```bash
2021-03-27 21:03:58 +01:00
$ $HOME/gccrs-install/gccrs -g -O2 -c test.rs -o test.o
$ $HOME/gccrs-install/gccrs -o test test.o
2020-11-29 21:38:51 +01:00
```
2021-03-27 21:03:58 +01:00
2021-11-20 12:25:45 +01:00
You can also setup your shell to automatically find the installed compiler. For example for `bash` ,
add the following in your `$HOME/.bashrc` :
2021-03-27 21:03:58 +01:00
2021-03-23 10:46:49 +01:00
```bash
2021-03-27 21:03:58 +01:00
export PATH=$HOME/gccrs-install/bin:$PATH
2021-03-23 10:46:49 +01:00
```
2020-11-29 21:38:51 +01:00
## Testsuite
2021-06-02 11:05:44 +02:00
Invoke the full testsuite from the build directory (`gccrs-build` in the previous commands):
2020-11-29 21:38:51 +01:00
2021-01-11 05:34:23 +01:00
```bash
2020-11-29 21:38:51 +01:00
$ make check-rust
```
2021-06-02 11:05:44 +02:00
Invoke a subset of the testsuite. For example, to only run tests that are currently known/expected to fail:
2021-03-27 21:03:58 +01:00
```bash
2021-06-02 11:05:44 +02:00
$ make check-rust RUNTESTFLAGS="xfail.exp"
2021-03-27 21:03:58 +01:00
```
2021-06-02 11:05:44 +02:00
There are the following sets of tests:
- `compile.exp` : compilation tests
2021-03-27 21:03:58 +01:00
- `execute.exp` : execution tests
2021-06-02 11:05:44 +02:00
- `xfail.exp` : tests that are currently known/expected to fail
2021-03-27 21:03:58 +01:00
2021-03-29 21:14:54 +02:00
Invoke only a specific test :
2021-03-27 21:03:58 +01:00
```bash
2021-06-02 11:05:44 +02:00
$ make check-rust RUNTESTFLAGS="--all compile.exp=continue1.rs"
2021-03-27 21:03:58 +01:00
```
Logs (with corresponding commands) can be found in : `gccrs-build/gcc/testsuite/rust/rust.log` .
See [GCC Testing documentation ](https://gcc.gnu.org/install/test.html ) for more details.
2021-06-02 11:05:44 +02:00
Test cases are located within [`gcc/testsuite/rust/` ](gcc/testsuite/rust/ ).
Please contribute your specific
2021-01-11 05:34:23 +01:00
test cases referencing any issues on Github.
2020-11-29 21:38:51 +01:00
2021-03-27 21:03:58 +01:00
## Debugging
### Enabling internal checks
2021-11-20 12:25:45 +01:00
GCC has several internal checks that can be enabled during configuration. In the case of `gccrs` ,
you can enable the following:
2021-03-27 21:03:58 +01:00
```bash
$ ../gccrs/configure --prefix=$HOME/gccrs-install --disable-bootstrap --enable-multilib --enable-languages=rust --enable-checking=gimple,tree,types
```
### GDB
You can directly invoke `gdb` on the `rust1` compiler process (you can find the
exact command adding `--verbose` to your `gccrs` invocation):
```bash
$ gccrs test.rs -O0 -S -o arithmetic_expressions1.s --verbose
...
/some/path/../../rust1 test.rs -quiet -dumpbase arithmetic_expressions1.rs -dumpbase-ext .rs
-mtune=generic -march=x86-64 -O0 -w -version -fdiagnostics-color=never -fno-diagnostics-show-caret -fno-diagnostics-show-line-numbers -fdiagnostics-urls=never -fdiagnostics-path-format=separate-events -o test.s -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu
...
$ gdb --args /some/path/../../rust1 test.rs -quiet -dumpbase arithmetic_expressions1.rs -dumpbase-ext .rs
-mtune=generic -march=x86-64 -O0 -w -version -fdiagnostics-color=never -fno-diagnostics-show-caret -fno-diagnostics-show-line-numbers -fdiagnostics-urls=never -fdiagnostics-path-format=separate-events -o test.s -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu
```
2021-11-20 12:25:45 +01:00
Or simply add the `-wrapper gdb,--args` option.
This will call each subcommand in `gdb` and you simply have to break/debug in `rust1` :
2021-03-27 21:03:58 +01:00
```bash
$ gccrs test.rs -O0 -S -o arithmetic_expressions1.s -wrapper gdb,--args
```
2020-11-29 21:38:51 +01:00
## Docker image
There is a docker image hosted over on:
https://hub.docker.com/repository/docker/philberty/gccrs
2021-01-11 05:34:23 +01:00
```bash
2020-12-23 16:00:47 +01:00
$ docker pull philberty/gccrs
```
2020-11-29 21:38:51 +01:00
Or you can build your own image:
2021-01-11 05:34:23 +01:00
```bash
2020-11-29 21:38:51 +01:00
$ docker build . -t gccrs-dev
2021-03-15 16:34:08 +01:00
```
If you want to build an object file:
```bash
2020-11-29 21:38:51 +01:00
$ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp \
gccrs-dev:latest gccrs -g -O2 -c \
2021-06-02 11:05:44 +02:00
gcc/testsuite/rust/compile/torture/type_infer1.rs -o type_infer1.o
2020-11-29 21:38:51 +01:00
```
2021-03-15 16:34:08 +01:00
If you want to build an executable file:
```bash
$ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp \
gccrs-dev:latest gccrs -g -O2 \
2021-06-02 11:05:44 +02:00
gcc/testsuite/rust/compile/torture/type_infer1.rs -o type_infer1
2021-03-15 16:34:08 +01:00
```
To emit assembly :
```bash
$ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp \
gccrs-dev:latest gccrs -g -O2 \
2021-06-02 11:05:44 +02:00
gcc/testsuite/rust/compile/torture/type_infer1.rs -S -o type_infer1.s
2021-03-15 16:34:08 +01:00
```
2021-06-03 23:57:34 +02:00
To emit Rust front end debug output, you may add options like `-frust-debug` , `-frust-dump-all` .
2021-03-15 16:34:08 +01:00
2020-11-29 21:38:51 +01:00
## Contributing
2021-05-14 14:40:18 +02:00
If you want to contribute to GCC Rust, you can find more information in [CONTRIBUTING.md ](https://github.com/Rust-GCC/gccrs/blob/master/CONTRIBUTING.md ).
2021-11-20 12:25:45 +01:00
Please be aware this project is designed to be pushed upstream to GCC when we reach some milestones,
and this means we require copyright assignment or the Developer's Certificate of Origin sign-off.
Please see the [Contributing to GCC ](https://gcc.gnu.org/contribute.html ) guide or [Developer's Certificate of Origin (DCO) Sign-off ](https://gcc.gnu.org/dco.html ) guide.
2020-11-29 21:38:51 +01:00
2021-11-20 12:25:45 +01:00
Not all contributions must be code; we would love to see new test cases or bugs and issues to be reported.
Feel free to add any comments on open PRs
2020-11-29 21:38:51 +01:00
2020-11-30 13:38:16 +01:00
## Community
2020-11-29 21:38:51 +01:00
2021-01-11 05:34:23 +01:00
We can be found on all usual Rust channels such as Zulip, but we also have our own channels:
2020-11-30 13:38:16 +01:00
2021-11-20 12:25:45 +01:00
* GCC Rust Zulip: https://gcc-rust.zulipchat.com/
* Twitter: https://twitter.com/gcc_rust
* GCC Mailing List: https://gcc.gnu.org/mailman/listinfo/gcc-rust
* irc: irc.oftc.net - gccrust