From 1361088f7bd8c2d9c9f9b5859d6cea5230d79fdf Mon Sep 17 00:00:00 2001 From: Andrzej Warzynski Date: Sun, 2 Oct 2022 17:57:27 +0100 Subject: [PATCH] Fix the special treatment for Homebrew When using Homebrew packages, `static` needs to be linked with `libLLVM` rather than a more specialised set of LLVM libraries. But this only applies to Homebrew packages. This patch fixes how llvm-tutor decides whether to use `libLLVM` or not. --- .../x86-darwin-llvm-from-sources.yml | 3 +- .../x86-ubuntu-llvm-from-sources-static.yml | 1 - .../x86-ubuntu-llvm-from-sources.yml | 3 +- tools/CMakeLists.txt | 30 ++++++++++++++----- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/.github/workflows/x86-darwin-llvm-from-sources.yml b/.github/workflows/x86-darwin-llvm-from-sources.yml index 0a801659..8055af90 100644 --- a/.github/workflows/x86-darwin-llvm-from-sources.yml +++ b/.github/workflows/x86-darwin-llvm-from-sources.yml @@ -29,10 +29,9 @@ jobs: cmake -G Ninja \ -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" \ -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_OPTIMIZED_TABLEGEN=ON \ - -DLLVM_BUILD_LLVM_DYLIB=ON \ ../llvm # Note that only the required tools are built - ninja clang opt lli not FileCheck LLVM + ninja clang opt lli not FileCheck - name: Install lit run: | sudo pip3 install lit diff --git a/.github/workflows/x86-ubuntu-llvm-from-sources-static.yml b/.github/workflows/x86-ubuntu-llvm-from-sources-static.yml index 2b151382..379de7dc 100644 --- a/.github/workflows/x86-ubuntu-llvm-from-sources-static.yml +++ b/.github/workflows/x86-ubuntu-llvm-from-sources-static.yml @@ -34,7 +34,6 @@ jobs: cmake -G Ninja \ -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" \ -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_OPTIMIZED_TABLEGEN=ON \ - -DLLVM_BUILD_LLVM_DYLIB=ON \ -DLLVM_BUILD_EXAMPLES=On -DLLVM_MBASUB_LINK_INTO_TOOLS=On \ ../llvm # Note that only the required tools are built diff --git a/.github/workflows/x86-ubuntu-llvm-from-sources.yml b/.github/workflows/x86-ubuntu-llvm-from-sources.yml index 6a6e94dd..2fdb4e63 100644 --- a/.github/workflows/x86-ubuntu-llvm-from-sources.yml +++ b/.github/workflows/x86-ubuntu-llvm-from-sources.yml @@ -32,10 +32,9 @@ jobs: cmake -G Ninja \ -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" \ -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_OPTIMIZED_TABLEGEN=ON \ - -DLLVM_BUILD_LLVM_DYLIB=ON \ ../llvm # Note that only the required tools are built - ninja clang opt lli not FileCheck LLVM + ninja clang opt lli not FileCheck - name: Install lit run: | sudo apt-get install python3-setuptools diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index f1184834..77d12b67 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,3 +1,6 @@ +# TODO: Once LLVM 16 is released, replace `try_compile` with a test for +# LLVM_ENABLE_LTO, see https://reviews.llvm.org/D134936. + # DEFINE THE TARGET #================== set(static_SOURCES @@ -14,25 +17,36 @@ target_include_directories( # DECIDE WHAT LIBRARIES TO LINK IN #================================= -# The list of the libraries below is the required minimum. However, when using -# LLVM from Homebrew your system linker might complain when using these: +# The minimal list of the required LLVM libraries. +set(libs LLVMCore LLVMPasses LLVMIRReader LLVMSupport) + +# The list above won't work when using LLVM from Homebrew. Indeed, your system +# linker will most likely complain: # ``` # (...) Opaque pointers are only supported in -opaque-pointers mode (Producer: 'LLVM15.0.0' Reader: 'LLVM APPLE_1_1400.0.29.102_0') # ``` -# To work around this this, you can use `libLLVM` instead. That solves the -# problem because: +# That's more or less due to Homebrew packages being built with LTO (i.e. +# LLVM_ENABLE_LTO set to "ON") To work around this, you can use `libLLVM` +# instead. That solves the problem because: # * `libLLVM` is always a dynamic library (and the problem above is only # triggered for static libs) # * libLLVM includes all LLVM libraries (i.e. all the libraries listed below # _and more_) -set(libs "LLVMCore LLVMPasses LLVMIRReader LLVMSupport") - -try_compile(testMinimalCompilation "${CMAKE_BINARY_DIR}/temp" SOURCES ${static_SOURCES}) +# Check whether the default set-up is sufficient ... +try_compile(testMinimalCompilation "${CMAKE_BINARY_DIR}/temp" + SOURCES ${static_SOURCES} + LINK_LIBRARIES ${libs} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES=${CMAKE_CURRENT_SOURCE_DIR}/../include;${LLVM_INCLUDE_DIRS}" + "-DLINK_DIRECTORIES=${LLVM_LIBRARY_DIRS}") +# ... if not, use libLLVM if(NOT ${testMinimalCompilation}) - set(libs "LLVM") + set(libs LLVM) endif() +# ADD THE LIBRARIES TO LINK +#========================== target_link_libraries(static ${libs} )