Skip to content

Commit

Permalink
extract out //c10/util:base library (pytorch#70854)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#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 0afa808)
  • Loading branch information
Michael Dagitses authored and pytorchmergebot committed Jan 26, 2022
1 parent 108b37d commit 40e88b7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions c10/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -77,7 +78,7 @@ cc_library(
local_defines = ["C10_BUILD_MAIN_LIB"],
deps = [
":headers",
"@fmt",
"//c10/util:base",
] + if_cuda(
["@cuda"],
[],
Expand Down
4 changes: 4 additions & 0 deletions c10/util/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
load("//:tools/bazel.bzl", "rules")
load(":build.bzl", "define_targets")

define_targets(rules = rules)
53 changes: 53 additions & 0 deletions c10/util/build.bzl
Original file line number Diff line number Diff line change
@@ -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__"],
)
2 changes: 2 additions & 0 deletions tools/bazel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit 40e88b7

Please sign in to comment.