Skip to content

Commit 5232f98

Browse files
committed
fix: Make LLVM optional on Windows
- Official LLVM Windows installers don't include CMake config files - Make LLVM optional on Windows, required on Unix - Set LLVM_AVAILABLE flag to track whether LLVM is found - Add USE_LLVM_BACKEND compilation flag when LLVM is available - Conditionally compile LLVM-dependent code - Build succeeds without LLVM on Windows Windows builds will work without LLVM backend optimization. Unix builds still require LLVM for full functionality.
1 parent acc6390 commit 5232f98

2 files changed

Lines changed: 35 additions & 22 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,22 @@ jobs:
7777
Add-Content $env:GITHUB_PATH "$llvmRoot/bin"
7878
Add-Content $env:GITHUB_ENV "LLVM_DIR=$llvmDir"
7979
Add-Content $env:GITHUB_ENV "LLVM_ROOT=$llvmRoot"
80+
Add-Content $env:GITHUB_ENV "LLVM_AVAILABLE=1"
8081
8182
Write-Host "✓ LLVM installed at: $llvmRoot"
8283
Write-Host "✓ LLVM_DIR set to: $llvmDir"
8384
} else {
84-
Write-Host "✗ Could not find LLVMConfig.cmake after installation"
85-
Write-Host "Listing LLVM directory structure..."
86-
Get-ChildItem -Path $llvmRoot -Recurse -Directory | Select-Object -First 20 | ForEach-Object { Write-Host $_.FullName }
87-
exit 1
85+
Write-Host "✗ LLVMConfig.cmake not found - LLVM backend will be disabled"
86+
Write-Host "Building without LLVM support on Windows"
87+
Add-Content $env:GITHUB_ENV "LLVM_AVAILABLE=0"
8888
}
8989
9090
- name: Install Ninja (Windows)
9191
if: matrix.os == 'windows-latest'
9292
run: choco install ninja -y
9393

9494
- name: Debug LLVM Configuration (Windows)
95-
if: matrix.os == 'windows-latest'
95+
if: matrix.os == 'windows-latest' && env.LLVM_AVAILABLE == '1'
9696
shell: pwsh
9797
run: |
9898
Write-Host "LLVM_DIR: $env:LLVM_DIR"

CMakeLists.txt

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,28 @@ if(WIN32)
4747
endif()
4848

4949
# --- LLVM Configuration ---
50-
find_package(LLVM CONFIG REQUIRED)
50+
if(WIN32)
51+
# Try to find LLVM, but don't require it on Windows
52+
find_package(LLVM CONFIG QUIET)
53+
else()
54+
# LLVM is required on Unix platforms
55+
find_package(LLVM CONFIG REQUIRED)
56+
endif()
5157

5258
if(NOT LLVM_FOUND)
53-
message(FATAL_ERROR "LLVM not found! Please install LLVM and set LLVM_DIR.")
59+
if(WIN32)
60+
message(WARNING "LLVM not found. Building without LLVM backend support on Windows.")
61+
else()
62+
message(FATAL_ERROR "LLVM not found! Please install LLVM and set LLVM_DIR.")
63+
endif()
64+
else()
65+
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
66+
message(STATUS "LLVM Include Dirs: ${LLVM_INCLUDE_DIRS}")
67+
message(STATUS "LLVM Library Dirs: ${LLVM_LIBRARY_DIRS}")
68+
message(STATUS "LLVM Definitions: ${LLVM_DEFINITIONS}")
69+
add_definitions(-DUSE_LLVM_BACKEND)
5470
endif()
5571

56-
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
57-
message(STATUS "LLVM Include Dirs: ${LLVM_INCLUDE_DIRS}")
58-
message(STATUS "LLVM Library Dirs: ${LLVM_LIBRARY_DIRS}")
59-
message(STATUS "LLVM Definitions: ${LLVM_DEFINITIONS}")
60-
6172
# --- LibFFI Configuration ---
6273
# specialized find_package might be needed if not in standard path, but let's try standard first
6374
find_package(PkgConfig QUIET)
@@ -82,19 +93,21 @@ else()
8293
message(WARNING "LibFFI not found. FFI features will be disabled.")
8394
endif()
8495

85-
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
86-
add_definitions(${LLVM_DEFINITIONS})
96+
if(LLVM_FOUND)
97+
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
98+
add_definitions(${LLVM_DEFINITIONS})
8799

88-
# Explicitly add LLVM library directories
89-
link_directories(${LLVM_LIBRARY_DIRS})
90-
91-
if(WIN32)
92-
# Additional linking configuration for Windows
100+
# Explicitly add LLVM library directories
93101
link_directories(${LLVM_LIBRARY_DIRS})
94-
endif()
95102

96-
# Map generic components to specific libs
97-
llvm_map_components_to_libnames(llvm_libs core support executionengine native ipo analysis transformutils bitwriter)
103+
if(WIN32)
104+
# Additional linking configuration for Windows
105+
link_directories(${LLVM_LIBRARY_DIRS})
106+
endif()
107+
108+
# Map generic components to specific libs
109+
llvm_map_components_to_libnames(llvm_libs core support executionengine native ipo analysis transformutils bitwriter)
110+
endif()
98111

99112
# Export symbols for Windows DLL
100113
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

0 commit comments

Comments
 (0)