|
| 1 | +load("@bazel_skylib//rules:write_file.bzl", "write_file") |
| 2 | +load("@rules_cc//cc:cc_library.bzl", "cc_library") |
| 3 | + |
| 4 | +_GIT2_FEATURES_H = """ |
| 5 | +#define GIT_REGEX_BUILTIN |
| 6 | +#define GIT_SHA1_COLLISIONDETECT |
| 7 | +#define GIT_SHA256_BUILTIN |
| 8 | +#define GIT_HTTPPARSER_BUILTIN |
| 9 | +#define GIT_THREADS |
| 10 | +""" |
| 11 | + |
| 12 | +write_file( |
| 13 | + name = "git2_features_h", |
| 14 | + out = "git2_features.h", |
| 15 | + content = [_GIT2_FEATURES_H] + |
| 16 | + select({ |
| 17 | + "@platforms//os:windows": ["#define GIT_IO_WSAPOLL 1"], |
| 18 | + "//conditions:default": ["#define GIT_IO_POLL"], |
| 19 | + }), |
| 20 | + newline = "unix", |
| 21 | +) |
| 22 | + |
| 23 | +cc_library( |
| 24 | + name = "git2_features", |
| 25 | + hdrs = [":git2_features_h"], |
| 26 | + strip_include_prefix = "/src/util", |
| 27 | +) |
| 28 | + |
| 29 | +cc_library( |
| 30 | + name = "util_hdrs", |
| 31 | + hdrs = glob(["**/*.h"]), |
| 32 | + strip_include_prefix = "/src/util", |
| 33 | + visibility = ["//:__subpackages__"], |
| 34 | + deps = [ |
| 35 | + ":git2_features", |
| 36 | + "//deps/pcre:pcre_hdrs", |
| 37 | + "//include:git2", |
| 38 | + "@zlib", |
| 39 | + ], |
| 40 | +) |
| 41 | + |
| 42 | +GIT2_UTIL_WINDOWS_SRCS = glob([ |
| 43 | + "win32/*", |
| 44 | +]) + ["hash/win32.c"] |
| 45 | + |
| 46 | +GIT2_UTIL_UNIX_SRCS = glob(["unix/*"]) |
| 47 | + |
| 48 | +GIT2_UTIL_SRCS = glob( |
| 49 | + include = ["**/*.c"], |
| 50 | + exclude = [ |
| 51 | + "hash/common_crypto.c", |
| 52 | + "hash/openssl.c", |
| 53 | + ] + GIT2_UTIL_WINDOWS_SRCS + GIT2_UTIL_UNIX_SRCS, |
| 54 | +) |
| 55 | + |
| 56 | +cc_library( |
| 57 | + name = "util", |
| 58 | + srcs = GIT2_UTIL_SRCS + select({ |
| 59 | + "@platforms//os:windows": GIT2_UTIL_WINDOWS_SRCS, |
| 60 | + "//conditions:default": GIT2_UTIL_UNIX_SRCS, |
| 61 | + }), |
| 62 | + implementation_deps = [ |
| 63 | + "//deps/pcre", |
| 64 | + "//deps/xdiff", |
| 65 | + ], |
| 66 | + linkopts = select({ |
| 67 | + "@platforms//os:windows": [ |
| 68 | + "secur32.lib", |
| 69 | + "ws2_32.lib", |
| 70 | + "advapi32.lib", |
| 71 | + ], |
| 72 | + "//conditions:default": [], |
| 73 | + }), |
| 74 | + visibility = ["//:__subpackages__"], |
| 75 | + deps = [":util_hdrs"], |
| 76 | +) |
0 commit comments