Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
# toolchains_gcc_packages
Bazel toolchains for GNU GCC

## Overview
This repository builds GCC toolchains for use with Bazel build system using crosstool-ng.

## Supported Architectures
- x86_64 (AMD64)
- aarch64 (ARM64)

## Building

### Using Docker (recommended)
```bash
# Build for x86_64 (default)
./docker_build_and_run.sh

# Build for ARM64
./docker_build_and_run.sh arm64

# Build for specific architecture and GCC version
./docker_build_and_run.sh arm64 12
```

### Manual Build
```bash
# Set required environment variables
export GCC=12 # GCC major version
export ARCH=x86_64 # or arm64/aarch64

# Run the build
./build.sh
```

## Output
The build will create a tarball in the `output/` directory:
- For x86_64: `x86_64-unknown-linux-gnu_gcc12.tar.gz`
- For ARM64: `aarch64-unknown-linux-gnu_gcc12.tar.gz`
26 changes: 21 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,33 @@
# *******************************************************************************

export GCC=${GCC:?Please set GCC variable to desired gcc major version}
export ARCH=${ARCH:-x86_64}

# Map architecture to target triplet
case $ARCH in
x86_64)
TARGET_TRIPLET="x86_64-unknown-linux-gnu"
;;
arm64|aarch64)
TARGET_TRIPLET="aarch64-unknown-linux-gnu"
;;
*)
echo "Unsupported architecture: $ARCH"
echo "Supported architectures: x86_64, arm64/aarch64"
exit 1
;;
esac

mkdir -p ${PWD}/output/downloads
mkdir -p ${PWD}/output/gcc${GCC}
mkdir -p ${PWD}/output/${TARGET_TRIPLET}_gcc${GCC}

###############################################################################
#
# Build
#
###############################################################################
export CT_PREFIX="${PWD}/output/gcc${GCC}"
DEFCONFIG=configs/x86_64-unknown-linux-gnu_gcc${GCC} ct-ng defconfig
export CT_PREFIX="${PWD}/output/${TARGET_TRIPLET}_gcc${GCC}"
DEFCONFIG=configs/${TARGET_TRIPLET}_gcc${GCC} ct-ng defconfig
ct-ng -j$(nproc) build

###############################################################################
Expand All @@ -46,5 +62,5 @@ tar -c \
--owner=0 \
--group=0 \
--numeric-owner \
-C "output/gcc${GCC}" . \
| gzip -n > "output/x86_64-unknown-linux-gnu_gcc${GCC}.tar.gz"
-C "output/${TARGET_TRIPLET}_gcc${GCC}" . \
| gzip -n > "output/${TARGET_TRIPLET}_gcc${GCC}.tar.gz"
16 changes: 16 additions & 0 deletions configs/aarch64-unknown-linux-gnu_gcc12
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CT_CONFIG_VERSION="4"
CT_LOCAL_TARBALLS_DIR="${CT_PREFIX}/../downloads"
CT_ARCH_ARM=y
CT_ARCH_64=y
CT_ARCH_ARM_MODE_ARM=y
CT_ARCH_ARM_V8=y
CT_STATIC_TOOLCHAIN=y
CT_KERNEL_LINUX=y
CT_LINUX_V_5_15=y
CT_BINUTILS_V_2_34=y
CT_GLIBC_V_2_31=y
CT_GLIBC_KERNEL_VERSION_NONE=y
CT_GCC_V_12=y
CT_CC_GCC_LNK_HASH_STYLE_BOTH=y
CT_CC_LANG_CXX=y
CT_COMP_LIBS_EXPAT=y
8 changes: 7 additions & 1 deletion docker_build_and_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ else
exit 1
fi

# Parse command line arguments
ARCH=${1:-x86_64}
GCC_VERSION=${2:-12}

echo "Building toolchain for architecture: $ARCH with GCC version: $GCC_VERSION"

# Execute the build of the selected toolchain
docker run --rm -it --user "$(id -u):$(id -g)" -v ${PWD}:/workspace $FULL_IMAGE_NAME /bin/bash -c "cd /workspace && GCC=12 ./build.sh"
docker run --rm -it --user "$(id -u):$(id -g)" -v ${PWD}:/workspace $FULL_IMAGE_NAME /bin/bash -c "cd /workspace && GCC=$GCC_VERSION ARCH=$ARCH ./build.sh"