blob: 46f24e4ce5cbff658a7076ac5f4417ae58e6738e [file] [log] [blame]
Marat Dukhan08c4a432019-10-03 09:29:21 -07001"""Build definitions and rules for XNNPACK."""
2
3load(":emscripten.bzl", "xnnpack_emscripten_benchmark_linkopts", "xnnpack_emscripten_deps", "xnnpack_emscripten_minimal_linkopts", "xnnpack_emscripten_test_linkopts")
4
5def xnnpack_visibility():
6 """Visibility of :XNNPACK target.
7
8 All other targets have private visibility, and can not have external
9 dependencies.
10 """
Marat Dukhan9d056a42019-10-03 12:13:35 -070011 return ["//visibility:public"]
Marat Dukhan08c4a432019-10-03 09:29:21 -070012
13def xnnpack_min_size_copts():
14 """Compiler flags for size-optimized builds."""
15 return ["-Os"]
16
Marat Dukhan10a38082020-04-17 03:58:35 -070017def xnnpack_gcc_std_copts():
18 """GCC-like compiler flags to specify language standard for C sources."""
Marat Dukhan08c4a432019-10-03 09:29:21 -070019 return ["-std=c99"]
20
Marat Dukhan10a38082020-04-17 03:58:35 -070021def xnnpack_msvc_std_copts():
22 """MSVC compiler flags to specify language standard for C sources."""
23 return ["/Drestrict="]
24
Marat Dukhan08c4a432019-10-03 09:29:21 -070025def xnnpack_std_cxxopts():
26 """Compiler flags to specify language standard for C++ sources."""
27 return ["-std=gnu++11"]
28
29def xnnpack_optional_ruy_copts():
30 """Compiler flags to optionally enable Ruy benchmarks."""
31 return []
32
33def xnnpack_optional_gemmlowp_copts():
34 """Compiler flags to optionally enable Gemmlowp benchmarks."""
35 return []
36
37def xnnpack_optional_tflite_copts():
38 """Compiler flags to optionally enable TensorFlow Lite benchmarks."""
39 return []
40
41def xnnpack_optional_armcl_copts():
42 """Compiler flags to optionally enable ARM ComputeLibrary benchmarks."""
43 return []
44
Marat Dukhan8d3c6932020-03-06 20:27:27 -080045def xnnpack_optional_dnnl_copts():
46 """Compiler flags to optionally enable Intel DNNL benchmarks."""
47 return []
48
Marat Dukhan08c4a432019-10-03 09:29:21 -070049def xnnpack_optional_ruy_deps():
50 """Optional Ruy dependencies."""
51 return []
52
53def xnnpack_optional_gemmlowp_deps():
54 """Optional Gemmlowp dependencies."""
55 return []
56
57def xnnpack_optional_tflite_deps():
58 """Optional TensorFlow Lite dependencies."""
59 return []
60
61def xnnpack_optional_armcl_deps():
62 """Optional ARM ComputeLibrary dependencies."""
63 return []
64
Marat Dukhan8d3c6932020-03-06 20:27:27 -080065def xnnpack_optional_dnnl_deps():
66 """Optional Intel DNNL dependencies."""
67 return []
68
Marat Dukhan08c4a432019-10-03 09:29:21 -070069def xnnpack_cc_library(
70 name,
71 srcs = [],
72 x86_srcs = [],
73 aarch32_srcs = [],
74 aarch64_srcs = [],
Marat Dukhan0ad47372022-01-04 16:05:25 -080075 riscv_srcs = [],
Marat Dukhancf056b22019-10-07 10:26:29 -070076 wasm_srcs = [],
77 wasmsimd_srcs = [],
Marat Dukhan19bfefe2021-12-21 19:16:06 -080078 wasmrelaxedsimd_srcs = [],
Marat Dukhan08c4a432019-10-03 09:29:21 -070079 copts = [],
Marat Dukhan10a38082020-04-17 03:58:35 -070080 gcc_copts = [],
81 msvc_copts = [],
82 mingw_copts = [],
83 msys_copts = [],
84 gcc_x86_copts = [],
85 msvc_x86_32_copts = [],
86 msvc_x86_64_copts = [],
Marat Dukhanbc69ed62020-06-09 21:34:56 -070087 apple_aarch32_copts = [],
Marat Dukhan08c4a432019-10-03 09:29:21 -070088 aarch32_copts = [],
89 aarch64_copts = [],
Marat Dukhan0ad47372022-01-04 16:05:25 -080090 riscv_copts = [],
Marat Dukhancf056b22019-10-07 10:26:29 -070091 wasm_copts = [],
92 wasmsimd_copts = [],
Marat Dukhan19bfefe2021-12-21 19:16:06 -080093 wasmrelaxedsimd_copts = [],
Marat Dukhan08c4a432019-10-03 09:29:21 -070094 optimized_copts = ["-O2"],
95 hdrs = [],
Marat Dukhan10a38082020-04-17 03:58:35 -070096 defines = [],
97 includes = [],
98 deps = [],
Zhi An Ngd90af6f2022-01-10 14:36:26 -080099 visibility = [],
100 testonly = False):
Marat Dukhancf056b22019-10-07 10:26:29 -0700101 """C/C++/assembly library with architecture-specific configuration.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700102
103 Define a static library with architecture- and instruction-specific
Marat Dukhancf056b22019-10-07 10:26:29 -0700104 source files and/or compiler flags.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700105
106 Args:
107 name: The name of the library target to define.
108 srcs: The list of architecture-independent source files.
109 x86_srcs: The list of x86-specific source files.
110 aarch32_srcs: The list of AArch32-specific source files.
111 aarch64_srcs: The list of AArch64-specific source files.
Marat Dukhan0ad47372022-01-04 16:05:25 -0800112 riscv_srcs: The list of RISC-V-specific source files.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800113 wasm_srcs: The list of WebAssembly 1.0-specific source files.
114 wasmsimd_srcs: The list of WebAssembly SIMD-specific source files.
115 wasmrelaxedsimd_srcs: The list of WebAssembly Relaxed SIMD-specific
116 source files.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700117 copts: The list of compiler flags to use in all builds. -I flags for
118 include/ and src/ directories of XNNPACK are always prepended
119 before these user-specified flags.
Marat Dukhan10a38082020-04-17 03:58:35 -0700120 gcc_copts: The list of compiler flags to use with GCC-like compilers.
121 msvc_copts: The list of compiler flags to use with MSVC compiler.
122 mingw_copts: The list of compiler flags to use with MinGW GCC compilers.
Marat Dukhanbc69ed62020-06-09 21:34:56 -0700123 msys_copts: The list of compiler flags to use with MSYS (Cygwin) GCC
124 compilers.
125 gcc_x86_copts: The list of GCC-like compiler flags to use in x86 (32-bit
126 and 64-bit) builds.
127 msvc_x86_32_copts: The list of MSVC compiler flags to use in x86 (32-bit)
128 builds.
129 msvc_x86_64_copts: The list of MSVC compiler flags to use in x86 (64-bit)
130 builds.
131 apple_aarch32_copts: The list of compiler flags to use in AArch32 builds
132 with Apple Clang.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700133 aarch32_copts: The list of compiler flags to use in AArch32 builds.
134 aarch64_copts: The list of compiler flags to use in AArch64 builds.
Marat Dukhan0ad47372022-01-04 16:05:25 -0800135 riscv_copts: The list of compiler flags to use in RISC-V builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800136 wasm_copts: The list of compiler flags to use in WebAssembly 1.0 builds.
137 wasmsimd_copts: The list of compiler flags to use in WebAssembly SIMD
Marat Dukhancf056b22019-10-07 10:26:29 -0700138 builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800139 wasmrelaxedsimd_copts: The list of compiler flags to use in WebAssembly
140 Relaxed SIMD builds.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700141 optimized_copts: The list of compiler flags to use in optimized builds.
142 Defaults to -O2.
143 hdrs: The list of header files published by this library to be textually
144 included by sources in dependent rules.
Marat Dukhan10a38082020-04-17 03:58:35 -0700145 defines: List of predefines macros to be added to the compile line.
146 includes: List of include dirs to be added to the compile line.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700147 deps: The list of other libraries to be linked.
Marat Dukhan10a38082020-04-17 03:58:35 -0700148 visibility: The list of packages that can depend on this target.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700149 """
150 native.cc_library(
151 name = name,
152 srcs = srcs + select({
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800153 ":linux_k8": x86_srcs,
154 ":linux_arm": aarch32_srcs,
155 ":linux_armeabi": aarch32_srcs,
156 ":linux_armhf": aarch32_srcs,
157 ":linux_armv7a": aarch32_srcs,
Marat Dukhan52e44432021-08-20 11:58:11 -0700158 ":linux_arm64": aarch64_srcs,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800159 ":macos_x86_64": x86_srcs,
Simon Maurer3b403c22021-03-03 14:24:02 +0100160 ":macos_arm64": aarch64_srcs,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800161 ":windows_x86_64_clang": x86_srcs,
162 ":windows_x86_64_mingw": x86_srcs,
163 ":windows_x86_64_msys": x86_srcs,
Marat Dukhan10a38082020-04-17 03:58:35 -0700164 ":windows_x86_64": x86_srcs,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800165 ":android_armv7": aarch32_srcs,
166 ":android_arm64": aarch64_srcs,
167 ":android_x86": x86_srcs,
168 ":android_x86_64": x86_srcs,
169 ":ios_armv7": aarch32_srcs,
170 ":ios_arm64": aarch64_srcs,
171 ":ios_arm64e": aarch64_srcs,
172 ":ios_x86": x86_srcs,
173 ":ios_x86_64": x86_srcs,
174 ":watchos_armv7k": aarch32_srcs,
175 ":watchos_arm64_32": aarch64_srcs,
176 ":watchos_x86": x86_srcs,
177 ":watchos_x86_64": x86_srcs,
178 ":tvos_arm64": aarch64_srcs,
179 ":tvos_x86_64": x86_srcs,
Marat Dukhancf056b22019-10-07 10:26:29 -0700180 ":emscripten_wasm": wasm_srcs,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800181 ":emscripten_wasmsimd": wasmsimd_srcs,
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800182 ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_srcs,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700183 "//conditions:default": [],
184 }),
185 copts = [
186 "-Iinclude",
187 "-Isrc",
188 ] + copts + select({
Marat Dukhan10a38082020-04-17 03:58:35 -0700189 ":linux_k8": gcc_x86_copts,
Marat Dukhan582094e2020-04-30 17:21:25 -0700190 ":linux_arm": aarch32_copts,
Marat Dukhanf0bd4de2020-06-15 15:53:19 -0700191 ":linux_armeabi": aarch32_copts,
Terry Heo68eef3f2020-04-13 22:53:52 -0700192 ":linux_armhf": aarch32_copts,
Marat Dukhan24567892020-06-10 13:15:48 -0700193 ":linux_armv7a": aarch32_copts,
Marat Dukhan52e44432021-08-20 11:58:11 -0700194 ":linux_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700195 ":macos_x86_64": gcc_x86_copts,
Simon Maurer3b403c22021-03-03 14:24:02 +0100196 ":macos_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700197 ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_x86_copts],
198 ":windows_x86_64_mingw": mingw_copts + gcc_x86_copts,
199 ":windows_x86_64_msys": msys_copts + gcc_x86_copts,
200 ":windows_x86_64": msvc_x86_64_copts,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700201 ":android_armv7": aarch32_copts,
202 ":android_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700203 ":android_x86": gcc_x86_copts,
204 ":android_x86_64": gcc_x86_copts,
Marat Dukhanbc69ed62020-06-09 21:34:56 -0700205 ":ios_armv7": apple_aarch32_copts,
Marat Dukhan1498d1d2020-02-11 20:00:05 -0800206 ":ios_arm64": aarch64_copts,
207 ":ios_arm64e": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700208 ":ios_x86": gcc_x86_copts,
209 ":ios_x86_64": gcc_x86_copts,
Marat Dukhanbc69ed62020-06-09 21:34:56 -0700210 ":watchos_armv7k": apple_aarch32_copts,
Marat Dukhan1498d1d2020-02-11 20:00:05 -0800211 ":watchos_arm64_32": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700212 ":watchos_x86": gcc_x86_copts,
213 ":watchos_x86_64": gcc_x86_copts,
Marat Dukhan1498d1d2020-02-11 20:00:05 -0800214 ":tvos_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700215 ":tvos_x86_64": gcc_x86_copts,
Marat Dukhancf056b22019-10-07 10:26:29 -0700216 ":emscripten_wasm": wasm_copts,
217 ":emscripten_wasmsimd": wasmsimd_copts,
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800218 ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_copts,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700219 "//conditions:default": [],
220 }) + select({
Marat Dukhan10a38082020-04-17 03:58:35 -0700221 ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_copts],
222 ":windows_x86_64_mingw": gcc_copts,
223 ":windows_x86_64_msys": gcc_copts,
224 ":windows_x86_64": msvc_copts,
225 "//conditions:default": gcc_copts,
226 }) + select({
Marat Dukhan08c4a432019-10-03 09:29:21 -0700227 ":optimized_build": optimized_copts,
228 "//conditions:default": [],
229 }),
Marat Dukhan10a38082020-04-17 03:58:35 -0700230 defines = defines,
231 deps = deps,
232 includes = ["include", "src"] + includes,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700233 linkstatic = True,
234 linkopts = select({
235 ":linux_k8": ["-lpthread"],
Marat Dukhan582094e2020-04-30 17:21:25 -0700236 ":linux_arm": ["-lpthread"],
Marat Dukhanf0bd4de2020-06-15 15:53:19 -0700237 ":linux_armeabi": ["-lpthread"],
Terry Heo68eef3f2020-04-13 22:53:52 -0700238 ":linux_armhf": ["-lpthread"],
Marat Dukhan24567892020-06-10 13:15:48 -0700239 ":linux_armv7a": ["-lpthread"],
Marat Dukhan52e44432021-08-20 11:58:11 -0700240 ":linux_arm64": ["-lpthread"],
Marat Dukhan08c4a432019-10-03 09:29:21 -0700241 ":android": ["-lm"],
242 "//conditions:default": [],
243 }),
244 textual_hdrs = hdrs,
Marat Dukhan10a38082020-04-17 03:58:35 -0700245 visibility = visibility,
Zhi An Ngd90af6f2022-01-10 14:36:26 -0800246 testonly = testonly,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700247 )
248
249def xnnpack_aggregate_library(
250 name,
251 generic_deps = [],
252 x86_deps = [],
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700253 aarch32_ios_deps = [],
254 aarch32_nonios_deps = [],
Marat Dukhan08c4a432019-10-03 09:29:21 -0700255 aarch64_deps = [],
Marat Dukhan0ad47372022-01-04 16:05:25 -0800256 riscv_deps = [],
Marat Dukhan08c4a432019-10-03 09:29:21 -0700257 wasm_deps = [],
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800258 wasmsimd_deps = [],
259 wasmrelaxedsimd_deps = []):
Marat Dukhan08c4a432019-10-03 09:29:21 -0700260 """Static library that aggregates architecture-specific dependencies.
261
262 Args:
263 name: The name of the library target to define.
264 generic_deps: The list of libraries to link on all architectures.
265 x86_deps: The list of libraries to link in x86 and x86-64 builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800266 aarch32_ios_deps: The list of libraries to link in AArch32 iOS (incl
267 WatchOS) builds.
268 aarch32_nonios_deps: The list of libraries to link in AArch32 non-iOS
269 builds.
Marat Dukhan0ad47372022-01-04 16:05:25 -0800270 aarch64_deps: The list of libraries to link in AArch64 builds.
271 riscv_deps: The list of libraries to link in RISC-V builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800272 wasm_deps: The list of libraries to link in WebAssembly 1.0 builds.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700273 wasmsimd_deps: The list of libraries to link in WebAssembly SIMD builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800274 wasmrelaxedsimd_deps: The list of libraries to link in WebAssembly
275 Relaxed SIMD builds.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700276 """
277
278 native.cc_library(
279 name = name,
280 linkstatic = True,
281 deps = generic_deps + select({
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800282 ":linux_k8": x86_deps,
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700283 ":linux_arm": aarch32_nonios_deps,
284 ":linux_armeabi": aarch32_nonios_deps,
285 ":linux_armhf": aarch32_nonios_deps,
286 ":linux_armv7a": aarch32_nonios_deps,
Marat Dukhan52e44432021-08-20 11:58:11 -0700287 ":linux_arm64": aarch64_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800288 ":macos_x86_64": x86_deps,
Simon Maurer3b403c22021-03-03 14:24:02 +0100289 ":macos_arm64": aarch64_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800290 ":windows_x86_64_clang": x86_deps,
291 ":windows_x86_64_mingw": x86_deps,
292 ":windows_x86_64_msys": x86_deps,
Marat Dukhan10a38082020-04-17 03:58:35 -0700293 ":windows_x86_64": x86_deps,
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700294 ":android_armv7": aarch32_nonios_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800295 ":android_arm64": aarch64_deps,
296 ":android_x86": x86_deps,
297 ":android_x86_64": x86_deps,
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700298 ":ios_armv7": aarch32_ios_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800299 ":ios_arm64": aarch64_deps,
300 ":ios_arm64e": aarch64_deps,
301 ":ios_x86": x86_deps,
302 ":ios_x86_64": x86_deps,
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700303 ":watchos_armv7k": aarch32_ios_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800304 ":watchos_arm64_32": aarch64_deps,
305 ":watchos_x86": x86_deps,
306 ":watchos_x86_64": x86_deps,
307 ":tvos_arm64": aarch64_deps,
308 ":tvos_x86_64": x86_deps,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700309 ":emscripten_wasm": wasm_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800310 ":emscripten_wasmsimd": wasmsimd_deps,
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800311 ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_deps,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700312 }),
313 )
314
Alan Kelly66210582021-11-23 00:57:36 -0800315def xnnpack_unit_test(name, srcs, copts = [], mingw_copts = [], msys_copts = [], deps = [], tags = [], automatic = True, timeout = "short", shard_count = 1):
Marat Dukhan08c4a432019-10-03 09:29:21 -0700316 """Unit test binary based on Google Test.
317
318 Args:
319 name: The name of the test target to define.
320 srcs: The list of source and header files.
321 copts: The list of additional compiler flags for the target. -I flags
322 for include/ and src/ directories of XNNPACK are always prepended
323 before these user-specified flags.
Marat Dukhan10a38082020-04-17 03:58:35 -0700324 mingw_copts: The list of compiler flags to use with MinGW GCC compilers.
325 msys_copts: The list of compiler flags to use with MSYS (Cygwin) GCC compilers.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700326 deps: The list of additional libraries to be linked. Google Test library
327 (with main() function) is always added as a dependency and does not
328 need to be explicitly specified.
Artsiom Ablavatskic1aa2972020-12-08 11:23:34 -0800329 tags: List of arbitrary text tags.
330 automatic: Whether to create the test or testable binary.
331 timeout: How long the test is expected to run before returning.
Alan Kelly66210582021-11-23 00:57:36 -0800332 shard_count: Specifies the number of parallel shards to use to run the test.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700333 """
334
Marat Dukhan22eed3d2020-05-11 20:13:37 -0700335 if automatic:
336 native.cc_test(
337 name = name,
338 srcs = srcs,
339 copts = xnnpack_std_cxxopts() + [
340 "-Iinclude",
341 "-Isrc",
342 ] + select({
343 ":windows_x86_64_mingw": mingw_copts,
344 ":windows_x86_64_msys": msys_copts,
345 "//conditions:default": [],
346 }) + select({
347 ":windows_x86_64_clang": ["/clang:-Wno-unused-function"],
348 ":windows_x86_64_mingw": ["-Wno-unused-function"],
349 ":windows_x86_64_msys": ["-Wno-unused-function"],
350 ":windows_x86_64": [],
351 "//conditions:default": ["-Wno-unused-function"],
352 }) + copts,
353 linkopts = select({
354 ":emscripten": xnnpack_emscripten_test_linkopts(),
355 "//conditions:default": [],
356 }),
357 linkstatic = True,
358 deps = [
359 "@com_google_googletest//:gtest_main",
360 ] + deps + select({
361 ":emscripten": xnnpack_emscripten_deps(),
362 "//conditions:default": [],
363 }),
364 tags = tags,
Artsiom Ablavatskic1aa2972020-12-08 11:23:34 -0800365 timeout = timeout,
Alan Kelly66210582021-11-23 00:57:36 -0800366 shard_count = shard_count,
Marat Dukhan22eed3d2020-05-11 20:13:37 -0700367 )
368 else:
369 native.cc_binary(
370 name = name,
371 srcs = srcs,
372 copts = xnnpack_std_cxxopts() + [
373 "-Iinclude",
374 "-Isrc",
375 ] + select({
376 ":windows_x86_64_mingw": mingw_copts,
377 ":windows_x86_64_msys": msys_copts,
378 "//conditions:default": [],
379 }) + select({
380 ":windows_x86_64_clang": ["/clang:-Wno-unused-function"],
381 ":windows_x86_64_mingw": ["-Wno-unused-function"],
382 ":windows_x86_64_msys": ["-Wno-unused-function"],
383 ":windows_x86_64": [],
384 "//conditions:default": ["-Wno-unused-function"],
385 }) + copts,
386 linkopts = select({
387 ":emscripten": xnnpack_emscripten_test_linkopts(),
388 "//conditions:default": [],
389 }),
390 linkstatic = True,
391 deps = [
392 "@com_google_googletest//:gtest_main",
393 ] + deps + select({
394 ":emscripten": xnnpack_emscripten_deps(),
395 "//conditions:default": [],
396 }),
397 testonly = True,
398 tags = tags,
399 )
Marat Dukhan08c4a432019-10-03 09:29:21 -0700400
401def xnnpack_binary(name, srcs, copts = [], deps = []):
402 """Minimal binary
403
404 Args:
405 name: The name of the binary target to define.
406 srcs: The list of source and header files.
407 copts: The list of additional compiler flags for the target. -I flags
408 for include/ and src/ directories of XNNPACK are always prepended
409 before these user-specified flags.
410 deps: The list of libraries to be linked.
411 """
412 native.cc_binary(
413 name = name,
414 srcs = srcs,
415 copts = [
416 "-Iinclude",
417 "-Isrc",
418 ] + copts,
419 linkopts = select({
420 ":emscripten": xnnpack_emscripten_minimal_linkopts(),
421 "//conditions:default": [],
422 }),
423 linkstatic = True,
424 deps = deps,
425 )
426
Marat Dukhana98efa12020-05-04 17:07:49 -0700427def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []):
Marat Dukhan08c4a432019-10-03 09:29:21 -0700428 """Microbenchmark binary based on Google Benchmark
429
430 Args:
431 name: The name of the binary target to define.
432 srcs: The list of source and header files.
433 copts: The list of additional compiler flags for the target. -I flags
434 for include/ and src/ directories of XNNPACK are always prepended
435 before these user-specified flags.
436 deps: The list of additional libraries to be linked. Google Benchmark
437 library is always added as a dependency and does not need to be
438 explicitly specified.
439 """
440 native.cc_binary(
441 name = name,
442 srcs = srcs,
443 copts = xnnpack_std_cxxopts() + [
444 "-Iinclude",
445 "-Isrc",
Marat Dukhana98efa12020-05-04 17:07:49 -0700446 ] + select({
447 ":windows_x86_64_clang": ["/clang:-Wno-unused-function"],
448 ":windows_x86_64_mingw": ["-Wno-unused-function"],
449 ":windows_x86_64_msys": ["-Wno-unused-function"],
450 ":windows_x86_64": [],
451 "//conditions:default": ["-Wno-unused-function"],
452 }) + copts,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700453 linkopts = select({
454 ":emscripten": xnnpack_emscripten_benchmark_linkopts(),
Marat Dukhan10a38082020-04-17 03:58:35 -0700455 ":windows_x86_64_mingw": ["-lshlwapi"],
456 ":windows_x86_64_msys": ["-lshlwapi"],
Marat Dukhan08c4a432019-10-03 09:29:21 -0700457 "//conditions:default": [],
458 }),
459 linkstatic = True,
460 deps = [
461 "@com_google_benchmark//:benchmark",
462 ] + deps + select({
463 ":emscripten": xnnpack_emscripten_deps(),
464 "//conditions:default": [],
465 }),
Marat Dukhan8ea0b072020-04-23 16:12:18 -0700466 tags = tags,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700467 )