Skip to content

daryltucker/gcc-docker

Repository files navigation

GCC-Docker: Hermetic Toolchain Builder

"Our Compiler is an Island."

Build self-contained, OS-agnostic GCC toolchains using Docker. The resulting compiler works identically on any Linux distribution—because it carries its own world.


Quick Start

# Build GCC 13.3.0
./build.py 13.3.0

# Use pre-built image
docker run --rm daryltucker/gcc:13.3.0 gcc --version

Available Docker Images

Docker Hub Registries:

Pull from Docker Hub: docker pull daryltucker/gcc:<tag>

Native Toolchains (x86_64)

Tag GCC Status
9.5.0 9.5.0 ✅ Sovereign
10.2.0 10.2.0 ✅ Sovereign
12.4.0 12.4.0 ✅ Sovereign
13.3.0 13.3.0 ✅ Sovereign
14.2.0 14.2.0 ✅ Sovereign
15.2.0 15.2.0 ✅ Sovereign

Optimized Profiles

Tag GCC Optimization
12.4.0-legion_s7 12.4.0 AMD Zen 3
13.3.0-legion_s7 13.3.0 AMD Zen 3

Cross-Compilers

Tag GCC Target
12.4.0-rpi5 12.4.0 aarch64 (Raspberry Pi 5)
7.2.0-powerpc_ps3_ppu_v7 7.2.0 powerpc64 (PS3 PPU)
7.2.0-powerpc_ps3_spu_v7 7.2.0 spu (PS3 SPU)
9.5.0-powerpc_ps3_spu_v9 9.5.0 spu (PS3 SPU)

Using Pre-Built Images

Multi-Stage Build (Recommended)

FROM daryltucker/gcc:13.3.0 AS builder
COPY . /src
WORKDIR /src
RUN gcc -o myapp main.c

FROM debian:bookworm-slim
COPY --from=builder /src/myapp /usr/local/bin/
COPY --from=builder /opt/toolchains /opt/toolchains
CMD ["myapp"]

Quick Compile

docker run --rm -v $(pwd):/src -w /src daryltucker/gcc:13.3.0 gcc -o myapp main.c

Extract to Host

docker create --name gcc-extract daryltucker/gcc:12.4.0
docker cp gcc-extract:/opt/toolchains ./toolchains
docker rm gcc-extract

Note: Our toolchains use "Sovereign RPATH"—binaries automatically find their runtime libraries without setting LD_LIBRARY_PATH. You must preserve the original /opt/toolchains/... path.


Building Your Own

Build CLI

# List available versions
./build.py --list-versions

# Build native (x86_64)
./build.py 12.4.0

# Build with hardware optimization
./build.py 12.4.0 --profile legion_s7

# Cross-compile for ARM
./build.py 12.4.0 --profile rpi5

# Control parallelism (preserves cache)
JOBS=16 ./build.py 13.3.0

CLI Options

Option Description
--profile Hardware optimization (e.g., rpi5, legion_s7)
--target Specific triplet (e.g., aarch64-linux-gnu)
--no-cache Force full rebuild
--list-versions List all GCC versions
--list-profiles List all profiles

The 7-Pass Build

Every toolchain is built in seven passes:

  1. Binutils — Assembler and linker
  2. Linux Headers — Kernel API for glibc
  3. GCC Bootstrap — Minimal C compiler
  4. Glibc — C library
  5. Zlib — Compression library
  6. GCC Final — Full C/C++/Fortran compiler
  7. Validation — Tests: C, C++, Fortran, OpenMP, shared libs, LTO

Sovereign RPATH

Binaries compiled by our toolchains automatically find their runtime libraries (libstdc++, libgcc_s, libgfortran) without setting LD_LIBRARY_PATH.

This is achieved by patching GCC's specs file to inject -rpath flags pointing to the toolchain's library directory. The result: truly portable binaries.

Verification:

docker run --rm daryltucker/gcc:13.3.0 sh -c '
  echo "int main(){}" | gcc -x c - -o /tmp/test
  /tmp/test && echo "Binary runs without LD_LIBRARY_PATH"
'

Core Philosophy

  • Hermetic Isolation — The compiler works identically everywhere
  • Self-Reliance — No apt-get install; we build dependencies from source
  • Time Capsule — We recreate the exact ecosystem the compiler expects
  • Sovereign RPATH — Binaries find their libraries without environment hacks

Project Structure

gcc-docker/
├── configs/          # Production JSON configurations
├── profiles/         # Hardware optimization profiles
├── scripts/          # Build orchestration
├── templates/        # Jinja2 Dockerfile templates
├── patches/          # Source code patches
├── out/              # Build outputs (gitignored)
└── cache/            # Downloaded tarballs (gitignored)

Requirements

  • Docker
  • Python 3
  • wget
  • GnuPG (gpg)

License

MIT

About

Build self-contained, OS-agnostic GCC toolchains using Docker. The resulting compiler works identically on Debian, Red Hat, Arch, or any Linux distribution—because it carries its own world.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors