| load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") |
| load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") |
| load("//third_party:substitution.bzl", "header_template_rule") |
| load("//tools/config:defs.bzl", "if_cuda") |
| |
| # The bool_flag targets allow configuring the build from the |
| # command-line, e.g. --//c10:use_gflags or --no//c10:use_gflags to |
| # disable. |
| |
| bool_flag( |
| name = "use_gflags", |
| build_setting_default = True, |
| ) |
| |
| bool_flag( |
| name = "use_glog", |
| build_setting_default = True, |
| ) |
| |
| config_setting( |
| name = "using_gflags", |
| flag_values = {":use_gflags": "true"}, |
| ) |
| |
| config_setting( |
| name = "using_glog", |
| flag_values = {":use_glog": "true"}, |
| ) |
| |
| header_template_rule( |
| name = "cuda_cmake_macros_h", |
| src = "cuda/impl/cuda_cmake_macros.h.in", |
| out = "cuda/impl/cuda_cmake_macros.h", |
| substitutions = { |
| "cmakedefine": "define", |
| }, |
| ) |
| |
| cc_library( |
| name = "headers", |
| hdrs = [ |
| "//c10/core:headers", |
| "//c10/mobile:headers", |
| "//c10/util:headers", |
| ] + glob([ |
| "cuda/*.h", |
| "cuda/impl/*.h", |
| ]), |
| deps = [ |
| ":cuda_cmake_macros_h", |
| "//c10/core:alignment", |
| "//c10/macros", |
| ] + select({ |
| ":using_gflags": ["@com_github_gflags_gflags//:gflags"], |
| "//conditions:default": [], |
| }) + select({ |
| ":using_glog": ["@com_github_glog//:glog"], |
| "//conditions:default": [], |
| }), |
| visibility = ["//:__pkg__"], |
| ) |
| |
| cc_library( |
| name = "c10", |
| srcs = if_cuda( |
| glob([ |
| "cuda/*.cpp", |
| "cuda/impl/*.cpp", |
| ]), |
| [], |
| ), |
| local_defines = ["C10_BUILD_MAIN_LIB"], |
| deps = [ |
| ":headers", |
| "//c10/core:CPUAllocator", |
| "//c10/core:ScalarType", |
| "//c10/core:alloc_cpu", |
| "//c10/core:base", |
| "//c10/mobile:CPUCachingAllocator", |
| "//c10/mobile:CPUProfilingAllocator", |
| "//c10/util:TypeCast", |
| "//c10/util:base", |
| "//c10/util:typeid", |
| ] + if_cuda( |
| ["@cuda"], |
| [], |
| ), |
| alwayslink = True, |
| visibility = ["//:__pkg__"], |
| ) |
| |
| cc_test( |
| name = "tests", |
| size = "small", |
| srcs = glob([ |
| "test/util/*.cpp", |
| "test/util/*.h", |
| "test/core/*.cpp", |
| "test/core/impl/*.cpp", |
| ]), |
| copts = ["-Wno-deprecated-declarations"], |
| deps = [ |
| ":c10", |
| ":headers", |
| "@com_google_googletest//:gtest_main", |
| ], |
| visibility = ["//:__pkg__"], |
| ) |