Skip to content

Commit 91e442c

Browse files
mikey dagitsesfacebook-github-bot
authored andcommitted
use the //tools/codegen target in Bazel (#74465)
Summary: Pull Request resolved: #74465 This requires adding py_library and its PyPI dependency provider "requirement". ghstack-source-id: 152438643 Test Plan: Rely on CI to validate. Reviewed By: malfet Differential Revision: D35009795 fbshipit-source-id: 424c4968474b3c2fb37d2c7dba932b37605a63f7
1 parent ea8e3a8 commit 91e442c

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

BUILD.bazel

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ py_binary(
3131
name = "gen",
3232
srcs = ["tools/setup_helpers/gen.py"],
3333
deps = [
34-
":tools_codegen"
34+
"//tools/codegen"
3535
],
3636
)
3737

@@ -105,19 +105,14 @@ generate_aten(
105105
generator=":gen",
106106
)
107107

108-
py_library(
109-
name = "tools_codegen",
110-
srcs = glob(["tools/codegen/**/*.py"]),
111-
)
112-
113108
py_library(
114109
name = "tools_autograd",
115110
srcs = glob(["tools/autograd/*.py"]),
116111
data = glob([
117112
"tools/autograd/*.yaml",
118113
"tools/autograd/templates/*",
119114
]),
120-
deps = [":tools_codegen"],
115+
deps = ["//tools/codegen"],
121116
)
122117

123118
py_library(
@@ -1380,7 +1375,7 @@ cc_library(
13801375
py_binary(
13811376
name = "gen_op",
13821377
srcs = ["caffe2/contrib/aten/gen_op.py"],
1383-
deps = [":tools_codegen"],
1378+
deps = ["//tools/codegen"],
13841379
)
13851380

13861381
genrule(

tools/bazel.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ load("@rules_cuda//cuda:defs.bzl", "requires_cuda_enabled")
33
load("//c10/macros:cmake_configure_file.bzl", "cmake_configure_file")
44
load("//tools/config:defs.bzl", "if_cuda")
55

6+
def _py_library(name, **kwds):
7+
deps = [dep for dep in kwds.pop("deps", []) if dep != None]
8+
native.py_library(name = name, deps = deps, **kwds)
9+
10+
def _requirement(_pypi_project):
11+
return None
12+
613
# Rules implementation for the Bazel build system. Since the common
714
# build structure aims to replicate Bazel as much as possible, most of
815
# the rules simply forward to the Bazel definitions.
@@ -14,6 +21,8 @@ rules = struct(
1421
filegroup = native.filegroup,
1522
glob = native.glob,
1623
if_cuda = if_cuda,
24+
py_library = _py_library,
25+
requirement = _requirement,
1726
requires_cuda_enabled = requires_cuda_enabled,
1827
select = select,
1928
test_suite = native.test_suite,

tools/codegen/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
load("//:tools/bazel.bzl", "rules")
2+
load(":build.bzl", "define_targets")
3+
4+
define_targets(rules = rules)

0 commit comments

Comments
 (0)