Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Jul 2023 14:13:44 GMT
From:      Palle Girgensohn <girgen@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: ab843ea1ee69 - main - databases/postgresql15-server: fix build with clang 16 (as system compiler)
Message-ID:  <202307051413.365EDipo085582@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by girgen:

URL: https://cgit.FreeBSD.org/ports/commit/?id=ab843ea1ee69a9f541c5c92913a1efe5cc2ca7e6

commit ab843ea1ee69a9f541c5c92913a1efe5cc2ca7e6
Author:     Palle Girgensohn <girgen@FreeBSD.org>
AuthorDate: 2023-05-30 22:52:02 +0000
Commit:     Palle Girgensohn <girgen@FreeBSD.org>
CommitDate: 2023-07-05 14:12:20 +0000

    databases/postgresql15-server: fix build with clang 16 (as system compiler)
    
    databases/postgresql??-server: use the default LLVM
    
    Always use the version of LLVM that is default for the ports tree,
    if PostgreSQL builds with it. This simplifies the build process.
    
    For i386, revert to using clang -msse2 instead of pulling in gcc. CPUs
    older than Pentium5 do not support SSE2 and the binary will not run
    there. We are not expected to support ancient hardware forever, so I've
    added a comment recommending users of ancient CPUs to build from ports
    using gcc.
    
    During an exp-run for llvm 16 (see bug 271047), it turned out that
    databases/postgresql15-server failed to build with clang 16 as the base
    system compiler:
    
      In file included from llvmjit.c:38:
      ../../../../src/include/jit/llvmjit_emit.h:112:23: warning: call to undeclared function 'LLVMBuildStructGEP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
              LLVMValueRef v_ptr = LLVMBuildStructGEP(b, v, idx, "");
                                   ^
      ../../../../src/include/jit/llvmjit_emit.h:112:15: error: incompatible integer to pointer conversion initializing 'LLVMValueRef' (aka 'struct LLVMOpaqueValue *') with an expression of type 'int' [-Wint-conversion]
              LLVMValueRef v_ptr = LLVMBuildStructGEP(b, v, idx, "");
                           ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ../../../../src/include/jit/llvmjit_emit.h:114:9: warning: call to undeclared function 'LLVMBuildLoad'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
              return LLVMBuildLoad(b, v_ptr, name);
                     ^
      ../../../../src/include/jit/llvmjit_emit.h:114:9: error: incompatible integer to pointer conversion returning 'int' from a function with result type 'LLVMValueRef' (aka 'struct LLVMOpaqueValue *') [-Wint-conversion]
              return LLVMBuildLoad(b, v_ptr, name);
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    and many more similar errors. The same applies to the slave ports
    postgresql11-server, postgresql12-server, postgresql13-server, and
    postgresql14-server.
    
    This is because PostgreSQL's llvmjit support is not yet ready for LLVM
    16's API changes. In LLVM 15 functions like LLVMBuildStructGEP were
    already declared deprecated, but in LLVM 16 these have been removed (and
    replaced with LLVMBuildStructGEP2, etc).
    
    Until PostgreSQL updates their llvmjit for the changed APIs, I would
    like to reintroduce the LLVM version restriction that was removed in
    <https://cgit.freebsd.org/ports/commit/?id=1e19f00e5e46>, but slightly
    adjusted: there is no more need to check for LLVM ports below 10.
    
    Another thing that is required is to pass a CLANG variable to the
    configure script, pointing to the same version that is used for the LLVM
    bindings. Otherwise, the .bc files will get compiled by the base system
    compiler, and this can lead to a ThinLTO link error, if the base system
    compiler is a newer version of llvm.
    
    PR:             271498
    Suggested by:   dim@
---
 databases/postgresql16-server/Makefile | 55 +++++-----------------------------
 1 file changed, 8 insertions(+), 47 deletions(-)

diff --git a/databases/postgresql16-server/Makefile b/databases/postgresql16-server/Makefile
index e3b783e7fa41..22f68ada81d9 100644
--- a/databases/postgresql16-server/Makefile
+++ b/databases/postgresql16-server/Makefile
@@ -105,13 +105,15 @@ ZSTD_CONFIGURE_WITH=	zstd
 ZSTD_LIB_DEPENDS+=	libzstd.so:archivers/zstd
 .  endif
 
-.  if ${DISTVERSION:C/([0-9][0-9]).*/\1/g} >= 11
 OPTIONS_DEFINE+=	LLVM
 OPTIONS_DEFAULT+=	LLVM
 LLVM_DESC=		Build with support for JIT-compiling expressions
 OPTIONS_EXCLUDE+=	${OPTIONS_EXCLUDE_${ARCH}_${OSREL:R}}
 OPTIONS_EXCLUDE_powerpc64_12=	LLVM
-.  endif
+LLVM_CONFIGURE_WITH=	llvm
+LLVM_CONFIGURE_ENV=	LLVM_CONFIG=${LLVM_CONFIG} \
+			CLANG=${LOCALBASE}/bin/clang${LLVM_VERSION}
+LLVM_USES=		llvm:max=15,min=11,lib
 
 # See http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/76999 for more info
 # (requires dump/restore if modified.)
@@ -185,10 +187,11 @@ SUB_LIST+=		PG_VERSION=${PORTVERSION:R} \
 
 .include <bsd.port.options.mk>
 
+# i386 older than Pentium lacks SSE2 so the binary will not run if we build with clang -msse2
+# For such ancient CPUs, gcc must be used to build PostgreSQL.
+# https://www.postgresql.org/message-id/20190307140421.GA8362%40gate.oper.dinoex.org
 .if ${ARCH} == "i386"
-USES+=		compiler:gcc-c++11-lib
-.else
-USES+=		compiler
+CFLAGS+=	-msse2
 .endif
 
 .if !defined(SLAVE_ONLY)
@@ -228,49 +231,7 @@ CONFIGURE_ARGS+=--with-krb5
 .include <bsd.port.pre.mk>
 
 .if ${PORT_OPTIONS:MLLVM}
-CONFIGURE_ARGS+=	--with-llvm
-BUILD_DEPENDS+=		llvm${PG_LLVM_VERSION}>0:devel/llvm${PG_LLVM_VERSION}
-BUILD_DEPENDS+=		llvm-config${PG_LLVM_VERSION}:devel/llvm${PG_LLVM_VERSION}
-RUN_DEPENDS+=		llvm-config${PG_LLVM_VERSION}:devel/llvm${PG_LLVM_VERSION}
-CONFIGURE_ENV+=		LLVM_CONFIG=${LOCALBASE}/bin/llvm-config${PG_LLVM_VERSION}
-.endif
-
-# Convert LLVM_DEFAULT to COMPILER_VERSION format to make it
-# suitable for version comparison.
-.if ${LLVM_DEFAULT} >= 70 && ${LLVM_DEFAULT} <= 90
-LLVM_DEFAULT_VERSION=	${LLVM_DEFAULT}
-.else
-LLVM_DEFAULT_VERSION=	${LLVM_DEFAULT}0
-.endif
-
-# Convert COMPILER_VERSION to LLVM_DEFAULT format to make it
-# suitable for LLVM port name.
-# All supported FreeBSD versions have Clang 10.0.1 or later.
-LLVM_PORT_SUFFIX=	${COMPILER_VERSION:C/.$//}
-
-# sync LLVM to the preferred compiler if possible
-# or else use a lower version compiler that is compatible
-.if ${COMPILER_VERSION} > ${LLVM_DEFAULT_VERSION}
-# LLVM versions in ports are, in order, 70, 80 90, 10, 11, 12... where 10 > 90. [sic]
-.  if ${LLVM_PORT_SUFFIX} < 70
-PG_LLVM_VERSION=${LLVM_PORT_SUFFIX}
-PG_COMPILER_VERSION=${LLVM_PORT_SUFFIX}
-.  else
-PG_LLVM_VERSION=11
-PG_COMPILER_VERSION=11
-.  endif
-.else
-PG_LLVM_VERSION=${LLVM_DEFAULT}
-PG_COMPILER_VERSION=${LLVM_PORT_SUFFIX}
-.endif
-
-.if ${DISTVERSION:C/([0-9]*).*/\1/} >= 11
-.  if defined(SERVER_ONLY) && ${PORT_OPTIONS:MLLVM}
 INSTALL_DIRS+=		src/backend/jit/llvm
-.    if ${LLVM_PORT_SUFFIX} != ${PG_COMPILER_VERSION}
-LLVM_CONFIGURE_ARGS?=	CC=${LOCALBASE}/bin/clang${PG_COMPILER_VERSION}
-.    endif
-.  endif
 .endif
 
 .if defined(SERVER_ONLY)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202307051413.365EDipo085582>