diff --git a/build.zig b/build.zig index 6ee23b7..129d321 100644 --- a/build.zig +++ b/build.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const libcquery = @import("libcquery"); const version = std.SemanticVersion.parse(@import("build.zig.zon").version) catch unreachable; @@ -614,6 +615,11 @@ pub fn build(b: *std.Build) !void { } } + const lc_features = libcquery.libc_features.detect(target.result); + const lc_headers = libcquery.libc_headers.detect(target.result); + const lc_constants = libcquery.libc_constants.detect(target.result); + const lc_types = libcquery.libc_types.detect(target.result); + const curl_config = b.addConfigHeader(.{ .style = .{ .cmake = upstream.path("lib/curl_config-cmake.h.in") }, .include_path = "curl_config.h", @@ -671,87 +677,55 @@ pub fn build(b: *std.Build) !void { .USE_WIN32_CRYPTO = target.result.os.tag == .windows, // Assumes 'NOT WINDOWS_STORE' .USE_WIN32_LDAP = target.result.os.tag == .windows and use_win32_ldap and !disable_ldap, // Assumes 'NOT WINDOWS_STORE' .USE_IPV6 = enable_ipv6, - .HAVE_ALARM = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_ARC4RANDOM = switch (target.result.os.tag) { - .dragonfly, - .netbsd, - .freebsd, - .openbsd, - .macos, - .ios, - .tvos, - .watchos, - .visionos, - .wasi, - => true, - else => false, - }, - .HAVE_ARPA_INET_H = target.result.os.tag != .windows, + .HAVE_ALARM = lc_features.alarm, + .HAVE_ARC4RANDOM = lc_features.arc4random, + .HAVE_ARPA_INET_H = lc_headers.arpa_inet_h, .HAVE_ATOMIC = true, - .HAVE_ACCEPT4 = switch (target.result.os.tag) { - .linux => true, - .freebsd => target.result.os.isAtLeast(.freebsd, .{ .major = 10, .minor = 0, .patch = 0 }) orelse false, - .dragonfly => target.result.os.isAtLeast(.dragonfly, .{ .major = 4, .minor = 3, .patch = 0 }) orelse false, - .netbsd => target.result.os.isAtLeast(.netbsd, .{ .major = 8, .minor = 0, .patch = 0 }) orelse false, - .openbsd => false, - else => false, - }, - .HAVE_FNMATCH = target.result.os.tag != .windows, + .HAVE_ACCEPT4 = lc_features.accept4, + .HAVE_FNMATCH = lc_features.fnmatch, .HAVE_BASENAME = true, .HAVE_BOOL_T = true, .HAVE_BUILTIN_AVAILABLE = target.result.os.tag.isDarwin(), - .HAVE_CLOCK_GETTIME_MONOTONIC = target.result.os.tag != .windows, - .HAVE_CLOCK_GETTIME_MONOTONIC_RAW = target.result.os.tag == .linux or target.result.os.tag.isDarwin(), + .HAVE_CLOCK_GETTIME_MONOTONIC = lc_features.clock_gettime and lc_constants.clock_monotonic, + .HAVE_CLOCK_GETTIME_MONOTONIC_RAW = lc_constants.clock_monotonic_raw, .HAVE_CLOSESOCKET = target.result.os.tag == .windows, .HAVE_CLOSESOCKET_CAMEL = null, - .HAVE_DIRENT_H = true, - .HAVE_OPENDIR = true, - .HAVE_FCNTL = target.result.os.tag != .windows, - .HAVE_FCNTL_H = true, - .HAVE_FCNTL_O_NONBLOCK = target.result.os.tag != .windows, - .HAVE_FREEADDRINFO = target.result.os.tag != .wasi, - .HAVE_FSEEKO = target.result.os.tag != .windows, - .HAVE_DECL_FSEEKO = target.result.os.tag != .windows, - .HAVE_FTRUNCATE = true, - .HAVE_GETADDRINFO = target.result.os.tag != .wasi, - .HAVE_GETADDRINFO_THREADSAFE = target.result.os.tag != .wasi and target.result.os.tag != .openbsd, - .HAVE_GETEUID = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_GETPPID = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_GETHOSTBYNAME_R = switch (target.result.os.tag) { - .linux => true, - .windows, .wasi => false, - .freebsd => target.result.os.isAtLeast(.freebsd, .{ .major = 6, .minor = 2, .patch = 0 }) orelse false, - .dragonfly => target.result.os.isAtLeast(.dragonfly, .{ .major = 2, .minor = 1, .patch = 0 }) orelse false, - else => false, - }, + .HAVE_DIRENT_H = lc_headers.dirent_h, + .HAVE_OPENDIR = lc_features.opendir, + .HAVE_FCNTL = lc_features.fcntl, + .HAVE_FCNTL_H = lc_headers.fcntl_h, + .HAVE_FCNTL_O_NONBLOCK = lc_constants.o_nonblock, + .HAVE_FREEADDRINFO = lc_features.freeaddrinfo, + .HAVE_FSEEKO = lc_features.fseeko, + .HAVE_DECL_FSEEKO = lc_features.fseeko, + .HAVE_FTRUNCATE = lc_features.ftruncate, + .HAVE_GETADDRINFO = lc_features.getaddrinfo, + .HAVE_GETADDRINFO_THREADSAFE = lc_features.getaddrinfo_threadsafe, + .HAVE_GETEUID = lc_features.geteuid, + .HAVE_GETPPID = lc_features.getppid, + .HAVE_GETHOSTBYNAME_R = lc_features.gethostbyname_r, .HAVE_GETHOSTBYNAME_R_3 = null, .HAVE_GETHOSTBYNAME_R_5 = null, - .HAVE_GETHOSTBYNAME_R_6 = switch (target.result.os.tag) { - .linux => true, - .windows, .wasi => false, - .freebsd => target.result.os.isAtLeast(.freebsd, .{ .major = 6, .minor = 2, .patch = 0 }) orelse false, - .dragonfly => target.result.os.isAtLeast(.dragonfly, .{ .major = 2, .minor = 1, .patch = 0 }) orelse false, - else => false, - }, - .HAVE_GETHOSTNAME = target.result.os.tag != .wasi, - .HAVE_GETIFADDRS = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_GETPASS_R = target.result.os.isAtLeast(.netbsd, .{ .major = 7, .minor = 0, .patch = 0 }) orelse false, - .HAVE_GETPEERNAME = target.result.os.tag != .wasi, - .HAVE_GETSOCKNAME = target.result.os.tag != .wasi, - .HAVE_IF_NAMETOINDEX = target.result.os.tag != .wasi, - .HAVE_GETPWUID = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_GETPWUID_R = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_GETRLIMIT = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_GETTIMEOFDAY = true, + .HAVE_GETHOSTBYNAME_R_6 = lc_features.gethostbyname_r, + .HAVE_GETHOSTNAME = lc_features.gethostname, + .HAVE_GETIFADDRS = lc_features.getifaddrs, + .HAVE_GETPASS_R = lc_features.getpass_r, + .HAVE_GETPEERNAME = lc_features.getpeername, + .HAVE_GETSOCKNAME = lc_features.getsockname, + .HAVE_IF_NAMETOINDEX = lc_features.if_nametoindex, + .HAVE_GETPWUID = lc_features.getpwuid, + .HAVE_GETPWUID_R = lc_features.getpwuid_r, + .HAVE_GETRLIMIT = lc_features.getrlimit, + .HAVE_GETTIMEOFDAY = lc_features.gettimeofday, .HAVE_GLIBC_STRERROR_R = false, // TODO why not target.result.isGnuLibC()? - .HAVE_GMTIME_R = target.result.os.tag != .windows, + .HAVE_GMTIME_R = lc_features.gmtime_r, .HAVE_GSSAPI = null, .HAVE_GSSGNU = null, .CURL_KRB5_VERSION = null, - .HAVE_IFADDRS_H = target.result.os.tag != .windows, - .HAVE_INET_NTOP = target.result.os.tag != .windows, - .HAVE_INET_PTON = target.result.os.tag != .windows, - .HAVE_SA_FAMILY_T = target.result.os.tag != .windows, + .HAVE_IFADDRS_H = lc_headers.ifaddrs_h, + .HAVE_INET_NTOP = lc_features.inet_ntop, + .HAVE_INET_PTON = lc_features.inet_pton, + .HAVE_SA_FAMILY_T = lc_types.sa_family_t, .HAVE_ADDRESS_FAMILY = target.result.os.tag == .windows, .HAVE_IOCTLSOCKET = target.result.os.tag == .windows, .HAVE_IOCTLSOCKET_CAMEL = null, @@ -759,124 +733,96 @@ pub fn build(b: *std.Build) !void { .HAVE_IOCTLSOCKET_FIONBIO = target.result.os.tag == .windows, .HAVE_IOCTL_FIONBIO = target.result.os.tag != .windows, .HAVE_IOCTL_SIOCGIFADDR = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_IO_H = target.result.os.tag == .windows, + .HAVE_IO_H = lc_headers.io_h, .HAVE_LBER_H = have_lber_h, .HAVE_LDAP_SSL = have_ldap_ssl, .HAVE_LDAP_SSL_H = null, .HAVE_LDAP_URL_PARSE = null, - .HAVE_LIBGEN_H = true, + .HAVE_LIBGEN_H = lc_headers.libgen_h, .HAVE_LIBIDN2 = use_libidn2 and !use_apple_idn and !use_win32_idn, .HAVE_IDN2_H = use_libidn2 and !use_apple_idn and !use_win32_idn, .HAVE_LIBZ = use_zlib, .HAVE_BROTLI = use_brotli, .HAVE_ZSTD = use_zstd, - .HAVE_LOCALE_H = true, - .HAVE_LOCALTIME_R = target.result.os.tag != .windows, + .HAVE_LOCALE_H = lc_headers.locale_h, + .HAVE_LOCALTIME_R = lc_features.localtime_r, .HAVE_LONGLONG = true, - .HAVE_SUSECONDS_T = target.result.os.tag != .windows, - .HAVE_MSG_NOSIGNAL = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_NETDB_H = target.result.os.tag != .windows, - .HAVE_NETINET_IN_H = target.result.os.tag != .windows, + .HAVE_SUSECONDS_T = lc_types.suseconds_t, + .HAVE_MSG_NOSIGNAL = lc_constants.msg_nosignal, + .HAVE_NETDB_H = lc_headers.netdb_h, + .HAVE_NETINET_IN_H = lc_headers.netinet_in_h, .HAVE_NETINET_IN6_H = null, - .HAVE_NETINET_TCP_H = target.result.os.tag != .windows, - .HAVE_NETINET_UDP_H = target.result.os.tag != .windows, - .HAVE_LINUX_TCP_H = target.result.os.tag == .linux, - .HAVE_NET_IF_H = target.result.os.tag != .windows, + .HAVE_NETINET_TCP_H = lc_headers.netinet_tcp_h, + .HAVE_NETINET_UDP_H = lc_headers.netinet_udp_h, + .HAVE_LINUX_TCP_H = lc_headers.linux_tcp_h, + .HAVE_NET_IF_H = lc_headers.net_if_h, .HAVE_OLD_GSSMIT = null, - .HAVE_PIPE = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_PIPE2 = switch (target.result.os.tag) { - .linux => true, - .dragonfly, .freebsd, .netbsd, .openbsd => true, - else => false, - }, - .HAVE_EVENTFD = switch (target.result.os.tag) { - .windows, .wasi => false, - .linux => if (target.result.isMuslLibC()) - true - else - target.result.os.isAtLeast(.linux, .{ .major = 2, .minor = 8, .patch = 0 }), - .freebsd => target.result.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0, .patch = 0 }) orelse false, - .netbsd => target.result.os.isAtLeast(.netbsd, .{ .major = 10, .minor = 0, .patch = 0 }) orelse false, - else => !target.result.os.tag.isDarwin(), - }, - .HAVE_POLL = target.result.os.tag != .windows, - .HAVE_POLL_H = target.result.os.tag != .windows, + .HAVE_PIPE = lc_features.pipe, + .HAVE_PIPE2 = lc_features.pipe2, + .HAVE_EVENTFD = lc_features.eventfd, + .HAVE_POLL = lc_features.poll, + .HAVE_POLL_H = lc_headers.poll_h, .HAVE_POSIX_STRERROR_R = switch (target.result.os.tag) { .windows => false, .linux => true, // TODO why not target.result.isMuslLibC()? else => true, }, - .HAVE_PWD_H = target.result.os.tag != .windows, + .HAVE_PWD_H = lc_headers.pwd_h, .HAVE_SSL_SET0_WBIO = null, // TODO - .HAVE_RECV = true, - .HAVE_SELECT = true, - .HAVE_SCHED_YIELD = target.result.os.tag != .windows, - .HAVE_SEND = true, - .HAVE_SENDMSG = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_SENDMMSG = switch (target.result.os.tag) { - .windows, .wasi => false, - .linux => if (target.result.isMuslLibC()) - true - else - target.result.os.isAtLeast(.linux, .{ .major = 2, .minor = 14, .patch = 0 }), - else => !target.result.os.tag.isDarwin(), - }, - .HAVE_FSETXATTR = switch (target.result.os.tag) { - .linux => true, - .netbsd => true, - else => false, - }, - .HAVE_FSETXATTR_5 = switch (target.result.os.tag) { - .linux => true, - .netbsd => true, - else => false, - }, - .HAVE_FSETXATTR_6 = null, - .HAVE_SETLOCALE = true, - .HAVE_SETMODE = target.result.os.tag == .windows or target.result.os.tag.isBSD(), + .HAVE_RECV = lc_features.recv, + .HAVE_SELECT = lc_features.select, + .HAVE_SCHED_YIELD = lc_features.sched_yield, + .HAVE_SEND = lc_features.send, + .HAVE_SENDMSG = lc_features.sendmsg, + .HAVE_SENDMMSG = lc_features.sendmmsg, + .HAVE_FSETXATTR = lc_features.fsetxattr, + .HAVE_FSETXATTR_5 = lc_features.fsetxattr and !target.result.os.tag.isDarwin(), + .HAVE_FSETXATTR_6 = lc_features.fsetxattr and target.result.os.tag.isDarwin(), + .HAVE_SETLOCALE = lc_features.setlocale, + .HAVE_SETMODE = lc_features.setmode, .HAVE__SETMODE = target.result.os.tag == .windows, - .HAVE_SETRLIMIT = target.result.os.tag != .wasi, + .HAVE_SETRLIMIT = lc_features.setrlimit, .HAVE_SETSOCKOPT_SO_NONBLOCK = null, - .HAVE_SIGACTION = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_SIGINTERRUPT = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_SIGNAL = target.result.os.tag != .wasi, - .HAVE_SIGSETJMP = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_SNPRINTF = true, + .HAVE_SIGACTION = lc_features.sigaction, + .HAVE_SIGINTERRUPT = lc_features.siginterrupt, + .HAVE_SIGNAL = lc_features.signal, + .HAVE_SIGSETJMP = lc_features.sigsetjmp, + .HAVE_SNPRINTF = lc_features.snprintf, .HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID = target.result.os.tag == .windows, // TODO - .HAVE_SOCKET = target.result.os.tag != .wasi, + .HAVE_SOCKET = lc_features.socket, .HAVE_PROTO_BSDSOCKET_H = null, - .HAVE_SOCKETPAIR = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_STDATOMIC_H = true, - .HAVE_STDBOOL_H = true, - .HAVE_STDINT_H = true, - .HAVE_STRCASECMP = target.result.os.tag != .windows, + .HAVE_SOCKETPAIR = lc_features.socketpair, + .HAVE_STDATOMIC_H = lc_headers.stdatomic_h, + .HAVE_STDBOOL_H = lc_headers.stdbool_h, + .HAVE_STDINT_H = lc_headers.stdint_h, + .HAVE_STRCASECMP = lc_features.strcasecmp, .HAVE_STRCMPI = null, - .HAVE_STRDUP = true, - .HAVE_STRERROR_R = target.result.os.tag != .windows, + .HAVE_STRDUP = lc_features.strdup, + .HAVE_STRERROR_R = lc_features.strerror_r, .HAVE_STRICMP = null, - .HAVE_STRINGS_H = true, - .HAVE_STROPTS_H = target.result.isMuslLibC(), - .HAVE_MEMRCHR = target.result.os.tag != .windows and !target.result.os.tag.isDarwin() and target.result.os.tag != .wasi, - .HAVE_STRUCT_SOCKADDR_STORAGE = true, - .HAVE_STRUCT_TIMEVAL = true, - .HAVE_SYS_EVENTFD_H = target.result.os.tag != .windows and !target.result.os.tag.isDarwin() and target.result.os.tag != .openbsd, - .HAVE_SYS_FILIO_H = target.result.os.tag.isBSD(), - .HAVE_SYS_IOCTL_H = target.result.os.tag != .windows, - .HAVE_SYS_PARAM_H = true, - .HAVE_SYS_POLL_H = target.result.os.tag != .windows, - .HAVE_SYS_RESOURCE_H = target.result.os.tag != .windows and target.result.os.tag != .wasi, - .HAVE_SYS_SELECT_H = target.result.os.tag != .windows, - .HAVE_SYS_SOCKIO_H = target.result.os.tag.isBSD(), - .HAVE_SYS_STAT_H = true, - .HAVE_SYS_TYPES_H = true, - .HAVE_SYS_UN_H = target.result.os.tag != .windows, - .HAVE_SYS_UTIME_H = target.result.os.tag == .windows, - .HAVE_TERMIOS_H = target.result.os.tag != .windows, + .HAVE_STRINGS_H = lc_headers.strings_h, + .HAVE_STROPTS_H = lc_headers.stropts_h, + .HAVE_MEMRCHR = lc_features.memrchr, + .HAVE_STRUCT_SOCKADDR_STORAGE = lc_types.struct_sockaddr_storage, + .HAVE_STRUCT_TIMEVAL = lc_types.struct_timeval, + .HAVE_SYS_EVENTFD_H = lc_headers.sys_eventfd_h, + .HAVE_SYS_FILIO_H = lc_headers.sys_filio_h, + .HAVE_SYS_IOCTL_H = lc_headers.sys_ioctl_h, + .HAVE_SYS_PARAM_H = lc_headers.sys_param_h, + .HAVE_SYS_POLL_H = lc_headers.poll_h, + .HAVE_SYS_RESOURCE_H = lc_headers.sys_resource_h, + .HAVE_SYS_SELECT_H = lc_headers.sys_select_h, + .HAVE_SYS_SOCKIO_H = lc_headers.sys_sockio_h, + .HAVE_SYS_STAT_H = lc_headers.sys_stat_h, + .HAVE_SYS_TYPES_H = lc_headers.sys_types_h, + .HAVE_SYS_UN_H = lc_headers.sys_un_h, + .HAVE_SYS_UTIME_H = lc_headers.sys_utime_h, + .HAVE_TERMIOS_H = lc_headers.termios_h, .HAVE_TERMIO_H = null, - .HAVE_UNISTD_H = true, + .HAVE_UNISTD_H = lc_headers.unistd_h, .HAVE_UTIME = true, - .HAVE_UTIMES = target.result.os.tag != .windows, - .HAVE_UTIME_H = true, + .HAVE_UTIMES = lc_features.utimes, + .HAVE_UTIME_H = lc_headers.utime_h, .HAVE_WRITABLE_ARGV = target.result.os.tag.isDarwin(), .HAVE_TIME_T_UNSIGNED = null, .NEED_REENTRANT = null, diff --git a/build.zig.zon b/build.zig.zon index 5119a2a..ce5bec2 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -32,6 +32,10 @@ .hash = "mbedtls-3.6.4-E4NUR2wWAAAUSvVbho9aaU31-e4D8glu9l1VfxKezBkV", .lazy = true, }, + .libcquery = .{ + .url = "git+https://github.com/agagniere/libc-query#b441e4923bb7d39018e9f5aaaf9ed0189349e173", + .hash = "libcquery-0.1.1-_2254XxFAQB6zE9xGH9hJSglKeE80Yq1fgsaNiokLP2v", + }, }, .paths = .{ "build.zig",