llvm: Build optimized and static binaries #368
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR takes inspiration from #306 to update the build process of the binaries in the
llvm
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 optimizationSince the binaries are now all static, they can be delivered in a
FROM scratch
image instead of the currentubuntu
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:
linux/arm64
linux/amd64
/usr/local/bin
: 161 Mb/usr/local/bin
: 175 Mblinux/arm64
linux/amd64
/usr/local/bin
: 151 Mb/usr/local/bin
: 168 Mbflto
:linux/arm64
linux/amd64
/usr/local/bin
: 126 Mb/usr/local/bin
: 137 MbCombined with the switch from an
ubuntu
base to ascratch
one, this reduces thellvm
image size by about 50% (from 262Mb to 126Mb forlinux/arm64
).Additional changes:
which
testldd
test<bin> --version
smoke test-flto
and building a crossed-compiledarm64
image from theamd64
CI runner.