blob: dc481e8e10aeabe7861f391136cf6c04714de8ea [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 = [],
99 visibility = []):
Marat Dukhancf056b22019-10-07 10:26:29 -0700100 """C/C++/assembly library with architecture-specific configuration.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700101
102 Define a static library with architecture- and instruction-specific
Marat Dukhancf056b22019-10-07 10:26:29 -0700103 source files and/or compiler flags.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700104
105 Args:
106 name: The name of the library target to define.
107 srcs: The list of architecture-independent source files.
108 x86_srcs: The list of x86-specific source files.
109 aarch32_srcs: The list of AArch32-specific source files.
110 aarch64_srcs: The list of AArch64-specific source files.
Marat Dukhan0ad47372022-01-04 16:05:25 -0800111 riscv_srcs: The list of RISC-V-specific source files.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800112 wasm_srcs: The list of WebAssembly 1.0-specific source files.
113 wasmsimd_srcs: The list of WebAssembly SIMD-specific source files.
114 wasmrelaxedsimd_srcs: The list of WebAssembly Relaxed SIMD-specific
115 source files.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700116 copts: The list of compiler flags to use in all builds. -I flags for
117 include/ and src/ directories of XNNPACK are always prepended
118 before these user-specified flags.
Marat Dukhan10a38082020-04-17 03:58:35 -0700119 gcc_copts: The list of compiler flags to use with GCC-like compilers.
120 msvc_copts: The list of compiler flags to use with MSVC compiler.
121 mingw_copts: The list of compiler flags to use with MinGW GCC compilers.
Marat Dukhanbc69ed62020-06-09 21:34:56 -0700122 msys_copts: The list of compiler flags to use with MSYS (Cygwin) GCC
123 compilers.
124 gcc_x86_copts: The list of GCC-like compiler flags to use in x86 (32-bit
125 and 64-bit) builds.
126 msvc_x86_32_copts: The list of MSVC compiler flags to use in x86 (32-bit)
127 builds.
128 msvc_x86_64_copts: The list of MSVC compiler flags to use in x86 (64-bit)
129 builds.
130 apple_aarch32_copts: The list of compiler flags to use in AArch32 builds
131 with Apple Clang.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700132 aarch32_copts: The list of compiler flags to use in AArch32 builds.
133 aarch64_copts: The list of compiler flags to use in AArch64 builds.
Marat Dukhan0ad47372022-01-04 16:05:25 -0800134 riscv_copts: The list of compiler flags to use in RISC-V builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800135 wasm_copts: The list of compiler flags to use in WebAssembly 1.0 builds.
136 wasmsimd_copts: The list of compiler flags to use in WebAssembly SIMD
Marat Dukhancf056b22019-10-07 10:26:29 -0700137 builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800138 wasmrelaxedsimd_copts: The list of compiler flags to use in WebAssembly
139 Relaxed SIMD builds.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700140 optimized_copts: The list of compiler flags to use in optimized builds.
141 Defaults to -O2.
142 hdrs: The list of header files published by this library to be textually
143 included by sources in dependent rules.
Marat Dukhan10a38082020-04-17 03:58:35 -0700144 defines: List of predefines macros to be added to the compile line.
145 includes: List of include dirs to be added to the compile line.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700146 deps: The list of other libraries to be linked.
Marat Dukhan10a38082020-04-17 03:58:35 -0700147 visibility: The list of packages that can depend on this target.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700148 """
149 native.cc_library(
150 name = name,
151 srcs = srcs + select({
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800152 ":linux_k8": x86_srcs,
153 ":linux_arm": aarch32_srcs,
154 ":linux_armeabi": aarch32_srcs,
155 ":linux_armhf": aarch32_srcs,
156 ":linux_armv7a": aarch32_srcs,
Marat Dukhan52e44432021-08-20 11:58:11 -0700157 ":linux_arm64": aarch64_srcs,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800158 ":macos_x86_64": x86_srcs,
Simon Maurer3b403c22021-03-03 14:24:02 +0100159 ":macos_arm64": aarch64_srcs,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800160 ":windows_x86_64_clang": x86_srcs,
161 ":windows_x86_64_mingw": x86_srcs,
162 ":windows_x86_64_msys": x86_srcs,
Marat Dukhan10a38082020-04-17 03:58:35 -0700163 ":windows_x86_64": x86_srcs,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800164 ":android_armv7": aarch32_srcs,
165 ":android_arm64": aarch64_srcs,
166 ":android_x86": x86_srcs,
167 ":android_x86_64": x86_srcs,
168 ":ios_armv7": aarch32_srcs,
169 ":ios_arm64": aarch64_srcs,
170 ":ios_arm64e": aarch64_srcs,
171 ":ios_x86": x86_srcs,
172 ":ios_x86_64": x86_srcs,
173 ":watchos_armv7k": aarch32_srcs,
174 ":watchos_arm64_32": aarch64_srcs,
175 ":watchos_x86": x86_srcs,
176 ":watchos_x86_64": x86_srcs,
177 ":tvos_arm64": aarch64_srcs,
178 ":tvos_x86_64": x86_srcs,
Marat Dukhancf056b22019-10-07 10:26:29 -0700179 ":emscripten_wasm": wasm_srcs,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800180 ":emscripten_wasmsimd": wasmsimd_srcs,
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800181 ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_srcs,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700182 "//conditions:default": [],
183 }),
184 copts = [
185 "-Iinclude",
186 "-Isrc",
187 ] + copts + select({
Marat Dukhan10a38082020-04-17 03:58:35 -0700188 ":linux_k8": gcc_x86_copts,
Marat Dukhan582094e2020-04-30 17:21:25 -0700189 ":linux_arm": aarch32_copts,
Marat Dukhanf0bd4de2020-06-15 15:53:19 -0700190 ":linux_armeabi": aarch32_copts,
Terry Heo68eef3f2020-04-13 22:53:52 -0700191 ":linux_armhf": aarch32_copts,
Marat Dukhan24567892020-06-10 13:15:48 -0700192 ":linux_armv7a": aarch32_copts,
Marat Dukhan52e44432021-08-20 11:58:11 -0700193 ":linux_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700194 ":macos_x86_64": gcc_x86_copts,
Simon Maurer3b403c22021-03-03 14:24:02 +0100195 ":macos_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700196 ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_x86_copts],
197 ":windows_x86_64_mingw": mingw_copts + gcc_x86_copts,
198 ":windows_x86_64_msys": msys_copts + gcc_x86_copts,
199 ":windows_x86_64": msvc_x86_64_copts,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700200 ":android_armv7": aarch32_copts,
201 ":android_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700202 ":android_x86": gcc_x86_copts,
203 ":android_x86_64": gcc_x86_copts,
Marat Dukhanbc69ed62020-06-09 21:34:56 -0700204 ":ios_armv7": apple_aarch32_copts,
Marat Dukhan1498d1d2020-02-11 20:00:05 -0800205 ":ios_arm64": aarch64_copts,
206 ":ios_arm64e": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700207 ":ios_x86": gcc_x86_copts,
208 ":ios_x86_64": gcc_x86_copts,
Marat Dukhanbc69ed62020-06-09 21:34:56 -0700209 ":watchos_armv7k": apple_aarch32_copts,
Marat Dukhan1498d1d2020-02-11 20:00:05 -0800210 ":watchos_arm64_32": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700211 ":watchos_x86": gcc_x86_copts,
212 ":watchos_x86_64": gcc_x86_copts,
Marat Dukhan1498d1d2020-02-11 20:00:05 -0800213 ":tvos_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700214 ":tvos_x86_64": gcc_x86_copts,
Marat Dukhancf056b22019-10-07 10:26:29 -0700215 ":emscripten_wasm": wasm_copts,
216 ":emscripten_wasmsimd": wasmsimd_copts,
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800217 ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_copts,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700218 "//conditions:default": [],
219 }) + select({
Marat Dukhan10a38082020-04-17 03:58:35 -0700220 ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_copts],
221 ":windows_x86_64_mingw": gcc_copts,
222 ":windows_x86_64_msys": gcc_copts,
223 ":windows_x86_64": msvc_copts,
224 "//conditions:default": gcc_copts,
225 }) + select({
Marat Dukhan08c4a432019-10-03 09:29:21 -0700226 ":optimized_build": optimized_copts,
227 "//conditions:default": [],
228 }),
Marat Dukhan10a38082020-04-17 03:58:35 -0700229 defines = defines,
230 deps = deps,
231 includes = ["include", "src"] + includes,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700232 linkstatic = True,
233 linkopts = select({
234 ":linux_k8": ["-lpthread"],
Marat Dukhan582094e2020-04-30 17:21:25 -0700235 ":linux_arm": ["-lpthread"],
Marat Dukhanf0bd4de2020-06-15 15:53:19 -0700236 ":linux_armeabi": ["-lpthread"],
Terry Heo68eef3f2020-04-13 22:53:52 -0700237 ":linux_armhf": ["-lpthread"],
Marat Dukhan24567892020-06-10 13:15:48 -0700238 ":linux_armv7a": ["-lpthread"],
Marat Dukhan52e44432021-08-20 11:58:11 -0700239 ":linux_arm64": ["-lpthread"],
Marat Dukhan08c4a432019-10-03 09:29:21 -0700240 ":android": ["-lm"],
241 "//conditions:default": [],
242 }),
243 textual_hdrs = hdrs,
Marat Dukhan10a38082020-04-17 03:58:35 -0700244 visibility = visibility,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700245 )
246
247def xnnpack_aggregate_library(
248 name,
249 generic_deps = [],
250 x86_deps = [],
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700251 aarch32_ios_deps = [],
252 aarch32_nonios_deps = [],
Marat Dukhan08c4a432019-10-03 09:29:21 -0700253 aarch64_deps = [],
Marat Dukhan0ad47372022-01-04 16:05:25 -0800254 riscv_deps = [],
Marat Dukhan08c4a432019-10-03 09:29:21 -0700255 wasm_deps = [],
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800256 wasmsimd_deps = [],
257 wasmrelaxedsimd_deps = []):
Marat Dukhan08c4a432019-10-03 09:29:21 -0700258 """Static library that aggregates architecture-specific dependencies.
259
260 Args:
261 name: The name of the library target to define.
262 generic_deps: The list of libraries to link on all architectures.
263 x86_deps: The list of libraries to link in x86 and x86-64 builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800264 aarch32_ios_deps: The list of libraries to link in AArch32 iOS (incl
265 WatchOS) builds.
266 aarch32_nonios_deps: The list of libraries to link in AArch32 non-iOS
267 builds.
Marat Dukhan0ad47372022-01-04 16:05:25 -0800268 aarch64_deps: The list of libraries to link in AArch64 builds.
269 riscv_deps: The list of libraries to link in RISC-V builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800270 wasm_deps: The list of libraries to link in WebAssembly 1.0 builds.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700271 wasmsimd_deps: The list of libraries to link in WebAssembly SIMD builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800272 wasmrelaxedsimd_deps: The list of libraries to link in WebAssembly
273 Relaxed SIMD builds.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700274 """
275
276 native.cc_library(
277 name = name,
278 linkstatic = True,
279 deps = generic_deps + select({
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800280 ":linux_k8": x86_deps,
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700281 ":linux_arm": aarch32_nonios_deps,
282 ":linux_armeabi": aarch32_nonios_deps,
283 ":linux_armhf": aarch32_nonios_deps,
284 ":linux_armv7a": aarch32_nonios_deps,
Marat Dukhan52e44432021-08-20 11:58:11 -0700285 ":linux_arm64": aarch64_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800286 ":macos_x86_64": x86_deps,
Simon Maurer3b403c22021-03-03 14:24:02 +0100287 ":macos_arm64": aarch64_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800288 ":windows_x86_64_clang": x86_deps,
289 ":windows_x86_64_mingw": x86_deps,
290 ":windows_x86_64_msys": x86_deps,
Marat Dukhan10a38082020-04-17 03:58:35 -0700291 ":windows_x86_64": x86_deps,
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700292 ":android_armv7": aarch32_nonios_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800293 ":android_arm64": aarch64_deps,
294 ":android_x86": x86_deps,
295 ":android_x86_64": x86_deps,
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700296 ":ios_armv7": aarch32_ios_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800297 ":ios_arm64": aarch64_deps,
298 ":ios_arm64e": aarch64_deps,
299 ":ios_x86": x86_deps,
300 ":ios_x86_64": x86_deps,
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700301 ":watchos_armv7k": aarch32_ios_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800302 ":watchos_arm64_32": aarch64_deps,
303 ":watchos_x86": x86_deps,
304 ":watchos_x86_64": x86_deps,
305 ":tvos_arm64": aarch64_deps,
306 ":tvos_x86_64": x86_deps,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700307 ":emscripten_wasm": wasm_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800308 ":emscripten_wasmsimd": wasmsimd_deps,
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800309 ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_deps,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700310 }),
311 )
312
Alan Kelly66210582021-11-23 00:57:36 -0800313def 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 -0700314 """Unit test binary based on Google Test.
315
316 Args:
317 name: The name of the test target to define.
318 srcs: The list of source and header files.
319 copts: The list of additional compiler flags for the target. -I flags
320 for include/ and src/ directories of XNNPACK are always prepended
321 before these user-specified flags.
Marat Dukhan10a38082020-04-17 03:58:35 -0700322 mingw_copts: The list of compiler flags to use with MinGW GCC compilers.
323 msys_copts: The list of compiler flags to use with MSYS (Cygwin) GCC compilers.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700324 deps: The list of additional libraries to be linked. Google Test library
325 (with main() function) is always added as a dependency and does not
326 need to be explicitly specified.
Artsiom Ablavatskic1aa2972020-12-08 11:23:34 -0800327 tags: List of arbitrary text tags.
328 automatic: Whether to create the test or testable binary.
329 timeout: How long the test is expected to run before returning.
Alan Kelly66210582021-11-23 00:57:36 -0800330 shard_count: Specifies the number of parallel shards to use to run the test.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700331 """
332
Marat Dukhan22eed3d2020-05-11 20:13:37 -0700333 if automatic:
334 native.cc_test(
335 name = name,
336 srcs = srcs,
337 copts = xnnpack_std_cxxopts() + [
338 "-Iinclude",
339 "-Isrc",
340 ] + select({
341 ":windows_x86_64_mingw": mingw_copts,
342 ":windows_x86_64_msys": msys_copts,
343 "//conditions:default": [],
344 }) + select({
345 ":windows_x86_64_clang": ["/clang:-Wno-unused-function"],
346 ":windows_x86_64_mingw": ["-Wno-unused-function"],
347 ":windows_x86_64_msys": ["-Wno-unused-function"],
348 ":windows_x86_64": [],
349 "//conditions:default": ["-Wno-unused-function"],
350 }) + copts,
351 linkopts = select({
352 ":emscripten": xnnpack_emscripten_test_linkopts(),
353 "//conditions:default": [],
354 }),
355 linkstatic = True,
356 deps = [
357 "@com_google_googletest//:gtest_main",
358 ] + deps + select({
359 ":emscripten": xnnpack_emscripten_deps(),
360 "//conditions:default": [],
361 }),
362 tags = tags,
Artsiom Ablavatskic1aa2972020-12-08 11:23:34 -0800363 timeout = timeout,
Alan Kelly66210582021-11-23 00:57:36 -0800364 shard_count = shard_count,
Marat Dukhan22eed3d2020-05-11 20:13:37 -0700365 )
366 else:
367 native.cc_binary(
368 name = name,
369 srcs = srcs,
370 copts = xnnpack_std_cxxopts() + [
371 "-Iinclude",
372 "-Isrc",
373 ] + select({
374 ":windows_x86_64_mingw": mingw_copts,
375 ":windows_x86_64_msys": msys_copts,
376 "//conditions:default": [],
377 }) + select({
378 ":windows_x86_64_clang": ["/clang:-Wno-unused-function"],
379 ":windows_x86_64_mingw": ["-Wno-unused-function"],
380 ":windows_x86_64_msys": ["-Wno-unused-function"],
381 ":windows_x86_64": [],
382 "//conditions:default": ["-Wno-unused-function"],
383 }) + copts,
384 linkopts = select({
385 ":emscripten": xnnpack_emscripten_test_linkopts(),
386 "//conditions:default": [],
387 }),
388 linkstatic = True,
389 deps = [
390 "@com_google_googletest//:gtest_main",
391 ] + deps + select({
392 ":emscripten": xnnpack_emscripten_deps(),
393 "//conditions:default": [],
394 }),
395 testonly = True,
396 tags = tags,
397 )
Marat Dukhan08c4a432019-10-03 09:29:21 -0700398
399def xnnpack_binary(name, srcs, copts = [], deps = []):
400 """Minimal binary
401
402 Args:
403 name: The name of the binary target to define.
404 srcs: The list of source and header files.
405 copts: The list of additional compiler flags for the target. -I flags
406 for include/ and src/ directories of XNNPACK are always prepended
407 before these user-specified flags.
408 deps: The list of libraries to be linked.
409 """
410 native.cc_binary(
411 name = name,
412 srcs = srcs,
413 copts = [
414 "-Iinclude",
415 "-Isrc",
416 ] + copts,
417 linkopts = select({
418 ":emscripten": xnnpack_emscripten_minimal_linkopts(),
419 "//conditions:default": [],
420 }),
421 linkstatic = True,
422 deps = deps,
423 )
424
Marat Dukhana98efa12020-05-04 17:07:49 -0700425def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []):
Marat Dukhan08c4a432019-10-03 09:29:21 -0700426 """Microbenchmark binary based on Google Benchmark
427
428 Args:
429 name: The name of the binary target to define.
430 srcs: The list of source and header files.
431 copts: The list of additional compiler flags for the target. -I flags
432 for include/ and src/ directories of XNNPACK are always prepended
433 before these user-specified flags.
434 deps: The list of additional libraries to be linked. Google Benchmark
435 library is always added as a dependency and does not need to be
436 explicitly specified.
437 """
438 native.cc_binary(
439 name = name,
440 srcs = srcs,
441 copts = xnnpack_std_cxxopts() + [
442 "-Iinclude",
443 "-Isrc",
Marat Dukhana98efa12020-05-04 17:07:49 -0700444 ] + select({
445 ":windows_x86_64_clang": ["/clang:-Wno-unused-function"],
446 ":windows_x86_64_mingw": ["-Wno-unused-function"],
447 ":windows_x86_64_msys": ["-Wno-unused-function"],
448 ":windows_x86_64": [],
449 "//conditions:default": ["-Wno-unused-function"],
450 }) + copts,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700451 linkopts = select({
452 ":emscripten": xnnpack_emscripten_benchmark_linkopts(),
Marat Dukhan10a38082020-04-17 03:58:35 -0700453 ":windows_x86_64_mingw": ["-lshlwapi"],
454 ":windows_x86_64_msys": ["-lshlwapi"],
Marat Dukhan08c4a432019-10-03 09:29:21 -0700455 "//conditions:default": [],
456 }),
457 linkstatic = True,
458 deps = [
459 "@com_google_benchmark//:benchmark",
460 ] + deps + select({
461 ":emscripten": xnnpack_emscripten_deps(),
462 "//conditions:default": [],
463 }),
Marat Dukhan8ea0b072020-04-23 16:12:18 -0700464 tags = tags,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700465 )