1- load ("@rules_cc//cc:defs.bzl" , "cc_library" , "cc_test" )
21load ("@bazel_skylib//rules:copy_file.bzl" , "copy_file" )
2+ load ("@bazel_skylib//rules:native_binary.bzl" , "native_test" )
3+ load ("@rules_cc//cc:defs.bzl" , "cc_binary" , "cc_library" )
34
45copy_file (
56 name = "config_h_generic" ,
@@ -36,6 +37,7 @@ cc_library(
3637 "src/pcre2_error.c" ,
3738 "src/pcre2_extuni.c" ,
3839 "src/pcre2_find_bracket.c" ,
40+ "src/pcre2_jit_compile.c" ,
3941 "src/pcre2_maketables.c" ,
4042 "src/pcre2_match.c" ,
4143 "src/pcre2_match_data.c" ,
@@ -53,24 +55,118 @@ cc_library(
5355 "src/pcre2_valid_utf.c" ,
5456 "src/pcre2_xclass.c" ,
5557 ":pcre2_chartables_c" ,
56- ],
57- hdrs = glob (["src/*.h" ]) + [
58+ "src/pcre2_compile.h" ,
59+ "src/pcre2_internal.h" ,
60+ "src/pcre2_intmodedep.h" ,
61+ "src/pcre2_ucp.h" ,
62+ "src/pcre2_util.h" ,
5863 ":config_h_generic" ,
64+ ],
65+ textual_hdrs = [
66+ "src/pcre2_jit_match.c" ,
67+ "src/pcre2_jit_misc.c" ,
68+ "src/pcre2_ucptables.c" ,
69+ ],
70+ hdrs = [
5971 ":pcre2_h_generic" ,
6072 ],
61- defines = [
73+ local_defines = [
6274 "HAVE_CONFIG_H" ,
75+ "HAVE_MEMMOVE" ,
6376 "PCRE2_CODE_UNIT_WIDTH=8" ,
6477 "PCRE2_STATIC" ,
78+ "SUPPORT_UNICODE" ,
6579 ],
6680 includes = ["src" ],
6781 strip_include_prefix = "src" ,
6882 visibility = ["//visibility:public" ],
6983)
7084
71- cc_binary (
72- name = "pcre2demo" ,
73- srcs = ["src/pcre2demo.c" ],
85+ cc_library (
86+ name = "pcre2-posix" ,
87+ srcs = [
88+ "src/pcre2posix.c" ,
89+ ":config_h_generic" ,
90+ ],
91+ hdrs = [
92+ "src/pcre2posix.h" ,
93+ ],
94+ local_defines = [
95+ "HAVE_CONFIG_H" ,
96+ "HAVE_MEMMOVE" ,
97+ "PCRE2_CODE_UNIT_WIDTH=8" ,
98+ "PCRE2_STATIC" ,
99+ "SUPPORT_UNICODE" ,
100+ ],
101+ includes = ["src" ],
102+ strip_include_prefix = "src" ,
74103 visibility = ["//visibility:public" ],
75104 deps = [":pcre2" ],
76105)
106+
107+ # Totally weird issue in Bazel. It won't let you #include any files unless they
108+ # are declared to the build system. OK, fair enough. But - for a cc_binary it
109+ # uses the file extension to determine whether it's a header or a compilation
110+ # unit. But... we have several .c files which are #included, rather than treated
111+ # as a compilation unit.
112+ #
113+ # For cc_library() above, we can overcome this with textual_hdrs. But that
114+ # doesn't work for cc_binary(). Here's our workaround.
115+ #
116+ # https://github.com/bazelbuild/bazel/issues/680
117+ cc_library (
118+ name = "pcre2test_dotc_headers" ,
119+ hdrs = [
120+ "src/pcre2_chkdint.c" ,
121+ "src/pcre2_printint.c" ,
122+ "src/pcre2_tables.c" ,
123+ "src/pcre2_ucd.c" ,
124+ "src/pcre2_valid_utf.c" ,
125+ ],
126+ strip_include_prefix = "src" ,
127+ visibility = ["//visibility:private" ],
128+ )
129+
130+ cc_binary (
131+ name = "pcre2test" ,
132+ srcs = [
133+ "src/pcre2test.c" ,
134+ ":config_h_generic" ,
135+ ],
136+ local_defines = [
137+ "HAVE_CONFIG_H" ,
138+ "HAVE_MEMMOVE" ,
139+ "HAVE_STRERROR" ,
140+ "PCRE2_STATIC" ,
141+ "SUPPORT_UNICODE" ,
142+ "SUPPORT_PCRE2_8" ,
143+ ] + select ({
144+ "@platforms//os:windows" : [],
145+ "//conditions:default" : ["HAVE_UNISTD_H" ],
146+ }),
147+ linkopts = select ({
148+ "@platforms//os:windows" : ["-STACK:2500000" ],
149+ "//conditions:default" : [],
150+ }),
151+ visibility = ["//visibility:public" ],
152+ deps = [":pcre2test_dotc_headers" , ":pcre2" , ":pcre2-posix" ],
153+ )
154+
155+ filegroup (
156+ name = "testdata" ,
157+ srcs = glob (["testdata/*" ]),
158+ )
159+
160+ native_test (
161+ name = "pcre2_test" ,
162+ src = select ({
163+ "@platforms//os:windows" : "RunTest.bat" ,
164+ "//conditions:default" : "RunTest" ,
165+ }),
166+ out = select ({
167+ "@platforms//os:windows" : "RunTest.bat" ,
168+ "//conditions:default" : "RunTest" ,
169+ }),
170+ data = [":pcre2test" , ":testdata" ],
171+ size = "small" ,
172+ )
0 commit comments