Skip to content

Commit 4788feb

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Make codegen.bzl oss compliant
Summary: This is part of an effort to enable OSS BUCK2 build for Executorch. codegen.bzl is required for kernel registration and it's currently accessing external (non-executorch) deps. This diff uses the new `external_deps` feature added to `runtime_wrapper` to support these deps. Notice that we have two places depending on `libtorch` in fbcode but we depend on `torch_mobile_all_ops` and `torch` respectively in fbsource. Here I'm choosing `torch_mobile_all_ops` and see if it passes CI. Reviewed By: cccclai, dbort Differential Revision: D47615228 fbshipit-source-id: 86716736958f605a5e377f18e81e3ef4be94d99a
1 parent f8bddd7 commit 4788feb

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

build/env_interface.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ _EXTERNAL_DEPS_MAP = {
9292
_FBCODE: _EXTERNAL_DEP_FALLTHROUGH,
9393
_XPLAT: "//xplat/third-party/gflags:gflags",
9494
},
95+
"libtorch": {
96+
_FBCODE: "//caffe2:libtorch",
97+
_XPLAT: "//xplat/caffe2:torch_mobile_all_ops",
98+
},
9599
}
96100

97101
def _start_with_et_targets(target):

codegen/codegen.bzl

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_xplat")
21
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_default_executorch_platforms", "runtime")
32

43
# Headers that declare the function signatures of the C++ functions that
@@ -111,11 +110,13 @@ def _prepare_genrule_and_lib(
111110
},
112111
}
113112
"""
113+
target = runtime.external_dep_location("gen-executorch")
114+
aten_src_path = runtime.external_dep_location("aten-src-path")
114115
genrule_cmd = [
115-
"$(exe " + runtime.external_dep_location("gen-executorch") + ")",
116+
"$(exe {})".format(target),
116117
"--source-path=$(location //executorch/codegen:templates)",
117-
"--tags-path $(location " + runtime.external_dep_location("aten-src-path") + ")/aten/src/ATen/native/tags.yaml",
118-
"--aten_yaml_path $(location " + runtime.external_dep_location("aten-src-path") + ")/aten/src/ATen/native/native_functions.yaml",
118+
"--tags-path $(location {})/aten/src/ATen/native/tags.yaml".format(aten_src_path),
119+
"--aten_yaml_path $(location {})/aten/src/ATen/native/native_functions.yaml".format(aten_src_path),
119120
"--install_dir=${OUT}",
120121
# TODO(dbort): Add a second step that verifies that the set of
121122
# actually-generated files matches GENERATED_FILES.
@@ -146,7 +147,7 @@ def _prepare_genrule_and_lib(
146147

147148
if need_reg_aten_ops:
148149
path = (
149-
"$(location fbsource//xplat/caffe2:aten_src_path)/aten/src/ATen/native/native_functions.yaml"
150+
"$(location {})/aten/src/ATen/native/native_functions.yaml".format(aten_src_path)
150151
) if not functions_yaml_path else functions_yaml_path
151152
genrule_cmd = genrule_cmd + [
152153
"--functions_yaml_path={}".format(path),
@@ -341,8 +342,6 @@ def executorch_generated_lib(
341342
],
342343
)
343344

344-
xplat_deps = xplat_deps + (["//xplat/caffe2:torch_mobile_all_ops"] if aten_mode and use_default_aten_ops_lib else [])
345-
fbcode_deps = fbcode_deps + (["//caffe2:libtorch"] if aten_mode and use_default_aten_ops_lib else [])
346345
if name in libs:
347346
lib_name = name
348347
runtime.cxx_library(
@@ -376,6 +375,7 @@ def executorch_generated_lib(
376375
],
377376
xplat_deps = xplat_deps,
378377
fbcode_deps = fbcode_deps,
378+
external_deps = ["libtorch"] if aten_mode and use_default_aten_ops_lib else [],
379379
define_static_target = define_static_targets,
380380
# Relax visibility restrictions since deps may include targets outside
381381
# of //executorch.
@@ -392,12 +392,6 @@ def executorch_generated_lib(
392392
# custom_ops_requires_runtime_registration is True.
393393
compiler_lib = "custom_ops_" + name if "custom_ops_" + name in libs else None
394394
if compiler_lib:
395-
# The library needs to be able to include <torch/library.h>.
396-
if is_xplat():
397-
torch_dep = ["//xplat/caffe2:torch"]
398-
else:
399-
torch_dep = ["//caffe2:libtorch"]
400-
401395
# TODO(T129125039): Rename this to make it clear that it's not part of
402396
# the embedded runtime; it's only for registering custom ops with the
403397
# PyTorch authoring runtime.
@@ -419,10 +413,11 @@ def executorch_generated_lib(
419413
"//executorch/runtime/core/exec_aten:lib_aten",
420414
"//executorch/runtime/core:core",
421415
"//executorch/codegen:macros",
422-
] + torch_dep + custom_ops_aten_kernel_deps,
416+
] + custom_ops_aten_kernel_deps,
423417
exported_deps = [
424418
"//executorch/runtime/kernel:kernel_runtime_context_aten",
425419
],
420+
external_deps = ["libtorch"],
426421
define_static_target = define_static_targets,
427422
# Relax visibility restrictions since deps may include targets
428423
# outside of //executorch.

shim/xplat/executorch/build/env_interface.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ _EXTERNAL_DEPS = {
2323
"gen-executorch": "//third-party:gen_executorch",
2424
# Commandline flags library
2525
"gflags": [], # TODO(larryliu0820): Add support
26+
"libtorch": [], # TODO(larryliu0820): Add support
2627
}
2728

2829
def _resolve_external_dep(name):

0 commit comments

Comments
 (0)