From 397a81d5bd7957c25ebc4ad48bd86189f9ddf4e5 Mon Sep 17 00:00:00 2001 From: Mark Wiebe Date: Sat, 25 Aug 2012 13:21:38 -0700 Subject: [PATCH] Switch to using a fake llvm-config program, so there's just one setup.py This should help keep windows and other platforms in synch easier. --- llvm-config-win32.py | 70 +++++++++++++++++++ setup-win32.py | 161 ------------------------------------------- setup.py | 15 +++- 3 files changed, 83 insertions(+), 163 deletions(-) create mode 100644 llvm-config-win32.py delete mode 100644 setup-win32.py diff --git a/llvm-config-win32.py b/llvm-config-win32.py new file mode 100644 index 0000000..db9de65 --- /dev/null +++ b/llvm-config-win32.py @@ -0,0 +1,70 @@ +import sys, os + +def find_path_of(filename): + """Finds the path from $PATH where the file exists, returns None if not found.""" + pathlist = os.getenv('PATH').split(os.pathsep) + for path in pathlist: + if os.path.exists(os.path.join(path, filename)): + return os.path.abspath(path) + return None + +if sys.argv[1] == '--version': + cmd = 'llvm-tblgen --version' + # Hardcoded extraction, only tested on llvm 3.1 + result = os.popen(cmd).read().split('\n')[1].strip().split(' ')[2] + print result +elif sys.argv[1] == '--libs': + # NOTE: instead of actually looking at the components requested, + # we just spit out a bunch of libs + for lib in """ +LLVMAnalysis +LLVMAsmParser +LLVMAsmPrinter +LLVMBitReader +LLVMBitWriter +LLVMCodeGen +LLVMCore +LLVMExecutionEngine +LLVMInstCombine +LLVMInstrumentation +LLVMInterpreter +LLVMipa +LLVMipo +LLVMJIT +LLVMLinker +LLVMMC +LLVMMCParser +LLVMScalarOpts +LLVMSelectionDAG +LLVMSupport +LLVMTarget +LLVMTransformUtils +LLVMVectorize +LLVMX86AsmParser +LLVMX86AsmPrinter +LLVMX86CodeGen +LLVMX86Desc +LLVMX86Info +LLVMX86Utils +Advapi32 +Shell32 +""".split(): + print('-l%s' % lib) +elif sys.argv[1] == '--includedir': + llvmbin = find_path_of('llvm-tblgen.exe') + if llvmbin is None: + raise RuntimeError('Could not find LLVM') + incdir = os.path.abspath(os.path.join(llvmbin, '../include')) + if not os.path.exists(os.path.join(incdir, 'llvm/BasicBlock.h')): + raise RuntimeError('Could not find LLVM include dir') + print incdir +elif sys.argv[1] == '--libdir': + llvmbin = find_path_of('llvm-tblgen.exe') + if llvmbin is None: + raise RuntimeError('Could not find LLVM') + libdir = os.path.abspath(os.path.join(llvmbin, '../lib')) + if not os.path.exists(os.path.join(libdir, 'LLVMCore.lib')): + raise RuntimeError('Could not find LLVM lib dir') + print libdir +else: + raise RuntimeError('Unrecognized llvm-config command %s' % sys.argv[1]) diff --git a/setup-win32.py b/setup-win32.py deleted file mode 100644 index 7001b6f..0000000 --- a/setup-win32.py +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2008, Mahadevan R All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of this software, nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -import sys, os -import os.path -from distutils.core import setup, Extension - -LLVM_PY_VERSION = '0.7' - - -def get_libs_and_objs(llvm_lib_dir): - # Libraries that are not included in the build - not_required_libs = """ -BrainF -bugpoint -Fibonacci -HowToUseJIT -Kaleidoscope -llc -lli -llvm-as -llvm-bcanalyzer -llvm-extract -llvm-ld -llvm-link -llvm-mc -LLVMArchive -LLVMAsmPrinter -LLVMHello -LLVMDebugger -llvm_headers_do_not_build -ModuleMaker -opt -tblgen -""" - libs = """ -LLVMAnalysis -LLVMAsmParser -LLVMAsmPrinter -LLVMBitReader -LLVMBitWriter -LLVMCodeGen -LLVMCore -LLVMExecutionEngine -LLVMInstCombine -LLVMInstrumentation -LLVMInterpreter -LLVMipa -LLVMipo -LLVMJIT -LLVMLinker -LLVMMC -LLVMMCParser -LLVMScalarOpts -LLVMSelectionDAG -LLVMSupport -LLVMTarget -LLVMTransformUtils -LLVMVectorize -LLVMX86AsmParser -LLVMX86AsmPrinter -LLVMX86CodeGen -LLVMX86Desc -LLVMX86Info -LLVMX86Utils -Advapi32 -Shell32 -""".split() - return (libs, []) - - -def get_llvm_config(): - - # get from command-line, or use default - llvm_dir = r'C:\Program Files\LLVM 3.1.1' - i = 0 - while i < len(sys.argv): - arg = sys.argv[i] - if arg.startswith('--llvm-dir='): - del sys.argv[i] - llvm_dir = arg.split('=')[1] - else: - i += 1 - good = os.path.isdir( llvm_dir ) - return (llvm_dir, good) - - -def call_setup(llvm_dir): - incdirs = [os.path.join(llvm_dir, 'include')] - libdir = os.path.join(llvm_dir, 'lib') - - libs_core, objs_core = get_libs_and_objs(libdir) - std_libs = [] - - ext_core = Extension( - 'llvm._core', - ['llvm/_core.cpp', 'llvm/wrap.cpp', 'llvm/extra.cpp'], - include_dirs = incdirs, - library_dirs = [libdir], - libraries = std_libs + libs_core, - language = 'c++' ) - - setup( - name='llvm-py', - version=LLVM_PY_VERSION, - description='Python Bindings for LLVM', - author='Mahadevan R', - author_email='mdevan@mdevan.org', - url='http://www.mdevan.org/llvm-py/', - packages=['llvm'], - py_modules = [ 'llvm.core' ], - ext_modules = [ ext_core ],) - - -def main(): - - # get llvm config - llvm_dir, is_good = get_llvm_config() - print("Using llvm-dir=" + llvm_dir) - if not is_good: - print("Cannot find llvm-dir") - print("Try again with --llvm-dir=/path/to/llvm-top-dir.") - return 1 - - # setup - call_setup(llvm_dir) - - # done - return 0 - - -ev = main() -sys.exit(ev) diff --git a/setup.py b/setup.py index f5338d0..e8d9e58 100644 --- a/setup.py +++ b/setup.py @@ -4,8 +4,13 @@ import re from distutils.core import setup, Extension +# On win32, there is a fake llvm-config since llvm doesn't supply one +if sys.platform == 'win32': + default_llvm_config = 'python llvm-config-win32.py' +else: + default_llvm_config = 'llvm-config' -llvm_config = os.environ.get('LLVM_CONFIG_PATH', 'llvm-config') +llvm_config = os.environ.get('LLVM_CONFIG_PATH', default_llvm_config) # set LLVMPY_DYNLINK=1, if you want to link _core.so dynamically to libLLVM.so dynlink = int(os.environ.get('LLVMPY_DYNLINK', 0)) @@ -61,7 +66,10 @@ if dynlink: libs_core = ['LLVM-%d.%d' % llvm_version] objs_core = [] else: - if llvm_version <= (3, 1): # select between PTX & NVPTX + if sys.platform == 'win32': + print('PTX is disabled on Win32 at the moment') + ptx_components = [] + elif llvm_version <= (3, 1): # select between PTX & NVPTX print('Using PTX') ptx_components = ['ptx', 'ptxasmprinter', @@ -86,6 +94,9 @@ std_libs = ['pthread', 'm', 'stdc++', 'dl'] extra_link_args = ["-fPIC"] if sys.platform == 'darwin': std_libs.append("ffi") +elif sys.platform == 'win32': + std_libs = [] + extra_link_args = [] kwds = dict(ext_modules = [Extension( name='llvm._core',