-
Notifications
You must be signed in to change notification settings - Fork 512
/
Copy pathtargets.bzl
106 lines (94 loc) · 3.67 KB
/
targets.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
# Construct the input and output file names. All input and output files rely on scalar_type file.
PROGRAM_STEM = "program"
SCALAR_TYPE_STEM = "scalar_type"
INPUT_PROGRAM = PROGRAM_STEM + ".fbs"
INPUT_SCALAR_TYPE = SCALAR_TYPE_STEM + ".fbs"
OUTPUT_PROGRAM_HEADER = PROGRAM_STEM + "_generated.h"
OUTPUT_SCALAR_TYPE_HEADER = SCALAR_TYPE_STEM + "_generated.h"
PROGRAM_GEN_RULE_NAME = "generate_program"
PROGRAM_LIRRARY_NAME = PROGRAM_STEM
def _generate_schema_header(rule_name, srcs, headers, default_header):
"""Generate header file given flatbuffer schema
"""
runtime.genrule(
name = rule_name,
srcs = srcs,
# We're only generating a single file, so it seems like we could use
# `out`, but `flatc` takes a directory as a parameter, not a single
# file. Use `outs` so that `${OUT}` is expanded as the containing
# directory instead of the file itself.
outs = {header: [header] for header in headers},
default_outs = [default_header],
cmd = " ".join([
"$(exe {})".format(runtime.external_dep_location("flatc")),
"--cpp",
"--cpp-std c++11",
"--gen-mutable",
"--scoped-enums",
"-o ${OUT}",
"${SRCS}",
# Let our infra know that the file was generated.
" ".join(["&& echo // @" + "generated >> ${OUT}/" + header for header in headers]),
]),
visibility = [], # Private
)
def define_common_targets():
"""Defines targets that should be shared between fbcode and xplat.
The directory containing this targets.bzl file should also contain both
TARGETS and BUCK files that call this function.
"""
runtime.export_file(
name = INPUT_PROGRAM,
visibility = [
"//executorch/exir/_serialize/...",
],
)
runtime.export_file(
name = INPUT_SCALAR_TYPE,
visibility = [
"//executorch/exir/_serialize/...",
"//executorch/devtools/etdump/...",
],
)
_generate_schema_header(
PROGRAM_GEN_RULE_NAME,
[INPUT_PROGRAM, INPUT_SCALAR_TYPE],
[OUTPUT_PROGRAM_HEADER, OUTPUT_SCALAR_TYPE_HEADER],
OUTPUT_PROGRAM_HEADER,
)
# Header-only library target with the generate executorch program schema header.
runtime.cxx_library(
name = PROGRAM_LIRRARY_NAME,
srcs = [],
visibility = [
# Lock this down as tightly as possible to ensure that flatbuffers
# are an implementation detail. Ideally this list would only include
# //executorch/runtime/executor/...
"//executorch/codegen/tools/...",
"//executorch/runtime/executor/...",
# Tests have a set up which uses raw flatbuffer.
# TODO will refactor these setup steps into
# testing utils in runtime/executor/... path
"//executorch/backends/xnnpack/test/...",
],
exported_headers = {
OUTPUT_PROGRAM_HEADER: ":{}[{}]".format(PROGRAM_GEN_RULE_NAME, OUTPUT_PROGRAM_HEADER),
OUTPUT_SCALAR_TYPE_HEADER: ":{}[{}]".format(PROGRAM_GEN_RULE_NAME, OUTPUT_SCALAR_TYPE_HEADER),
},
exported_external_deps = ["flatbuffers-api"],
)
runtime.cxx_library(
name = "extended_header",
srcs = ["extended_header.cpp"],
exported_headers = [
"extended_header.h",
],
visibility = [
"//executorch/runtime/executor/...",
"//executorch/schema/test/...",
],
exported_deps = [
"//executorch/runtime/core:core",
],
)