{"id":13648621,"url":"https://github.com/rust-lang/rustc_codegen_gcc","last_synced_at":"2025-04-13T08:57:31.846Z","repository":{"id":37023001,"uuid":"292145357","full_name":"rust-lang/rustc_codegen_gcc","owner":"rust-lang","description":"libgccjit AOT codegen for rustc","archived":false,"fork":false,"pushed_at":"2025-03-27T19:36:20.000Z","size":8018,"stargazers_count":959,"open_issues_count":150,"forks_count":70,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-03-30T04:06:01.564Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rust-lang.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-02T01:15:35.000Z","updated_at":"2025-03-18T00:46:21.000Z","dependencies_parsed_at":"2024-01-12T03:18:49.472Z","dependency_job_id":"b628067b-29ee-40ad-8140-fc2c76907320","html_url":"https://github.com/rust-lang/rustc_codegen_gcc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-lang%2Frustc_codegen_gcc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-lang%2Frustc_codegen_gcc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-lang%2Frustc_codegen_gcc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-lang%2Frustc_codegen_gcc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rust-lang","download_url":"https://codeload.github.com/rust-lang/rustc_codegen_gcc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247436283,"owners_count":20938533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-08-02T01:04:23.944Z","updated_at":"2025-04-06T05:11:53.894Z","avatar_url":"https://github.com/rust-lang.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":["Other dialects and variants"],"readme":"# WIP libgccjit codegen backend for rust\n\n[![Chat on IRC](https://img.shields.io/badge/irc.libera.chat-%23rustc__codegen__gcc-blue.svg)](https://web.libera.chat/#rustc_codegen_gcc)\n[![Chat on Matrix](https://img.shields.io/badge/matrix.org-%23rustc__codegen__gcc-blue.svg)](https://matrix.to/#/#rustc_codegen_gcc:matrix.org)\n\nThis is a GCC codegen for rustc, which means it can be loaded by the existing rustc frontend, but benefits from GCC: more architectures are supported and GCC's optimizations are used.\n\n**Despite its name, libgccjit can be used for ahead-of-time compilation, as is used here.**\n\n## Motivation\n\nThe primary goal of this project is to be able to compile Rust code on platforms unsupported by LLVM.\nA secondary goal is to check if using the gcc backend will provide any run-time speed improvement for the programs compiled using rustc.\n\n### Dependencies\n\n**rustup:** Follow the instructions on the official [website](https://www.rust-lang.org/tools/install)\n\n**DejaGnu:** Consider to install DejaGnu which is necessary for running the libgccjit test suite. [website](https://www.gnu.org/software/dejagnu/#downloading)\n\n\n\n## Building\n\n**This requires a patched libgccjit in order to work.\nYou need to use my [fork of gcc](https://github.com/rust-lang/gcc) which already includes these patches.**\n\n```bash\n$ cp config.example.toml config.toml\n```\n\nIf don't need to test GCC patches you wrote in our GCC fork, then the default configuration should\nbe all you need. You can update the `rustc_codegen_gcc` without worrying about GCC.\n\n### Building with your own GCC version\n\nIf you wrote a patch for GCC and want to test it without this backend, you will need\nto do a few more things.\n\nTo build it (most of these instructions come from [here](https://gcc.gnu.org/onlinedocs/jit/internals/index.html), so don't hesitate to take a look there if you encounter an issue):\n\n```bash\n$ git clone https://github.com/rust-lang/gcc\n$ sudo apt install flex libmpfr-dev libgmp-dev libmpc3 libmpc-dev\n$ mkdir gcc-build gcc-install\n$ cd gcc-build\n$ ../gcc/configure \\\n    --enable-host-shared \\\n    --enable-languages=jit \\\n    --enable-checking=release \\ # it enables extra checks which allow to find bugs\n    --disable-bootstrap \\\n    --disable-multilib \\\n    --prefix=$(pwd)/../gcc-install\n$ make -j4 # You can replace `4` with another number depending on how many cores you have.\n```\n\nIf you want to run libgccjit tests, you will need to also enable the C++ language in the `configure`:\n\n```bash\n--enable-languages=jit,c++\n```\n\nThen to run libgccjit tests:\n\n```bash\n$ cd gcc # from the `gcc-build` folder\n$ make check-jit\n# To run one specific test:\n$ make check-jit RUNTESTFLAGS=\"-v -v -v jit.exp=jit.dg/test-asm.cc\"\n```\n\n**Put the path to your custom build of libgccjit in the file `config.toml`.**\n\nYou now need to set the `gcc-path` value in `config.toml` with the result of this command:\n\n```bash\n$ dirname $(readlink -f `find . -name libgccjit.so`)\n```\n\nand to comment the `download-gccjit` setting:\n\n```toml\ngcc-path = \"[MY PATH]\"\n# download-gccjit = true\n```\n\nThen you can run commands like this:\n\n```bash\n$ ./y.sh prepare # download and patch sysroot src and install hyperfine for benchmarking\n$ ./y.sh build --sysroot --release\n```\n\nTo run the tests:\n\n```bash\n$ ./y.sh test --release\n```\n\n## Usage\n\nYou have to run these commands, in the corresponding order:\n\n```bash\n$ ./y.sh prepare\n$ ./y.sh build --sysroot\n```\nTo check if all is  working correctly, run:\n\n ```bash\n$ ./y.sh cargo build --manifest-path tests/hello-world/Cargo.toml\n```\n\n### Cargo\n\n```bash\n$ CHANNEL=\"release\" $CG_GCCJIT_DIR/y.sh cargo run\n```\n\nIf you compiled cg_gccjit in debug mode (aka you didn't pass `--release` to `./y.sh test`) you should use `CHANNEL=\"debug\"` instead or omit `CHANNEL=\"release\"` completely.\n\n### LTO\n\nTo use LTO, you need to set the variable `EMBED_LTO_BITCODE=1` in addition to setting `lto = \"fat\"` in the `Cargo.toml`.\n\nFailing to set `EMBED_LTO_BITCODE` will give you the following error:\n\n```\nerror: failed to copy bitcode to object file: No such file or directory (os error 2)\n```\n\n### Rustc\n\nIf you want to run `rustc` directly, you can do so with:\n\n```bash\n$ ./y.sh rustc my_crate.rs\n```\n\nYou can do the same manually (although we don't recommend it):\n\n```bash\n$ LIBRARY_PATH=\"[gcc-path value]\" LD_LIBRARY_PATH=\"[gcc-path value]\" rustc +$(cat $CG_GCCJIT_DIR/rust-toolchain | grep 'channel' | cut -d '=' -f 2 | sed 's/\"//g' | sed 's/ //g') -Cpanic=abort -Zcodegen-backend=$CG_GCCJIT_DIR/target/release/librustc_codegen_gcc.so --sysroot $CG_GCCJIT_DIR/build_sysroot/sysroot my_crate.rs\n```\n\n## Env vars\n\n * _**CG_GCCJIT_DUMP_ALL_MODULES**_: Enables dumping of all compilation modules. When set to \"1\", a dump is created for each module during compilation and stored in `/tmp/reproducers/`.\n * _**CG_GCCJIT_DUMP_MODULE**_: Enables dumping of a specific module. When set with the module name, e.g., `CG_GCCJIT_DUMP_MODULE=module_name`, a dump of that specific module is created in `/tmp/reproducers/`.\n * _**CG_RUSTFLAGS**_: Send additional flags to rustc. Can be used to build the sysroot without unwinding by setting `CG_RUSTFLAGS=-Cpanic=abort`.\n * _**CG_GCCJIT_DUMP_TO_FILE**_: Dump a C-like representation to /tmp/gccjit_dumps and enable debug info in order to debug this C-like representation.\n * _**CG_GCCJIT_DUMP_RTL**_: Dumps RTL (Register Transfer Language) for virtual registers.\n * _**CG_GCCJIT_DUMP_RTL_ALL**_: Dumps all RTL passes.\n * _**CG_GCCJIT_DUMP_TREE_ALL**_: Dumps all tree (GIMPLE) passes.\n * _**CG_GCCJIT_DUMP_IPA_ALL**_: Dumps all Interprocedural Analysis (IPA) passes.\n * _**CG_GCCJIT_DUMP_CODE**_: Dumps the final generated code.\n * _**CG_GCCJIT_DUMP_GIMPLE**_: Dumps the initial GIMPLE representation.\n * _**CG_GCCJIT_DUMP_EVERYTHING**_: Enables dumping of all intermediate representations and passes.\n * _**CG_GCCJIT_KEEP_INTERMEDIATES**_: Keeps intermediate files generated during the compilation process.\n * _**CG_GCCJIT_VERBOSE**_: Enables verbose output from the GCC driver.\n\n## Extra documentation\n\nMore specific documentation is available in the [`doc`](./doc) folder:\n\n * [Common errors](./doc/errors.md)\n * [Debugging GCC LTO](./doc/debugging-gcc-lto.md)\n * [Debugging libgccjit](./doc/debugging-libgccjit.md)\n * [Git subtree sync](./doc/subtree.md)\n * [List of useful commands](./doc/tips.md)\n * [Send a patch to GCC](./doc/sending-gcc-patch.md)\n\n## Licensing\n\nWhile this crate is licensed under a dual Apache/MIT license, it links to `libgccjit` which is under the GPLv3+ and thus, the resulting toolchain (rustc + GCC codegen) will need to be released under the GPL license.\n\nHowever, programs compiled with `rustc_codegen_gcc` do not need to be released under a GPL license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-lang%2Frustc_codegen_gcc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frust-lang%2Frustc_codegen_gcc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-lang%2Frustc_codegen_gcc/lists"}