1licenses(["restricted"]) 2 3package(default_visibility = ["//visibility:public"]) 4 5# Point both runtimes to the same python binary to ensure we always 6# use the python binary specified by ./configure.py script. 7load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair") 8 9py_runtime( 10 name = "py2_runtime", 11 interpreter_path = "/usr/bin/python3", 12 python_version = "PY2", 13) 14 15py_runtime( 16 name = "py3_runtime", 17 interpreter_path = "/usr/bin/python3", 18 python_version = "PY3", 19) 20 21py_runtime_pair( 22 name = "py_runtime_pair", 23 py2_runtime = ":py2_runtime", 24 py3_runtime = ":py3_runtime", 25) 26 27toolchain( 28 name = "py_toolchain", 29 toolchain = ":py_runtime_pair", 30 toolchain_type = "@bazel_tools//tools/python:toolchain_type", 31) 32 33# To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib 34# See https://docs.python.org/3/extending/windows.html 35cc_import( 36 name = "python_lib", 37 interface_library = select({ 38 ":windows": ":python_import_lib", 39 # A placeholder for Unix platforms which makes --no_build happy. 40 "//conditions:default": "not-existing.lib", 41 }), 42 system_provided = 1, 43) 44 45cc_library( 46 name = "python_headers", 47 hdrs = [":python_include"], 48 includes = ["python_include"], 49 deps = select({ 50 ":windows": [":python_lib"], 51 "//conditions:default": [], 52 }), 53) 54 55cc_library( 56 name = "numpy_headers", 57 hdrs = [":numpy_include"], 58 includes = ["numpy_include"], 59) 60 61config_setting( 62 name = "windows", 63 values = {"cpu": "x64_windows"}, 64 visibility = ["//visibility:public"], 65) 66 67genrule( 68 name = "python_include", 69 outs = [ 70 "python_include/Python-ast.h", 71 "python_include/Python.h", 72 "python_include/abstract.h", 73 "python_include/accu.h", 74 "python_include/asdl.h", 75 "python_include/ast.h", 76 "python_include/bitset.h", 77 "python_include/bltinmodule.h", 78 "python_include/boolobject.h", 79 "python_include/bytearrayobject.h", 80 "python_include/bytes_methods.h", 81 "python_include/bytesobject.h", 82 "python_include/cellobject.h", 83 "python_include/ceval.h", 84 "python_include/classobject.h", 85 "python_include/code.h", 86 "python_include/codecs.h", 87 "python_include/compile.h", 88 "python_include/complexobject.h", 89 "python_include/datetime.h", 90 "python_include/descrobject.h", 91 "python_include/dictobject.h", 92 "python_include/dtoa.h", 93 "python_include/dynamic_annotations.h", 94 "python_include/enumobject.h", 95 "python_include/errcode.h", 96 "python_include/eval.h", 97 "python_include/fileobject.h", 98 "python_include/fileutils.h", 99 "python_include/floatobject.h", 100 "python_include/frameobject.h", 101 "python_include/funcobject.h", 102 "python_include/genobject.h", 103 "python_include/graminit.h", 104 "python_include/grammar.h", 105 "python_include/import.h", 106 "python_include/intrcheck.h", 107 "python_include/iterobject.h", 108 "python_include/listobject.h", 109 "python_include/longintrepr.h", 110 "python_include/longobject.h", 111 "python_include/marshal.h", 112 "python_include/memoryobject.h", 113 "python_include/metagrammar.h", 114 "python_include/methodobject.h", 115 "python_include/modsupport.h", 116 "python_include/moduleobject.h", 117 "python_include/namespaceobject.h", 118 "python_include/node.h", 119 "python_include/object.h", 120 "python_include/objimpl.h", 121 "python_include/odictobject.h", 122 "python_include/opcode.h", 123 "python_include/osdefs.h", 124 "python_include/osmodule.h", 125 "python_include/parsetok.h", 126 "python_include/patchlevel.h", 127 "python_include/pgen.h", 128 "python_include/pgenheaders.h", 129 "python_include/py_curses.h", 130 "python_include/pyarena.h", 131 "python_include/pyatomic.h", 132 "python_include/pycapsule.h", 133 "python_include/pyconfig.h", 134 "python_include/pyctype.h", 135 "python_include/pydebug.h", 136 "python_include/pydtrace.h", 137 "python_include/pyerrors.h", 138 "python_include/pyexpat.h", 139 "python_include/pyfpe.h", 140 "python_include/pygetopt.h", 141 "python_include/pyhash.h", 142 "python_include/pylifecycle.h", 143 "python_include/pymacconfig.h", 144 "python_include/pymacro.h", 145 "python_include/pymath.h", 146 "python_include/pymem.h", 147 "python_include/pyport.h", 148 "python_include/pystate.h", 149 "python_include/pystrcmp.h", 150 "python_include/pystrhex.h", 151 "python_include/pystrtod.h", 152 "python_include/pythonrun.h", 153 "python_include/pythread.h", 154 "python_include/pytime.h", 155 "python_include/rangeobject.h", 156 "python_include/setobject.h", 157 "python_include/sliceobject.h", 158 "python_include/structmember.h", 159 "python_include/structseq.h", 160 "python_include/symtable.h", 161 "python_include/sysmodule.h", 162 "python_include/token.h", 163 "python_include/traceback.h", 164 "python_include/tupleobject.h", 165 "python_include/typeslots.h", 166 "python_include/ucnhash.h", 167 "python_include/unicodeobject.h", 168 "python_include/warnings.h", 169 "python_include/weakrefobject.h", 170 ], 171 cmd = """ 172cp -f "/opt/python3.6/include/python3.6m/Python-ast.h" "$(@D)/python_include/Python-ast.h" && cp -f "/opt/python3.6/include/python3.6m/Python.h" "$(@D)/python_include/Python.h" && cp -f "/opt/python3.6/include/python3.6m/abstract.h" "$(@D)/python_include/abstract.h" && cp -f "/opt/python3.6/include/python3.6m/accu.h" "$(@D)/python_include/accu.h" && cp -f "/opt/python3.6/include/python3.6m/asdl.h" "$(@D)/python_include/asdl.h" && cp -f "/opt/python3.6/include/python3.6m/ast.h" "$(@D)/python_include/ast.h" && cp -f "/opt/python3.6/include/python3.6m/bitset.h" "$(@D)/python_include/bitset.h" && cp -f "/opt/python3.6/include/python3.6m/bltinmodule.h" "$(@D)/python_include/bltinmodule.h" && cp -f "/opt/python3.6/include/python3.6m/boolobject.h" "$(@D)/python_include/boolobject.h" && cp -f "/opt/python3.6/include/python3.6m/bytearrayobject.h" "$(@D)/python_include/bytearrayobject.h" && cp -f "/opt/python3.6/include/python3.6m/bytes_methods.h" "$(@D)/python_include/bytes_methods.h" && cp -f "/opt/python3.6/include/python3.6m/bytesobject.h" "$(@D)/python_include/bytesobject.h" && cp -f "/opt/python3.6/include/python3.6m/cellobject.h" "$(@D)/python_include/cellobject.h" && cp -f "/opt/python3.6/include/python3.6m/ceval.h" "$(@D)/python_include/ceval.h" && cp -f "/opt/python3.6/include/python3.6m/classobject.h" "$(@D)/python_include/classobject.h" && cp -f "/opt/python3.6/include/python3.6m/code.h" "$(@D)/python_include/code.h" && cp -f "/opt/python3.6/include/python3.6m/codecs.h" "$(@D)/python_include/codecs.h" && cp -f "/opt/python3.6/include/python3.6m/compile.h" "$(@D)/python_include/compile.h" && cp -f "/opt/python3.6/include/python3.6m/complexobject.h" "$(@D)/python_include/complexobject.h" && cp -f "/opt/python3.6/include/python3.6m/datetime.h" "$(@D)/python_include/datetime.h" && cp -f "/opt/python3.6/include/python3.6m/descrobject.h" "$(@D)/python_include/descrobject.h" && cp -f "/opt/python3.6/include/python3.6m/dictobject.h" "$(@D)/python_include/dictobject.h" && cp -f "/opt/python3.6/include/python3.6m/dtoa.h" "$(@D)/python_include/dtoa.h" && cp -f "/opt/python3.6/include/python3.6m/dynamic_annotations.h" "$(@D)/python_include/dynamic_annotations.h" && cp -f "/opt/python3.6/include/python3.6m/enumobject.h" "$(@D)/python_include/enumobject.h" && cp -f "/opt/python3.6/include/python3.6m/errcode.h" "$(@D)/python_include/errcode.h" && cp -f "/opt/python3.6/include/python3.6m/eval.h" "$(@D)/python_include/eval.h" && cp -f "/opt/python3.6/include/python3.6m/fileobject.h" "$(@D)/python_include/fileobject.h" && cp -f "/opt/python3.6/include/python3.6m/fileutils.h" "$(@D)/python_include/fileutils.h" && cp -f "/opt/python3.6/include/python3.6m/floatobject.h" "$(@D)/python_include/floatobject.h" && cp -f "/opt/python3.6/include/python3.6m/frameobject.h" "$(@D)/python_include/frameobject.h" && cp -f "/opt/python3.6/include/python3.6m/funcobject.h" "$(@D)/python_include/funcobject.h" && cp -f "/opt/python3.6/include/python3.6m/genobject.h" "$(@D)/python_include/genobject.h" && cp -f "/opt/python3.6/include/python3.6m/graminit.h" "$(@D)/python_include/graminit.h" && cp -f "/opt/python3.6/include/python3.6m/grammar.h" "$(@D)/python_include/grammar.h" && cp -f "/opt/python3.6/include/python3.6m/import.h" "$(@D)/python_include/import.h" && cp -f "/opt/python3.6/include/python3.6m/intrcheck.h" "$(@D)/python_include/intrcheck.h" && cp -f "/opt/python3.6/include/python3.6m/iterobject.h" "$(@D)/python_include/iterobject.h" && cp -f "/opt/python3.6/include/python3.6m/listobject.h" "$(@D)/python_include/listobject.h" && cp -f "/opt/python3.6/include/python3.6m/longintrepr.h" "$(@D)/python_include/longintrepr.h" && cp -f "/opt/python3.6/include/python3.6m/longobject.h" "$(@D)/python_include/longobject.h" && cp -f "/opt/python3.6/include/python3.6m/marshal.h" "$(@D)/python_include/marshal.h" && cp -f "/opt/python3.6/include/python3.6m/memoryobject.h" "$(@D)/python_include/memoryobject.h" && cp -f "/opt/python3.6/include/python3.6m/metagrammar.h" "$(@D)/python_include/metagrammar.h" && cp -f "/opt/python3.6/include/python3.6m/methodobject.h" "$(@D)/python_include/methodobject.h" && cp -f "/opt/python3.6/include/python3.6m/modsupport.h" "$(@D)/python_include/modsupport.h" && cp -f "/opt/python3.6/include/python3.6m/moduleobject.h" "$(@D)/python_include/moduleobject.h" && cp -f "/opt/python3.6/include/python3.6m/namespaceobject.h" "$(@D)/python_include/namespaceobject.h" && cp -f "/opt/python3.6/include/python3.6m/node.h" "$(@D)/python_include/node.h" && cp -f "/opt/python3.6/include/python3.6m/object.h" "$(@D)/python_include/object.h" && cp -f "/opt/python3.6/include/python3.6m/objimpl.h" "$(@D)/python_include/objimpl.h" && cp -f "/opt/python3.6/include/python3.6m/odictobject.h" "$(@D)/python_include/odictobject.h" && cp -f "/opt/python3.6/include/python3.6m/opcode.h" "$(@D)/python_include/opcode.h" && cp -f "/opt/python3.6/include/python3.6m/osdefs.h" "$(@D)/python_include/osdefs.h" && cp -f "/opt/python3.6/include/python3.6m/osmodule.h" "$(@D)/python_include/osmodule.h" && cp -f "/opt/python3.6/include/python3.6m/parsetok.h" "$(@D)/python_include/parsetok.h" && cp -f "/opt/python3.6/include/python3.6m/patchlevel.h" "$(@D)/python_include/patchlevel.h" && cp -f "/opt/python3.6/include/python3.6m/pgen.h" "$(@D)/python_include/pgen.h" && cp -f "/opt/python3.6/include/python3.6m/pgenheaders.h" "$(@D)/python_include/pgenheaders.h" && cp -f "/opt/python3.6/include/python3.6m/py_curses.h" "$(@D)/python_include/py_curses.h" && cp -f "/opt/python3.6/include/python3.6m/pyarena.h" "$(@D)/python_include/pyarena.h" && cp -f "/opt/python3.6/include/python3.6m/pyatomic.h" "$(@D)/python_include/pyatomic.h" && cp -f "/opt/python3.6/include/python3.6m/pycapsule.h" "$(@D)/python_include/pycapsule.h" && cp -f "/opt/python3.6/include/python3.6m/pyconfig.h" "$(@D)/python_include/pyconfig.h" && cp -f "/opt/python3.6/include/python3.6m/pyctype.h" "$(@D)/python_include/pyctype.h" && cp -f "/opt/python3.6/include/python3.6m/pydebug.h" "$(@D)/python_include/pydebug.h" && cp -f "/opt/python3.6/include/python3.6m/pydtrace.h" "$(@D)/python_include/pydtrace.h" && cp -f "/opt/python3.6/include/python3.6m/pyerrors.h" "$(@D)/python_include/pyerrors.h" && cp -f "/opt/python3.6/include/python3.6m/pyexpat.h" "$(@D)/python_include/pyexpat.h" && cp -f "/opt/python3.6/include/python3.6m/pyfpe.h" "$(@D)/python_include/pyfpe.h" && cp -f "/opt/python3.6/include/python3.6m/pygetopt.h" "$(@D)/python_include/pygetopt.h" && cp -f "/opt/python3.6/include/python3.6m/pyhash.h" "$(@D)/python_include/pyhash.h" && cp -f "/opt/python3.6/include/python3.6m/pylifecycle.h" "$(@D)/python_include/pylifecycle.h" && cp -f "/opt/python3.6/include/python3.6m/pymacconfig.h" "$(@D)/python_include/pymacconfig.h" && cp -f "/opt/python3.6/include/python3.6m/pymacro.h" "$(@D)/python_include/pymacro.h" && cp -f "/opt/python3.6/include/python3.6m/pymath.h" "$(@D)/python_include/pymath.h" && cp -f "/opt/python3.6/include/python3.6m/pymem.h" "$(@D)/python_include/pymem.h" && cp -f "/opt/python3.6/include/python3.6m/pyport.h" "$(@D)/python_include/pyport.h" && cp -f "/opt/python3.6/include/python3.6m/pystate.h" "$(@D)/python_include/pystate.h" && cp -f "/opt/python3.6/include/python3.6m/pystrcmp.h" "$(@D)/python_include/pystrcmp.h" && cp -f "/opt/python3.6/include/python3.6m/pystrhex.h" "$(@D)/python_include/pystrhex.h" && cp -f "/opt/python3.6/include/python3.6m/pystrtod.h" "$(@D)/python_include/pystrtod.h" && cp -f "/opt/python3.6/include/python3.6m/pythonrun.h" "$(@D)/python_include/pythonrun.h" && cp -f "/opt/python3.6/include/python3.6m/pythread.h" "$(@D)/python_include/pythread.h" && cp -f "/opt/python3.6/include/python3.6m/pytime.h" "$(@D)/python_include/pytime.h" && cp -f "/opt/python3.6/include/python3.6m/rangeobject.h" "$(@D)/python_include/rangeobject.h" && cp -f "/opt/python3.6/include/python3.6m/setobject.h" "$(@D)/python_include/setobject.h" && cp -f "/opt/python3.6/include/python3.6m/sliceobject.h" "$(@D)/python_include/sliceobject.h" && cp -f "/opt/python3.6/include/python3.6m/structmember.h" "$(@D)/python_include/structmember.h" && cp -f "/opt/python3.6/include/python3.6m/structseq.h" "$(@D)/python_include/structseq.h" && cp -f "/opt/python3.6/include/python3.6m/symtable.h" "$(@D)/python_include/symtable.h" && cp -f "/opt/python3.6/include/python3.6m/sysmodule.h" "$(@D)/python_include/sysmodule.h" && cp -f "/opt/python3.6/include/python3.6m/token.h" "$(@D)/python_include/token.h" && cp -f "/opt/python3.6/include/python3.6m/traceback.h" "$(@D)/python_include/traceback.h" && cp -f "/opt/python3.6/include/python3.6m/tupleobject.h" "$(@D)/python_include/tupleobject.h" && cp -f "/opt/python3.6/include/python3.6m/typeslots.h" "$(@D)/python_include/typeslots.h" && cp -f "/opt/python3.6/include/python3.6m/ucnhash.h" "$(@D)/python_include/ucnhash.h" && cp -f "/opt/python3.6/include/python3.6m/unicodeobject.h" "$(@D)/python_include/unicodeobject.h" && cp -f "/opt/python3.6/include/python3.6m/warnings.h" "$(@D)/python_include/warnings.h" && cp -f "/opt/python3.6/include/python3.6m/weakrefobject.h" "$(@D)/python_include/weakrefobject.h" 173 """, 174) 175 176genrule( 177 name = "numpy_include", 178 outs = [ 179 "numpy_include/numpy/__multiarray_api.h", 180 "numpy_include/numpy/__ufunc_api.h", 181 "numpy_include/numpy/_neighborhood_iterator_imp.h", 182 "numpy_include/numpy/_numpyconfig.h", 183 "numpy_include/numpy/arrayobject.h", 184 "numpy_include/numpy/arrayscalars.h", 185 "numpy_include/numpy/halffloat.h", 186 "numpy_include/numpy/multiarray_api.txt", 187 "numpy_include/numpy/ndarrayobject.h", 188 "numpy_include/numpy/ndarraytypes.h", 189 "numpy_include/numpy/noprefix.h", 190 "numpy_include/numpy/npy_1_7_deprecated_api.h", 191 "numpy_include/numpy/npy_3kcompat.h", 192 "numpy_include/numpy/npy_common.h", 193 "numpy_include/numpy/npy_cpu.h", 194 "numpy_include/numpy/npy_endian.h", 195 "numpy_include/numpy/npy_interrupt.h", 196 "numpy_include/numpy/npy_math.h", 197 "numpy_include/numpy/npy_no_deprecated_api.h", 198 "numpy_include/numpy/npy_os.h", 199 "numpy_include/numpy/numpyconfig.h", 200 "numpy_include/numpy/old_defines.h", 201 "numpy_include/numpy/oldnumeric.h", 202 "numpy_include/numpy/ufunc_api.txt", 203 "numpy_include/numpy/ufuncobject.h", 204 "numpy_include/numpy/utils.h", 205 ], 206 cmd = """ 207cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/__multiarray_api.h" "$(@D)/numpy_include/numpy/__multiarray_api.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/__ufunc_api.h" "$(@D)/numpy_include/numpy/__ufunc_api.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/_neighborhood_iterator_imp.h" "$(@D)/numpy_include/numpy/_neighborhood_iterator_imp.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/_numpyconfig.h" "$(@D)/numpy_include/numpy/_numpyconfig.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/arrayobject.h" "$(@D)/numpy_include/numpy/arrayobject.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/arrayscalars.h" "$(@D)/numpy_include/numpy/arrayscalars.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/halffloat.h" "$(@D)/numpy_include/numpy/halffloat.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/multiarray_api.txt" "$(@D)/numpy_include/numpy/multiarray_api.txt" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/ndarrayobject.h" "$(@D)/numpy_include/numpy/ndarrayobject.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/ndarraytypes.h" "$(@D)/numpy_include/numpy/ndarraytypes.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/noprefix.h" "$(@D)/numpy_include/numpy/noprefix.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h" "$(@D)/numpy_include/numpy/npy_1_7_deprecated_api.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/npy_3kcompat.h" "$(@D)/numpy_include/numpy/npy_3kcompat.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/npy_common.h" "$(@D)/numpy_include/numpy/npy_common.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/npy_cpu.h" "$(@D)/numpy_include/numpy/npy_cpu.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/npy_endian.h" "$(@D)/numpy_include/numpy/npy_endian.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/npy_interrupt.h" "$(@D)/numpy_include/numpy/npy_interrupt.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/npy_math.h" "$(@D)/numpy_include/numpy/npy_math.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/npy_no_deprecated_api.h" "$(@D)/numpy_include/numpy/npy_no_deprecated_api.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/npy_os.h" "$(@D)/numpy_include/numpy/npy_os.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/numpyconfig.h" "$(@D)/numpy_include/numpy/numpyconfig.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/old_defines.h" "$(@D)/numpy_include/numpy/old_defines.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/oldnumeric.h" "$(@D)/numpy_include/numpy/oldnumeric.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/ufunc_api.txt" "$(@D)/numpy_include/numpy/ufunc_api.txt" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/ufuncobject.h" "$(@D)/numpy_include/numpy/ufuncobject.h" && cp -f "/opt/python3.6/lib/python3.6/site-packages/numpy/core/include/numpy/utils.h" "$(@D)/numpy_include/numpy/utils.h" 208 """, 209) 210