Skip to content

Commit

Permalink
Add macOS build support
Browse files Browse the repository at this point in the history
  • Loading branch information
zadockmaloba authored and agagniere committed Sep 26, 2024
1 parent 949cc6d commit a7f29a2
Showing 1 changed file with 266 additions and 7 deletions.
273 changes: 266 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const std = @import("std");
const version = .{ .major = 16, .minor = 4 };
const libpq_path = "src/interfaces/libpq";

const libPQBuildErrors = error{
OsNotSupported,
OsConfigNotCreated,
};

pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
Expand All @@ -17,12 +22,27 @@ pub fn build(b: *std.Build) !void {
.{ .style = .{ .autoconf = upstream.path("src/include/pg_config_ext.h.in") }, .include_path = "pg_config_ext.h" },
.{ .PG_INT64_TYPE = .@"long int" },
);
const pg_config = b.addConfigHeader(
.{ .style = .{ .autoconf = upstream.path("src/include/pg_config.h.in") }, .include_path = "pg_config.h" },
autoconf,
);
const pg_config = switch (target.result.os.tag) {
.linux => b.addConfigHeader(
.{ .style = .{ .autoconf = upstream.path("src/include/pg_config.h.in") }, .include_path = "pg_config.h" },
autoconf_linux,
),
.macos => b.addConfigHeader(
.{ .style = .{ .autoconf = upstream.path("src/include/pg_config.h.in") }, .include_path = "pg_config.h" },
autoconf_darwin,
),
else => return libPQBuildErrors.OsConfigNotCreated,
};

const os_header = switch (target.result.os.tag) {
.linux => "src/include/port/linux.h",
.windows => "src/include/port/win32.h",
.macos => "src/include/port/darwin.h",
else => return libPQBuildErrors.OsNotSupported,
};

const config_os = b.addConfigHeader(
.{ .style = .{ .autoconf = upstream.path("src/include/port/linux.h") }, .include_path = "pg_config_os.h" },
.{ .style = .{ .autoconf = upstream.path(os_header) }, .include_path = "pg_config_os.h" },
.{},
);
const config_path = b.addConfigHeader(
Expand Down Expand Up @@ -168,7 +188,7 @@ pub fn build(b: *std.Build) !void {
}

// if (target.glibc_version < 2.38) // ???
if (true) {
if (target.result.os.tag != .macos) {
libport.addCSourceFiles(.{
.root = upstream.path("src/port"),
.files = &.{
Expand Down Expand Up @@ -358,7 +378,7 @@ const default_paths = .{
.MANDIR = "/usr/local/pgsql/share/man",
};

const autoconf = .{
const autoconf_linux = .{
.ALIGNOF_DOUBLE = @alignOf(f64),
.ALIGNOF_INT = @alignOf(c_int),
.ALIGNOF_LONG = @alignOf(c_long),
Expand Down Expand Up @@ -596,3 +616,242 @@ const autoconf = .{
.@"inline" = null,
.typeof = null,
};

const autoconf_darwin = .{
.ALIGNOF_DOUBLE = @alignOf(f64),
.ALIGNOF_INT = @alignOf(c_int),
.ALIGNOF_LONG = @alignOf(c_long),
.ALIGNOF_PG_INT128_TYPE = @alignOf(i128),
.ALIGNOF_SHORT = @alignOf(c_short),
.MAXIMUM_ALIGNOF = @alignOf(c_longlong),

.SIZEOF_BOOL = @sizeOf(bool),
.SIZEOF_LONG = @sizeOf(c_long),
.SIZEOF_OFF_T = @sizeOf(c_long),
.SIZEOF_SIZE_T = @sizeOf(usize),
.SIZEOF_VOID_P = @sizeOf(*void),

.BLCKSZ = 8192,
.CONFIGURE_ARGS = " '--with-ssl=openssl' 'CC=zig cc' 'CXX=zig c++'",
.DEF_PGPORT = 5432,
.DEF_PGPORT_STR = "5432",
.DLSUFFIX = ".so",
.ENABLE_THREAD_SAFETY = 1,
.HAVE_APPEND_HISTORY = 1,
.HAVE_ATOMICS = 1,
.HAVE_BACKTRACE_SYMBOLS = 1,
.HAVE_COMPUTED_GOTO = 1,
.HAVE_DECL_FDATASYNC = 1,
.HAVE_DECL_F_FULLFSYNC = 0,
.HAVE_DECL_POSIX_FADVISE = 1,
.HAVE_DECL_PREADV = 1,
.HAVE_DECL_PWRITEV = 1,
.HAVE_DECL_STRNLEN = 1,
.HAVE_EXECINFO_H = 1,
.HAVE_EXPLICIT_BZERO = null,
.HAVE_FSEEKO = 1,
.HAVE_GCC__ATOMIC_INT32_CAS = 1,
.HAVE_GCC__ATOMIC_INT64_CAS = 1,
.HAVE_GCC__SYNC_CHAR_TAS = 1,
.HAVE_GCC__SYNC_INT32_CAS = 1,
.HAVE_GCC__SYNC_INT32_TAS = 1,
.HAVE_GCC__SYNC_INT64_CAS = 1,
.HAVE_GETIFADDRS = 1,
.HAVE_GETOPT = 1,
.HAVE_GETOPT_H = 1,
.HAVE_GETOPT_LONG = 1,
.HAVE_HISTORY_TRUNCATE_FILE = 1,
.HAVE_IFADDRS_H = 1,
.HAVE_INET_ATON = 1,
.HAVE_INET_PTON = 1,
.HAVE_INTTYPES_H = 1,
.HAVE_INT_OPTERR = 1,
.HAVE_INT_TIMEZONE = 1,
.HAVE_LANGINFO_H = 1,
.HAVE_LIBM = 1,
.HAVE_LIBREADLINE = 1,
.HAVE_LOCALE_T = 1,
.HAVE_LONG_INT_64 = 1,
.HAVE_MEMORY_H = 1,
.HAVE_MKDTEMP = 1,
.HAVE_POSIX_FADVISE = 1,
.HAVE_POSIX_FALLOCATE = 1,
.HAVE_PPOLL = 1,
.HAVE_PTHREAD = 1,
.HAVE_PTHREAD_BARRIER_WAIT = 1,
.HAVE_PTHREAD_PRIO_INHERIT = 1,
.HAVE_READLINE_HISTORY_H = 1,
.HAVE_READLINE_READLINE_H = 1,
.HAVE_RL_COMPLETION_MATCHES = 1,
.HAVE_RL_COMPLETION_SUPPRESS_QUOTE = 1,
.HAVE_RL_FILENAME_COMPLETION_FUNCTION = 1,
.HAVE_RL_FILENAME_QUOTE_CHARACTERS = 1,
.HAVE_RL_FILENAME_QUOTING_FUNCTION = 1,
.HAVE_RL_RESET_SCREEN_SIZE = 1,
.HAVE_RL_VARIABLE_BIND = 1,
.HAVE_SOCKLEN_T = 1,
.HAVE_SPINLOCKS = 1,
.HAVE_STDBOOL_H = 1,
.HAVE_STDINT_H = 1,
.HAVE_STDLIB_H = 1,
.HAVE_STRCHRNUL = null,
.HAVE_STRERROR_R = null,
.HAVE_STRINGS_H = 0,
.HAVE_STRING_H = 1,
.HAVE_STRNLEN = 1,
.HAVE_STRSIGNAL = 1,
.HAVE_STRUCT_OPTION = 1,
.HAVE_STRUCT_TM_TM_ZONE = 1,
.HAVE_SYNCFS = 1,
.HAVE_SYNC_FILE_RANGE = null,
.HAVE_SYSLOG = 1,
.HAVE_SYS_EPOLL_H = 1,
.HAVE_SYS_PERSONALITY_H = 1,
.HAVE_SYS_PRCTL_H = 1,
.HAVE_SYS_SIGNALFD_H = 1,
.HAVE_SYS_STAT_H = 1,
.HAVE_SYS_TYPES_H = 1,
.HAVE_TERMIOS_H = 1,
.HAVE_TYPEOF = 1,
.HAVE_UNISTD_H = 1,
.HAVE_USELOCALE = 1,
.HAVE_VISIBILITY_ATTRIBUTE = 1,
.HAVE_X86_64_POPCNTQ = 1,
.HAVE__BOOL = 1,
.HAVE__BUILTIN_BSWAP16 = 1,
.HAVE__BUILTIN_BSWAP32 = 1,
.HAVE__BUILTIN_BSWAP64 = 1,
.HAVE__BUILTIN_CLZ = 1,
.HAVE__BUILTIN_CONSTANT_P = 1,
.HAVE__BUILTIN_CTZ = 1,
.HAVE__BUILTIN_FRAME_ADDRESS = 1,
.HAVE__BUILTIN_OP_OVERFLOW = 1,
.HAVE__BUILTIN_POPCOUNT = 1,
.HAVE__BUILTIN_TYPES_COMPATIBLE_P = 1,
.HAVE__BUILTIN_UNREACHABLE = 1,
.HAVE__GET_CPUID = 1,
.HAVE__STATIC_ASSERT = 1,
.MEMSET_LOOP_LIMIT = 1024,
.PG_INT128_TYPE = .__int128,
.PG_INT64_TYPE = .@"long int",
.PG_KRB_SRVNAM = "postgres",
.PG_PRINTF_ATTRIBUTE = .printf,
.INT64_MODIFIER = "l",
.PG_USE_STDBOOL = 1,
.PG_VERSION_NUM = version.major * 10000 + version.minor,
.RELSEG_SIZE = 131072,
.STDC_HEADERS = 1,
.USE_ICU = 1,
.USE_SLICING_BY_8_CRC32C = 1,
.USE_SYSV_SHARED_MEMORY = 1,
.USE_UNNAMED_POSIX_SEMAPHORES = 1,
.XLOG_BLCKSZ = 8192,
.pg_restrict = .__restrict,
.restrict = .__restrict,

.PACKAGE_BUGREPORT = "pgsql-bugs@lists.postgresql.org",
.PACKAGE_NAME = "PostgreSQL",
.PACKAGE_STRING = std.fmt.comptimePrint("PostgreSQL {}.{}", .{ version.major, version.minor }),
.PACKAGE_TARNAME = "postgresql",
.PACKAGE_URL = "https://www.postgresql.org/",
.PACKAGE_VERSION = std.fmt.comptimePrint("{}.{}", .{ version.major, version.minor }),

.PG_MAJORVERSION_NUM = version.major,
.PG_MINORVERSION_NUM = version.minor,
.PG_MAJORVERSION = std.fmt.comptimePrint("{}", .{version.major}),
.PG_VERSION = std.fmt.comptimePrint("{}.{}", .{ version.major, version.minor }),
.PG_VERSION_STR = std.fmt.comptimePrint("PostgreSQL {}.{}", .{ version.major, version.minor }),

.AC_APPLE_UNIVERSAL_BUILD = null,
.ALIGNOF_LONG_LONG_INT = null,
.ENABLE_GSS = null,
.ENABLE_NLS = null,
.HAVE_ATOMIC_H = null,
.HAVE_COPYFILE = null,
.HAVE_COPYFILE_H = null,
.HAVE_CRTDEFS_H = null,
.HAVE_CRYPTO_LOCK = null,
.HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER = null,
.HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER = null,
.HAVE_DECL_LLVMGETHOSTCPUFEATURES = null,
.HAVE_DECL_LLVMGETHOSTCPUNAME = null,
.HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN = null,
.HAVE_EDITLINE_HISTORY_H = null,
.HAVE_EDITLINE_READLINE_H = null,
.HAVE_GETPEEREID = null,
.HAVE_GETPEERUCRED = null,
.HAVE_GSSAPI_EXT_H = null,
.HAVE_GSSAPI_GSSAPI_EXT_H = null,
.HAVE_GSSAPI_GSSAPI_H = null,
.HAVE_GSSAPI_H = null,
.HAVE_HISTORY_H = null,
.HAVE_INT64 = null,
.HAVE_INT8 = null,
.HAVE_INT_OPTRESET = null,
.HAVE_I_CONSTRAINT__BUILTIN_CONSTANT_P = null,
.HAVE_KQUEUE = null,
.HAVE_LDAP_INITIALIZE = null,
.HAVE_LIBLDAP = null,
.HAVE_LIBLZ4 = null,
.HAVE_LIBPAM = null,
.HAVE_LIBSELINUX = null,
.HAVE_LIBWLDAP32 = null,
.HAVE_LIBXML2 = null,
.HAVE_LIBXSLT = null,
.HAVE_LONG_LONG_INT_64 = null,
.HAVE_MBARRIER_H = null,
.HAVE_MBSTOWCS_L = null,
.HAVE_MEMSET_S = 1,
.HAVE_OSSP_UUID_H = null,
.HAVE_PAM_PAM_APPL_H = null,
.HAVE_PTHREAD_IS_THREADED_NP = null,
.HAVE_READLINE_H = null,
.HAVE_SECURITY_PAM_APPL_H = null,
.HAVE_SETPROCTITLE = null,
.HAVE_SETPROCTITLE_FAST = null,
.HAVE_STRUCT_SOCKADDR_SA_LEN = null,
.HAVE_SYS_EVENT_H = null,
.HAVE_SYS_PROCCTL_H = null,
.HAVE_SYS_UCRED_H = 1,
.HAVE_UCRED_H = null,
.HAVE_UINT64 = null,
.HAVE_UINT8 = null,
.HAVE_UNION_SEMUN = null,
.HAVE_UUID_BSD = null,
.HAVE_UUID_E2FS = null,
.HAVE_UUID_H = null,
.HAVE_UUID_OSSP = null,
.HAVE_UUID_UUID_H = null,
.HAVE_WCSTOMBS_L = null,
.HAVE__CONFIGTHREADLOCALE = null,
.HAVE__CPUID = null,
.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,
.USE_BONJOUR = null,
.USE_BSD_AUTH = null,
.USE_LDAP = null,
.USE_LIBXML = null,
.USE_LIBXSLT = null,
.USE_LLVM = null,
.USE_LZ4 = null,
.USE_NAMED_POSIX_SEMAPHORES = null,
.USE_PAM = null,
.USE_SSE42_CRC32C = null,
.USE_SSE42_CRC32C_WITH_RUNTIME_CHECK = null,
.USE_SYSTEMD = null,
.USE_SYSV_SEMAPHORES = null,
.USE_WIN32_SEMAPHORES = null,
.USE_WIN32_SHARED_MEMORY = null,
.WCSTOMBS_L_IN_XLOCALE = null,
.WORDS_BIGENDIAN = null,
._FILE_OFFSET_BITS = null,
._LARGEFILE_SOURCE = null,
._LARGE_FILES = null,
.@"inline" = null,
.typeof = null,
};

0 comments on commit a7f29a2

Please sign in to comment.