Skip to content

Commit a756b18

Browse files
committed
improve incrementality of the dockerfile
1 parent d4dc1d7 commit a756b18

File tree

9 files changed

+145
-174
lines changed

9 files changed

+145
-174
lines changed

.github/workflows/build_gcc.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env:
99
ARTIFACT_DIR: /tmp/toolchain/artifacts
1010
OUTPUT_DIR: /tmp/toolchain/output
1111
WORK_DIR: /tmp/toolchain/work
12-
BUILD_GCC_SH: ./infra/gcc/build_gcc.sh
12+
SCRIPTS_DIR: ./.github/workflows/build_gcc
1313

1414
GCC_VERSION: 15
1515
LIBC: gnu
@@ -31,19 +31,19 @@ jobs:
3131
mkdir -p $WORK_DIR
3232
3333
- name: Install Dependencies
34-
run: $BUILD_GCC_SH install_dependencies
34+
run: $SCRIPTS_DIR/step-1_install_dependencies
3535

3636
- name: Build crosstool-NG
37-
run: $BUILD_GCC_SH build_crosstool_ng
37+
run: $SCRIPTS_DIR/step-2_build_crosstool_ng
3838

3939
- name: Configure Toolchain
40-
run: $BUILD_GCC_SH configure_toolchain
40+
run: $SCRIPTS_DIR/step-3_configure_toolchain
4141

4242
- name: Build Toolchain
43-
run: $BUILD_GCC_SH build_toolchain
43+
run: $SCRIPTS_DIR/step-4_build_toolchain
4444

4545
- name: Package Toolchain
46-
run: $BUILD_GCC_SH package_toolchain
46+
run: $SCRIPTS_DIR/step-5_package_toolchain
4747

4848
- name: Upload Toolchain Artifacts
4949
uses: actions/upload-artifact@v4
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ ENV CT_NG_SRC_DIR="/tmp/crosstool-ng"
2020
ENV ARTIFACT_DIR="/tmp/toolchain/artifacts"
2121
ENV OUTPUT_DIR="/tmp/toolchain/output"
2222
ENV WORK_DIR="/tmp/toolchain/work"
23-
ENV BUILD_GCC_SH="/tmp/build_gcc.sh"
23+
ENV SCRIPTS_DIR="/tmp/scripts"
2424

2525
RUN mkdir -p $CT_NG_SRC_DIR
2626
RUN mkdir -p $ARTIFACT_DIR
2727
RUN mkdir -p $OUTPUT_DIR
2828
RUN mkdir -p $WORK_DIR
29-
30-
COPY build_gcc.sh $BUILD_GCC_SH
29+
RUN mkdir -p $SCRIPTS_DIR
3130

3231
ARG GCC_VERSION=15
3332
ARG LIBC=gnu
@@ -37,8 +36,17 @@ ARG REBUILD_ID=1
3736
# =====================
3837
# || Build Toolchain ||
3938
# =====================
40-
RUN $BUILD_GCC_SH install_dependencies
41-
RUN $BUILD_GCC_SH build_crosstool_ng
42-
RUN $BUILD_GCC_SH configure_toolchain
43-
RUN $BUILD_GCC_SH build_toolchain
44-
RUN $BUILD_GCC_SH package_toolchain
39+
COPY step-1_install_dependencies $SCRIPTS_DIR/step-1_install_dependencies
40+
RUN $SCRIPTS_DIR/step-1_install_dependencies
41+
42+
COPY step-2_build_crosstool_ng $SCRIPTS_DIR/step-2_build_crosstool_ng
43+
RUN $SCRIPTS_DIR/step-2_build_crosstool_ng
44+
45+
COPY step-3_configure_toolchain $SCRIPTS_DIR/step-3_configure_toolchain
46+
RUN $SCRIPTS_DIR/step-3_configure_toolchain
47+
48+
COPY step-4_build_toolchain $SCRIPTS_DIR/step-4_build_toolchain
49+
RUN $SCRIPTS_DIR/step-4_build_toolchain
50+
51+
COPY step-5_package_toolchain $SCRIPTS_DIR/step-5_package_toolchain
52+
RUN $SCRIPTS_DIR/step-5_package_toolchain
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -euox pipefail
3+
4+
sudo apt update
5+
DEBIAN_FRONTEND=noninteractive sudo apt install -y \
6+
build-essential \
7+
autoconf \
8+
flex \
9+
bison \
10+
texinfo \
11+
help2man \
12+
file \
13+
gawk \
14+
libtool \
15+
libtool-bin \
16+
libncurses-dev \
17+
python3 \
18+
python3-dev \
19+
unzip \
20+
git \
21+
wget \
22+
curl
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -euox pipefail
3+
4+
git clone https://github.com/crosstool-ng/crosstool-ng "$CT_NG_SRC_DIR"
5+
pushd "$CT_NG_SRC_DIR"
6+
./bootstrap
7+
./configure
8+
make
9+
sudo make install
10+
popd
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
set -euox pipefail
3+
4+
pushd "${WORK_DIR}"
5+
6+
# Standard configs
7+
echo 'CT_CONFIG_VERSION="4"' > defconfig && \
8+
echo 'CT_ARCH_X86=y' >> defconfig && \
9+
echo 'CT_OMIT_TARGET_VENDOR=y' >> defconfig && \
10+
echo 'CT_ARCH_64=y' >> defconfig && \
11+
echo 'CT_STATIC_TOOLCHAIN=y' >> defconfig && \
12+
echo 'CT_KERNEL_LINUX=y' >> defconfig && \
13+
echo 'CT_LOG_PROGRESS_BAR=n' >> defconfig && \
14+
echo 'CT_PREFIX_DIR_RO=n' >> defconfig && \
15+
echo 'CT_CC_LANG_CXX=y' >> defconfig && \
16+
echo "CT_PREFIX_DIR=\"${OUTPUT_DIR}/\"" >> defconfig && \
17+
echo 'CT_DEBUG_GDB=y' >> defconfig && \
18+
echo 'CT_CC_GCC_LNK_HASH_STYLE_BOTH=y' >> defconfig
19+
20+
# GCC version configs
21+
case "$GCC_VERSION" in
22+
15)
23+
echo 'CT_GCC_V_15=y' >> defconfig
24+
;;
25+
14)
26+
echo 'CT_GCC_V_14=y' >> defconfig
27+
echo 'CT_GMP_EXTRA_CFLAGS="-std=gnu17"' >> defconfig
28+
echo 'CT_NCURSES_EXTRA_CFLAGS="-std=gnu17"' >> defconfig
29+
;;
30+
13)
31+
echo 'CT_GCC_V_13=y' >> defconfig
32+
echo 'CT_GMP_EXTRA_CFLAGS="-std=gnu17"' >> defconfig
33+
echo 'CT_NCURSES_EXTRA_CFLAGS="-std=gnu17"' >> defconfig
34+
;;
35+
12)
36+
echo 'CT_GCC_V_12=y' >> defconfig
37+
echo 'CT_GMP_EXTRA_CFLAGS="-std=gnu17"' >> defconfig
38+
echo 'CT_NCURSES_EXTRA_CFLAGS="-std=gnu17"' >> defconfig
39+
;;
40+
*)
41+
echo "Error: Unsupported gcc_version: $GCC_VERSION" >&2
42+
echo "Supported versions: 15, 14, 13, 12" >&2
43+
exit 1
44+
;;
45+
esac
46+
47+
# glibc configs
48+
if [ "$LIBC" = "gnu" ]; then
49+
echo 'CT_GLIBC_KERNEL_VERSION_NONE=y' >> defconfig
50+
echo "CT_GLIBC_V_$(echo "$LIBC_VERSION" | sed 's/\./_/g')=y" >> defconfig
51+
fi
52+
53+
# musl configs
54+
if [ "$LIBC" = "musl" ]; then
55+
echo 'CT_LIBC_MUSL=y' >> defconfig
56+
echo "CT_MUSL_V_$(echo "$LIBC_VERSION" | sed 's/\./_/g')=y" >> defconfig
57+
fi
58+
59+
popd
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -euox pipefail
3+
4+
pushd "${WORK_DIR}"
5+
ct-ng defconfig
6+
ct-ng build
7+
popd
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -euox pipefail
3+
4+
pushd "${OUTPUT_DIR}"
5+
GCC_FULL_VERSION=$("bin/x86_64-linux-${LIBC}-gcc" --version | head -n1 | awk '{print $NF}')
6+
7+
XZ_OPT=-e9 tar cJf "${ARTIFACT_DIR}/gcc-${GCC_FULL_VERSION}-x86_64-linux-${LIBC}-r${REBUILD_ID}.tar.xz" \
8+
bin/ \
9+
libexec/ \
10+
"x86_64-linux-${LIBC}/lib/" \
11+
"x86_64-linux-${LIBC}/bin/"
12+
13+
XZ_OPT=-e9 tar cJf "${ARTIFACT_DIR}/libgcc-${GCC_FULL_VERSION}-x86_64-linux-${LIBC}-r${REBUILD_ID}.tar.xz" \
14+
lib/
15+
16+
XZ_OPT=-e9 tar cJf "${ARTIFACT_DIR}/libstdcxx-${GCC_FULL_VERSION}-x86_64-linux-${LIBC}-r${REBUILD_ID}.tar.xz" \
17+
"x86_64-linux-${LIBC}/include/" \
18+
"x86_64-linux-${LIBC}/lib64/"
19+
20+
XZ_OPT=-e9 tar cJf "${ARTIFACT_DIR}/sysroot-x86_64-linux-${LIBC}-r${REBUILD_ID}.tar.xz" \
21+
"x86_64-linux-${LIBC}/sysroot/"
22+
23+
popd

MODULE.bazel.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/gcc/build_gcc.sh

Lines changed: 0 additions & 158 deletions
This file was deleted.

0 commit comments

Comments
 (0)