Skip to content

Commit

Permalink
Fix the special treatment for Homebrew
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
banach-space committed Oct 3, 2022
1 parent 65e163b commit 1361088
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/x86-darwin-llvm-from-sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/x86-ubuntu-llvm-from-sources-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/x86-ubuntu-llvm-from-sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 22 additions & 8 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}
)

0 comments on commit 1361088

Please sign in to comment.