Skip to content

Commit c9274c2

Browse files
dylandreimerinktklauser
authored andcommitted
images: Add clang-format image
This commit adds a clang-format image that can be used to format C code. The image is made to be as minimal as possible, just a statically compiled clang-format binary in a scratch container. This makes it quick to pull and allows for the extraction of the binary to run on a host system. Signed-off-by: Dylan Reimerink <[email protected]>
1 parent 9813e68 commit c9274c2

File tree

6 files changed

+118
-1
lines changed

6 files changed

+118
-1
lines changed

Diff for: .github/workflows/images.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ jobs:
8282
with:
8383
entrypoint: make
8484
args: llvm-image PUSH=${{ steps.vars.outputs.push }}
85+
- uses: docker://quay.io/cilium/image-maker:e55375ca5ccaea76dc15a0666d4f57ccd9ab89de
86+
name: Run make clang-format-image
87+
env:
88+
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD_CI }}
89+
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME_CI }}
90+
QUAY_PASSWORD: ${{ secrets.QUAY_PASSWORD_IMAGE_TOOLS }}
91+
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME_IMAGE_TOOLS }}
92+
with:
93+
entrypoint: make
94+
args: clang-format-image PUSH=${{ steps.vars.outputs.push }}
8595
- uses: docker://quay.io/cilium/image-maker:e55375ca5ccaea76dc15a0666d4f57ccd9ab89de
8696
name: Run make startup-script-image
8797
env:

Diff for: Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PUSH ?= false
77
EXPORT ?= false
88
PLATFORMS ?= linux/amd64,linux/arm64
99

10-
all-images: lint maker-image tester-image compilers-image bpftool-image llvm-image network-perf-image ca-certificates-image startup-script-image checkpatch-image iptables-image
10+
all-images: lint maker-image tester-image compilers-image bpftool-image llvm-image clang-format-image network-perf-image ca-certificates-image startup-script-image checkpatch-image iptables-image
1111

1212

1313
lint:
@@ -31,6 +31,9 @@ bpftool-image: .buildx_builder
3131
llvm-image: .buildx_builder
3232
PUSH=$(PUSH) EXPORT=$(EXPORT) TEST=true scripts/build-image.sh cilium-llvm images/llvm $(PLATFORMS) "$$(cat .buildx_builder)" $(REGISTRIES)
3333

34+
clang-format-image: .buildx_builder
35+
PUSH=$(PUSH) EXPORT=$(EXPORT) scripts/build-image.sh cilium-clang-format images/clang-format $(PLATFORMS) "$$(cat .buildx_builder)" $(REGISTRIES)
36+
3437
ca-certificates-image: .buildx_builder
3538
PUSH=$(PUSH) EXPORT=$(EXPORT) scripts/build-image.sh ca-certificates images/ca-certificates $(PLATFORMS) "$$(cat .buildx_builder)" $(REGISTRIES)
3639

Diff for: images/clang-format/Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2024 Authors of Cilium
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
ARG COMPILERS_IMAGE=quay.io/cilium/image-compilers:5569a29cea6b3ad50aeb03102aaf3dc03841197c@sha256:b15dbedb7c49816c74a765e2f6ecdb9359763b8e4e4328d794f48b9cefae9804
5+
6+
FROM --platform=linux/amd64 ${COMPILERS_IMAGE} as builder
7+
8+
COPY checkout-llvm.sh /tmp/checkout-llvm.sh
9+
RUN /tmp/checkout-llvm.sh
10+
11+
COPY build-llvm-native.sh /tmp/build-llvm-native.sh
12+
RUN /tmp/build-llvm-native.sh
13+
14+
COPY build-llvm-cross-aarch64.sh /tmp/build-llvm-cross-aarch64.sh
15+
RUN /tmp/build-llvm-cross-aarch64.sh
16+
17+
FROM scratch
18+
LABEL maintainer="[email protected]"
19+
20+
ARG TARGETPLATFORM
21+
COPY --from=builder /out/${TARGETPLATFORM}/bin /

Diff for: images/clang-format/build-llvm-cross-aarch64.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017-2024 Authors of Cilium
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -o xtrace
7+
set -o errexit
8+
set -o pipefail
9+
set -o nounset
10+
11+
triplet="aarch64-linux-gnu"
12+
13+
mkdir -p /src/llvm/llvm/build-cross-aarch64
14+
15+
cd /src/llvm/llvm/build-cross-aarch64
16+
17+
CC="${triplet}-gcc" CXX="${triplet}-g++" \
18+
cmake .. -G "Ninja" \
19+
-DLLVM_TARGETS_TO_BUILD="BPF" \
20+
-DLLVM_ENABLE_PROJECTS="clang" \
21+
-DBUILD_SHARED_LIBS="OFF" \
22+
-DLLVM_BUILD_STATIC="ON" \
23+
-DCMAKE_CXX_FLAGS="-s -flto" \
24+
-DCMAKE_BUILD_TYPE="Release" \
25+
-DLLVM_BUILD_RUNTIME="OFF" \
26+
-DLLVM_TABLEGEN="/src/llvm/llvm/build-native/bin/llvm-tblgen" \
27+
-DCLANG_TABLEGEN="/src/llvm/llvm/build-native/bin/clang-tblgen" \
28+
-DCMAKE_CROSSCOMPILING="True" \
29+
-DCMAKE_INSTALL_PREFIX="/usr/local"
30+
31+
ninja clang-format
32+
33+
${triplet}-strip bin/clang-format
34+
35+
mkdir -p /out/linux/arm64/bin
36+
cp bin/clang-format /out/linux/arm64/bin

Diff for: images/clang-format/build-llvm-native.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017-2024 Authors of Cilium
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -o xtrace
7+
set -o errexit
8+
set -o pipefail
9+
set -o nounset
10+
11+
mkdir -p /src/llvm/llvm/build-native
12+
13+
cd /src/llvm/llvm/build-native
14+
15+
cmake .. -G "Ninja" \
16+
-DLLVM_TARGETS_TO_BUILD="BPF" \
17+
-DLLVM_ENABLE_PROJECTS="clang" \
18+
-DBUILD_SHARED_LIBS="OFF" \
19+
-DLLVM_BUILD_STATIC="ON" \
20+
-DCMAKE_CXX_FLAGS="-s -flto" \
21+
-DCMAKE_BUILD_TYPE="Release" \
22+
-DLLVM_BUILD_RUNTIME="OFF" \
23+
-DCMAKE_INSTALL_PREFIX="/usr/local"
24+
25+
# llvm-tblgen and clang-tblgen are needed to build the aarch64 version of clang-format
26+
ninja clang-format llvm-tblgen clang-tblgen
27+
28+
strip bin/clang-format
29+
30+
mkdir -p /out/linux/amd64/bin
31+
cp bin/clang-format /out/linux/amd64/bin

Diff for: images/clang-format/checkout-llvm.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017-2024 Authors of Cilium
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -o xtrace
7+
set -o errexit
8+
set -o pipefail
9+
set -o nounset
10+
11+
rev="llvmorg-17.0.6"
12+
13+
git config --global user.email "[email protected]"
14+
git config --global user.name "Cilium Maintainers"
15+
16+
git clone --branch "${rev}" https://github.com/llvm/llvm-project.git /src/llvm

0 commit comments

Comments
 (0)