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)
This commit is contained in:
mikey dagitses
2022-03-02 02:49:38 -08:00
committed by PyTorch MergeBot
parent 81437e66c1
commit e9dfc61938
3 changed files with 30 additions and 25 deletions

View File

@ -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__"],
)

24
c10/build.bzl Normal file
View File

@ -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"],
)

View File

@ -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,
)