|
9 | 9 | import tarfile |
10 | 10 | import urllib.request |
11 | 11 | from distutils.version import LooseVersion |
| 12 | +from typing import NamedTuple |
12 | 13 |
|
13 | 14 | from setuptools import Extension, setup |
14 | 15 | from setuptools.command.build_ext import build_ext |
@@ -38,34 +39,42 @@ def use_system_llvm(): |
38 | 39 |
|
39 | 40 |
|
40 | 41 | def get_thirdparty_packages(triton_cache_path): |
| 42 | + class Package(NamedTuple): |
| 43 | + package: str |
| 44 | + name: str |
| 45 | + url: str |
| 46 | + test_file: str |
| 47 | + include_flag: str |
| 48 | + lib_flag: str |
| 49 | + |
41 | 50 | packages = [ |
42 | | - ("pybind11", "pybind11-2.10.0", "https://github.com/pybind/pybind11/archive/refs/tags/v2.10.0.tar.gz", "include/pybind11/pybind11.h", "PYBIND11_INCLUDE_DIR", "") |
| 51 | + Package("pybind11", "pybind11-2.10.0", "https://github.com/pybind/pybind11/archive/refs/tags/v2.10.0.tar.gz", "include/pybind11/pybind11.h", "PYBIND11_INCLUDE_DIR", "") |
43 | 52 | ] |
44 | 53 | if not use_system_llvm(): |
45 | 54 | # donwload LLVM if no suitable system LLVM is installed |
46 | 55 | packages.append( |
47 | | - ("llvm", "clang+llvm-11.0.1-x86_64-linux-gnu-ubuntu-16.04", "https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.1/clang+llvm-11.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz", "lib", "LLVM_INCLUDE_DIRS", "LLVM_LIBRARY_DIR") |
| 56 | + Package("llvm", "clang+llvm-11.0.1-x86_64-linux-gnu-ubuntu-16.04", "https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.1/clang+llvm-11.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz", "lib", "LLVM_INCLUDE_DIRS", "LLVM_LIBRARY_DIR") |
48 | 57 | ) |
49 | 58 |
|
50 | 59 | thirdparty_cmake_args = [] |
51 | | - for package, name, url, test_file, include_flag, lib_flag in packages: |
52 | | - package_root_dir = os.path.join(triton_cache_path, package) |
53 | | - package_dir = os.path.join(package_root_dir, name) |
54 | | - test_file_path = os.path.join(package_dir, test_file) |
| 60 | + for p in packages: |
| 61 | + package_root_dir = os.path.join(triton_cache_path, p.package) |
| 62 | + package_dir = os.path.join(package_root_dir, p.name) |
| 63 | + test_file_path = os.path.join(package_dir, p.test_file) |
55 | 64 | if not os.path.exists(test_file_path): |
56 | 65 | try: |
57 | 66 | shutil.rmtree(package_root_dir) |
58 | 67 | except Exception: |
59 | 68 | pass |
60 | 69 | os.makedirs(package_root_dir, exist_ok=True) |
61 | | - print('downloading and extracting {} ...'.format(url)) |
62 | | - ftpstream = urllib.request.urlopen(url) |
| 70 | + print('downloading and extracting {} ...'.format(p.url)) |
| 71 | + ftpstream = urllib.request.urlopen(p.url) |
63 | 72 | file = tarfile.open(fileobj=ftpstream, mode="r|*") |
64 | 73 | file.extractall(path=package_root_dir) |
65 | | - if include_flag: |
66 | | - thirdparty_cmake_args.append("-D{}={}/include".format(include_flag, package_dir)) |
67 | | - if lib_flag: |
68 | | - thirdparty_cmake_args.append("-D{}={}/lib".format(lib_flag, package_dir)) |
| 74 | + if p.include_flag: |
| 75 | + thirdparty_cmake_args.append("-D{}={}/include".format(p.include_flag, package_dir)) |
| 76 | + if p.lib_flag: |
| 77 | + thirdparty_cmake_args.append("-D{}={}/lib".format(p.lib_flag, package_dir)) |
69 | 78 | return thirdparty_cmake_args |
70 | 79 |
|
71 | 80 |
|
|
0 commit comments