extract out //c10/util:base library (#70854)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/70854

We can't do the entire package since parts of it depend on //c10/core.
ghstack-source-id: 147170901

Test Plan: Rely on CI.

Reviewed By: malfet

Differential Revision: D33321821

fbshipit-source-id: 6d634da872a382a60548e2eea37a0f9f93c6f080
(cherry picked from commit 0afa808367ff92b6011b61dcbb398a2a32e5e90d)
This commit is contained in:
Michael Dagitses
2022-01-26 03:41:33 -08:00
committed by PyTorch MergeBot
parent 108b37db84
commit 40e88b75c4
5 changed files with 73 additions and 6 deletions

View File

@ -1,5 +1,9 @@
build --copt=--std=c++14
build --copt=-I.
# Bazel does not support including its cc_library targets as system
# headers. We work around this for generated code
# (e.g. c10/macros/cmake_macros.h) by making the generated directory a
# system include path.
build --copt=-isystem --copt bazel-out/k8-fastbuild/bin
build --experimental_ui_max_stdouterr_bytes=2048576
@ -12,6 +16,9 @@ build:no-tty --show_progress_rate_limit 10
build:gpu --define=cuda=true
# define a separate build folder for faster switching between configs
build:gpu --platform_suffix=-gpu
# See the note on the config-less build for details about why we are
# doing this. We must also do it for the "-gpu" platform suffix.
build --copt=-isystem --copt=bazel-out/k8-fastbuild-gpu/bin
# rules_cuda configuration
build:gpu --@rules_cuda//cuda:enable_cuda
build:gpu --@rules_cuda//cuda:cuda_targets=sm_52

View File

@ -38,14 +38,14 @@ header_template_rule(
cc_library(
name = "headers",
hdrs = glob([
hdrs = [
"//c10/util:headers",
] + glob([
"core/*.h",
"core/impl/*.h",
"cuda/*.h",
"cuda/impl/*.h",
"mobile/*.h",
"util/*.h",
"util/*.hpp",
]),
deps = [
":cuda_cmake_macros_h",
@ -62,11 +62,12 @@ cc_library(
cc_library(
name = "c10",
srcs = glob([
srcs = [
"//c10/util:sources",
] + glob([
"core/*.cpp",
"core/impl/*.cpp",
"mobile/*.cpp",
"util/*.cpp",
]) + if_cuda(
glob([
"cuda/*.cpp",
@ -77,7 +78,7 @@ cc_library(
local_defines = ["C10_BUILD_MAIN_LIB"],
deps = [
":headers",
"@fmt",
"//c10/util:base",
] + if_cuda(
["@cuda"],
[],

4
c10/util/BUILD.bazel Normal file
View File

@ -0,0 +1,4 @@
load("//:tools/bazel.bzl", "rules")
load(":build.bzl", "define_targets")
define_targets(rules = rules)

53
c10/util/build.bzl Normal file
View File

@ -0,0 +1,53 @@
def define_targets(rules):
rules.cc_library(
name = "base",
srcs = rules.glob(
["*.cpp"],
exclude = [
"TypeCast.cpp",
"typeid.cpp",
],
),
hdrs = rules.glob(
["*.h"],
exclude = [
"TypeCast.h",
"typeid.h",
],
),
# This library uses flags and registration. Do not let the
# linker remove them.
alwayslink = True,
linkstatic = True,
local_defines = ["C10_BUILD_MAIN_LIB"],
visibility = ["//visibility:public"],
deps = [
"@fmt",
"//c10/macros",
] + rules.select({
"//c10:using_gflags": ["@com_github_gflags_gflags//:gflags"],
"//conditions:default": [],
}) + rules.select({
"//c10:using_glog": ["@com_github_glog//:glog"],
"//conditions:default": [],
}),
)
rules.filegroup(
name = "headers",
srcs = rules.glob(
["*.h"],
exclude = [
],
),
visibility = ["//c10:__pkg__"],
)
rules.filegroup(
name = "sources",
srcs = [
"TypeCast.cpp",
"typeid.cpp",
],
visibility = ["//c10:__pkg__"],
)

View File

@ -7,5 +7,7 @@ load("//c10/macros:cmake_configure_file.bzl", "cmake_configure_file")
rules = struct(
cc_library = cc_library,
cmake_configure_file = cmake_configure_file,
filegroup = native.filegroup,
glob = native.glob,
select = select,
)