MSYS2 support

Started by Peter Eisentrautabout 6 years ago2 messages
#1Peter Eisentraut
peter.eisentraut@2ndquadrant.com
3 attachment(s)

There were a number of recent threads about building PostgreSQL on
MSYS2. This has been confusing on occasion; see for example [0]/messages/by-id/6672cebd-0c07-ce1e-36f8-6ae82c496eb0@2ndquadrant.com. MSYS2
is actually a derivative of Cygwin. What most people are actually doing
is using MSYS2 has the host environment for doing a kind of
cross-compilation to MinGW.

You can also build natively on MSYS2, using the existing Cygwin support.
Except that it won't work because configure doesn't recognize the
config.guess output. Attached are a couple of small patches to fix that
up. The first patch fixes configure as explained. The second patch
fixes some warnings in ps_status.c. It's curious why the existing build
farm members don't issue warnings there, but maybe their compilers are
too old. The third patch fixes another warning; again, not sure why
original Cygwin doesn't warn. It might be a bit too broad to apply like
that.

MSYS2 doesn't ship with cygserver AFAICT, so you can't run a PostgreSQL
server, but everything else should work.

[0]: /messages/by-id/6672cebd-0c07-ce1e-36f8-6ae82c496eb0@2ndquadrant.com
/messages/by-id/6672cebd-0c07-ce1e-36f8-6ae82c496eb0@2ndquadrant.com

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Add-support-for-MSYS2.patchtext/plain; charset=UTF-8; name=0001-Add-support-for-MSYS2.patch; x-mac-creator=0; x-mac-type=0Download
From 676e1392705e017cc5ae17e0f35952f8a1405eab Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Sun, 18 Aug 2019 00:17:16 +0200
Subject: [PATCH 1/3] Add support for MSYS2

It's basically a variant of Cygwin, so use that template.
---
 configure    | 12 +++++-------
 configure.in | 12 +++++-------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/configure b/configure
index 3d9bd0bdf8..7f86a7e5ff 100755
--- a/configure
+++ b/configure
@@ -2946,7 +2946,7 @@ else
 
 case $host_os in
      aix*) template=aix ;;
-  cygwin*) template=cygwin ;;
+  cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
  freebsd*) template=freebsd ;;
@@ -15843,24 +15843,22 @@ fi
 
 
 
-case $host_os in
+if test "$PORTNAME" = "win32" -o "$PORTNAME" = "cygwin"; then
 	# Cygwin and (apparently, based on test results) Mingw both
 	# have a broken strtof(), so substitute the same replacement
 	# code we use with VS2013. That's not a perfect fix, since
 	# (unlike with VS2013) it doesn't avoid double-rounding, but
 	# we have no better options. To get that, though, we have to
 	# force the file to be compiled despite HAVE_STRTOF.
-	mingw*|cygwin*)
-		case " $LIBOBJS " in
+	case " $LIBOBJS " in
   *" strtof.$ac_objext "* ) ;;
   *) LIBOBJS="$LIBOBJS strtof.$ac_objext"
  ;;
 esac
 
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: On $host_os we will use our strtof wrapper." >&5
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: On $host_os we will use our strtof wrapper." >&5
 $as_echo "$as_me: On $host_os we will use our strtof wrapper." >&6;}
-	;;
-esac
+fi
 
 case $host_os in
 
diff --git a/configure.in b/configure.in
index 34aea0b4ac..797a9db01d 100644
--- a/configure.in
+++ b/configure.in
@@ -59,7 +59,7 @@ PGAC_ARG_REQ(with, template, [NAME], [override operating system template],
 
 case $host_os in
      aix*) template=aix ;;
-  cygwin*) template=cygwin ;;
+  cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
  freebsd*) template=freebsd ;;
@@ -1743,18 +1743,16 @@ AC_REPLACE_FUNCS(m4_normalize([
 	strtof
 ]))
 
-case $host_os in
+if test "$PORTNAME" = "win32" -o "$PORTNAME" = "cygwin"; then
 	# Cygwin and (apparently, based on test results) Mingw both
 	# have a broken strtof(), so substitute the same replacement
 	# code we use with VS2013. That's not a perfect fix, since
 	# (unlike with VS2013) it doesn't avoid double-rounding, but
 	# we have no better options. To get that, though, we have to
 	# force the file to be compiled despite HAVE_STRTOF.
-	mingw*|cygwin*)
-		AC_LIBOBJ([strtof])
-		AC_MSG_NOTICE([On $host_os we will use our strtof wrapper.])
-	;;
-esac
+	AC_LIBOBJ([strtof])
+	AC_MSG_NOTICE([On $host_os we will use our strtof wrapper.])
+fi
 
 case $host_os in
 
-- 
2.24.0

0002-Fix-compiler-warnings.patchtext/plain; charset=UTF-8; name=0002-Fix-compiler-warnings.patch; x-mac-creator=0; x-mac-type=0Download
From bf5be8c29babcd86e12d9f3acfb87d391d61e187 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 11 Dec 2019 08:52:50 +0100
Subject: [PATCH 2/3] Fix compiler warnings

The PS_USE_NONE case left a couple of unused variables exposed.
---
 src/backend/utils/misc/ps_status.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index 6c851dd498..288d71d4d2 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -89,6 +89,8 @@ bool		update_process_title = true;
 #endif
 
 
+#ifndef PS_USE_NONE
+
 #ifndef PS_USE_CLOBBER_ARGV
 /* all but one option need a buffer to write their ps line in */
 #define PS_BUFFER_SIZE 256
@@ -104,6 +106,8 @@ static size_t ps_buffer_cur_len;	/* nominal strlen(ps_buffer) */
 
 static size_t ps_buffer_fixed_size; /* size of the constant prefix */
 
+#endif
+
 /* save the original argv[] location here */
 static int	save_argc;
 static char **save_argv;
@@ -420,7 +424,11 @@ get_ps_display(int *displen)
 	}
 #endif
 
+#ifdef PS_USE_NONE
+	return "";
+#else
 	*displen = (int) (ps_buffer_cur_len - ps_buffer_fixed_size);
 
 	return ps_buffer + ps_buffer_fixed_size;
+#endif
 }
-- 
2.24.0

0003-Fix-compiler-warning-for-ppoll-on-MSYS2.patchtext/plain; charset=UTF-8; name=0003-Fix-compiler-warning-for-ppoll-on-MSYS2.patch; x-mac-creator=0; x-mac-type=0Download
From c265d26a9c73555860980f36a127049407dcf695 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 11 Dec 2019 08:55:25 +0100
Subject: [PATCH 3/3] Fix compiler warning for ppoll() on MSYS2

Apparently, _GNU_SOURCE is required to get the prototype, so just
define that globally.
---
 src/template/cygwin | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/template/cygwin b/src/template/cygwin
index 79a108145f..0a1ab04e3d 100644
--- a/src/template/cygwin
+++ b/src/template/cygwin
@@ -2,6 +2,9 @@
 
 SRCH_LIB="/usr/local/lib"
 
+# to get ppoll() prototype
+CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+
 # Extra CFLAGS for code that will go into a shared library
 CFLAGS_SL=""
 
-- 
2.24.0

#2Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Peter Eisentraut (#1)
Re: MSYS2 support

On 2019-12-12 22:11, Peter Eisentraut wrote:

You can also build natively on MSYS2, using the existing Cygwin support.
Except that it won't work because configure doesn't recognize the
config.guess output. Attached are a couple of small patches to fix that
up. The first patch fixes configure as explained. The second patch
fixes some warnings in ps_status.c. It's curious why the existing build
farm members don't issue warnings there, but maybe their compilers are
too old. The third patch fixes another warning; again, not sure why
original Cygwin doesn't warn. It might be a bit too broad to apply like
that.

For completeness: These patches have all been applied. They were also
useful for more recent Cygwin versions than the build farm currently has.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services