blob: 44abd130be8135491f0745a7c31bf48f4969aa6a [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,
XNNPACK Team708874b2022-01-24 13:55:04 -0800172 ":ios_sim_arm64": aarch64_srcs,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800173 ":ios_x86": x86_srcs,
174 ":ios_x86_64": x86_srcs,
175 ":watchos_armv7k": aarch32_srcs,
176 ":watchos_arm64_32": aarch64_srcs,
177 ":watchos_x86": x86_srcs,
178 ":watchos_x86_64": x86_srcs,
179 ":tvos_arm64": aarch64_srcs,
180 ":tvos_x86_64": x86_srcs,
Marat Dukhancf056b22019-10-07 10:26:29 -0700181 ":emscripten_wasm": wasm_srcs,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800182 ":emscripten_wasmsimd": wasmsimd_srcs,
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800183 ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_srcs,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700184 "//conditions:default": [],
185 }),
186 copts = [
187 "-Iinclude",
188 "-Isrc",
189 ] + copts + select({
Marat Dukhan10a38082020-04-17 03:58:35 -0700190 ":linux_k8": gcc_x86_copts,
Marat Dukhan582094e2020-04-30 17:21:25 -0700191 ":linux_arm": aarch32_copts,
Marat Dukhanf0bd4de2020-06-15 15:53:19 -0700192 ":linux_armeabi": aarch32_copts,
Terry Heo68eef3f2020-04-13 22:53:52 -0700193 ":linux_armhf": aarch32_copts,
Marat Dukhan24567892020-06-10 13:15:48 -0700194 ":linux_armv7a": aarch32_copts,
Marat Dukhan52e44432021-08-20 11:58:11 -0700195 ":linux_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700196 ":macos_x86_64": gcc_x86_copts,
Simon Maurer3b403c22021-03-03 14:24:02 +0100197 ":macos_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700198 ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_x86_copts],
199 ":windows_x86_64_mingw": mingw_copts + gcc_x86_copts,
200 ":windows_x86_64_msys": msys_copts + gcc_x86_copts,
201 ":windows_x86_64": msvc_x86_64_copts,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700202 ":android_armv7": aarch32_copts,
203 ":android_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700204 ":android_x86": gcc_x86_copts,
205 ":android_x86_64": gcc_x86_copts,
Marat Dukhanbc69ed62020-06-09 21:34:56 -0700206 ":ios_armv7": apple_aarch32_copts,
Marat Dukhan1498d1d2020-02-11 20:00:05 -0800207 ":ios_arm64": aarch64_copts,
208 ":ios_arm64e": aarch64_copts,
XNNPACK Team708874b2022-01-24 13:55:04 -0800209 ":ios_sim_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700210 ":ios_x86": gcc_x86_copts,
211 ":ios_x86_64": gcc_x86_copts,
Marat Dukhanbc69ed62020-06-09 21:34:56 -0700212 ":watchos_armv7k": apple_aarch32_copts,
Marat Dukhan1498d1d2020-02-11 20:00:05 -0800213 ":watchos_arm64_32": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700214 ":watchos_x86": gcc_x86_copts,
215 ":watchos_x86_64": gcc_x86_copts,
Marat Dukhan1498d1d2020-02-11 20:00:05 -0800216 ":tvos_arm64": aarch64_copts,
Marat Dukhan10a38082020-04-17 03:58:35 -0700217 ":tvos_x86_64": gcc_x86_copts,
Marat Dukhancf056b22019-10-07 10:26:29 -0700218 ":emscripten_wasm": wasm_copts,
219 ":emscripten_wasmsimd": wasmsimd_copts,
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800220 ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_copts,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700221 "//conditions:default": [],
222 }) + select({
Marat Dukhan10a38082020-04-17 03:58:35 -0700223 ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_copts],
224 ":windows_x86_64_mingw": gcc_copts,
225 ":windows_x86_64_msys": gcc_copts,
226 ":windows_x86_64": msvc_copts,
227 "//conditions:default": gcc_copts,
228 }) + select({
Marat Dukhan08c4a432019-10-03 09:29:21 -0700229 ":optimized_build": optimized_copts,
230 "//conditions:default": [],
231 }),
Marat Dukhan10a38082020-04-17 03:58:35 -0700232 defines = defines,
233 deps = deps,
234 includes = ["include", "src"] + includes,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700235 linkstatic = True,
236 linkopts = select({
237 ":linux_k8": ["-lpthread"],
Marat Dukhan582094e2020-04-30 17:21:25 -0700238 ":linux_arm": ["-lpthread"],
Marat Dukhanf0bd4de2020-06-15 15:53:19 -0700239 ":linux_armeabi": ["-lpthread"],
Terry Heo68eef3f2020-04-13 22:53:52 -0700240 ":linux_armhf": ["-lpthread"],
Marat Dukhan24567892020-06-10 13:15:48 -0700241 ":linux_armv7a": ["-lpthread"],
Marat Dukhan52e44432021-08-20 11:58:11 -0700242 ":linux_arm64": ["-lpthread"],
Marat Dukhan08c4a432019-10-03 09:29:21 -0700243 ":android": ["-lm"],
244 "//conditions:default": [],
245 }),
246 textual_hdrs = hdrs,
Marat Dukhan10a38082020-04-17 03:58:35 -0700247 visibility = visibility,
Zhi An Ngd90af6f2022-01-10 14:36:26 -0800248 testonly = testonly,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700249 )
250
251def xnnpack_aggregate_library(
252 name,
253 generic_deps = [],
254 x86_deps = [],
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700255 aarch32_ios_deps = [],
256 aarch32_nonios_deps = [],
Marat Dukhan08c4a432019-10-03 09:29:21 -0700257 aarch64_deps = [],
Marat Dukhan0ad47372022-01-04 16:05:25 -0800258 riscv_deps = [],
Marat Dukhan08c4a432019-10-03 09:29:21 -0700259 wasm_deps = [],
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800260 wasmsimd_deps = [],
261 wasmrelaxedsimd_deps = []):
Marat Dukhan08c4a432019-10-03 09:29:21 -0700262 """Static library that aggregates architecture-specific dependencies.
263
264 Args:
265 name: The name of the library target to define.
266 generic_deps: The list of libraries to link on all architectures.
267 x86_deps: The list of libraries to link in x86 and x86-64 builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800268 aarch32_ios_deps: The list of libraries to link in AArch32 iOS (incl
269 WatchOS) builds.
270 aarch32_nonios_deps: The list of libraries to link in AArch32 non-iOS
271 builds.
Marat Dukhan0ad47372022-01-04 16:05:25 -0800272 aarch64_deps: The list of libraries to link in AArch64 builds.
273 riscv_deps: The list of libraries to link in RISC-V builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800274 wasm_deps: The list of libraries to link in WebAssembly 1.0 builds.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700275 wasmsimd_deps: The list of libraries to link in WebAssembly SIMD builds.
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800276 wasmrelaxedsimd_deps: The list of libraries to link in WebAssembly
277 Relaxed SIMD builds.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700278 """
279
280 native.cc_library(
281 name = name,
282 linkstatic = True,
283 deps = generic_deps + select({
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800284 ":linux_k8": x86_deps,
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700285 ":linux_arm": aarch32_nonios_deps,
286 ":linux_armeabi": aarch32_nonios_deps,
287 ":linux_armhf": aarch32_nonios_deps,
288 ":linux_armv7a": aarch32_nonios_deps,
Marat Dukhan52e44432021-08-20 11:58:11 -0700289 ":linux_arm64": aarch64_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800290 ":macos_x86_64": x86_deps,
Simon Maurer3b403c22021-03-03 14:24:02 +0100291 ":macos_arm64": aarch64_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800292 ":windows_x86_64_clang": x86_deps,
293 ":windows_x86_64_mingw": x86_deps,
294 ":windows_x86_64_msys": x86_deps,
Marat Dukhan10a38082020-04-17 03:58:35 -0700295 ":windows_x86_64": x86_deps,
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700296 ":android_armv7": aarch32_nonios_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800297 ":android_arm64": aarch64_deps,
298 ":android_x86": x86_deps,
299 ":android_x86_64": x86_deps,
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700300 ":ios_armv7": aarch32_ios_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800301 ":ios_arm64": aarch64_deps,
302 ":ios_arm64e": aarch64_deps,
XNNPACK Team708874b2022-01-24 13:55:04 -0800303 ":ios_sim_arm64": aarch64_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800304 ":ios_x86": x86_deps,
305 ":ios_x86_64": x86_deps,
Marat Dukhan6e8c0ce2021-04-13 14:35:08 -0700306 ":watchos_armv7k": aarch32_ios_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800307 ":watchos_arm64_32": aarch64_deps,
308 ":watchos_x86": x86_deps,
309 ":watchos_x86_64": x86_deps,
310 ":tvos_arm64": aarch64_deps,
311 ":tvos_x86_64": x86_deps,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700312 ":emscripten_wasm": wasm_deps,
Marat Dukhan3de5dfa2020-12-10 11:19:47 -0800313 ":emscripten_wasmsimd": wasmsimd_deps,
Marat Dukhan19bfefe2021-12-21 19:16:06 -0800314 ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_deps,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700315 }),
316 )
317
Alan Kelly66210582021-11-23 00:57:36 -0800318def 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 -0700319 """Unit test binary based on Google Test.
320
321 Args:
322 name: The name of the test target to define.
323 srcs: The list of source and header files.
324 copts: The list of additional compiler flags for the target. -I flags
325 for include/ and src/ directories of XNNPACK are always prepended
326 before these user-specified flags.
Marat Dukhan10a38082020-04-17 03:58:35 -0700327 mingw_copts: The list of compiler flags to use with MinGW GCC compilers.
328 msys_copts: The list of compiler flags to use with MSYS (Cygwin) GCC compilers.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700329 deps: The list of additional libraries to be linked. Google Test library
330 (with main() function) is always added as a dependency and does not
331 need to be explicitly specified.
Artsiom Ablavatskic1aa2972020-12-08 11:23:34 -0800332 tags: List of arbitrary text tags.
333 automatic: Whether to create the test or testable binary.
334 timeout: How long the test is expected to run before returning.
Alan Kelly66210582021-11-23 00:57:36 -0800335 shard_count: Specifies the number of parallel shards to use to run the test.
Marat Dukhan08c4a432019-10-03 09:29:21 -0700336 """
337
Marat Dukhan22eed3d2020-05-11 20:13:37 -0700338 if automatic:
339 native.cc_test(
340 name = name,
341 srcs = srcs,
342 copts = xnnpack_std_cxxopts() + [
343 "-Iinclude",
344 "-Isrc",
345 ] + select({
346 ":windows_x86_64_mingw": mingw_copts,
347 ":windows_x86_64_msys": msys_copts,
348 "//conditions:default": [],
349 }) + select({
350 ":windows_x86_64_clang": ["/clang:-Wno-unused-function"],
351 ":windows_x86_64_mingw": ["-Wno-unused-function"],
352 ":windows_x86_64_msys": ["-Wno-unused-function"],
353 ":windows_x86_64": [],
354 "//conditions:default": ["-Wno-unused-function"],
355 }) + copts,
356 linkopts = select({
357 ":emscripten": xnnpack_emscripten_test_linkopts(),
358 "//conditions:default": [],
359 }),
360 linkstatic = True,
361 deps = [
362 "@com_google_googletest//:gtest_main",
363 ] + deps + select({
364 ":emscripten": xnnpack_emscripten_deps(),
365 "//conditions:default": [],
366 }),
367 tags = tags,
Artsiom Ablavatskic1aa2972020-12-08 11:23:34 -0800368 timeout = timeout,
Alan Kelly66210582021-11-23 00:57:36 -0800369 shard_count = shard_count,
Marat Dukhan22eed3d2020-05-11 20:13:37 -0700370 )
371 else:
372 native.cc_binary(
373 name = name,
374 srcs = srcs,
375 copts = xnnpack_std_cxxopts() + [
376 "-Iinclude",
377 "-Isrc",
378 ] + select({
379 ":windows_x86_64_mingw": mingw_copts,
380 ":windows_x86_64_msys": msys_copts,
381 "//conditions:default": [],
382 }) + select({
383 ":windows_x86_64_clang": ["/clang:-Wno-unused-function"],
384 ":windows_x86_64_mingw": ["-Wno-unused-function"],
385 ":windows_x86_64_msys": ["-Wno-unused-function"],
386 ":windows_x86_64": [],
387 "//conditions:default": ["-Wno-unused-function"],
388 }) + copts,
389 linkopts = select({
390 ":emscripten": xnnpack_emscripten_test_linkopts(),
391 "//conditions:default": [],
392 }),
393 linkstatic = True,
394 deps = [
395 "@com_google_googletest//:gtest_main",
396 ] + deps + select({
397 ":emscripten": xnnpack_emscripten_deps(),
398 "//conditions:default": [],
399 }),
400 testonly = True,
401 tags = tags,
402 )
Marat Dukhan08c4a432019-10-03 09:29:21 -0700403
404def xnnpack_binary(name, srcs, copts = [], deps = []):
405 """Minimal binary
406
407 Args:
408 name: The name of the binary target to define.
409 srcs: The list of source and header files.
410 copts: The list of additional compiler flags for the target. -I flags
411 for include/ and src/ directories of XNNPACK are always prepended
412 before these user-specified flags.
413 deps: The list of libraries to be linked.
414 """
415 native.cc_binary(
416 name = name,
417 srcs = srcs,
418 copts = [
419 "-Iinclude",
420 "-Isrc",
421 ] + copts,
422 linkopts = select({
423 ":emscripten": xnnpack_emscripten_minimal_linkopts(),
424 "//conditions:default": [],
425 }),
426 linkstatic = True,
427 deps = deps,
428 )
429
Marat Dukhana98efa12020-05-04 17:07:49 -0700430def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []):
Marat Dukhan08c4a432019-10-03 09:29:21 -0700431 """Microbenchmark binary based on Google Benchmark
432
433 Args:
434 name: The name of the binary target to define.
435 srcs: The list of source and header files.
436 copts: The list of additional compiler flags for the target. -I flags
437 for include/ and src/ directories of XNNPACK are always prepended
438 before these user-specified flags.
439 deps: The list of additional libraries to be linked. Google Benchmark
440 library is always added as a dependency and does not need to be
441 explicitly specified.
442 """
443 native.cc_binary(
444 name = name,
445 srcs = srcs,
446 copts = xnnpack_std_cxxopts() + [
447 "-Iinclude",
448 "-Isrc",
Marat Dukhana98efa12020-05-04 17:07:49 -0700449 ] + select({
450 ":windows_x86_64_clang": ["/clang:-Wno-unused-function"],
451 ":windows_x86_64_mingw": ["-Wno-unused-function"],
452 ":windows_x86_64_msys": ["-Wno-unused-function"],
453 ":windows_x86_64": [],
454 "//conditions:default": ["-Wno-unused-function"],
455 }) + copts,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700456 linkopts = select({
457 ":emscripten": xnnpack_emscripten_benchmark_linkopts(),
Marat Dukhan10a38082020-04-17 03:58:35 -0700458 ":windows_x86_64_mingw": ["-lshlwapi"],
459 ":windows_x86_64_msys": ["-lshlwapi"],
Marat Dukhan08c4a432019-10-03 09:29:21 -0700460 "//conditions:default": [],
461 }),
462 linkstatic = True,
463 deps = [
464 "@com_google_benchmark//:benchmark",
465 ] + deps + select({
466 ":emscripten": xnnpack_emscripten_deps(),
467 "//conditions:default": [],
468 }),
Marat Dukhan8ea0b072020-04-23 16:12:18 -0700469 tags = tags,
Marat Dukhan08c4a432019-10-03 09:29:21 -0700470 )