Skip to content

Build Failure on Termux with LLVM 20 due to find_package incompatibility #1328

@Manamama-Gemini-Cloud-AI-01

Description

This is an update to the situation first described in #1061.

Problem

With llvmlite now requiring LLVM 20, the previous workaround of using LLVM 14 is no longer valid. Attempting to build llvmlite from source on Termux with the system-provided LLVM 20 fails during the CMake configuration step.

Root Cause

The build fails because llvmlite uses the standard find_package(LLVM REQUIRED CONFIG) command. This fails on Termux because the libllvm-20 package contains a faulty CMake manifest (LLVMExports.cmake) that incorrectly defines and requires a static library (libLLVMCGData.a) that doesn't exist in the shared-only package.

Successful Workaround

A successful build was achieved by modifying ffi/CMakeLists.txt to bypass the faulty find_package command and use the llvm-config-20 tool directly.

1. Patch ffi/CMakeLists.txt:

Replace the line find_package(LLVM REQUIRED CONFIG) with the following block:

# --- Start of llvm-config patch ---
# Use llvm-config to bypass the faulty CMake export files.
find_program(LLVM_CONFIG_EXECUTABLE llvm-config-20 HINTS /data/data/com.termux/files/usr/bin)
if(NOT LLVM_CONFIG_EXECUTABLE)
    message(FATAL_ERROR "llvm-config-20 not found! Please ensure it is in your PATH.")
endif()

# Get version for the version check
execute_process(COMMAND ${LLVM_CONFIG_EXECUTABLE} --version OUTPUT_VARIABLE LLVM_PACKAGE_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "([0-9]+)" LLVM_VERSION_MAJOR "${LLVM_PACKAGE_VERSION}")

# Get include dirs and definitions
execute_process(COMMAND ${LLVM_CONFIG_EXECUTABLE} --cxxflags OUTPUT_VARIABLE LLVM_CXX_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCHALL "-I[^ ]+" LLVM_INCLUDE_DIRS_RAW "${LLVM_CXX_FLAGS}")
foreach(dir ${LLVM_INCLUDE_DIRS_RAW})
    string(REPLACE "-I" "" dir_stripped ${dir})
    list(APPEND LLVM_INCLUDE_DIRS ${dir_stripped})
endforeach()
string(REGEX MATCHALL "-D[^ ]+" LLVM_DEFINITIONS "${LLVM_CXX_FLAGS}")

# Get the main shared library for linking
execute_process(COMMAND ${LLVM_CONFIG_EXECUTABLE} --link-shared --libs OUTPUT_VARIABLE llvm_libs OUTPUT_STRIP_TRAILING_WHITESPACE)
# --- End of llvm-config patch ---

2. Build Command:

After applying the patch and ensuring a clean build directory, the installation was successful with the following command:

LLVMLITE_SHARED=ON LLVMLITE_USE_RTTI=OFF pip install . -U --force-reinstall

Clean Build Log

Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cpu
Processing /data/data/com.termux/files/home/Downloads/GitHub/llvmlite
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Building wheels for collected packages: llvmlite
  Building wheel for llvmlite (setup.py): started
  Building wheel for llvmlite (setup.py): finished with status 'done'
  Created wheel for llvmlite: filename=llvmlite-0.46.0b1+14.g7c0e103.dirty-cp312-cp312-linux_aarch64.whl size=1602828 sha256=a77af22e420d0091c882d05d7e165923241386e46fc33d4b0d5ca1c33e835245
  Stored in directory: /data/data/com.termux/files/usr/tmp/pip-ephem-wheel-cache-q1687gvq/wheels/c0/2e/9e/8fb4cf2bfad383accfc8ef3cdfae92204801101f334763f467
Successfully built llvmlite
Installing collected packages: llvmlite
Successfully installed llvmlite-0.46.0b1+14.g7c0e103.dirty

Suggestion

It might be beneficial for llvmlite's build system to have a fallback or an explicit option to use llvm-config instead of find_package. This would make it more robust against packaging issues like the one found in the Termux libllvm-20 package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions