-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathBUILD.bazel
176 lines (165 loc) · 4.9 KB
/
BUILD.bazel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@bazel_skylib//rules:native_binary.bzl", "native_test")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
copy_file(
name = "config_h_generic",
src = "src/config.h.generic",
out = "src/config.h",
)
copy_file(
name = "pcre2_h_generic",
src = "src/pcre2.h.generic",
out = "src/pcre2.h",
)
copy_file(
name = "pcre2_chartables_c",
src = "src/pcre2_chartables.c.dist",
out = "src/pcre2_chartables.c",
)
LOCAL_DEFINES = [
"HAVE_CONFIG_H",
"HAVE_MEMMOVE",
"HAVE_STRERROR",
"PCRE2_CODE_UNIT_WIDTH=8",
"PCRE2_STATIC",
"SUPPORT_PCRE2_8",
"SUPPORT_UNICODE",
] + select({
"@platforms//os:windows": [],
"//conditions:default": ["HAVE_UNISTD_H"],
})
# Workaround for a Bazel quirk. It is extremely strict about the #include path
# used for internal headers. We have our headers inside src/, but we #include
# them as '#include "pcre2_internal.h"', assuming that src/ is added to the
# compiler's include path. Unfortunately, that violates the conventions used by
# Bazel.
#
# This is a workaround. Note that we can't use the "include = [...]" property
# to add the src/ directory, since that pollutes the include path for projects
# depending on PCRE2 (we must not make our config.h file visible to consumers
# of PCRE2).
cc_library(
name = "pcre2_internal_headers",
hdrs = [
"src/pcre2_compile.h",
"src/pcre2_internal.h",
"src/pcre2_intmodedep.h",
"src/pcre2_jit_match_inc.h",
"src/pcre2_jit_misc_inc.h",
"src/pcre2_printint_inc.h",
"src/pcre2_ucp.h",
"src/pcre2_ucptables_inc.h",
"src/pcre2_util.h",
":config_h_generic",
],
strip_include_prefix = "src",
visibility = ["//visibility:private"],
)
cc_library(
name = "pcre2",
srcs = [
"src/pcre2_auto_possess.c",
"src/pcre2_chkdint.c",
"src/pcre2_compile.c",
"src/pcre2_compile_cgroup.c",
"src/pcre2_compile_class.c",
"src/pcre2_config.c",
"src/pcre2_context.c",
"src/pcre2_convert.c",
"src/pcre2_dfa_match.c",
"src/pcre2_error.c",
"src/pcre2_extuni.c",
"src/pcre2_find_bracket.c",
"src/pcre2_jit_compile.c",
"src/pcre2_maketables.c",
"src/pcre2_match.c",
"src/pcre2_match_data.c",
"src/pcre2_match_next.c",
"src/pcre2_newline.c",
"src/pcre2_ord2utf.c",
"src/pcre2_pattern_info.c",
"src/pcre2_script_run.c",
"src/pcre2_serialize.c",
"src/pcre2_string_utils.c",
"src/pcre2_study.c",
"src/pcre2_substitute.c",
"src/pcre2_substring.c",
"src/pcre2_tables.c",
"src/pcre2_ucd.c",
"src/pcre2_valid_utf.c",
"src/pcre2_xclass.c",
":pcre2_chartables_c",
],
hdrs = [":pcre2_h_generic"],
implementation_deps = [":pcre2_internal_headers"],
local_defines = LOCAL_DEFINES,
strip_include_prefix = "src",
visibility = ["//visibility:public"],
)
cc_library(
name = "pcre2-posix",
srcs = ["src/pcre2posix.c"],
hdrs = ["src/pcre2posix.h"],
implementation_deps = [":pcre2_internal_headers"],
local_defines = LOCAL_DEFINES,
strip_include_prefix = "src",
visibility = ["//visibility:public"],
deps = [":pcre2"],
)
# Totally weird issue in Bazel. It won't let you #include any files unless they
# are declared to the build system. OK, fair enough. But - for a cc_binary it
# uses the file extension to determine whether it's a header or a compilation
# unit. But... we have several .c files which are #included, rather than treated
# as a compilation unit.
#
# For cc_library() above, we can overcome this with textual_hdrs. But that
# doesn't work for cc_binary(). Here's our workaround.
#
# https://github.com/bazelbuild/bazel/issues/680
cc_library(
name = "pcre2test_dotc_headers",
hdrs = [
"src/pcre2_chkdint.c",
"src/pcre2_tables.c",
"src/pcre2_ucd.c",
"src/pcre2_valid_utf.c",
],
strip_include_prefix = "src",
visibility = ["//visibility:private"],
)
cc_binary(
name = "pcre2test",
srcs = ["src/pcre2test.c"],
linkopts = select({
"@platforms//os:windows": ["-STACK:2500000"],
"//conditions:default": [],
}),
local_defines = LOCAL_DEFINES,
visibility = ["//visibility:public"],
deps = [
":pcre2",
":pcre2-posix",
":pcre2_internal_headers",
":pcre2test_dotc_headers",
],
)
filegroup(
name = "testdata",
srcs = glob(["testdata/*"]),
)
native_test(
name = "pcre2_test",
size = "small",
src = select({
"@platforms//os:windows": "RunTest.bat",
"//conditions:default": "RunTest",
}),
out = select({
"@platforms//os:windows": "RunTest.bat",
"//conditions:default": "RunTest",
}),
data = [
":pcre2test",
":testdata",
],
)