From 1c3d4e8f1fb39119f968ce92367a75fe037be33f Mon Sep 17 00:00:00 2001 From: Antoine Date: Fri, 27 Dec 2024 18:59:32 +0100 Subject: [PATCH 1/3] strerror_r: posix returns int, gnu returns string --- build.zig | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/build.zig b/build.zig index d42a2f9..e4e1910 100644 --- a/build.zig +++ b/build.zig @@ -62,7 +62,6 @@ pub fn build(b: *std.Build) !void { lib.addIncludePath(upstream.path("src/include")); lib.addIncludePath(b.path("include")); lib.addConfigHeader(config_path); - lib.root_module.addCMacro("_GNU_SOURCE", "1"); lib.root_module.addCMacro("FRONTEND", "1"); lib.linkLibC(); b.installArtifact(lib); @@ -74,6 +73,11 @@ pub fn build(b: *std.Build) !void { var use_openssl: ?u8 = null; var use_ssl: ?u8 = null; + var not_gnu: ?u8 = null; + + if (target.result.isGnu()) { + lib.root_module.addCMacro("_GNU_SOURCE", "1"); + } else not_gnu = 1; switch (ssl_option) { .OpenSSL => { @@ -108,6 +112,7 @@ pub fn build(b: *std.Build) !void { .HAVE_HMAC_CTX_FREE = use_ssl, .HAVE_HMAC_CTX_NEW = use_ssl, .HAVE_ASN1_STRING_GET0_DATA = use_ssl, + .STRERROR_R_INT = not_gnu, }); if (ssl_option != .None) { @@ -191,7 +196,6 @@ pub fn build(b: *std.Build) !void { pg_config.addValues(.{ .HAVE_EXPLICIT_BZERO = 1, .HAVE_STRCHRNUL = 1, - .HAVE_STRERROR_R = 1, .HAVE_STRINGS_H = 1, .HAVE_SYNC_FILE_RANGE = 1, .HAVE_MEMSET_S = null, @@ -201,7 +205,6 @@ pub fn build(b: *std.Build) !void { pg_config.addValues(.{ .HAVE_EXPLICIT_BZERO = null, .HAVE_STRCHRNUL = null, - .HAVE_STRERROR_R = null, .HAVE_STRINGS_H = 0, .HAVE_SYNC_FILE_RANGE = null, .HAVE_MEMSET_S = 1, @@ -456,6 +459,7 @@ const autoconf = .{ .HAVE_STDLIB_H = 1, .HAVE_STRING_H = 1, .HAVE_STRNLEN = 1, + .HAVE_STRERROR_R = 1, .HAVE_STRSIGNAL = 1, .HAVE_STRUCT_OPTION = 1, .HAVE_STRUCT_TM_TM_ZONE = 1, @@ -580,7 +584,6 @@ const autoconf = .{ .LOCALE_T_IN_XLOCALE = null, .PROFILE_PID_DIR = null, .PTHREAD_CREATE_JOINABLE = null, - .STRERROR_R_INT = null, // 1 if not _GNU_SOURCE .USE_ARMV8_CRC32C = null, .USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK = null, .USE_ASSERT_CHECKING = null, From 60aa28d367a62c993b2bf3bd8a93d7c767f6dc66 Mon Sep 17 00:00:00 2001 From: Antoine Date: Sat, 28 Dec 2024 15:26:42 +0100 Subject: [PATCH 2/3] Define _GNU_SOURCE regardless of the target !? --- build.zig | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/build.zig b/build.zig index e4e1910..ce2316e 100644 --- a/build.zig +++ b/build.zig @@ -73,11 +73,6 @@ pub fn build(b: *std.Build) !void { var use_openssl: ?u8 = null; var use_ssl: ?u8 = null; - var not_gnu: ?u8 = null; - - if (target.result.isGnu()) { - lib.root_module.addCMacro("_GNU_SOURCE", "1"); - } else not_gnu = 1; switch (ssl_option) { .OpenSSL => { @@ -112,7 +107,6 @@ pub fn build(b: *std.Build) !void { .HAVE_HMAC_CTX_FREE = use_ssl, .HAVE_HMAC_CTX_NEW = use_ssl, .HAVE_ASN1_STRING_GET0_DATA = use_ssl, - .STRERROR_R_INT = not_gnu, }); if (ssl_option != .None) { @@ -192,12 +186,21 @@ pub fn build(b: *std.Build) !void { .HAVE_X86_64_POPCNTQ = is_amd64, }); + const is_gnu: ?u8 = if (target.result.isGnu()) 1 else null; + const not_gnu: ?u8 = if (is_gnu == null) 1 else null; + // While building with musl, defining _GNU_SOURCE makes musl declare extra things (e.g. struct ucred) + lib.root_module.addCMacro("_GNU_SOURCE", "1"); + + pg_config.addValues(.{ + .HAVE_SYNC_FILE_RANGE = is_gnu, + .STRERROR_R_INT = not_gnu, + }); + if (target.result.os.tag == .linux) { pg_config.addValues(.{ .HAVE_EXPLICIT_BZERO = 1, .HAVE_STRCHRNUL = 1, .HAVE_STRINGS_H = 1, - .HAVE_SYNC_FILE_RANGE = 1, .HAVE_MEMSET_S = null, .HAVE_SYS_UCRED_H = null, }); @@ -206,7 +209,6 @@ pub fn build(b: *std.Build) !void { .HAVE_EXPLICIT_BZERO = null, .HAVE_STRCHRNUL = null, .HAVE_STRINGS_H = 0, - .HAVE_SYNC_FILE_RANGE = null, .HAVE_MEMSET_S = 1, .HAVE_SYS_UCRED_H = 1, }); From 83196a6449ccc7738979f834950b5d40d5a4345e Mon Sep 17 00:00:00 2001 From: Antoine Date: Sat, 28 Dec 2024 15:29:06 +0100 Subject: [PATCH 3/3] Bump dependencies to fix building with master --- README.md | 4 ++-- build.zig.zon | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9406e90..1b81d84 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ To update this project dependencies: ```bash zig fetch --save=upstream git+https://github.com/postgres/postgres#REL_16_4 zig fetch --save git+https://github.com/allyourcodebase/openssl#3.3.0 -zig fetch --save git+https://github.com/allyourcodebase/libressl#3.9.2+1 +zig fetch --save git+https://github.com/allyourcodebase/libressl#4.0.0+1 zig fetch --save git+https://github.com/allyourcodebase/zlib#1.3.1 -zig fetch --save git+https://github.com/allyourcodebase/zstd#1.5.6-1 +zig fetch --save git+https://github.com/allyourcodebase/zstd#1.5.6-2 ``` diff --git a/build.zig.zon b/build.zig.zon index 589f543..04702f9 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -12,8 +12,8 @@ .lazy = true, }, .libressl = .{ - .url = "git+https://github.com/allyourcodebase/libressl?ref=3.9.2+1#02abfefee4e4eda28ce53c637b3c0d204ace8a6d", - .hash = "12201f5cc06c88f191696106723797449baacb6ea38b07b6cf31c18c0382a6bea33e", + .url = "git+https://github.com/allyourcodebase/libressl?ref=4.0.0+1#fd0fe777153a75217e97ba22cd8b32005bb90d08", + .hash = "1220c6521dd6d37f0426fbe6c3b3c3f4282f28495311abc08fb4cebf21ea2346ba2f", .lazy = true, }, .zlib = .{ @@ -22,8 +22,8 @@ .lazy = true, }, .zstd = .{ - .url = "git+https://github.com/allyourcodebase/zstd?ref=1.5.6-1#3247ffbcbc31f014027a5776a25c4261054e9fe9", - .hash = "12200dbfe91946451bab186f584edbec9f9f7fdbcf818ad984b7182fea655b3c10e3", + .url = "git+https://github.com/allyourcodebase/zstd?ref=1.5.6-2#ea25e89037dc251a3ba50a5005e2c8566eb3c2bd", + .hash = "122040924472b1c510a7058596d43fb9461dcc20406f681eb9c2f6443375d2f571c4", .lazy = true, }, },