1load("//arvr/tools/build_defs:genrule_utils.bzl", "gen_cmake_header") 2load("//arvr/tools/build_defs:oxx.bzl", "oxx_static_library") 3 4cpu_supported_platforms = [ 5 "ovr_config//os:android", 6 "ovr_config//os:iphoneos", 7 "ovr_config//os:linux-x86_64", 8 "ovr_config//os:macos", 9 "ovr_config//os:windows-x86_64", 10 "ovr_config//runtime:arm64-linux-ubuntu-neon", 11 "ovr_config//os:linux-arm64", 12] 13 14cuda_supported_platforms = [ 15 "ovr_config//os:linux-cuda", 16 "ovr_config//os:windows-cuda", 17] 18 19def define_c10_ovrsource(name, is_mobile): 20 if is_mobile: 21 pp_flags = ["-DC10_MOBILE=1"] 22 else: 23 pp_flags = [] 24 25 oxx_static_library( 26 name = name, 27 srcs = native.glob([ 28 "core/*.cpp", 29 "core/impl/*.cpp", 30 "mobile/*.cpp", 31 "util/*.cpp", 32 ]), 33 compatible_with = cpu_supported_platforms, 34 compiler_flags = select({ 35 "DEFAULT": [], 36 "ovr_config//compiler:cl": [ 37 "/w", 38 ], 39 "ovr_config//toolchain/clang:win": [ 40 "-Wno-error", 41 "-Wno-shadow", 42 "-Wno-undef", 43 "-Wno-unused-variable", 44 ], 45 }), 46 include_directories = [".."], 47 preprocessor_flags = [ 48 "-DNO_EXPORT", 49 "-DC10_BUILD_MAIN_LIB=1", 50 "-DSUPPORTS_BACKTRACE=0", 51 ], 52 fbobjc_compiler_flags = ["-Wno-error=global-constructors", "-Wno-error=missing-prototypes"], 53 public_include_directories = [".."], 54 public_preprocessor_flags = pp_flags, 55 public_raw_headers = native.glob([ 56 "core/*.h", 57 "macros/*.h", 58 "mobile/*.h", 59 "test/util/*.h", # some external tests use this 60 "util/*.h", 61 ]), 62 raw_headers = native.glob([ 63 "core/impl/*.h", 64 ]), 65 reexport_all_header_dependencies = False, 66 # tests = C10_CPU_TEST_TARGETS, 67 visibility = [ 68 "//xplat/caffe2/c10:c10_ovrsource", 69 ], 70 deps = select({ 71 "DEFAULT": [], 72 "ovr_config//os:linux": [ 73 "//third-party/numactl:numactl", 74 ], 75 }), 76 exported_deps = [ 77 ":ovrsource_c10_cmake_macros.h", 78 "//arvr/third-party/gflags:gflags", 79 "//third-party/cpuinfo:cpuinfo", 80 "//third-party/fmt:fmt", 81 "//third-party/glog:glog", 82 ], 83 ) 84 85def define_ovrsource_targets(): 86 # C10_CPU_TEST_FILES = native.glob([ 87 # "test/core/*.cpp", 88 # "test/util/*.cpp", 89 # ]) 90 91 # C10_GPU_TEST_FILES = native.glob([ 92 # "cuda/test/**/*.cpp", 93 # ]) 94 95 # C10_CPU_TEST_TARGETS = [ 96 # ":" + paths.basename(test)[:-len(".cpp")] + "_ovrsource" 97 # for test in C10_CPU_TEST_FILES 98 # ] 99 100 # C10_GPU_TEST_TARGETS = [ 101 # ":" + paths.basename(test)[:-len(".cpp")] + "_ovrsource" 102 # for test in C10_GPU_TEST_FILES 103 # ] 104 105 common_c10_cmake_defines = [ 106 ("#cmakedefine C10_BUILD_SHARED_LIBS", ""), 107 ("#cmakedefine C10_USE_NUMA", ""), 108 ("#cmakedefine C10_USE_MSVC_STATIC_RUNTIME", ""), 109 ("#cmakedefine C10_USE_ROCM_KERNEL_ASSERT", ""), 110 ] 111 112 mobile_c10_cmake_defines = [ 113 ("#cmakedefine C10_USE_GLOG", ""), 114 ("#cmakedefine C10_USE_GFLAGS", ""), 115 ] 116 117 non_mobile_c10_cmake_defines = [ 118 ("#cmakedefine C10_USE_GLOG", "#define C10_USE_GLOG 1"), 119 ("#cmakedefine C10_USE_GFLAGS", "#define C10_USE_GFLAGS 1"), 120 ] 121 122 gen_cmake_header( 123 src = "macros/cmake_macros.h.in", 124 defines = common_c10_cmake_defines + mobile_c10_cmake_defines, 125 header = "c10/macros/cmake_macros.h", 126 prefix = "ovrsource_c10_mobile_", 127 ) 128 129 gen_cmake_header( 130 src = "macros/cmake_macros.h.in", 131 defines = common_c10_cmake_defines + non_mobile_c10_cmake_defines, 132 header = "c10/macros/cmake_macros.h", 133 prefix = "ovrsource_c10_non_mobile_", 134 ) 135 136 oxx_static_library( 137 name = "ovrsource_c10_cmake_macros.h", 138 compatible_with = [ 139 "ovr_config//os:android", 140 "ovr_config//os:iphoneos", 141 "ovr_config//os:linux", 142 "ovr_config//os:macos", 143 "ovr_config//os:windows", 144 ], 145 deps = select({ 146 "ovr_config//os:android": [":ovrsource_c10_mobile_cmake_macros.h"], 147 "ovr_config//os:iphoneos": [":ovrsource_c10_mobile_cmake_macros.h"], 148 "ovr_config//os:linux": [":ovrsource_c10_non_mobile_cmake_macros.h"], 149 "ovr_config//os:macos": [":ovrsource_c10_non_mobile_cmake_macros.h"], 150 "ovr_config//os:windows": [":ovrsource_c10_non_mobile_cmake_macros.h"], 151 }), 152 ) 153 154 c10_cuda_macros = gen_cmake_header( 155 src = "cuda/impl/cuda_cmake_macros.h.in", 156 defines = [ 157 ("#cmakedefine C10_CUDA_BUILD_SHARED_LIBS", ""), 158 ], 159 header = "c10/cuda/impl/cuda_cmake_macros.h", 160 prefix = "ovrsource", 161 ) 162 163 oxx_static_library( 164 name = "c10_ovrsource", 165 compatible_with = cpu_supported_platforms, 166 exported_deps = select({ 167 "DEFAULT": [":c10_full_ovrsource"], 168 "ovr_config//os:android": [":c10_mobile_ovrsource"], 169 "ovr_config//os:iphoneos": [":c10_mobile_ovrsource"], 170 }), 171 visibility = ["PUBLIC"], 172 ) 173 174 """ 175 Most users should use c10_ovrsource, not these targets directly. 176 """ 177 define_c10_ovrsource("c10_mobile_ovrsource", True) 178 define_c10_ovrsource("c10_full_ovrsource", False) 179 180 oxx_static_library( 181 name = "c10_cuda_ovrsource", 182 srcs = native.glob([ 183 "cuda/*.cpp", 184 "cuda/impl/*.cpp", 185 ]), 186 compatible_with = cuda_supported_platforms, 187 compiler_flags = select({ 188 "DEFAULT": [], 189 "ovr_config//compiler:cl": [ 190 "/w", 191 ], 192 "ovr_config//toolchain/clang:win": [ 193 "-Wno-error", 194 "-Wno-shadow", 195 "-Wno-undef", 196 "-Wno-unused-variable", 197 ], 198 }), 199 link_whole = True, 200 preprocessor_flags = [ 201 "-DNO_EXPORT", 202 "-DC10_CUDA_BUILD_MAIN_LIB=1", 203 ], 204 raw_headers = native.glob([ 205 "cuda/*.h", 206 "cuda/impl/*.h", 207 ]), 208 reexport_all_header_dependencies = False, 209 # tests = C10_GPU_TEST_TARGETS, 210 visibility = ["PUBLIC"], 211 deps = [ 212 "//third-party/cuda:libcuda", 213 "//third-party/cuda:libcudart", 214 ], 215 exported_deps = c10_cuda_macros + [ 216 ":c10_ovrsource", 217 ], 218 ) 219 220 # [ 221 # oxx_test( 222 # name = paths.basename(test)[:-len(".cpp")] + "_ovrsource", 223 # srcs = [test], 224 # compatible_with = cpu_supported_platforms, 225 # compiler_flags = select({ 226 # "DEFAULT": [], 227 # "ovr_config//compiler:cl": [ 228 # "/w", 229 # ], 230 # "ovr_config//compiler:clang": [ 231 # "-Wno-error", 232 # "-Wno-self-assign-overloaded", 233 # "-Wno-self-move", 234 # "-Wno-shadow", 235 # "-Wno-undef", 236 # "-Wno-unused-function", 237 # "-Wno-unused-variable", 238 # ], 239 # }), 240 # framework = "gtest", 241 # oncall = "ovrsource_pytorch", 242 # raw_headers = native.glob([ 243 # "test/**/*.h", 244 # ]), 245 # deps = [ 246 # ":c10_ovrsource", 247 # ], 248 # ) 249 # for test in C10_CPU_TEST_FILES 250 # ] 251 252 # [ 253 # oxx_test( 254 # name = paths.basename(test)[:-len(".cpp")] + "_ovrsource", 255 # srcs = [test], 256 # compatible_with = cuda_supported_platforms, 257 # compiler_flags = select({ 258 # "DEFAULT": [], 259 # "ovr_config//compiler:cl": [ 260 # "/w", 261 # ], 262 # "ovr_config//compiler:clang": [ 263 # "-Wno-error", 264 # ], 265 # }), 266 # framework = "gtest", 267 # oncall = "ovrsource_pytorch", 268 # raw_headers = native.glob([ 269 # "test/**/*.h", 270 # ]), 271 # runtime_shared_libraries = [ 272 # "//third-party/cuda:cudart", 273 # ], 274 # deps = [ 275 # ":c10_cuda_ovrsource", 276 # ], 277 # ) 278 # for test in C10_GPU_TEST_FILES 279 # ] 280