xref: /llvm-project/third-party/benchmark/bindings/python/build_defs.bzl (revision a5b797172cc902db166e9a695716fb81405f86e4)
1"""
2This file contains some build definitions for C++ extensions used in the Google Benchmark Python bindings.
3"""
4
5_SHARED_LIB_SUFFIX = {
6    "//conditions:default": ".so",
7    "//:windows": ".dll",
8}
9
10def py_extension(name, srcs, hdrs = [], copts = [], features = [], deps = []):
11    for shared_lib_suffix in _SHARED_LIB_SUFFIX.values():
12        shared_lib_name = name + shared_lib_suffix
13        native.cc_binary(
14            name = shared_lib_name,
15            linkshared = True,
16            linkstatic = True,
17            srcs = srcs + hdrs,
18            copts = copts,
19            features = features,
20            deps = deps,
21        )
22
23    return native.py_library(
24        name = name,
25        data = select({
26            platform: [name + shared_lib_suffix]
27            for platform, shared_lib_suffix in _SHARED_LIB_SUFFIX.items()
28        }),
29    )
30