Skip to content

Commit 00a2de7

Browse files
btashtonxiaoxiang781216
authored andcommitted
CI: Test enabling ccache for builds
1 parent cd8abf1 commit 00a2de7

File tree

3 files changed

+85
-22
lines changed

3 files changed

+85
-22
lines changed

.github/workflows/build.yml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
runs-on: ubuntu-18.04
2121
env:
2222
DOCKER_BUILDKIT: 1
23+
IMAGE_TAG: docker.pkg.github.com/${{ github.repository }}/nuttx-ci-linux
2324

2425
strategy:
2526
matrix:
@@ -63,16 +64,27 @@ jobs:
6364
timeout_minutes: 10
6465
max_attempts: 3
6566
retry_wait_seconds: 10
66-
command: docker pull docker.pkg.github.com/apache/incubator-nuttx-testing/nuttx-ci-linux
67+
command: docker pull $IMAGE_TAG
6768

69+
- name: Restore ccache
70+
id: ccache
71+
uses: actions/cache@v2
72+
with:
73+
path: ccache
74+
key: ccache-${{ runner.os }}-${{matrix.boards}}-${{ github.run_id }}
75+
restore-keys: ccache-${{ runner.os }}-${{matrix.boards}}-
6876
- name: Run builds
6977
uses: ./testing/.github/actions/ci-container
7078
env:
7179
BLOBDIR: /tools/blobs
7280
with:
7381
run: |
82+
export CCACHE_DIR=`pwd`/ccache
7483
cd testing
75-
./cibuild.sh -x testlist/${{matrix.boards}}.dat
84+
./cibuild.sh -c -x testlist/${{matrix.boards}}.dat
85+
ccache -s
86+
ccache -M 400M
87+
ccache -c
7688
7789
macOS:
7890
runs-on: macos-10.15
@@ -107,16 +119,28 @@ jobs:
107119
repository: apache/incubator-nuttx-testing
108120
path: testing
109121

110-
- name: Restore cache
122+
- name: Restore tools cache
111123
id: cache-tools
112-
uses: actions/cache@v1
124+
uses: actions/cache@v2
113125
env:
114126
cache-name: ${{ runner.os }}-cache-tools
115127
with:
116128
path: prebuilt
117129
key: ${{ runner.os }}-tools-${{ hashFiles('./testing/cibuild.sh') }}
118130

131+
- name: Restore ccache
132+
id: ccache
133+
uses: actions/cache@v2
134+
with:
135+
path: ccache
136+
key: ccache-${{ runner.os }}-${{matrix.boards}}-${{ github.run_id }}
137+
restore-keys: ccache-${{ runner.os }}-${{matrix.boards}}-
119138
- name: Run builds
120139
run: |
140+
export CCACHE_DIR=`pwd`/ccache
121141
cd testing
122-
./cibuild.sh -i -x testlist/${{matrix.boards}}.dat
142+
./cibuild.sh -i -c -x testlist/${{matrix.boards}}.dat
143+
ccache -s
144+
ccache -M 400M
145+
ccache -c
146+

cibuild.sh

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# - wget
2525

2626
set -e
27+
set -o xtrace
2728

2829
WD=$(cd $(dirname $0) && pwd)
2930
WORKSPACE=$(cd $WD/.. && pwd -P)
@@ -36,12 +37,12 @@ EXTRA_PATH=
3637

3738
case $os in
3839
Darwin)
39-
install="python-tools u-boot-tools discoteq-flock elf-toolchain gen-romfs kconfig-frontends bloaty arm-gcc-toolchain riscv-gcc-toolchain xtensa-esp32-gcc-toolchain avr-gcc-toolchain"
40+
install="python-tools u-boot-tools discoteq-flock elf-toolchain gen-romfs kconfig-frontends arm-gcc-toolchain riscv-gcc-toolchain xtensa-esp32-gcc-toolchain avr-gcc-toolchain c-cache"
4041
mkdir -p ${prebuilt}/homebrew
4142
export HOMEBREW_CACHE=${prebuilt}/homebrew
4243
;;
4344
Linux)
44-
install="python-tools gen-romfs gperf kconfig-frontends bloaty arm-gcc-toolchain mips-gcc-toolchain riscv-gcc-toolchain xtensa-esp32-gcc-toolchain rx-gcc-toolchain c-cache"
45+
install="python-tools gen-romfs gperf kconfig-frontends arm-gcc-toolchain mips-gcc-toolchain riscv-gcc-toolchain xtensa-esp32-gcc-toolchain rx-gcc-toolchain c-cache"
4546
;;
4647
esac
4748

@@ -289,21 +290,39 @@ function rx-gcc-toolchain {
289290
function c-cache {
290291
add_path $prebuilt/ccache/bin
291292

292-
if [ ! -f "$prebuilt/ccache/bin/ccache" ]; then
293-
cd $prebuilt;
294-
wget --quiet https://github.com/ccache/ccache/releases/download/v3.7.7/ccache-3.7.7.tar.gz
295-
tar zxf ccache-3.7.7.tar.gz
296-
cd ccache-3.7.7; ./configure --prefix=$prebuilt/ccache; make; make install
297-
cd $prebuilt; rm -rf ccache-3.7.7; rm ccache-3.7.7.tar.gz
298-
ln -sf $prebuilt/ccache/bin/ccache $prebuilt/ccache/bin/gcc
299-
ln -sf $prebuilt/ccache/bin/ccache $prebuilt/ccache/bin/g++
300-
ln -sf $prebuilt/ccache/bin/ccache $prebuilt/ccache/bin/arm-none-eabi-gcc
301-
ln -sf $prebuilt/ccache/bin/ccache $prebuilt/ccache/bin/arm-none-eabi-g++
302-
ln -sf $prebuilt/ccache/bin/ccache $prebuilt/ccache/bin/p32-gcc
303-
ln -sf $prebuilt/ccache/bin/ccache $prebuilt/ccache/bin/riscv64-unknown-elf-gcc
304-
ln -sf $prebuilt/ccache/bin/ccache $prebuilt/ccache/bin/riscv64-unknown-elf-g++
293+
if ! type ccache > /dev/null; then
294+
case $os in
295+
Darwin)
296+
brew install ccache
297+
;;
298+
Linux)
299+
cd $prebuilt;
300+
wget https://github.com/ccache/ccache/releases/download/v3.7.7/ccache-3.7.7.tar.gz
301+
tar zxf ccache-3.7.7.tar.gz
302+
cd ccache-3.7.7; ./configure --prefix=$prebuilt/ccache; make; make install
303+
cd $prebuilt; rm -rf ccache-3.7.7; rm ccache-3.7.7.tar.gz
304+
;;
305+
esac
305306
fi
307+
306308
ccache --version
309+
mkdir -p $prebuilt/ccache/bin/
310+
ln -sf `which ccache` $prebuilt/ccache/bin/x86_64-elf-gcc
311+
ln -sf `which ccache` $prebuilt/ccache/bin/x86_64-elf-g++
312+
ln -sf `which ccache` $prebuilt/ccache/bin/cc
313+
ln -sf `which ccache` $prebuilt/ccache/bin/c++
314+
ln -sf `which ccache` $prebuilt/ccache/bin/clang
315+
ln -sf `which ccache` $prebuilt/ccache/bin/clang++
316+
ln -sf `which ccache` $prebuilt/ccache/bin/gcc
317+
ln -sf `which ccache` $prebuilt/ccache/bin/g++
318+
ln -sf `which ccache` $prebuilt/ccache/bin/arm-none-eabi-gcc
319+
ln -sf `which ccache` $prebuilt/ccache/bin/arm-none-eabi-g++
320+
ln -sf `which ccache` $prebuilt/ccache/bin/p32-gcc
321+
ln -sf `which ccache` $prebuilt/ccache/bin/riscv64-unknown-elf-gcc
322+
ln -sf `which ccache` $prebuilt/ccache/bin/riscv64-unknown-elf-g++
323+
ln -sf `which ccache` $prebuilt/ccache/bin/xtensa-esp32-elf-gcc
324+
ln -sf `which ccache` $prebuilt/ccache/bin/avr-gcc
325+
ln -sf `which ccache` $prebuilt/ccache/bin/avr-g++
307326
}
308327

309328
function usage {
@@ -324,8 +343,7 @@ function usage {
324343

325344
function enable_ccache {
326345
export USE_CCACHE=1;
327-
export CCACHE_DIR=$prebuilt/ccache/.ccache;
328-
ccache -c
346+
ccache -z
329347
ccache -M 5G;
330348
ccache -s
331349
}

docker/linux/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
209209
unzip \
210210
python3 \
211211
python3-pip \
212+
ccache \
212213
&& rm -rf /var/lib/apt/lists/*
213214

214215

@@ -257,4 +258,24 @@ RUN pip3 install esptool
257258
COPY --from=nuttx-toolchain-renesas /tools/renesas-toolchain/rx-elf-gcc/ renesas-toolchain/rx-elf-gcc/
258259
ENV PATH="/tools/renesas-toolchain/rx-elf-gcc/bin:$PATH"
259260

261+
# Configure ccache
262+
RUN mkdir -p /tools/ccache/bin && \
263+
ln -sf `which ccache` /tools/ccache/bin/cc && \
264+
ln -sf `which ccache` /tools/ccache/bin/c++ && \
265+
ln -sf `which ccache` /tools/ccache/bin/clang && \
266+
ln -sf `which ccache` /tools/ccache/bin/clang++ && \
267+
ln -sf `which ccache` /tools/ccache/bin/gcc && \
268+
ln -sf `which ccache` /tools/ccache/bin/g++ && \
269+
ln -sf `which ccache` /tools/ccache/bin/arm-none-eabi-gcc && \
270+
ln -sf `which ccache` /tools/ccache/bin/arm-none-eabi-g++ && \
271+
ln -sf `which ccache` /tools/ccache/bin/p32-gcc && \
272+
ln -sf `which ccache` /tools/ccache/bin/riscv64-unknown-elf-gcc && \
273+
ln -sf `which ccache` /tools/ccache/bin/riscv64-unknown-elf-g++ && \
274+
ln -sf `which ccache` /tools/ccache/bin/xtensa-esp32-elf-gcc && \
275+
ln -sf `which ccache` /tools/ccache/bin/xtensa-esp32-elf-g++ && \
276+
ln -sf `which ccache` /tools/ccache/bin/avr-gcc && \
277+
ln -sf `which ccache` /tools/ccache/bin/avr-g++ && \
278+
ln -sf `which ccache` /tools/ccache/bin/rx-elf-gcc
279+
ENV PATH="/tools/ccache/bin:$PATH"
280+
260281
CMD [ "/bin/bash" ]

0 commit comments

Comments
 (0)