From e9dfc61938aa93b70c9918370b1b209b33e59c9c Mon Sep 17 00:00:00 2001 From: mikey dagitses Date: Wed, 2 Mar 2022 02:49:38 -0800 Subject: [PATCH] extract //c10 to common build system (#71411) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/71411 This library is mostly the same now externally and internally, though internal to Meta we never include cuda in this library, so our select resolves internally unconditionally to false. ghstack-source-id: 150235103 Test Plan: This ought to be a no-op, rely on CI. Reviewed By: malfet Differential Revision: D33635739 fbshipit-source-id: a4d3c7e30995c0e43ecd4c69ad0abb23498ee098 (cherry picked from commit c574a123615588adbe42cc51a713fccfa1b2cac0) --- c10/BUILD.bazel | 29 ++++------------------------- c10/build.bzl | 24 ++++++++++++++++++++++++ tools/bazel.bzl | 2 ++ 3 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 c10/build.bzl 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, )