diff --git a/c10/BUILD.bazel b/c10/BUILD.bazel index f4a43cf9301..5e6ed8297e5 100644 --- a/c10/BUILD.bazel +++ b/c10/BUILD.bazel @@ -1,6 +1,9 @@ load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") load("@rules_cc//cc:defs.bzl", "cc_library") -load("//tools/config:defs.bzl", "if_cuda") +load("//:tools/bazel.bzl", "rules") +load(":build.bzl", "define_targets") + +define_targets(rules = rules) # The bool_flag targets allow configuring the build from the # command-line, e.g. --//c10:use_gflags or --no//c10:use_gflags to @@ -47,27 +50,3 @@ cc_library( }), visibility = ["//:__pkg__"], ) - -cc_library( - name = "c10", - deps = [ - "//c10/core:CPUAllocator", - "//c10/core:ScalarType", - "//c10/core:alignment", - "//c10/core:alloc_cpu", - "//c10/core:base", - "//c10/macros", - "//c10/mobile:CPUCachingAllocator", - "//c10/mobile:CPUProfilingAllocator", - "//c10/util:TypeCast", - "//c10/util:base", - "//c10/util:typeid", - ] + if_cuda( - [ - "//c10/cuda", - "//c10/cuda:Macros", - ], - [], - ), - visibility = ["//:__pkg__"], -) diff --git a/c10/build.bzl b/c10/build.bzl new file mode 100644 index 00000000000..21107eb8b99 --- /dev/null +++ b/c10/build.bzl @@ -0,0 +1,24 @@ +def define_targets(rules): + rules.cc_library( + name = "c10", + deps = [ + "//c10/core:CPUAllocator", + "//c10/core:ScalarType", + "//c10/core:alignment", + "//c10/core:alloc_cpu", + "//c10/core:base", + "//c10/macros", + "//c10/mobile:CPUCachingAllocator", + "//c10/mobile:CPUProfilingAllocator", + "//c10/util:TypeCast", + "//c10/util:base", + "//c10/util:typeid", + ] + rules.if_cuda( + [ + "//c10/cuda", + "//c10/cuda:Macros", + ], + [], + ), + visibility = ["//visibility:public"], + ) diff --git a/tools/bazel.bzl b/tools/bazel.bzl index b932b812c32..bb58b8aab53 100644 --- a/tools/bazel.bzl +++ b/tools/bazel.bzl @@ -1,6 +1,7 @@ load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("@rules_cuda//cuda:defs.bzl", "requires_cuda_enabled") load("//c10/macros:cmake_configure_file.bzl", "cmake_configure_file") +load("//tools/config:defs.bzl", "if_cuda") # Rules implementation for the Bazel build system. Since the common # build structure aims to replicate Bazel as much as possible, most of @@ -11,6 +12,7 @@ rules = struct( cmake_configure_file = cmake_configure_file, filegroup = native.filegroup, glob = native.glob, + if_cuda = if_cuda, requires_cuda_enabled = requires_cuda_enabled, select = select, )