|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import subprocess |
| 4 | +import shutil |
| 5 | +import glob |
| 6 | + |
| 7 | +IS_WIN = False |
| 8 | +IS_LIN = False |
| 9 | + |
| 10 | +if "linux" in sys.platform: |
| 11 | + IS_LIN = True |
| 12 | +elif sys.platform in ["win32", "cygwin"]: |
| 13 | + IS_WIN = True |
| 14 | +else: |
| 15 | + assert False, sys.platform + " not supported" |
| 16 | + |
| 17 | +ONEAPI_ROOT = os.environ.get("ONEAPI_ROOT") |
| 18 | + |
| 19 | +if IS_LIN: |
| 20 | + DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler/latest/linux") |
| 21 | +if IS_WIN: |
| 22 | + DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler\latest\windows") |
| 23 | + |
| 24 | +dpctl_dir = os.getcwd() |
| 25 | +build_cmake_dir = os.path.join(dpctl_dir, "build_cmake") |
| 26 | +if os.path.exists(build_cmake_dir): |
| 27 | + shutil.rmtree(build_cmake_dir) |
| 28 | +os.mkdir(build_cmake_dir) |
| 29 | +os.chdir(build_cmake_dir) |
| 30 | + |
| 31 | +INSTALL_PREFIX = os.path.join(dpctl_dir, "install") |
| 32 | +if os.path.exists(INSTALL_PREFIX): |
| 33 | + shutil.rmtree(INSTALL_PREFIX) |
| 34 | + |
| 35 | +backends_dir = os.path.join(dpctl_dir, "backends") |
| 36 | + |
| 37 | +if IS_LIN: |
| 38 | + cmake_args = [ |
| 39 | + "cmake", |
| 40 | + "-DCMAKE_BUILD_TYPE=Release", |
| 41 | + "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, |
| 42 | + "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, |
| 43 | + "-DDPCPP_ROOT=" + DPCPP_ROOT, |
| 44 | + "-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "clang"), |
| 45 | + "-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "clang++"), |
| 46 | + backends_dir, |
| 47 | + ] |
| 48 | + subprocess.check_call(cmake_args, stderr=subprocess.STDOUT, shell=False) |
| 49 | + subprocess.check_call(["make", "-j", "4"]) |
| 50 | + subprocess.check_call(["make", "install"]) |
| 51 | + |
| 52 | + os.chdir(dpctl_dir) |
| 53 | + for file in glob.glob(os.path.join(dpctl_dir, "install", "lib", "*.so")): |
| 54 | + shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) |
| 55 | + |
| 56 | +if IS_WIN: |
| 57 | + cmake_args = [ |
| 58 | + "cmake", |
| 59 | + "-G", |
| 60 | + "Ninja", |
| 61 | + "-DCMAKE_BUILD_TYPE=Release", |
| 62 | + "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, |
| 63 | + "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, |
| 64 | + "-DDPCPP_ROOT=" + DPCPP_ROOT, |
| 65 | + backends_dir, |
| 66 | + ] |
| 67 | + subprocess.check_call(cmake_args, stderr=subprocess.STDOUT, shell=True) |
| 68 | + subprocess.check_call(["ninja", "-n"]) |
| 69 | + subprocess.check_call(["ninja", "install"]) |
| 70 | + |
| 71 | + os.chdir(dpctl_dir) |
| 72 | + for file in glob.glob(os.path.join(dpctl_dir, "install", "lib", "*.lib")): |
| 73 | + shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) |
| 74 | + |
| 75 | + for file in glob.glob(os.path.join(dpctl_dir, "install", "bin", "*.dll")): |
| 76 | + shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) |
| 77 | + |
| 78 | +include_dir = os.path.join(dpctl_dir, "dpctl", "include") |
| 79 | +if os.path.exists(include_dir): |
| 80 | + shutil.rmtree(include_dir) |
| 81 | + |
| 82 | +shutil.copytree(os.path.join(dpctl_dir, "backends", "include"), include_dir) |
0 commit comments