@@ -34,41 +34,41 @@ pub fn build(b: *std.Build) !void {
3434 .{ .style = .blank , .include_path = "pg_config_paths.h" },
3535 default_paths ,
3636 );
37-
38- const lib = b . addLibrary (.{
39- .name = "pq" ,
40- .root_module = b . createModule (.{ . target = target , . optimize = optimize }) ,
37+ const mod = b . createModule (.{
38+ . target = target ,
39+ .optimize = optimize ,
40+ .link_libc = true ,
4141 });
42+ const lib = b .addLibrary (.{ .name = "pq" , .root_module = mod });
4243
43- lib .addCSourceFiles (.{
44+ mod .addCSourceFiles (.{
4445 .root = upstream .path (libpq_path ),
4546 .files = & libpq_sources ,
4647 .flags = & CFLAGS ,
4748 });
48- lib .addCSourceFiles (.{
49+ mod .addCSourceFiles (.{
4950 .root = upstream .path ("src/port" ),
5051 .files = & libport_sources ,
5152 .flags = & CFLAGS ,
5253 });
53- lib .addCSourceFiles (.{
54+ mod .addCSourceFiles (.{
5455 .root = upstream .path ("src/common" ),
5556 .files = & common_sources ,
5657 .flags = & CFLAGS ,
5758 });
5859
5960 const config_headers = [_ ]* std.Build.Step.ConfigHeader { pg_config , config_os };
6061
61- lib .addIncludePath (upstream .path ("src/include" ));
62- lib .addIncludePath (b .path ("include" ));
63- lib .addIncludePath (upstream .path (libpq_path ));
64- lib .addConfigHeader (config_path );
65- lib .root_module .addCMacro ("FRONTEND" , "1" );
66- lib .root_module .addCMacro ("JSONAPI_USE_PQEXPBUFFER" , "1" );
67- lib .linkLibC ();
62+ mod .addIncludePath (upstream .path ("src/include" ));
63+ mod .addIncludePath (b .path ("include" ));
64+ mod .addIncludePath (upstream .path (libpq_path ));
65+ mod .addConfigHeader (config_path );
66+ mod .addCMacro ("FRONTEND" , "1" );
67+ mod .addCMacro ("JSONAPI_USE_PQEXPBUFFER" , "1" );
6868 b .installArtifact (lib );
6969
7070 for (config_headers ) | header | {
71- lib .addConfigHeader (header );
71+ mod .addConfigHeader (header );
7272 lib .installConfigHeader (header );
7373 }
7474
@@ -81,14 +81,14 @@ pub fn build(b: *std.Build) !void {
8181 use_openssl = 1 ;
8282 if (b .lazyDependency ("openssl" , .{ .target = target , .optimize = optimize })) | openssl_dep | {
8383 const openssl = openssl_dep .artifact ("openssl" );
84- lib .linkLibrary (openssl );
84+ mod .linkLibrary (openssl );
8585 }
8686 },
8787 .LibreSSL = > {
8888 use_ssl = 1 ;
8989 if (b .lazyDependency ("libressl" , .{ .target = target , .optimize = optimize })) | libressl_dep | {
9090 const libressl = libressl_dep .artifact ("ssl" );
91- lib .linkLibrary (libressl );
91+ mod .linkLibrary (libressl );
9292 }
9393 },
9494 .None = > {},
@@ -105,15 +105,15 @@ pub fn build(b: *std.Build) !void {
105105 });
106106
107107 if (ssl_option != .None ) {
108- lib .addCSourceFiles (.{
108+ mod .addCSourceFiles (.{
109109 .root = upstream .path (libpq_path ),
110110 .files = &.{
111111 "fe-secure-common.c" ,
112112 "fe-secure-openssl.c" ,
113113 },
114114 .flags = & CFLAGS ,
115115 });
116- lib .addCSourceFiles (.{
116+ mod .addCSourceFiles (.{
117117 .root = upstream .path ("src/common" ),
118118 .files = &.{
119119 "cryptohash_openssl.c" ,
@@ -122,7 +122,7 @@ pub fn build(b: *std.Build) !void {
122122 .flags = & CFLAGS ,
123123 });
124124 } else {
125- lib .addCSourceFiles (.{
125+ mod .addCSourceFiles (.{
126126 .root = upstream .path ("src/common" ),
127127 .files = &.{
128128 "cryptohash.c" ,
@@ -137,15 +137,15 @@ pub fn build(b: *std.Build) !void {
137137
138138 if (! disable_zlib ) {
139139 if (b .lazyDependency ("zlib" , .{ .target = target , .optimize = optimize })) | zlib_dep | {
140- lib .linkLibrary (zlib_dep .artifact ("z" ));
140+ mod .linkLibrary (zlib_dep .artifact ("z" ));
141141 }
142142 }
143143 const use_z : ? u8 = if (disable_zlib ) null else 1 ;
144144 pg_config .addValues (.{ .HAVE_LIBZ = use_z });
145145
146146 if (! disable_zstd ) {
147147 if (b .lazyDependency ("zstd" , .{ .target = target , .optimize = optimize })) | zstd_dep | {
148- lib .linkLibrary (zstd_dep .artifact ("zstd" ));
148+ mod .linkLibrary (zstd_dep .artifact ("zstd" ));
149149 }
150150 }
151151 const use_zstd : ? u8 = if (disable_zstd ) null else 1 ;
@@ -156,7 +156,7 @@ pub fn build(b: *std.Build) !void {
156156
157157 const have_strlcat : bool = target .result .os .tag == .macos or (target .result .os .tag == .linux and target .result .os .versionRange ().gnuLibCVersion ().? .order (.{ .major = 2 , .minor = 38 , .patch = 0 }) == .gt );
158158 if (! have_strlcat ) {
159- lib .addCSourceFiles (.{
159+ mod .addCSourceFiles (.{
160160 .root = upstream .path ("src/port" ),
161161 .files = &.{
162162 "strlcat.c" ,
@@ -183,7 +183,7 @@ pub fn build(b: *std.Build) !void {
183183 const is_gnu : ? u8 = if (target .result .isGnuLibC ()) 1 else null ;
184184 const not_gnu : ? u8 = if (is_gnu == null ) 1 else null ;
185185 // While building with musl, defining _GNU_SOURCE makes musl declare extra things (e.g. struct ucred)
186- lib . root_module .addCMacro ("_GNU_SOURCE" , "1" );
186+ mod .addCMacro ("_GNU_SOURCE" , "1" );
187187
188188 pg_config .addValues (.{
189189 .HAVE_SYNC_FILE_RANGE = is_gnu ,
@@ -215,7 +215,7 @@ pub fn build(b: *std.Build) !void {
215215 .HAVE_SYNCFS = null ,
216216 .HAVE_XLOCALE_H = 1 ,
217217 });
218- lib .addCSourceFile (.{
218+ mod .addCSourceFile (.{
219219 .file = upstream .path ("src/port/explicit_bzero.c" ),
220220 .flags = & CFLAGS ,
221221 });
@@ -284,17 +284,17 @@ pub fn build(b: *std.Build) !void {
284284 const test5 = b .addExecutable (.{ .name = "testlo" , .root_module = b .createModule (.{ .target = target , .optimize = optimize }) });
285285 const test6 = b .addExecutable (.{ .name = "testlo64" , .root_module = b .createModule (.{ .target = target , .optimize = optimize }) });
286286
287- test1 .addCSourceFiles (.{ .root = upstream .path ("src/test/examples" ), .files = &.{"testlibpq.c" } });
288- test2 .addCSourceFiles (.{ .root = upstream .path ("src/test/examples" ), .files = &.{"testlibpq2.c" } });
289- test3 .addCSourceFiles (.{ .root = upstream .path ("src/test/examples" ), .files = &.{"testlibpq3.c" } });
290- test4 .addCSourceFiles (.{ .root = upstream .path ("src/test/examples" ), .files = &.{"testlibpq4.c" } });
291- test5 .addCSourceFiles (.{ .root = upstream .path ("src/test/examples" ), .files = &.{"testlo.c" } });
292- test6 .addCSourceFiles (.{ .root = upstream .path ("src/test/examples" ), .files = &.{"testlo64.c" } });
287+ test1 .root_module . addCSourceFiles (.{ .root = upstream .path ("src/test/examples" ), .files = &.{"testlibpq.c" } });
288+ test2 .root_module . addCSourceFiles (.{ .root = upstream .path ("src/test/examples" ), .files = &.{"testlibpq2.c" } });
289+ test3 .root_module . addCSourceFiles (.{ .root = upstream .path ("src/test/examples" ), .files = &.{"testlibpq3.c" } });
290+ test4 .root_module . addCSourceFiles (.{ .root = upstream .path ("src/test/examples" ), .files = &.{"testlibpq4.c" } });
291+ test5 .root_module . addCSourceFiles (.{ .root = upstream .path ("src/test/examples" ), .files = &.{"testlo.c" } });
292+ test6 .root_module . addCSourceFiles (.{ .root = upstream .path ("src/test/examples" ), .files = &.{"testlo64.c" } });
293293
294294 const tests = [_ ]* std.Build.Step.Compile { test1 , test2 , test3 , test4 , test5 , test6 };
295295 for (tests ) | t | {
296- t .linkLibC () ;
297- t .linkLibrary (lib );
296+ t .root_module . link_libc = true ;
297+ t .root_module . linkLibrary (lib );
298298 const install_test = b .addInstallArtifact (t , .{});
299299 test_step .dependOn (& install_test .step );
300300 }
0 commit comments