f0rmiga/gcc-toolchain

A fully-hermetic Bazel GCC toolchain for Linux.

138

stars

178

commits

Starlark

primary language

Aug 11, 2026

updated

aarch64
armv7
bazel
bazel-rules
c
cpp
fortran
gcc
linux
rbe
x86-64
Browse cluster: Bazel build rules and language support

README

Bazel GCC Toolchain

This is a fully-hermetic Bazel GCC toolchain for Linux that provides cross-compilation support for multiple architectures. The toolchain includes custom-built GCC binaries and sysroots optimized for performance and portability. You can find the comprehensive documentation under docs.

Features

  • Multi-architecture: Support for x86_64, aarch64, and armv7 Linux targets.
  • Hermetic: Fully self-contained with no system dependencies.
  • Optimized: Reduced toolchain sizes and improved build performance.
  • Fortran Support: Complete Fortran compilation, including OpenMP support.
  • Sanitizers: Built-in support for AddressSanitizer, LeakSanitizer, ThreadSanitizer, and UndefinedBehaviorSanitizer.
  • Linker Choice: Use the default GNU BFD linker or opt into LLVM's lld via the linker-lld feature.
  • Remote Execution: Ready for use with Bazel Remote Build Execution (RBE).

Why Use a Hermetic Toolchain?

Reproducibility

Hermetic toolchains ensure that builds are reproducible across different machines and environments. Without identical headers and libraries, the output produced by Bazel will differ between systems, making C++ caches unsharable and introducing machine-specific bugs that make the development lifecycle unreliable.

Portability

When building portable ELF binaries, the libc version plays a crucial role. The linker attempts to link against newer symbols, and GNU libc's symbol versioning means linking against a newer glibc prevents programs from running on systems with older glibc versions. This toolchain ships with glibc 2.26, providing broad compatibility with modern Linux distributions.

Performance

The toolchain has been optimized to reduce size and improve build performance through:

  • Unified GCC binaries and sysroot compilation.
  • Optimized compiler flags and includes.
  • Streamlined dependencies and reduced overhead.

Use Cases

  • First-party Code: Your repository contains C/C++/Fortran code.
  • Sanitizer Testing: Need to run sanitizers (asan, lsan, tsan, ubsan) on your code.
  • Cross-compilation: Build for Linux armv7 or aarch64 from x86_64.
  • Portability: Create binaries compatible with any Linux distribution.
  • Reproducibility: Ensure consistent builds across development and CI environments.
  • Remote Execution: Use with Bazel RBE for distributed builds.

Quick Start

Prerequisites

  • Bazel 7+: This toolchain is tested with Bazel 7.
  • Linux: Primary development and testing environment (RBE supports other platforms).

Installation

Add to your WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "gcc_toolchain",
    sha256 = "...",  # Use the SHA256 of the release
    urls = ["https://github.com/f0rmiga/gcc-toolchain/archive/refs/tags/vX.X.X.tar.gz"],
)

load("@gcc_toolchain//toolchain:repositories.bzl", "gcc_toolchain_dependencies")

gcc_toolchain_dependencies()

load("@gcc_toolchain//toolchain:defs.bzl", "gcc_register_toolchain", "ARCHS")

gcc_register_toolchain(
    name = "gcc_toolchain_x86_64",
    target_arch = ARCHS.x86_64,
)

Documentation

Contributors

f0rmiga

112 commits

renovate[bot]

41 commits

blorente

6 commits

gregmagolan

5 commits

f0rmiga/gcc-toolchain

A fully-hermetic Bazel GCC toolchain for Linux.

138

stars

178

commits

Starlark

primary language

Aug 11, 2026

updated

aarch64
armv7
bazel
bazel-rules
c
cpp
fortran
gcc
linux
rbe
x86-64
Browse cluster: Bazel build rules and language support

README

Bazel GCC Toolchain

This is a fully-hermetic Bazel GCC toolchain for Linux that provides cross-compilation support for multiple architectures. The toolchain includes custom-built GCC binaries and sysroots optimized for performance and portability. You can find the comprehensive documentation under docs.

Features

  • Multi-architecture: Support for x86_64, aarch64, and armv7 Linux targets.
  • Hermetic: Fully self-contained with no system dependencies.
  • Optimized: Reduced toolchain sizes and improved build performance.
  • Fortran Support: Complete Fortran compilation, including OpenMP support.
  • Sanitizers: Built-in support for AddressSanitizer, LeakSanitizer, ThreadSanitizer, and UndefinedBehaviorSanitizer.
  • Linker Choice: Use the default GNU BFD linker or opt into LLVM's lld via the linker-lld feature.
  • Remote Execution: Ready for use with Bazel Remote Build Execution (RBE).

Why Use a Hermetic Toolchain?

Reproducibility

Hermetic toolchains ensure that builds are reproducible across different machines and environments. Without identical headers and libraries, the output produced by Bazel will differ between systems, making C++ caches unsharable and introducing machine-specific bugs that make the development lifecycle unreliable.

Portability

When building portable ELF binaries, the libc version plays a crucial role. The linker attempts to link against newer symbols, and GNU libc's symbol versioning means linking against a newer glibc prevents programs from running on systems with older glibc versions. This toolchain ships with glibc 2.26, providing broad compatibility with modern Linux distributions.

Performance

The toolchain has been optimized to reduce size and improve build performance through:

  • Unified GCC binaries and sysroot compilation.
  • Optimized compiler flags and includes.
  • Streamlined dependencies and reduced overhead.

Use Cases

  • First-party Code: Your repository contains C/C++/Fortran code.
  • Sanitizer Testing: Need to run sanitizers (asan, lsan, tsan, ubsan) on your code.
  • Cross-compilation: Build for Linux armv7 or aarch64 from x86_64.
  • Portability: Create binaries compatible with any Linux distribution.
  • Reproducibility: Ensure consistent builds across development and CI environments.
  • Remote Execution: Use with Bazel RBE for distributed builds.

Quick Start

Prerequisites

  • Bazel 7+: This toolchain is tested with Bazel 7.
  • Linux: Primary development and testing environment (RBE supports other platforms).

Installation

Add to your WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "gcc_toolchain",
    sha256 = "...",  # Use the SHA256 of the release
    urls = ["https://github.com/f0rmiga/gcc-toolchain/archive/refs/tags/vX.X.X.tar.gz"],
)

load("@gcc_toolchain//toolchain:repositories.bzl", "gcc_toolchain_dependencies")

gcc_toolchain_dependencies()

load("@gcc_toolchain//toolchain:defs.bzl", "gcc_register_toolchain", "ARCHS")

gcc_register_toolchain(
    name = "gcc_toolchain_x86_64",
    target_arch = ARCHS.x86_64,
)

Documentation

Contributors

f0rmiga

112 commits

renovate[bot]

41 commits

blorente

6 commits

gregmagolan

5 commits

Languages

Starlark

90.4%

Shell

3.6%

C

2.9%

C++

2.3%