Skip to content

Commit 13abc73

Browse files
authored
Pcre2 buck target in third-party (#55) (#58)
Summary: Pull Request resolved: #55 Reviewed By: larryliu0820 Differential Revision: D73412412 Pulled By: jackzhxng
1 parent 1e2c6f7 commit 13abc73

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

targets.bzl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ def define_common_targets():
2828
srcs = ["src/regex.cpp"] + glob([
2929
"src/*_regex.cpp",
3030
]),
31-
deps = [
32-
"fbsource//third-party/pcre2:pcre2-8",
33-
],
3431
exported_headers = subdir_glob([
3532
("include", "pytorch/tokenizers/regex.h"),
3633
("include", "pytorch/tokenizers/*_regex.h"),
@@ -39,6 +36,7 @@ def define_common_targets():
3936
":headers",
4037
],
4138
exported_external_deps = [
39+
"pcre2",
4240
"re2",
4341
],
4442
visibility = ["//pytorch/tokenizers/..."],

third-party/targets.bzl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,55 @@ def define_common_targets():
5959
":abseil",
6060
],
6161
)
62+
63+
runtime.genrule(
64+
name = "config_h_generic",
65+
srcs = ["pcre2/src/config.h.generic"],
66+
cmd = "cp $SRCS $OUT",
67+
out = "pcre2/src/config.h",
68+
)
69+
runtime.genrule(
70+
name = "pcre2_h_generic",
71+
srcs = ["pcre2/src/pcre2.h.generic"],
72+
cmd = "cp $SRCS $OUT",
73+
out = "pcre2/src/pcre2.h",
74+
)
75+
runtime.genrule(
76+
name = "pcre2_chartables_c",
77+
srcs = ["pcre2/src/pcre2_chartables.c.dist"],
78+
cmd = "cp $SRCS $OUT",
79+
out = "pcre2/src/pcre2_chartables.c",
80+
)
81+
82+
runtime.cxx_library(
83+
name = "pcre2",
84+
srcs = glob([
85+
"pcre2/src/*.c",
86+
]) + [
87+
":pcre2_chartables_c",
88+
],
89+
exported_headers = [
90+
":pcre2_h_generic",
91+
],
92+
headers = [
93+
":config_h_generic",
94+
] + glob([
95+
"pcre2/src/*.h",
96+
]),
97+
# Preprocessor flags from https://github.com/PCRE2Project/pcre2/blob/2e03e323339ab692640626f02f8d8d6f95bff9c6/BUILD.bazel#L23.
98+
preprocessor_flags = [
99+
"-DHAVE_CONFIG_H",
100+
"-DHAVE_MEMMOVE",
101+
"-DHAVE_STRERROR",
102+
"-DPCRE2_CODE_UNIT_WIDTH=8",
103+
"-DPCRE2_STATIC",
104+
"-DSUPPORT_PCRE2_8",
105+
"-DSUPPORT_UNICODE",
106+
] + select({
107+
"DEFAULT": ["-DHAVE_UNISTD_H"],
108+
"ovr_config//os:windows": [],
109+
}),
110+
_is_external_target = True,
111+
public_include_directories = ["pcre2"],
112+
visibility = ["PUBLIC"],
113+
)

0 commit comments

Comments
 (0)