From c99db9352972b60e40e65d4c4fe5f1be88d35105 Mon Sep 17 00:00:00 2001 From: Xiang Chen Date: Wed, 24 Jul 2024 23:08:35 +0800 Subject: [PATCH] update LLVM version to 18 choose dynamic link when building on Arch Linux https://gitlab.archlinux.org/archlinux/packaging/packages/llvm/-/blob/main/PKGBUILD?ref_type=heads#L89 Update Dockerfile_ubuntu --- .github/workflows/docker-archlinux.yml | 2 +- .github/workflows/docker-fedora.yml | 2 +- .github/workflows/docker-ubuntu.yml | 2 +- .github/workflows/docker-ubunut-apt.yml | 2 +- Dockerfile_archlinux | 5 +++-- Dockerfile_fedora | 7 ++++--- Dockerfile_ubuntu | 9 +++++---- Dockerfile_ubuntu_apt | 15 ++++++++------- tools/CMakeLists.txt | 11 ++++++++--- 9 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.github/workflows/docker-archlinux.yml b/.github/workflows/docker-archlinux.yml index 3eddcce8..a042b550 100644 --- a/.github/workflows/docker-archlinux.yml +++ b/.github/workflows/docker-archlinux.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v2 - name: Build the Docker image - run: docker build . --file Dockerfile_archlinux --tag llvm-tutor:llvm-15 + run: docker build . --file Dockerfile_archlinux --tag llvm-tutor:llvm-18 diff --git a/.github/workflows/docker-fedora.yml b/.github/workflows/docker-fedora.yml index 1c164b0a..cd05254e 100644 --- a/.github/workflows/docker-fedora.yml +++ b/.github/workflows/docker-fedora.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v2 - name: Build the Docker image - run: docker build . --file Dockerfile_fedora --tag llvm-tutor:llvm-17 + run: docker build . --file Dockerfile_fedora --tag llvm-tutor:llvm-18 diff --git a/.github/workflows/docker-ubuntu.yml b/.github/workflows/docker-ubuntu.yml index 84cfa28c..4a681859 100644 --- a/.github/workflows/docker-ubuntu.yml +++ b/.github/workflows/docker-ubuntu.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v2 - name: Build the Docker image - run: docker build . --file Dockerfile_ubuntu --tag llvm-tutor:llvm-17 + run: docker build . --file Dockerfile_ubuntu --tag llvm-tutor:llvm-18 diff --git a/.github/workflows/docker-ubunut-apt.yml b/.github/workflows/docker-ubunut-apt.yml index c04866dc..90573c40 100644 --- a/.github/workflows/docker-ubunut-apt.yml +++ b/.github/workflows/docker-ubunut-apt.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v2 - name: Build the Docker image - run: docker build . --file Dockerfile_ubuntu_apt --tag llvm-tutor:llvm-17 + run: docker build . --file Dockerfile_ubuntu_apt --tag llvm-tutor:llvm-18 diff --git a/Dockerfile_archlinux b/Dockerfile_archlinux index eaf41370..e20ec43b 100644 --- a/Dockerfile_archlinux +++ b/Dockerfile_archlinux @@ -5,8 +5,8 @@ # USAGE: # ```bash # wget https://raw.githubusercontent.com/banach-space/llvm-tutor/main/Dockerfile_archlinux -# docker build -t=llvm-tutor:llvm-14 . -# docker run --rm -it --hostname=llvm-tutor llvm-tutor:llvm-14 /bin/bash +# docker build -t=llvm-tutor:llvm-18 . +# docker run --rm -it --hostname=llvm-tutor llvm-tutor:llvm-18 /bin/bash # ``` # ============================================================================= @@ -19,6 +19,7 @@ ENV VENV_DIR /venv # 1. INSTALL DEPENDENCIES RUN pacman -Syu --noconfirm \ git \ + zstd \ cmake \ ninja \ gcc \ diff --git a/Dockerfile_fedora b/Dockerfile_fedora index d174309f..166c4991 100644 --- a/Dockerfile_fedora +++ b/Dockerfile_fedora @@ -5,12 +5,12 @@ # USAGE: # ```bash # wget https://raw.githubusercontent.com/banach-space/llvm-tutor/main/Dockerfile_fedora -# docker build -t=llvm-tutor:llvm-15 . -# docker run --rm -it --hostname=llvm-tutor llvm-tutor:llvm-15 /bin/bash +# docker build -t=llvm-tutor:llvm-18 . +# docker run --rm -it --hostname=llvm-tutor llvm-tutor:llvm-18 /bin/bash # ``` # ============================================================================= -FROM fedora:38 +FROM fedora:40 ENV LLVM_DIR /usr/ ENV TUTOR_DIR /llvm-tutor @@ -25,6 +25,7 @@ RUN dnf -y install \ llvm-devel \ clang \ zlib-devel \ + libzstd-devel \ python3-pip # 2. INSTALL LIT diff --git a/Dockerfile_ubuntu b/Dockerfile_ubuntu index 82eab6d8..325e8829 100644 --- a/Dockerfile_ubuntu +++ b/Dockerfile_ubuntu @@ -6,17 +6,18 @@ # USAGE: # ```bash # wget https://raw.githubusercontent.com/banach-space/llvm-tutor/main/Dockerfile_ubuntu -# docker build -t=llvm-tutor:llvm-16 . -# docker run --rm -it --hostname=llvm-tutor llvm-tutor:llvm-16 /bin/bash +# docker build -t=llvm-tutor:llvm-18 . +# docker run --rm -it --hostname=llvm-tutor llvm-tutor:llvm-18 /bin/bash # ``` # ============================================================================= -FROM debian:buster +FROM ubuntu:22.04 # 1. INSTALL DEPENDENCIES RUN apt-get update && apt-get install -y \ git \ cmake \ + libzstd-dev \ ninja-build \ build-essential \ python3-minimal python3-pip\ @@ -30,7 +31,7 @@ RUN pip3 install lit # reason, we need to add `-DLLVM_INSTALL_UTILS=ON` CMake flag when building # LLVM. ENV LLVM_DIR /opt/llvm -RUN git clone --branch release/17.x --depth 1 https://github.com/llvm/llvm-project \ +RUN git clone --branch release/18.x --depth 1 https://github.com/llvm/llvm-project \ && mkdir -p $LLVM_DIR \ && mkdir -p llvm-project/build \ && cd llvm-project/build \ diff --git a/Dockerfile_ubuntu_apt b/Dockerfile_ubuntu_apt index 13e9b754..267badd6 100644 --- a/Dockerfile_ubuntu_apt +++ b/Dockerfile_ubuntu_apt @@ -6,14 +6,14 @@ # USAGE: # ```bash # wget https://raw.githubusercontent.com/banach-space/llvm-tutor/main/Dockerfile_ubuntu_apt -# docker build -t=llvm-tutor:llvm-17 . -# docker run --rm -it --hostname=llvm-tutor llvm-tutor:llvm-17 /bin/bash +# docker build -t=llvm-tutor:llvm-18 . +# docker run --rm -it --hostname=llvm-tutor llvm-tutor:llvm-18 /bin/bash # ``` # ============================================================================= FROM ubuntu:22.04 -ENV LLVM_DIR /usr/lib/llvm-17/ +ENV LLVM_DIR /usr/lib/llvm-18/ ENV TUTOR_DIR /llvm-tutor # 1. INSTALL DEPENDENCIES @@ -30,13 +30,14 @@ RUN apt-get update && apt-get install -y \ build-essential \ python3-minimal python3-pip\ wget \ + libzstd-dev \ software-properties-common \ && rm -rf /var/lib/apt/lists/* RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - -RUN apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" +RUN apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" RUN apt-get update -RUN apt-get install -y llvm-17 llvm-17-dev llvm-17-tools clang-17 +RUN apt-get install -y llvm-18 llvm-18-dev llvm-18-tools clang-18 RUN apt-get install -y python3-setuptools # 2. INSTALL LIT @@ -50,8 +51,8 @@ RUN mkdir -p $TUTOR_DIR/hello-world-build \ && cd $TUTOR_DIR/hello-world-build \ && cmake -G Ninja -DLT_LLVM_INSTALL_DIR=$LLVM_DIR ../HelloWorld \ && ninja -RUN cd $TUTOR_DIR/hello-world-build && /usr/bin/clang-17 -S -O1 -emit-llvm ../inputs/input_for_hello.c -o input_for_hello.ll -RUN cd $TUTOR_DIR/hello-world-build && /usr/bin/opt-17 -load-pass-plugin ./libHelloWorld.so -passes=hello-world -disable-output input_for_hello.ll 2>&1 | grep "(llvm-tutor) Hello from: foo" +RUN cd $TUTOR_DIR/hello-world-build && /usr/bin/clang-18 -S -O1 -emit-llvm ../inputs/input_for_hello.c -o input_for_hello.ll +RUN cd $TUTOR_DIR/hello-world-build && /usr/bin/opt-18 -load-pass-plugin ./libHelloWorld.so -passes=hello-world -disable-output input_for_hello.ll 2>&1 | grep "(llvm-tutor) Hello from: foo" # 5. BUILD AND RUN LLVM-TUTOR RUN mkdir -p $TUTOR_DIR/build \ diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 742a0857..6cdc8de8 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -10,6 +10,11 @@ target_include_directories( PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../include") -target_link_libraries(static - LLVMCore LLVMPasses LLVMIRReader LLVMSupport -) +if(UNIX AND EXISTS "/etc/arch-release") + message("LLVM is installed as shared library on Arch Linux") + target_link_libraries(static LLVM) +else() + target_link_libraries(static + LLVMCore LLVMPasses LLVMIRReader LLVMSupport + ) +endif()