@@ -41,28 +41,33 @@ pub fn build(b: *std.Build) !void {
4141 .PCRE2_MAX_VARLOOKBEHIND = 255 ,
4242 .NEWLINE_DEFAULT = 2 ,
4343 .PCRE2_PARENS_NEST_LIMIT = 250 ,
44+
45+ .PCRE2GREP_BUFSIZE = 20480 ,
46+ .PCRE2GREP_MAX_BUFSIZE = 1048576 ,
4447 },
4548 );
4649
4750 // pcre2-8/16/32.so
4851
52+ const lib_mod = std .Build .Module .create (b , .{
53+ .target = target ,
54+ .optimize = optimize ,
55+ .link_libc = true ,
56+ });
57+
58+ lib_mod .addCMacro ("HAVE_CONFIG_H" , "" );
59+ lib_mod .addCMacro ("PCRE2_CODE_UNIT_WIDTH" , @tagName (codeUnitWidth ));
60+ if (linkage == .static ) {
61+ lib_mod .addCMacro ("PCRE2_STATIC" , "" );
62+ }
63+
4964 const lib = std .Build .Step .Compile .create (b , .{
5065 .name = b .fmt ("pcre2-{s}" , .{@tagName (codeUnitWidth )}),
51- .root_module = .{
52- .target = target ,
53- .optimize = optimize ,
54- .link_libc = true ,
55- },
66+ .root_module = lib_mod ,
5667 .kind = .lib ,
5768 .linkage = linkage ,
5869 });
5970
60- lib .defineCMacro ("HAVE_CONFIG_H" , null );
61- lib .defineCMacro ("PCRE2_CODE_UNIT_WIDTH" , @tagName (codeUnitWidth ));
62- if (linkage == .static ) {
63- lib .defineCMacro ("PCRE2_STATIC" , null );
64- }
65-
6671 lib .addConfigHeader (config_header );
6772 lib .addIncludePath (pcre2_header_dir .getDirectory ());
6873 lib .addIncludePath (b .path ("src" ));
@@ -108,36 +113,46 @@ pub fn build(b: *std.Build) !void {
108113 lib .installHeader (pcre2_header , "pcre2.h" );
109114 b .installArtifact (lib );
110115
111-
112116 // pcre2test
113117
114- const pcre2test = b .addExecutable (.{
115- .name = "pcre2test" ,
118+ const pcre2test_mod = std .Build .Module .create (b , .{
116119 .target = target ,
117120 .optimize = optimize ,
121+ .link_libc = true ,
122+ .imports = &.{std.Build.Module.Import { .name = b .fmt ("pcre2-{s}" , .{@tagName (codeUnitWidth )}), .module = lib_mod }},
118123 });
119124
125+ pcre2test_mod .addCMacro ("HAVE_CONFIG_H" , "" );
126+
127+ const pcre2test = b .addExecutable (.{
128+ .name = "pcre2test" ,
129+ .root_module = pcre2test_mod ,
130+ });
120131
121132 // pcre2-posix.so
122133
123134 if (codeUnitWidth == CodeUnitWidth .@"8" ) {
135+ const posixLib_mod = std .Build .Module .create (b , .{
136+ .target = target ,
137+ .optimize = optimize ,
138+ .link_libc = true ,
139+ });
140+
141+ pcre2test_mod .addImport ("pcre2_posix" , posixLib_mod );
142+
143+ posixLib_mod .addCMacro ("HAVE_CONFIG_H" , "" );
144+ posixLib_mod .addCMacro ("PCRE2_CODE_UNIT_WIDTH" , @tagName (codeUnitWidth ));
145+ if (linkage == .static ) {
146+ posixLib_mod .addCMacro ("PCRE2_STATIC" , "" );
147+ }
148+
124149 const posixLib = std .Build .Step .Compile .create (b , .{
125150 .name = "pcre2-posix" ,
126- .root_module = .{
127- .target = target ,
128- .optimize = optimize ,
129- .link_libc = true ,
130- },
151+ .root_module = posixLib_mod ,
131152 .kind = .lib ,
132153 .linkage = linkage ,
133154 });
134155
135- posixLib .defineCMacro ("HAVE_CONFIG_H" , null );
136- posixLib .defineCMacro ("PCRE2_CODE_UNIT_WIDTH" , @tagName (codeUnitWidth ));
137- if (linkage == .static ) {
138- posixLib .defineCMacro ("PCRE2_STATIC" , null );
139- }
140-
141156 posixLib .addConfigHeader (config_header );
142157 posixLib .addIncludePath (pcre2_header_dir .getDirectory ());
143158 posixLib .addIncludePath (b .path ("src" ));
@@ -150,15 +165,10 @@ pub fn build(b: *std.Build) !void {
150165
151166 posixLib .installHeader (b .path ("src/pcre2posix.h" ), "pcre2posix.h" );
152167 b .installArtifact (posixLib );
153-
154- pcre2test .linkLibrary (posixLib );
155168 }
156169
157-
158170 // pcre2test (again)
159171
160- pcre2test .defineCMacro ("HAVE_CONFIG_H" , null );
161-
162172 pcre2test .addConfigHeader (config_header );
163173 pcre2test .addIncludePath (pcre2_header_dir .getDirectory ());
164174 pcre2test .addIncludePath (b .path ("src" ));
@@ -168,7 +178,6 @@ pub fn build(b: *std.Build) !void {
168178 });
169179
170180 pcre2test .linkLibC ();
171- pcre2test .linkLibrary (lib );
172181
173182 b .installArtifact (pcre2test );
174183}
0 commit comments