Files
dragonpilot/tinygrad_repo/tinygrad/runtime/support/llvm.py
T
Vehicle Researcher db5cbadcf2 openpilot v0.9.9 release
date: 2025-06-05T19:54:08
master commit: 8aadf02b2fd91f4e1285e18c2c7feb32d93b66f5
2025-06-12 14:30:06 -07:00

26 lines
1.5 KiB
Python

import ctypes, ctypes.util, os, sys, subprocess
from tinygrad.helpers import DEBUG, OSX, getenv
if sys.platform == 'win32':
# Windows llvm distribution doesn't seem to add itself to PATH or anywhere else where it can be easily retrieved from.
# winget also doesn't have something like `brew --prefix llvm` so just hardcode default installation path with an option to override
LLVM_PATH = getenv('LLVM_PATH', 'C:\\Program Files\\LLVM\\bin\\LLVM-C.dll')
if not os.path.exists(LLVM_PATH):
raise FileNotFoundError('LLVM not found, you can install it with `winget install LLVM.LLVM` or point at a custom dll with LLVM_PATH')
elif OSX:
# Will raise FileNotFoundError if brew is not installed
# `brew --prefix` will return even if formula is not installed
if not os.path.exists(brew_prefix:=subprocess.check_output(['brew', '--prefix', 'llvm@19']).decode().strip()):
raise FileNotFoundError('LLVM not found, you can install it with `brew install llvm@19`')
LLVM_PATH: str|None = os.path.join(brew_prefix, 'lib', 'libLLVM.dylib')
else:
LLVM_PATH = ctypes.util.find_library('LLVM')
# use newer LLVM if possible
for ver in reversed(range(14, 19+1)):
if LLVM_PATH is not None: break
LLVM_PATH = ctypes.util.find_library(f'LLVM-{ver}')
if LLVM_PATH is None:
raise FileNotFoundError("No LLVM library found on the system. Install it via your distro's package manager and ensure it's findable as 'LLVM'")
if DEBUG>=3: print(f'Using LLVM at {repr(LLVM_PATH)}')