Skip to content

Conversation

HadrienPatte
Copy link
Member

@HadrienPatte HadrienPatte commented Jul 28, 2025

This PR takes inspiration from #306 to update the build process of the binaries in the llvm image:

main difference is that the resulting binaries are statically compiled. This allows them to run in a scratch image, drastically reducing the size of the docker image

The core differences are:

  • -DLLVM_BUILD_STATIC="ON" -> ensures the produced binaries are statically linked
  • -DCMAKE_CXX_FLAGS="-s -flto" -> ensures the produced binaries are stripped and use link time optimization

Since the binaries are now all static, they can be delivered in a FROM scratch image instead of the current ubuntu based image. This results in an overall smaller image.

Updating the build flags actually also leads to ~20% smaller binaries, contributing to a smaller final image:

  • Current image:
linux/arm64 linux/amd64
/usr/local/bin: 161 Mb
image
/usr/local/bin: 175 Mb
image
  • With static build:
linux/arm64 linux/amd64
/usr/local/bin: 151 Mb
image
/usr/local/bin: 168 Mb
image
  • With static build and flto:
linux/arm64 linux/amd64
/usr/local/bin: 126 Mb
image
/usr/local/bin: 137 Mb
image

Combined with the switch from an ubuntu base to a scratch one, this reduces the llvm image size by about 50% (from 262Mb to 126Mb for linux/arm64).

Additional changes:

  • I updated and extended the CST tests so that every binary in the image has at least:
    • a which test
    • an ldd test
    • a <bin> --version smoke test
  • I had to bump the timeout for the image build job as the LLVM image build was taking just a little over the default timeout, especially when using the optimizing flag -flto and building a crossed-compiled arm64 image from the amd64 CI runner.

Signed-off-by: Hadrien Patte <hadrien.patte@datadoghq.com>
@HadrienPatte HadrienPatte force-pushed the pr/HadrienPatte/static-llvm branch from e8598d0 to fb4d1c9 Compare July 29, 2025 10:48
@HadrienPatte HadrienPatte marked this pull request as ready for review July 29, 2025 18:32
@HadrienPatte HadrienPatte requested review from a team as code owners July 29, 2025 18:32
Copy link
Member

@aanm aanm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this takes more than 7 hours on a 32 core CPU machine 🤯

@HadrienPatte HadrienPatte added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jul 30, 2025
@pchaigno pchaigno merged commit dfe66ec into master Aug 12, 2025
12 checks passed
@pchaigno pchaigno deleted the pr/HadrienPatte/static-llvm branch August 12, 2025 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants