Debian Codegraph @

src/BUILD.bazel

raw
1 load("@aspect_bazel_lib//lib:diff_test.bzl", "diff_test")
2 load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
3 load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
4 load("@rules_python//python:py_library.bzl", "py_library")
5
6 package(default_visibility = ["//visibility:public"])
7
8 # Public C/C++ headers consumed by the root //:opencc_lib target. Bazel 10 no
9 # longer lets source files inherit package default_visibility, so export them
10 # explicitly for cross-package references.
11 exports_files(
12 [
13 "ConversionInspection.hpp",
14 "Export.hpp",
15 "ResourceProvider.hpp",
16 "SimpleConverter.hpp",
17 "opencc.h",
18 ],
19 visibility = ["//visibility:public"],
20 )
21
22 filegroup(
23 name = "all_files",
24 srcs = glob([
25 "**/*.cpp",
26 "**/*.h",
27 "**/*.hpp",
28 "**/*.inc",
29 ]),
30 )
31
32 cc_library(
33 name = "opencc_lib",
34 hdrs = [
35 "ConversionInspection.hpp",
36 "ResourceProvider.hpp",
37 ],
38 deps = [
39 ":binary_dict_lib",
40 ":common_lib",
41 ":config_lib",
42 ":conversion_lib",
43 ":conversion_chain_lib",
44 ":converter_lib",
45 ":darts_dict_lib",
46 ":dict_lib",
47 ":dict_converter_lib",
48 ":dict_entry_lib",
49 ":dict_group_lib",
50 ":exception_lib",
51 ":lexicon_lib",
52 ":marisa_dict_lib",
53 ":max_match_segmentation_lib",
54 ":pipeline_converter_lib",
55 ":plugin_segmentation_lib",
56 ":phrase_extract_lib",
57 ":resource_provider_lib",
58 ":segmentation_lib",
59 ":segments_lib",
60 ":serializable_dict_lib",
61 ":serialized_values_lib",
62 ":simple_converter_lib",
63 ":single_stage_converter_lib",
64 ":utf8_string_slice_lib",
65 ":utf8_util_lib",
66 ],
67 )
68
69 cc_library(
70 name = "binary_dict_lib",
71 srcs = ["BinaryDict.cpp"],
72 hdrs = ["BinaryDict.hpp"],
73 deps = [
74 ":common_lib",
75 ":lexicon_lib",
76 ":serializable_dict_lib",
77 ],
78 )
79
80 cc_test(
81 name = "binary_dict_test",
82 size = "small",
83 srcs = ["BinaryDictTest.cpp"],
84 deps = [
85 ":binary_dict_lib",
86 ":text_dict_test_base_lib",
87 "@googletest//:gtest_main",
88 ],
89 )
90
91 cc_library(
92 name = "cmd_line_output_lib",
93 hdrs = ["CmdLineOutput.hpp"],
94 visibility = ["//src/tools:__pkg__"],
95 deps = [
96 "@tclap",
97 ],
98 )
99
100 cc_library(
101 name = "common_lib",
102 hdrs = [
103 "Common.hpp",
104 "Export.hpp",
105 "Optional.hpp",
106 ],
107 defines = ["Opencc_BUILT_AS_STATIC"],
108 )
109
110 genrule(
111 name = "config_schema_inc",
112 srcs = ["//data/config:config_schema"],
113 outs = ["generated/opencc_config_schema.inc"],
114 cmd = "$(location //data/scripts:minify_json_to_inc) $< $@",
115 tools = ["//data/scripts:minify_json_to_inc"],
116 )
117
118 cc_library(
119 name = "config_schema_inc_lib",
120 hdrs = ["opencc_config_schema.inc"],
121 )
122
123 diff_test(
124 name = "config_schema_inc_sync_test",
125 file1 = ":config_schema_inc",
126 file2 = "opencc_config_schema.inc",
127 )
128
129 cc_library(
130 name = "config_lib",
131 srcs = [
132 "Config.cpp",
133 "ConfigBasedConverter.hpp",
134 ],
135 hdrs = ["Config.hpp"],
136 deps = [
137 ":common_lib",
138 ":config_schema_inc_lib",
139 ":conversion_chain_lib",
140 ":converter_lib",
141 ":darts_dict_lib",
142 ":dict_group_lib",
143 ":exception_lib",
144 ":marisa_dict_lib",
145 ":max_match_segmentation_lib",
146 ":pipeline_converter_lib",
147 ":plugin_segmentation_lib",
148 ":resource_provider_lib",
149 ":single_stage_converter_lib",
150 ":text_dict_lib",
151 ":utf8_util_lib",
152 ":win_util_lib",
153 "@rapidjson//:rapidjson",
154 ],
155 )
156
157 cc_library(
158 name = "resource_provider_lib",
159 srcs = ["ResourceProvider.cpp"],
160 hdrs = ["ResourceProvider.hpp"],
161 deps = [
162 ":exception_lib",
163 ":win_util_lib",
164 ],
165 )
166
167 cc_test(
168 name = "config_test",
169 size = "small",
170 srcs = ["ConfigTest.cpp"],
171 deps = [
172 ":common_lib",
173 ":config_lib",
174 ":config_test_base_lib",
175 ":converter_lib",
176 ":exception_lib",
177 ":resource_provider_lib",
178 ":test_utils_utf8_lib",
179 "@googletest//:gtest_main",
180 ],
181 )
182
183 cc_library(
184 name = "config_test_base_lib",
185 testonly = True,
186 hdrs = ["ConfigTestBase.hpp"],
187 data = ["//test/config_test"],
188 defines = ["BAZEL"],
189 deps = [
190 ":test_utils_lib",
191 "@bazel_tools//tools/cpp/runfiles",
192 ],
193 )
194
195 cc_library(
196 name = "conversion_lib",
197 srcs = ["Conversion.cpp"],
198 hdrs = ["Conversion.hpp"],
199 deps = [
200 ":common_lib",
201 ":prefix_match_lib",
202 ":segmentation_lib",
203 ":segments_lib",
204 ":utf8_util_lib",
205 ],
206 )
207
208 cc_test(
209 name = "conversion_test",
210 size = "small",
211 srcs = ["ConversionTest.cpp"],
212 deps = [
213 ":conversion_lib",
214 ":dict_group_test_base_lib",
215 "@googletest//:gtest_main",
216 ],
217 )
218
219 cc_library(
220 name = "conversion_chain_lib",
221 srcs = ["ConversionChain.cpp"],
222 hdrs = ["ConversionChain.hpp"],
223 deps = [
224 ":common_lib",
225 ":conversion_lib",
226 ":segments_lib",
227 ],
228 )
229
230 cc_test(
231 name = "conversion_chain_test",
232 size = "small",
233 srcs = ["ConversionChainTest.cpp"],
234 deps = [
235 ":conversion_chain_lib",
236 ":converter_lib",
237 ":dict_group_test_base_lib",
238 ":max_match_segmentation_lib",
239 ":pipeline_converter_lib",
240 ":single_stage_converter_lib",
241 "@googletest//:gtest_main",
242 ],
243 )
244
245 cc_test(
246 name = "conversion_inspection_test",
247 size = "small",
248 srcs = ["ConversionInspectionTest.cpp"],
249 deps = [
250 ":config_test_base_lib",
251 ":conversion_inspection_lib",
252 ":segments_lib",
253 ":simple_converter_lib",
254 ":test_utils_utf8_lib",
255 "@googletest//:gtest_main",
256 ],
257 )
258
259 cc_library(
260 name = "conversion_inspection_lib",
261 hdrs = ["ConversionInspection.hpp"],
262 )
263
264 cc_library(
265 name = "converter_lib",
266 srcs = ["Converter.cpp"],
267 hdrs = [
268 "ConversionInspection.hpp",
269 "Converter.hpp",
270 ],
271 deps = [
272 ":common_lib",
273 ":segmentation_lib",
274 ":utf8_util_lib",
275 ],
276 )
277
278 cc_library(
279 name = "single_stage_converter_lib",
280 srcs = ["SingleStageConverter.cpp"],
281 hdrs = ["SingleStageConverter.hpp"],
282 deps = [
283 ":conversion_chain_lib",
284 ":conversion_inspection_lib",
285 ":converter_lib",
286 ":segments_lib",
287 ],
288 )
289
290 cc_library(
291 name = "pipeline_converter_lib",
292 srcs = ["PipelineConverter.cpp"],
293 hdrs = ["PipelineConverter.hpp"],
294 deps = [
295 ":conversion_inspection_lib",
296 ":converter_lib",
297 ],
298 )
299
300 cc_library(
301 name = "darts_dict_lib",
302 srcs = ["DartsDict.cpp"],
303 hdrs = ["DartsDict.hpp"],
304 deps = [
305 ":binary_dict_lib",
306 ":common_lib",
307 ":lexicon_lib",
308 ":serializable_dict_lib",
309 "@darts-clone",
310 ],
311 )
312
313 cc_test(
314 name = "darts_dict_test",
315 size = "small",
316 srcs = ["DartsDictTest.cpp"],
317 deps = [
318 ":darts_dict_lib",
319 ":test_utils_utf8_lib",
320 ":text_dict_test_base_lib",
321 "@googletest//:gtest_main",
322 ],
323 )
324
325 cc_library(
326 name = "dict_lib",
327 srcs = ["Dict.cpp"],
328 hdrs = ["Dict.hpp"],
329 deps = [
330 ":common_lib",
331 ":dict_entry_lib",
332 ],
333 )
334
335 cc_library(
336 name = "dict_converter_lib",
337 srcs = ["DictConverter.cpp"],
338 hdrs = ["DictConverter.hpp"],
339 deps = [
340 ":common_lib",
341 ":darts_dict_lib",
342 ":exception_lib",
343 ":lexicon_lib",
344 ":marisa_dict_lib",
345 ":text_dict_lib",
346 ":win_util_lib",
347 ],
348 )
349
350 cc_library(
351 name = "dict_entry_lib",
352 srcs = ["DictEntry.cpp"],
353 hdrs = ["DictEntry.hpp"],
354 deps = [
355 ":common_lib",
356 ":segments_lib",
357 ":utf8_util_lib",
358 ],
359 )
360
361 cc_library(
362 name = "dict_group_lib",
363 srcs = ["DictGroup.cpp"],
364 hdrs = ["DictGroup.hpp"],
365 deps = [
366 ":common_lib",
367 ":dict_lib",
368 ":lexicon_lib",
369 ":text_dict_lib",
370 ],
371 )
372
373 cc_test(
374 name = "dict_group_test",
375 size = "small",
376 srcs = ["DictGroupTest.cpp"],
377 deps = [
378 ":dict_group_test_base_lib",
379 "@googletest//:gtest_main",
380 ],
381 )
382
383 cc_library(
384 name = "dict_group_test_base_lib",
385 testonly = True,
386 hdrs = ["DictGroupTestBase.hpp"],
387 deps = [
388 ":dict_group_lib",
389 ":text_dict_test_base_lib",
390 ],
391 )
392
393 cc_library(
394 name = "exception_lib",
395 hdrs = ["Exception.hpp"],
396 deps = [":common_lib"],
397 )
398
399 cc_library(
400 name = "lexicon_lib",
401 srcs = ["Lexicon.cpp"],
402 hdrs = ["Lexicon.hpp"],
403 deps = [
404 ":common_lib",
405 ":dict_entry_lib",
406 ],
407 )
408
409 cc_test(
410 name = "lexicon_annotation_test",
411 size = "small",
412 srcs = ["LexiconAnnotationTest.cpp"],
413 deps = [
414 ":lexicon_lib",
415 ":serializable_dict_lib",
416 ":test_utils_lib",
417 ":test_utils_utf8_lib",
418 ":text_dict_lib",
419 "@googletest//:gtest_main",
420 ],
421 )
422
423 cc_library(
424 name = "marisa_dict_lib",
425 srcs = ["MarisaDict.cpp"],
426 hdrs = ["MarisaDict.hpp"],
427 deps = [
428 ":common_lib",
429 ":lexicon_lib",
430 ":serialized_values_lib",
431 "@marisa-trie",
432 ],
433 )
434
435 cc_test(
436 name = "marisa_dict_test",
437 size = "small",
438 srcs = ["MarisaDictTest.cpp"],
439 deps = [
440 ":marisa_dict_lib",
441 ":test_utils_utf8_lib",
442 ":text_dict_test_base_lib",
443 "@googletest//:gtest_main",
444 ],
445 )
446
447 cc_library(
448 name = "max_match_segmentation_lib",
449 srcs = ["MaxMatchSegmentation.cpp"],
450 hdrs = ["MaxMatchSegmentation.hpp"],
451 deps = [
452 ":common_lib",
453 ":dict_group_lib",
454 ":prefix_match_lib",
455 ":segmentation_lib",
456 ":segments_lib",
457 ":utf8_util_lib",
458 ],
459 )
460
461 cc_library(
462 name = "prefix_match_lib",
463 srcs = ["PrefixMatch.cpp"],
464 hdrs = ["PrefixMatch.hpp"],
465 deps = [
466 ":common_lib",
467 ":dict_group_lib",
468 ":dict_lib",
469 ":lexicon_lib",
470 ":utf8_util_lib",
471 ],
472 )
473
474 cc_test(
475 name = "prefix_match_test",
476 size = "small",
477 srcs = ["PrefixMatchTest.cpp"],
478 deps = [
479 ":prefix_match_lib",
480 ":dict_group_lib",
481 ":marisa_dict_lib",
482 ":test_utils_utf8_lib",
483 ":text_dict_test_base_lib",
484 "@googletest//:gtest_main",
485 ],
486 )
487
488 cc_test(
489 name = "max_match_segmentation_test",
490 size = "small",
491 srcs = ["MaxMatchSegmentationTest.cpp"],
492 deps = [
493 ":dict_group_test_base_lib",
494 ":max_match_segmentation_lib",
495 "@googletest//:gtest_main",
496 ],
497 )
498
499 cc_library(
500 name = "phrase_extract_lib",
501 srcs = ["PhraseExtract.cpp"],
502 hdrs = ["PhraseExtract.hpp"],
503 visibility = [
504 "//src:__pkg__",
505 "//src/tools:__pkg__",
506 ],
507 deps = [
508 ":common_lib",
509 ":marisa_dict_lib",
510 ":utf8_string_slice_lib",
511 "@marisa-trie",
512 ],
513 )
514
515 cc_library(
516 name = "plugin_api_lib",
517 hdrs = ["plugin/OpenCCPlugin.h"],
518 )
519
520 cc_library(
521 name = "plugin_segmentation_lib",
522 srcs = ["PluginSegmentation.cpp"],
523 hdrs = [
524 "PluginSegmentation.hpp",
525 ],
526 linkopts = select({
527 "@platforms//os:linux": ["-ldl"],
528 "@platforms//os:osx": [],
529 "@platforms//os:windows": [],
530 "//conditions:default": ["-ldl"],
531 }),
532 deps = [
533 ":common_lib",
534 ":exception_lib",
535 ":plugin_api_lib",
536 ":segmentation_lib",
537 ":segments_lib",
538 ":utf8_util_lib",
539 ":win_util_lib",
540 ],
541 )
542
543 cc_test(
544 name = "phrase_extract_test",
545 size = "small",
546 srcs = ["PhraseExtractTest.cpp"],
547 deps = [
548 ":phrase_extract_lib",
549 ":test_utils_lib",
550 ":test_utils_utf8_lib",
551 "@googletest//:gtest_main",
552 ],
553 )
554
555 pybind_extension(
556 name = "opencc_clib",
557 srcs = ["py_opencc.cpp"],
558 deps = [":opencc_lib"],
559 )
560
561 py_library(
562 name = "py_opencc",
563 data = select({
564 "@platforms//os:windows": ["//src/pyd:opencc_clib_pyd_copy"],
565 "//conditions:default": [":opencc_clib"],
566 }),
567 imports = select({
568 "@platforms//os:windows": ["pyd"],
569 "//conditions:default": ["."],
570 }),
571 )
572
573 cc_library(
574 name = "segmentation_lib",
575 srcs = ["Segmentation.cpp"],
576 hdrs = ["Segmentation.hpp"],
577 deps = [":common_lib"],
578 )
579
580 cc_library(
581 name = "segments_lib",
582 hdrs = ["Segments.hpp"],
583 deps = [":common_lib"],
584 )
585
586 cc_library(
587 name = "serializable_dict_lib",
588 srcs = ["SerializableDict.cpp"],
589 hdrs = ["SerializableDict.hpp"],
590 deps = [
591 ":dict_lib",
592 ":win_util_lib",
593 ],
594 )
595
596 cc_library(
597 name = "serialized_values_lib",
598 srcs = ["SerializedValues.cpp"],
599 hdrs = ["SerializedValues.hpp"],
600 deps = [
601 ":common_lib",
602 ":lexicon_lib",
603 ":serializable_dict_lib",
604 ],
605 )
606
607 cc_test(
608 name = "serialized_values_test",
609 size = "small",
610 srcs = ["SerializedValuesTest.cpp"],
611 deps = [
612 ":serialized_values_lib",
613 ":text_dict_test_base_lib",
614 "@googletest//:gtest_main",
615 ],
616 )
617
618 cc_library(
619 name = "simple_converter_lib",
620 srcs = ["SimpleConverter.cpp"],
621 hdrs = [
622 "ConversionInspection.hpp",
623 "SimpleConverter.hpp",
624 "opencc.h",
625 ],
626 defines = ["BAZEL"],
627 deps = [
628 ":common_lib",
629 ":config_lib",
630 ":converter_lib",
631 ":resource_provider_lib",
632 ":utf8_util_lib",
633 "@bazel_tools//tools/cpp/runfiles",
634 ],
635 )
636
637 cc_test(
638 name = "simple_converter_test",
639 size = "small",
640 srcs = ["SimpleConverterTest.cpp"],
641 deps = [
642 ":config_test_base_lib",
643 ":simple_converter_lib",
644 ":test_utils_utf8_lib",
645 "@googletest//:gtest_main",
646 ],
647 )
648
649 cc_library(
650 name = "test_utils_lib",
651 testonly = True,
652 hdrs = ["TestUtils.hpp"],
653 deps = [
654 "@googletest//:gtest",
655 ],
656 )
657
658 cc_library(
659 name = "test_utils_utf8_lib",
660 testonly = True,
661 srcs = ["TestUtilsUTF8.hpp"],
662 )
663
664 cc_library(
665 name = "text_dict_lib",
666 srcs = ["TextDict.cpp"],
667 hdrs = ["TextDict.hpp"],
668 deps = [
669 ":common_lib",
670 ":lexicon_lib",
671 ":serializable_dict_lib",
672 ],
673 )
674
675 cc_test(
676 name = "text_dict_test",
677 size = "small",
678 srcs = ["TextDictTest.cpp"],
679 deps = [
680 ":test_utils_utf8_lib",
681 ":text_dict_lib",
682 ":text_dict_test_base_lib",
683 "@googletest//:gtest_main",
684 ],
685 )
686
687 cc_library(
688 name = "text_dict_test_base_lib",
689 testonly = True,
690 srcs = ["TextDictTestBase.hpp"],
691 deps = [
692 ":lexicon_lib",
693 ":test_utils_lib",
694 ":test_utils_utf8_lib",
695 ":text_dict_lib",
696 ],
697 )
698
699 cc_library(
700 name = "utf8_string_slice_lib",
701 srcs = ["UTF8StringSlice.cpp"],
702 hdrs = ["UTF8StringSlice.hpp"],
703 deps = [
704 ":common_lib",
705 ":utf8_util_lib",
706 ],
707 )
708
709 cc_test(
710 name = "utf8_string_slice_test",
711 size = "small",
712 srcs = ["UTF8StringSliceTest.cpp"],
713 deps = [
714 ":test_utils_lib",
715 ":utf8_string_slice_lib",
716 "@googletest//:gtest_main",
717 ],
718 )
719
720 cc_library(
721 name = "utf8_util_lib",
722 srcs = ["UTF8Util.cpp"],
723 hdrs = ["UTF8Util.hpp"],
724 deps = [
725 ":common_lib",
726 ":exception_lib",
727 ],
728 )
729
730 cc_test(
731 name = "utf8_util_test",
732 size = "small",
733 srcs = ["UTF8UtilTest.cpp"],
734 deps = [
735 ":test_utils_lib",
736 ":utf8_util_lib",
737 "@googletest//:gtest_main",
738 ],
739 )
740
741 cc_library(
742 name = "win_util_lib",
743 hdrs = ["WinUtil.hpp"],
744 )