Hi LLVM forums,
I’m trying to create a Docker image with clang-15, llvm-config, and LLVM libs. I’ve been following the guide located at …A guide to Dockerfiles for building LLVM… and I have successfully built a Docker image with clang-15 and llvm-config but I’m unsure of how to keep the libraries that are used for building clang-15 and llvm-config. My end goal is to use these libraries in a LibTooling project.
I’m creating the Dockerfile with
--source debian10 \
--docker-repository clang-debian10 --docker-tag "staging" \
-p clang -i install-clang -i install-clang-resource-headers \
-i install-llvm-config \
Could anybody help me or point me in the right direction?
I managed to solve my own problem by running the following commands:
# Clone LLVM repo
git clone https://github.com/llvm/llvm-project.git && \
cd llvm-project && git checkout release/14.x && \
cd llvm && mkdir build
# CMake llvm build
cmake -GNinja \
-S /llvm-project/llvm -B /llvm-project/llvm/build
# Build libraries, headers, and binaries
cd /llvm-project/llvm/build && \
ninja install-llvm-libraries install-llvm-headers \
install-clang-libraries install-clang-headers install-clang \
install-clang-resource-headers install-llvm-config install-cmake-exports
As of llvm-12, this unfortunately does not work, because
install-cmake-exports exports many additional targets, which are apparently not installed by the other
install-* arguments used in this command. Missing CMake exported targets make the CMake build of a user application project to fail. That’s why I believe this
install-* system is in fact unusable and hasn’t been designed thoughtfully enough. Only using a plain
install results into a fully usable installation.
Unfortunately, I can confirm @dmikushin’s reply. I stumbled upon this post while trying to generate a minimalistic docker image for a CI pipeline. The
install-cmake-exports target places several CMake files into the install folder. One of them (
LLVMConfig.cmake) is always used to resolve the location of the installed LLVM library. The problem is that it contains an include of the
LLVMExports.cmake file very close to the end of the
LLVMConfig.cmake file which checks if other targets have been installed. I ended up commenting the include so that subsequent checks are not triggered. By doing this, I was able to only run the following targets:
cmake <...> --target install-clang install-clang-headers install-llvm-headers install-llvm-libraries install-cmake-exports
This results in an image that is 1) working perfectly fine without any missing libraries errors and 2) is even smaller than the image produced by the script from the LLVM repository. Hope that helps a bit.
I’ve ended up by creating a fork of LLVM’s official docker container scripts, you can find it here: refactorial/docker at master · dmikushin/refactorial · GitHub I’m using Ubuntu as a base, you may find it more convinient. Build container as shown here
Looking good! I created my own version which is heavily inspired by LLVM’s official docker scripts and adjusted for my needs. To further reduce the size of the image, I only installed the LLVM libraries by name as the target
install-llvm-libraries does not exist prior to version 8.
Note: The scripts are probably unusable for other purposes and projects, but since they fit my goal perfectly I kept them that way. They are currently still WIP, but will be published soon in a new docker folder in the repository croemheld/icarus.