|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# ***************************************************************************** |
| 3 | +# Copyright (c) 2016-2023, Intel Corporation |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Redistribution and use in source and binary forms, with or without |
| 7 | +# modification, are permitted provided that the following conditions are met: |
| 8 | +# - Redistributions of source code must retain the above copyright notice, |
| 9 | +# this list of conditions and the following disclaimer. |
| 10 | +# - Redistributions in binary form must reproduce the above copyright notice, |
| 11 | +# this list of conditions and the following disclaimer in the documentation |
| 12 | +# and/or other materials provided with the distribution. |
| 13 | +# |
| 14 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 15 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 18 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 19 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 20 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 22 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 23 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 24 | +# THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | +# ***************************************************************************** |
| 26 | + |
| 27 | +import os |
| 28 | +import subprocess |
| 29 | +import sys |
| 30 | +import dpctl |
| 31 | + |
| 32 | + |
| 33 | +def run( |
| 34 | + use_oneapi=True, |
| 35 | + build_type="Release", |
| 36 | + c_compiler=None, |
| 37 | + cxx_compiler=None, |
| 38 | + compiler_root=None, |
| 39 | + cmake_executable=None, |
| 40 | + verbose=False, |
| 41 | + cmake_opts="", |
| 42 | +): |
| 43 | + build_system = None |
| 44 | + |
| 45 | + if "linux" in sys.platform: |
| 46 | + build_system = "Ninja" |
| 47 | + elif sys.platform in ["win32", "cygwin"]: |
| 48 | + build_system = "Ninja" |
| 49 | + else: |
| 50 | + assert False, sys.platform + " not supported" |
| 51 | + |
| 52 | + setup_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 53 | + cmake_args = [ |
| 54 | + sys.executable, |
| 55 | + "setup.py", |
| 56 | + "develop", |
| 57 | + ] |
| 58 | + if cmake_executable: |
| 59 | + cmake_args += [ |
| 60 | + "--cmake-executable=" + cmake_executable, |
| 61 | + ] |
| 62 | + dpctl_module_path = os.path.join(dpctl.get_include(), "..", "resources", "cmake") |
| 63 | + cmake_args += [ |
| 64 | + "--build-type=" + build_type, |
| 65 | + "--generator=" + build_system, |
| 66 | + "--", |
| 67 | + "-DCMAKE_C_COMPILER:PATH=" + c_compiler, |
| 68 | + "-DCMAKE_CXX_COMPILER:PATH=" + cxx_compiler, |
| 69 | + "-DDPCTL_MODULE_PATH:PATH=" + dpctl_module_path, |
| 70 | + ] |
| 71 | + if verbose: |
| 72 | + cmake_args += [ |
| 73 | + "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON", |
| 74 | + ] |
| 75 | + if cmake_opts: |
| 76 | + cmake_args += cmake_opts.split() |
| 77 | + if use_oneapi: |
| 78 | + if "DPL_ROOT" in os.environ: |
| 79 | + os.environ["DPL_ROOT_HINT"] = os.environ["DPL_ROOT"] |
| 80 | + subprocess.check_call( |
| 81 | + cmake_args, shell=False, cwd=setup_dir, env=os.environ |
| 82 | + ) |
| 83 | + |
| 84 | + |
| 85 | +if __name__ == "__main__": |
| 86 | + import argparse |
| 87 | + |
| 88 | + parser = argparse.ArgumentParser( |
| 89 | + description="Driver to build dpnp for in-place installation" |
| 90 | + ) |
| 91 | + driver = parser.add_argument_group(title="Coverage driver arguments") |
| 92 | + driver.add_argument("--c-compiler", help="Name of C compiler", default=None) |
| 93 | + driver.add_argument( |
| 94 | + "--cxx-compiler", help="Name of C++ compiler", default=None |
| 95 | + ) |
| 96 | + driver.add_argument( |
| 97 | + "--oneapi", |
| 98 | + help="Set if using one-API installation", |
| 99 | + dest="oneapi", |
| 100 | + action="store_true", |
| 101 | + ) |
| 102 | + driver.add_argument( |
| 103 | + "--debug", |
| 104 | + default="Release", |
| 105 | + const="Debug", |
| 106 | + action="store_const", |
| 107 | + help="Set the compilation mode to debugging", |
| 108 | + ) |
| 109 | + driver.add_argument( |
| 110 | + "--compiler-root", |
| 111 | + type=str, |
| 112 | + help="Path to compiler home directory", |
| 113 | + default=None, |
| 114 | + ) |
| 115 | + driver.add_argument( |
| 116 | + "--cmake-executable", |
| 117 | + type=str, |
| 118 | + help="Path to cmake executable", |
| 119 | + default=None, |
| 120 | + ) |
| 121 | + driver.add_argument( |
| 122 | + "--verbose", |
| 123 | + help="Build using vebose makefile mode", |
| 124 | + dest="verbose", |
| 125 | + action="store_true", |
| 126 | + ) |
| 127 | + driver.add_argument( |
| 128 | + "--cmake-opts", |
| 129 | + help="Channels through additional cmake options", |
| 130 | + dest="cmake_opts", |
| 131 | + default="", |
| 132 | + type=str, |
| 133 | + ) |
| 134 | + args = parser.parse_args() |
| 135 | + |
| 136 | + args_to_validate = [ |
| 137 | + "c_compiler", |
| 138 | + "cxx_compiler", |
| 139 | + "compiler_root", |
| 140 | + ] |
| 141 | + |
| 142 | + if args.oneapi or ( |
| 143 | + args.c_compiler is None |
| 144 | + and args.cxx_compiler is None |
| 145 | + and args.compiler_root is None |
| 146 | + ): |
| 147 | + args.c_compiler = "icx" |
| 148 | + args.cxx_compiler = "icpx" if "linux" in sys.platform else "icx" |
| 149 | + args.compiler_root = None |
| 150 | + else: |
| 151 | + cr = args.compiler_root |
| 152 | + if isinstance(cr, str) and os.path.exists(cr): |
| 153 | + if args.c_compiler is None: |
| 154 | + args.c_compiler = "icx" |
| 155 | + if args.cxx_compiler is None: |
| 156 | + args.cxx_compiler = "icpx" if "linux" in sys.platform else "icx" |
| 157 | + else: |
| 158 | + raise RuntimeError( |
| 159 | + "Option 'compiler-root' must be provided when " |
| 160 | + "using non-default DPC++ layout." |
| 161 | + ) |
| 162 | + args_to_validate = [ |
| 163 | + "c_compiler", |
| 164 | + "cxx_compiler", |
| 165 | + ] |
| 166 | + for p in args_to_validate: |
| 167 | + arg = getattr(args, p) |
| 168 | + assert isinstance(arg, str) |
| 169 | + if not os.path.exists(arg): |
| 170 | + arg2 = os.path.join(cr, arg) |
| 171 | + if os.path.exists(arg2): |
| 172 | + arg = arg2 |
| 173 | + setattr(args, p, arg) |
| 174 | + if not os.path.exists(arg): |
| 175 | + opt_name = p.replace("_", "-") |
| 176 | + raise RuntimeError(f"Option {opt_name} value {arg} must exist.") |
| 177 | + |
| 178 | + run( |
| 179 | + use_oneapi=args.oneapi, |
| 180 | + build_type=args.debug, |
| 181 | + c_compiler=args.c_compiler, |
| 182 | + cxx_compiler=args.cxx_compiler, |
| 183 | + compiler_root=args.compiler_root, |
| 184 | + cmake_executable=args.cmake_executable, |
| 185 | + verbose=args.verbose, |
| 186 | + cmake_opts=args.cmake_opts, |
| 187 | + ) |
0 commit comments