forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtargets.bzl
More file actions
120 lines (111 loc) · 4.33 KB
/
targets.bzl
File metadata and controls
120 lines (111 loc) · 4.33 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
load("@fbsource//xplat/executorch/build:build_variables.bzl", "PLATFORM_SRCS")
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load(":log.bzl", "get_et_logging_flags")
def _select_pal(dict_):
"""Returns an element of `dict_` based on the value of the
`executorch.pal_default` build config value. Fails if no corresponding entry
exists.
"""
pal_default = native.read_config("executorch", "pal_default", "posix")
if not pal_default in dict_:
fail("Missing key for executorch.pal_default value '{}' in dict '{}'".format(pal_default, dict_))
return dict_[pal_default]
def profiling_enabled():
return native.read_config("executorch", "prof_enabled", "false") == "true"
def get_profiling_flags():
profiling_flags = []
if profiling_enabled():
profiling_flags += ["-DPROFILING_ENABLED"]
prof_buf_size = native.read_config("executorch", "prof_buf_size", None)
if prof_buf_size != None:
if not profiling_enabled():
fail("Cannot set profiling buffer size without enabling profiling first.")
profiling_flags += ["-DMAX_PROFILE_EVENTS={}".format(prof_buf_size), "-DMAX_MEM_PROFILE_EVENTS={}".format(prof_buf_size)]
num_prof_blocks = native.read_config("executorch", "num_prof_blocks", None)
if num_prof_blocks != None:
if not profiling_enabled():
fail("Cannot configure number of profiling blocks without enabling profiling first.")
profiling_flags += ["-DMAX_PROFILE_BLOCKS={}".format(num_prof_blocks)]
return profiling_flags
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.
"""
# Default implementations of pal functions. These are weak symbols, so
# client defined implementations will overide them.
runtime.cxx_library(
name = "platform_private",
srcs = select({
"ovr_config//os:android": ["default/android.cpp"],
"DEFAULT": _select_pal({
"minimal": ["default/minimal.cpp"],
"posix": ["default/posix.cpp"],
})}),
deps = [
":pal_interface",
],
external_deps = ["log"],
visibility = [
"//executorch/core/...",
],
# WARNING: using a deprecated API to avoid being built into a shared
# library. In the case of dynamically loading .so library we don't want
# it to depend on other .so libraries because that way we have to
# specify library directory path.
force_static = True,
)
# Interfaces for executorch users
runtime.cxx_library(
name = "platform",
exported_headers = [
"abort.h",
"assert.h",
"clock.h",
"log.h",
"profiler.h",
"runtime.h",
"compat_unistd.h",
],
srcs = PLATFORM_SRCS,
exported_preprocessor_flags = get_profiling_flags() + get_et_logging_flags(),
exported_deps = [
"//executorch/runtime/platform:pal_interface",
":compiler",
":platform_private",
],
visibility = ["PUBLIC"],
# WARNING: using a deprecated API to avoid being built into a shared
# library. In the case of dynamically loading so library we don't want
# it to depend on other so libraries because that way we have to
# specify library directory path.
force_static = True,
)
# Library for backend implementers to define implementations against.
runtime.cxx_library(
name = "pal_interface",
exported_headers = [
"platform.h",
"system.h",
"types.h",
],
exported_deps = [
":compiler",
],
exported_preprocessor_flags = select(
{
"DEFAULT": [],
"ovr_config//os:linux": ["-DET_USE_LIBDL"],
"ovr_config//os:macos": ["-DET_USE_LIBDL"],
},
),
visibility = ["PUBLIC"],
)
# Common compiler directives such as 'unlikely' or 'deprecated'
runtime.cxx_library(
name = "compiler",
exported_headers = [
"compiler.h",
],
visibility = ["PUBLIC"],
)