Mingw task for Cirrus CI

Started by Melih Mutlualmost 4 years ago47 messages
#1Melih Mutlu
m.melihmutlu@gmail.com
1 attachment(s)

Hi All,

I've been working on adding Windows+MinGW environment into cirrus-ci tasks
(discussion about ci is here [1]/messages/by-id/20211001222752.wrz7erzh4cajvgp6@alap3.anarazel.de <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.postgresql.org%2Fmessage-id%2Fflat%2F20211001222752.wrz7erzh4cajvgp6%2540alap3.anarazel.de&amp;data=04%7C01%7CMelih.Mutlu%40microsoft.com%7C7f4780e35ab34e2f38d808d9f7d008e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637813295184245763%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=HkjuBWcQzmiyIyoCuIfKCzAEF9ME6SpGOYjBJMFhQvw%3D&amp;reserved=0&gt;).
It uses MSYS2 to set the environment. UCRT is chosen as C standard library,
instead of MSVCRT.
The task configures postgres with features that are available in MSYS2 (see
available packages [2]https://packages.msys2.org/package/ <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpackages.msys2.org%2Fpackage%2F&amp;data=04%7C01%7CMelih.Mutlu%40microsoft.com%7C7f4780e35ab34e2f38d808d9f7d008e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637813295184245763%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=VqfdnrxHv15FUGFXgnNaMli5n2R1tnPPglGq4xWqND0%3D&amp;reserved=0&gt;) and tap tests are enabled.
I already added the necessary docker image, you can find the related PR at
[3]: https://github.com/anarazel/pg-vm-images/pull/8 <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fanarazel%2Fpg-vm-images%2Fpull%2F8&amp;data=04%7C01%7CMelih.Mutlu%40microsoft.com%7C7f4780e35ab34e2f38d808d9f7d008e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637813295184245763%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=IASIgPhLd0%2Fvh1VSn9EC%2BCsH42riE%2Bt6gQPObOb0QmI%3D&amp;reserved=0&gt;
Attached patch adds a task runs on Windows with MinGW for cirrus-ci

However, I cannot run configure with --with-python, --with-perl or
--with-tcl.
There are two issues I encountered while trying to enable. e.g. for
--with-python

1- python_ldlibrary is set to "libpython3.9.dll.a". So the related line in
configure cannot retrieve "ldlibrary"
2- src/pl/plpython/Makefile looks under "C:/Windows/system32/" for
PYTHONDLL. gendef cannot open that file, give an error like " failed to
open()" when creating a .def file.

To overcome those, I added the correct pattern to extract ldlibrary by
appending "-e 's/\.dll.a$//'" at the end of the related line.
Then, I tried to use python dll from MSYS instead of windows/system32 by
changing PYTHONDLL path to "/ucrt64/bin/libpython3.9.dll". I'm not sure if
this is the correct dll.
Here is the diff of these two changes:

diff --git a/configure b/configure
index f3cb5c2b51..42ea580442 100755
--- a/configure
+++ b/configure
@@ -10536,7 +10536,7 @@ python_libdir=`${PYTHON} -c "import sysconfig;
print(' '.join(filter(None,syscon
 python_ldlibrary=`${PYTHON} -c "import sysconfig; print('
'.join(filter(None,sysconfig.get_config_vars('LDLIBRARY'))))"`
 # If LDLIBRARY exists and has a shlib extension, use it verbatim.
-ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//'
-e 's/\.dylib$//' -e 's/\.sl$//'`
+ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//'
-e 's/\.dylib$//' -e 's/\.sl$//' -e 's/\.dll.a$//'`
 if test -e "${python_libdir}/${python_ldlibrary}" -a
x"${python_ldlibrary}" != x"${ldlibrary}"
 then
        ldlibrary=`echo "${ldlibrary}" | sed "s/^lib//"`
diff --git a/src/pl/plpython/Makefile b/src/pl/plpython/Makefile
index a83ae8865c..4254ef94d7 100644
--- a/src/pl/plpython/Makefile
+++ b/src/pl/plpython/Makefile
@@ -61,7 +61,8 @@ INCS =        plpython.h \
 ifeq ($(PORTNAME), win32)
 pytverstr=$(subst .,,${python_version})
-PYTHONDLL=$(subst \,/,$(WINDIR))/system32/python${pytverstr}.dll
+#PYTHONDLL=$(subst \,/,$(WINDIR))/system32/python${pytverstr}.dll
+PYTHONDLL=/ucrt64/bin/libpython3.9.dll

OBJS += libpython${pytverstr}.a

In the end, make check-world still fails, even though I was able to run
configure and make without any obvious error.
I see bunch of errors in tests like:
+ERROR:  language "plpython3u" does not exist
+HINT:  Use CREATE EXTENSION to load the language into the database.

Here is the logs from failed ci run:
https://api.cirrus-ci.com/v1/artifact/task/4645682031099904/log/build/src/pl/plpython/regression.diffs

Any thoughts on how postgres can be built with --with-python etc. on mingw?

Best,
Melih

[1]: /messages/by-id/20211001222752.wrz7erzh4cajvgp6@alap3.anarazel.de <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.postgresql.org%2Fmessage-id%2Fflat%2F20211001222752.wrz7erzh4cajvgp6%2540alap3.anarazel.de&amp;data=04%7C01%7CMelih.Mutlu%40microsoft.com%7C7f4780e35ab34e2f38d808d9f7d008e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637813295184245763%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=HkjuBWcQzmiyIyoCuIfKCzAEF9ME6SpGOYjBJMFhQvw%3D&amp;reserved=0&gt;
/messages/by-id/20211001222752.wrz7erzh4cajvgp6@alap3.anarazel.de
<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.postgresql.org%2Fmessage-id%2Fflat%2F20211001222752.wrz7erzh4cajvgp6%2540alap3.anarazel.de&amp;data=04%7C01%7CMelih.Mutlu%40microsoft.com%7C7f4780e35ab34e2f38d808d9f7d008e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637813295184245763%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=HkjuBWcQzmiyIyoCuIfKCzAEF9ME6SpGOYjBJMFhQvw%3D&amp;reserved=0&gt;
[2]: https://packages.msys2.org/package/ <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpackages.msys2.org%2Fpackage%2F&amp;data=04%7C01%7CMelih.Mutlu%40microsoft.com%7C7f4780e35ab34e2f38d808d9f7d008e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637813295184245763%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=VqfdnrxHv15FUGFXgnNaMli5n2R1tnPPglGq4xWqND0%3D&amp;reserved=0&gt;
<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpackages.msys2.org%2Fpackage%2F&amp;data=04%7C01%7CMelih.Mutlu%40microsoft.com%7C7f4780e35ab34e2f38d808d9f7d008e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637813295184245763%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=VqfdnrxHv15FUGFXgnNaMli5n2R1tnPPglGq4xWqND0%3D&amp;reserved=0&gt;
[3]: https://github.com/anarazel/pg-vm-images/pull/8 <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fanarazel%2Fpg-vm-images%2Fpull%2F8&amp;data=04%7C01%7CMelih.Mutlu%40microsoft.com%7C7f4780e35ab34e2f38d808d9f7d008e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637813295184245763%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=IASIgPhLd0%2Fvh1VSn9EC%2BCsH42riE%2Bt6gQPObOb0QmI%3D&amp;reserved=0&gt;
<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fanarazel%2Fpg-vm-images%2Fpull%2F8&amp;data=04%7C01%7CMelih.Mutlu%40microsoft.com%7C7f4780e35ab34e2f38d808d9f7d008e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637813295184245763%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=IASIgPhLd0%2Fvh1VSn9EC%2BCsH42riE%2Bt6gQPObOb0QmI%3D&amp;reserved=0&gt;
[4]: https://cirrus-ci.com/build/4999469182746624 <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcirrus-ci.com%2Fbuild%2F5013577319841792&amp;data=04%7C01%7CMelih.Mutlu%40microsoft.com%7C7f4780e35ab34e2f38d808d9f7d008e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637813295184245763%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=hMGCtgm1uVBWzFHXPEl%2FiaavzWbEqxAuhmKjFcjH%2BF0%3D&amp;reserved=0&gt;
<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcirrus-ci.com%2Fbuild%2F5013577319841792&amp;data=04%7C01%7CMelih.Mutlu%40microsoft.com%7C7f4780e35ab34e2f38d808d9f7d008e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637813295184245763%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=hMGCtgm1uVBWzFHXPEl%2FiaavzWbEqxAuhmKjFcjH%2BF0%3D&amp;reserved=0&gt;

Attachments:

0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchapplication/octet-stream; name=0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchDownload
From 0ea1e22200e57538be61445c6ac8d4178e84832e Mon Sep 17 00:00:00 2001
From: Melih Mutlu <memutlu@microsoft.com>
Date: Mon, 21 Feb 2022 14:46:05 +0300
Subject: [PATCH] Added Windows with MinGW environment in Cirrus CI

---
 .cirrus.yml | 85 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 68 insertions(+), 17 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index d10b0a82f9..67717039f2 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -23,7 +23,6 @@ env:
   CHECKFLAGS: -Otarget
   PROVE_FLAGS: --timer
   PGCTLTIMEOUT: 120 # avoids spurious failures during parallel tests
-  TEMP_CONFIG: ${CIRRUS_WORKING_DIR}/src/tools/ci/pg_ci_base.conf
   PG_TEST_EXTRA: kerberos ldap ssl
 
 
@@ -329,13 +328,31 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh macos "${HOME}/cores"
 
 
+WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
+    env:
+      # Half the allowed per-user CPU cores
+      CPUS: 4
+      # The default working dir is in a directory msbuild complains about
+      CIRRUS_WORKING_DIR: "c:/cirrus"
+      TEMP_CONFIG: ${CIRRUS_WORKING_DIR}/src/tools/ci/pg_ci_base.conf
+
+      # Avoids port conflicts between concurrent tap test runs
+      PG_TEST_USE_UNIX_SOCKETS: 1
+
+    only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
+
+    sysinfo_script: |
+      chcp
+      systeminfo
+      powershell -Command get-psdrive -psprovider filesystem
+      set
+
+
 task:
+  << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, VS 2019
 
   env:
-    # Half the allowed per-user CPU cores
-    CPUS: 4
-
     # Our windows infrastructure doesn't have test concurrency above the level
     # of a single vcregress test target. Due to that, it's useful to run prove
     # with multiple jobs. For the other tasks it isn't, because two sources
@@ -345,15 +362,11 @@ task:
     # likely can be improved upon further.
     PROVE_FLAGS: -j10 --timer
 
-    # The default cirrus working dir is in a directory msbuild complains about
-    CIRRUS_WORKING_DIR: "c:/cirrus"
     # Avoid re-installing over and over
     NO_TEMP_INSTALL: 1
     # git's tar doesn't deal with drive letters, see
     # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
     TAR: "c:/windows/system32/tar.exe"
-    # Avoids port conflicts between concurrent tap test runs
-    PG_TEST_USE_UNIX_SOCKETS: 1
     PG_REGRESS_SOCK_DIR: "c:/cirrus/"
     # -m enables parallelism
     # verbosity:minimal + Summary reduce verbosity, while keeping a summary of
@@ -370,20 +383,11 @@ task:
     # "suites".
     T_C: "\"C:/Program Files/Git/usr/bin/timeout.exe\" -v -k60s 15m"
 
-
-  only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
-
   windows_container:
     image: $CONTAINER_REPO/windows_ci_vs_2019:latest
     cpu: $CPUS
     memory: 4G
 
-  sysinfo_script: |
-    chcp
-    systeminfo
-    powershell -Command get-psdrive -psprovider filesystem
-    set
-
   configure_script:
     # copy errors out when using forward slashes
     - copy src\tools\ci\windows_build_config.pl src\tools\msvc\config.pl
@@ -440,6 +444,53 @@ task:
       path: "crashlog-*.txt"
       type: text/plain
 
+task:
+  << : *WINDOWS_ENVIRONMENT_BASE
+  name: Windows - Server 2019, MinGW64
+  windows_container:
+    image: $CONTAINER_REPO/windows_ci_mingw64:latest
+    cpu: $CPUS
+    memory: 4G
+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    BUILD_DIR: "%CIRRUS_WORKING_DIR%/build"
+
+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  mingw_info_script:
+    - C:\msys64\usr\bin\bash.exe -lc "where gcc"
+    - C:\msys64\usr\bin\bash.exe -lc "gcc --version"
+    - C:\msys64\usr\bin\bash.exe -lc "where perl"
+    - C:\msys64\usr\bin\bash.exe -lc "perl --version"
+
+  configure_script:
+    - C:\msys64\usr\bin\bash.exe -lc " mkdir %BUILD_DIR% &&
+      cd %BUILD_DIR% &&
+      %CIRRUS_WORKING_DIR%/configure
+        --host=x86_64-w64-mingw32
+        --enable-cassert
+        --enable-tap-tests
+        --with-icu
+        --with-libxml
+        --with-libxslt
+        --with-lz4
+        --enable-debug
+        CC='ccache gcc'
+        CXX='ccache g++'"
+
+  build_script:
+    C:\msys64\usr\bin\bash.exe -lc "cd %BUILD_DIR% && make -s world-bin -j${CPUS}"
+
+  temp_install_script:
+    C:\msys64\usr\bin\bash.exe -lc "cd %BUILD_DIR% && make -s -j${CPUS} temp-install"
+
+  upload_caches: ccache
+
+  tests_script:
+    C:\msys64\usr\bin\bash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} NO_TEMP_INSTALL=1 TMPDIR=%BUILD_DIR%/tmp_install"
+
+  on_failure: *on_failure
 
 task:
   name: CompilerWarnings
-- 
2.33.0.windows.2

#2Andres Freund
andres@anarazel.de
In reply to: Melih Mutlu (#1)
Re: Mingw task for Cirrus CI

Hi,

Andrew, CCIng you both because you might be interested in the CI bit, and
because you might know the answer.

On 2022-02-25 19:44:27 +0300, Melih Mutlu wrote:

I've been working on adding Windows+MinGW environment into cirrus-ci tasks
(discussion about ci is here [1]).
It uses MSYS2 to set the environment. UCRT is chosen as C standard library,
instead of MSVCRT.
The task configures postgres with features that are available in MSYS2 (see
available packages [2]) and tap tests are enabled.
I already added the necessary docker image, you can find the related PR at
[3] and a successful cirruc-ci run with these changes at [4].
Attached patch adds a task runs on Windows with MinGW for cirrus-ci

However, I cannot run configure with --with-python, --with-perl or
--with-tcl.
There are two issues I encountered while trying to enable. e.g. for
--with-python

1- python_ldlibrary is set to "libpython3.9.dll.a". So the related line in
configure cannot retrieve "ldlibrary"

This presumably is due to using mingw's python rather than python.org's
python. Seems like a reasonable thing to support for the mingw build.

Melih, you could try to build against the python.org python (i installed in
the CI container).

2- src/pl/plpython/Makefile looks under "C:/Windows/system32/" for
PYTHONDLL. gendef cannot open that file, give an error like " failed to
open()" when creating a .def file.

On my win10 VM in which I installed python.org python I don't see a python dll
in c:/windows/system32 either. Looks like none of our windows mingw animals
build with python. So it might just be bitrot.

In the end, make check-world still fails, even though I was able to run
configure and make without any obvious error.
I see bunch of errors in tests like:
+ERROR:  language "plpython3u" does not exist
+HINT:  Use CREATE EXTENSION to load the language into the database.

Here is the logs from failed ci run:
https://api.cirrus-ci.com/v1/artifact/task/4645682031099904/log/build/src/pl/plpython/regression.diffs

The URL to the rest of the CI run is https://cirrus-ci.com/task/4645682031099904

The relevant failure is earlier:

+ERROR: could not load library "C:/cirrus/build/tmp_install/ucrt64/lib/postgresql/plpython3.dll": The specified module could not be found.

Clearly plpython is being built, because we see some warnings:

[22:44:24.456] C:/msys64/ucrt64/include/python3.9/pyconfig.h:1474: warning: "SIZEOF_OFF_T" redefined
[22:44:24.456] 1474 | #define SIZEOF_OFF_T 8
[22:44:24.456] |
[22:44:24.456] In file included from c:/cirrus/src/include/c.h:54,
[22:44:24.456] from c:/cirrus/src/include/postgres.h:46,
[22:44:24.456] from c:/cirrus/contrib/jsonb_plpython/jsonb_plpython.c:1:
[22:44:24.456] ../../src/include/pg_config.h:875: note: this is the location of the previous definition
[22:44:24.456] 875 | #define SIZEOF_OFF_T 4

Seems we're doing something wrong and end up with a 4 byte off_t, whereas
python ends up with an 8byte one. We probably need to fix that. But it's not
the cause of this problem.

You could take out -s from the make flags and see whether plpython3.dll is
being built and installed, and where to.

Greetings,

Andres Freund

#3Andrew Dunstan
andrew@dunslane.net
In reply to: Andres Freund (#2)
Re: Mingw task for Cirrus CI

On 2/25/22 19:27, Andres Freund wrote:

Hi,

Andrew, CCIng you both because you might be interested in the CI bit, and
because you might know the answer.

2- src/pl/plpython/Makefile looks under "C:/Windows/system32/" for
PYTHONDLL. gendef cannot open that file, give an error like " failed to
open()" when creating a .def file.

On my win10 VM in which I installed python.org python I don't see a python dll
in c:/windows/system32 either. Looks like none of our windows mingw animals
build with python. So it might just be bitrot.

There certainly was a time when python from python.org used to install
its DLL in the system32 directory, so I imagine that's why it's there.
I'm very glad to see that's no longer the case.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#4Melih Mutlu
m.melihmutlu@gmail.com
In reply to: Andres Freund (#2)
Re: Mingw task for Cirrus CI

Hi Andres,

This presumably is due to using mingw's python rather than python.org's
python. Seems like a reasonable thing to support for the mingw build.

Melih, you could try to build against the python.org python (i installed
in
the CI container).

I tried to use the installed python from python.org in the container.
The problem with this is that "LIBDIR" and "LDLIBRARY" configs of python
for windows from python.org are empty. Therefore python_libdir or other
related variables in configure file are not set correctly.

Seems we're doing something wrong and end up with a 4 byte off_t, whereas

python ends up with an 8byte one. We probably need to fix that. But it's
not
the cause of this problem.

You could take out -s from the make flags and see whether plpython3.dll is
being built and installed, and where to.

Here is a run without -s: https://cirrus-ci.com/task/4569363104661504
I couldn't get what's wrong from these logs to be honest. But I see that
plpython3.dll exists under src/pl/plpython after build when I run these
steps locally.

Best,
Melih

#5Andrew Dunstan
andrew@dunslane.net
In reply to: Melih Mutlu (#4)
Re: Mingw task for Cirrus CI

On 3/3/22 05:16, Melih Mutlu wrote:

Hi Andres, 
 

This presumably is due to using mingw's python rather than
python.org <http://python.org&gt;&#39;s
python. Seems like a reasonable thing to support for the mingw build.

Melih, you could try to build against the python.org
<http://python.org&gt; python (i installed in
the CI container).

I tried to use the installed python from python.org
<http://python.org&gt; in the container. 
The problem with this is that "LIBDIR" and "LDLIBRARY" configs of
python for windows from python.org <http://python.org&gt; are empty.
Therefore python_libdir or other related variables in configure file
are not set correctly.

Yeah, here's what it has:

# python -c "import sysconfig; import pprint; pp =
pprint.PrettyPrinter(); pp.pprint(sysconfig.get_config_vars())"
{'BINDIR': 'C:\\prog\\python310',
 'BINLIBDEST': 'C:\\prog\\python310\\Lib',
 'EXE': '.exe',
 'EXT_SUFFIX': '.cp310-win_amd64.pyd',
 'INCLUDEPY': 'C:\\prog\\python310\\Include',
 'LIBDEST': 'C:\\prog\\python310\\Lib',
 'SO': '.cp310-win_amd64.pyd',
 'TZPATH': '',
 'VERSION': '310',
 'abiflags': '',
 'base': 'C:\\prog\\python310',
 'exec_prefix': 'C:\\prog\\python310',
 'installed_base': 'C:\\prog\\python310',
 'installed_platbase': 'C:\\prog\\python310',
 'platbase': 'C:\\prog\\python310',
 'platlibdir': 'lib',
 'prefix': 'C:\\prog\\python310',
 'projectbase': 'C:\\prog\\python310',
 'py_version': '3.10.2',
 'py_version_nodot': '310',
 'py_version_nodot_plat': '310',
 'py_version_short': '3.10',
 'srcdir': 'C:\\prog\\python310',
 'userbase': 'C:\\Users\\Administrator\\AppData\\Roaming\\Python'}

The DLL lives in the BINDIR, so maybe I guess we should search there if
we can't get the other things.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#6Andres Freund
andres@anarazel.de
In reply to: Melih Mutlu (#1)
Re: Mingw task for Cirrus CI

Hi,

On 2022-02-25 19:44:27 +0300, Melih Mutlu wrote:

I've been working on adding Windows+MinGW environment into cirrus-ci tasks
(discussion about ci is here [1]).

This doesn't apply anymore: http://cfbot.cputube.org/patch_37_3575.log

Could you rebase?

Greetings,

Andres Freund

#7Melih Mutlu
m.melihmutlu@gmail.com
In reply to: Andres Freund (#6)
1 attachment(s)
Re: Mingw task for Cirrus CI

Hi Andres,

Rebased it.
I also removed the temp installation task and
used NoDefaultCurrentDirectoryInExePath env variable instead.

Best,
Melih

Attachments:

v2-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchapplication/x-patch; name=v2-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchDownload
From e8a1dae0ec10efd8a967070e0d412d2bf875fa93 Mon Sep 17 00:00:00 2001
From: Melih Mutlu <memutlu@microsoft.com>
Date: Mon, 21 Feb 2022 14:46:05 +0300
Subject: [PATCH] Added Windows with MinGW environment in Cirrus CI

---
 .cirrus.yml | 79 +++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 65 insertions(+), 14 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index e5335fede7..1ed40347cf 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -23,7 +23,6 @@ env:
   CHECKFLAGS: -Otarget
   PROVE_FLAGS: --timer
   PGCTLTIMEOUT: 120 # avoids spurious failures during parallel tests
-  TEMP_CONFIG: ${CIRRUS_WORKING_DIR}/src/tools/ci/pg_ci_base.conf
   PG_TEST_EXTRA: kerberos ldap ssl
 
 
@@ -334,13 +333,30 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh macos "${HOME}/cores"
 
 
+WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
+    env:
+      # Half the allowed per-user CPU cores
+      CPUS: 4
+      # The default working dir is in a directory msbuild complains about
+      CIRRUS_WORKING_DIR: "c:/cirrus"
+      TEMP_CONFIG: ${CIRRUS_WORKING_DIR}/src/tools/ci/pg_ci_base.conf
+
+      # Avoids port conflicts between concurrent tap test runs
+      PG_TEST_USE_UNIX_SOCKETS: 1
+
+    only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
+
+    sysinfo_script: |
+      chcp
+      systeminfo
+      powershell -Command get-psdrive -psprovider filesystem
+      set
+
 task:
+  << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, VS 2019
 
   env:
-    # Half the allowed per-user CPU cores
-    CPUS: 4
-
     # Our windows infrastructure doesn't have test concurrency above the level
     # of a single vcregress test target. Due to that, it's useful to run prove
     # with multiple jobs. For the other tasks it isn't, because two sources
@@ -350,15 +366,11 @@ task:
     # likely can be improved upon further.
     PROVE_FLAGS: -j10 --timer
 
-    # The default cirrus working dir is in a directory msbuild complains about
-    CIRRUS_WORKING_DIR: "c:/cirrus"
     # Avoid re-installing over and over
     NO_TEMP_INSTALL: 1
     # git's tar doesn't deal with drive letters, see
     # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
     TAR: "c:/windows/system32/tar.exe"
-    # Avoids port conflicts between concurrent tap test runs
-    PG_TEST_USE_UNIX_SOCKETS: 1
     PG_REGRESS_SOCK_DIR: "c:/cirrus/"
     # -m enables parallelism
     # verbosity:minimal + Summary reduce verbosity, while keeping a summary of
@@ -389,12 +401,6 @@ task:
     cpu: $CPUS
     memory: 4G
 
-  sysinfo_script: |
-    chcp
-    systeminfo
-    powershell -Command get-psdrive -psprovider filesystem
-    set
-
   setup_additional_packages_script: |
     REM choco install -y --no-progress ...
 
@@ -454,6 +460,51 @@ task:
       path: "crashlog-*.txt"
       type: text/plain
 
+task:
+  << : *WINDOWS_ENVIRONMENT_BASE
+  name: Windows - Server 2019, MinGW64
+  windows_container:
+    image: $CONTAINER_REPO/windows_ci_mingw64:latest
+    cpu: $CPUS
+    memory: 4G
+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    BUILD_DIR: "%CIRRUS_WORKING_DIR%/build"
+
+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  mingw_info_script:
+    - C:\msys64\usr\bin\bash.exe -lc "where gcc"
+    - C:\msys64\usr\bin\bash.exe -lc "gcc --version"
+    - C:\msys64\usr\bin\bash.exe -lc "where perl"
+    - C:\msys64\usr\bin\bash.exe -lc "perl --version"
+
+  configure_script:
+    - C:\msys64\usr\bin\bash.exe -lc "mkdir %BUILD_DIR% &&
+      cd %BUILD_DIR% &&
+      %CIRRUS_WORKING_DIR%/configure
+        --host=x86_64-w64-mingw32
+        --enable-cassert
+        --enable-tap-tests
+        --with-icu
+        --with-libxml
+        --with-libxslt
+        --with-lz4
+        --enable-debug
+        CC='ccache gcc'
+        CXX='ccache g++'"
+
+  build_script:
+    C:\msys64\usr\bin\bash.exe -lc "cd %BUILD_DIR% && make -s world-bin -j${CPUS}"
+
+  upload_caches: ccache
+
+  tests_script:
+  - set "NoDefaultCurrentDirectoryInExePath=0"
+  - C:\msys64\usr\bin\bash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
+
+  on_failure: *on_failure
 
 task:
   name: CompilerWarnings
-- 
2.35.1.windows.2

#8Andres Freund
andres@anarazel.de
In reply to: Melih Mutlu (#7)
Re: Mingw task for Cirrus CI

Hi,

On 2022-03-22 19:00:42 +0300, Melih Mutlu wrote:

Rebased it.
I also removed the temp installation task and
used NoDefaultCurrentDirectoryInExePath env variable instead.

Hm. But you're still using a separate build directory, from what I can see?
The NoDefaultCurrentDirectoryInExePath thing should only have an effect when
not using a separate build directory, no?

Does it work to not use the separate build dir? Without it we don't need the
the "preparing build tree" step, and that's quite slow on mingw:
https://cirrus-ci.com/task/4713509253545984?logs=configure#L392

[00:23:44.371] preparing build tree... done
[00:24:25.429] configure: creating ./config.status

Chatting about this patch with Thomas I started to wonder about other reasons
for the slow speed of configure. I briefly experimented locally, and it looks
like using 'dash' as the shell makes configure run a good bit quicker.

---
.cirrus.yml | 79 +++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 65 insertions(+), 14 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index e5335fede7..1ed40347cf 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -23,7 +23,6 @@ env:
CHECKFLAGS: -Otarget
PROVE_FLAGS: --timer
PGCTLTIMEOUT: 120 # avoids spurious failures during parallel tests
-  TEMP_CONFIG: ${CIRRUS_WORKING_DIR}/src/tools/ci/pg_ci_base.conf
PG_TEST_EXTRA: kerberos ldap ssl

This removes TEMP_CONFIG from all other tasks. You added it back to the VS
windows task, but not the others? I assume that was accidental?

+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    BUILD_DIR: "%CIRRUS_WORKING_DIR%/build"

I think this should use TEMP_CONFIG too. Is the problem that you need to
change the path?

+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  mingw_info_script:
+    - C:\msys64\usr\bin\bash.exe -lc "where gcc"
+    - C:\msys64\usr\bin\bash.exe -lc "gcc --version"
+    - C:\msys64\usr\bin\bash.exe -lc "where perl"
+    - C:\msys64\usr\bin\bash.exe -lc "perl --version"
+
+  configure_script:
+    - C:\msys64\usr\bin\bash.exe -lc "mkdir %BUILD_DIR% &&
+      cd %BUILD_DIR% &&
+      %CIRRUS_WORKING_DIR%/configure

Could you try using dash to invoke configure here, and whether it makes configure faster?

+        --host=x86_64-w64-mingw32
+        --enable-cassert
+        --enable-tap-tests
+        --with-icu
+        --with-libxml
+        --with-libxslt
+        --with-lz4
+        --enable-debug
+        CC='ccache gcc'
+        CXX='ccache g++'"

I think this task should specify CFLAGS="-Og", CXXFLAGS="-Og" similar to other
tasks. We end up with -O2 otherwise, which makes the build measurably slower.

+  tests_script:
+  - set "NoDefaultCurrentDirectoryInExePath=0"

A comment about why NoDefaultCurrentDirectoryInExePath=0 is used would be
good.

Greetings,

Andres Freund

#9Andres Freund
andres@anarazel.de
In reply to: Andres Freund (#8)
Re: Mingw task for Cirrus CI

Hi,

On 2022-03-30 17:26:18 -0700, Andres Freund wrote:

Hi,

On 2022-03-22 19:00:42 +0300, Melih Mutlu wrote:

Rebased it.
I also removed the temp installation task and
used NoDefaultCurrentDirectoryInExePath env variable instead.

Hm. But you're still using a separate build directory, from what I can see?
The NoDefaultCurrentDirectoryInExePath thing should only have an effect when
not using a separate build directory, no?

Melih chatted with me about making this work. Turns out it doesn't readily -
pg_ctl still fails.

The reason that NoDefaultCurrentDirectoryInExePath doesn't suffice to get a
working in-tree build, is that we break it ourselves:

int
find_my_exec(const char *argv0, char *retpath)
...
#ifdef WIN32
/* Win32 checks the current directory first for names without slashes */
join_path_components(retpath, cwd, argv0);
if (validate_exec(retpath) == 0)
return resolve_symlinks(retpath);
#endif

So even if windows doesn't actually use the current path, and the current
pg_ctl process isn't the one from the current directory, we *still* return
that.

Gah.

Maybe we should just use GetModuleFileName()?

But even after that the tests don't work. Commands started via IPC::Run do,
but when using system() they don't. Looks like perl parses the path the itself
:(.

- Andres

#10Andrew Dunstan
andrew@dunslane.net
In reply to: Andres Freund (#9)
Re: Mingw task for Cirrus CI

On 4/4/22 16:41, Andres Freund wrote:

Hi,

On 2022-03-30 17:26:18 -0700, Andres Freund wrote:

Hi,

On 2022-03-22 19:00:42 +0300, Melih Mutlu wrote:

Rebased it.
I also removed the temp installation task and
used NoDefaultCurrentDirectoryInExePath env variable instead.

Hm. But you're still using a separate build directory, from what I can see?
The NoDefaultCurrentDirectoryInExePath thing should only have an effect when
not using a separate build directory, no?

Melih chatted with me about making this work. Turns out it doesn't readily -
pg_ctl still fails.

The reason that NoDefaultCurrentDirectoryInExePath doesn't suffice to get a
working in-tree build, is that we break it ourselves:

int
find_my_exec(const char *argv0, char *retpath)
...
#ifdef WIN32
/* Win32 checks the current directory first for names without slashes */
join_path_components(retpath, cwd, argv0);
if (validate_exec(retpath) == 0)
return resolve_symlinks(retpath);
#endif

So even if windows doesn't actually use the current path, and the current
pg_ctl process isn't the one from the current directory, we *still* return
that.

Gah.

I notice a few things about the latest file in this thread.

You should set MSYSTEM=UCRT64 in the environment section. Given that,
there should be no need to specify a --host= setting for configure.

If it's not done already, the shebang line in
/ucrt64/bin/core_perl/prove needs to be modified to use /ucrt64/bin/perl.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#11Andrew Dunstan
andrew@dunslane.net
In reply to: Andres Freund (#8)
Re: Mingw task for Cirrus CI

On 3/30/22 20:26, Andres Freund wrote:

Could you try using dash to invoke configure here, and whether it makes configure faster?

I got weird failures re libxml/parser.h when I tried with dash. See
<https://cirrus-ci.com/task/5963254039052288&gt; (It would be nice if we
could see config.log on failure.)

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#12Andres Freund
andres@anarazel.de
In reply to: Andrew Dunstan (#11)
Re: Mingw task for Cirrus CI

Hi,

On 2022-04-06 11:03:37 -0400, Andrew Dunstan wrote:

On 3/30/22 20:26, Andres Freund wrote:

Could you try using dash to invoke configure here, and whether it makes configure faster?

I got weird failures re libxml/parser.h when I tried with dash.

Hm. Hadn't enabled that when I tried...

See <https://cirrus-ci.com/task/5963254039052288&gt; (It would be nice if we
could see config.log on failure.)

All *.log files are preserved on failure. There's a file directory brower at
the top to navigate around:
https://api.cirrus-ci.com/v1/artifact/task/5963254039052288/log/build/config.log

Greetings,

Andres Freund

#13Andres Freund
andres@anarazel.de
In reply to: Andrew Dunstan (#11)
1 attachment(s)
Re: Mingw task for Cirrus CI

Hi,

On 2022-04-06 11:03:37 -0400, Andrew Dunstan wrote:

On 3/30/22 20:26, Andres Freund wrote:

Could you try using dash to invoke configure here, and whether it makes configure faster?

I got weird failures re libxml/parser.h when I tried with dash. See
<https://cirrus-ci.com/task/5963254039052288&gt; (It would be nice if we
could see config.log on failure.)

Since dash won't help us to get the build time down sufficiently, and the
tests don't pass without a separate build tree, I looked at what makes
config/prep_buildtree so slow.

It's largely just bad code. The slowest part are spawning one expr and mkdir
-p for each directory. One 'cmp' for each makefile doesn't help either.

The expr can be replaced with
subdir=${item#$sourcetree}
that's afaics posix syntax ([1]https://pubs.opengroup.org/onlinepubs/009604499/utilities/xcu_chap02.html), not bash.

Spawning one mkdir for each directory can be replaced by a single mkdir
invocation with all the directories. On my linux workstation that gets the
time for the first loop down from 1005ms to 38ms, really.

That has the danger of the commandline getting too long. But since we rely on
the final link of the backend to be done in a single command, I don't think
it's making things worse? We could try to use xargs otherwise, iirc that's in
posix as well.

Using parameter substitution in the second loop takes it down from 775ms to
533ms. Not calling cmp when the file doesn't exist cuts it down to 337ms.

I don't know of a way to batch the call to ln. The time with ln replaced with
: is 151ms, fwiw.

On windows that makes prep_buildtree go from 42.4s to 5.8s for me.

Greetings,

Andres Freund

[1]: https://pubs.opengroup.org/onlinepubs/009604499/utilities/xcu_chap02.html

Attachments:

faster-prep-buildtree.difftext/x-diff; charset=us-asciiDownload
diff --git i/config/prep_buildtree w/config/prep_buildtree
index a0eabd3dee2..d26de429e61 100644
--- i/config/prep_buildtree
+++ w/config/prep_buildtree
@@ -26,19 +26,30 @@ buildtree=`cd ${2:-'.'} && pwd`
 # If we did, it would interfere with installation of prebuilt docs from
 # the source tree, if a VPATH build is done from a distribution tarball.
 # See bug #5595.
-for item in `find "$sourcetree" -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) | grep -v "$sourcetree/doc/src/sgml/\+"`; do
-    subdir=`expr "$item" : "$sourcetree\(.*\)"`
-    if test ! -d "$buildtree/$subdir"; then
-        mkdir -p "$buildtree/$subdir" || exit 1
-    fi
-done
+
+mkdir -p $(
+    for item in `find "$sourcetree" -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) | grep -v "$sourcetree/doc/src/sgml/\+"`; do
+        subdir=${item#$sourcetree}
+
+        if test ! -d "$buildtree/$subdir"; then
+            echo "$buildtree/$subdir"
+        fi
+    done
+)
 
 for item in `find "$sourcetree" -name Makefile -print -o -name GNUmakefile -print | grep -v "$sourcetree/doc/src/sgml/images/"`; do
-    filename=`expr "$item" : "$sourcetree\(.*\)"`
-    if test ! -f "${item}.in"; then
-        if cmp "$item" "$buildtree/$filename" >/dev/null 2>&1; then : ; else
-            ln -fs "$item" "$buildtree/$filename" || exit 1
-        fi
+    filename=${item#$sourcetree}
+
+    if test -f "${item}.in"; then
+        continue;
+    fi
+
+    if test ! -e "$buildtree/$filename"; then
+        ln -s "$item" "$buildtree/$filename" || exit 1;
+    elif cmp "$item" "$buildtree/$filename" >/dev/null 2>&1; then
+        : ;
+    else
+        ln -fs "$item" "$buildtree/$filename" || exit 1
     fi
 done
 
#14Andrew Dunstan
andrew@dunslane.net
In reply to: Andres Freund (#12)
Re: Mingw task for Cirrus CI

On 4/6/22 12:34, Andres Freund wrote:

Hi,

On 2022-04-06 11:03:37 -0400, Andrew Dunstan wrote:

On 3/30/22 20:26, Andres Freund wrote:

Could you try using dash to invoke configure here, and whether it makes configure faster?

I got weird failures re libxml/parser.h when I tried with dash.

Hm. Hadn't enabled that when I tried...

See <https://cirrus-ci.com/task/5963254039052288&gt; (It would be nice if we
could see config.log on failure.)

All *.log files are preserved on failure. There's a file directory brower at
the top to navigate around:
https://api.cirrus-ci.com/v1/artifact/task/5963254039052288/log/build/config.log

Thanks.

I got it working with this added to the config settings:

--with-includes='/ucrt64/include/libxml2 /c/cirrus/src/include/port/win32'

I conclude tentatively that while bash translates widows paths to msys
paths, dash does not.

see https://cirrus-ci.com/task/5968968560148480?logs=configure#L1

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#15Andrew Dunstan
andrew@dunslane.net
In reply to: Andres Freund (#13)
Re: Mingw task for Cirrus CI

On 4/7/22 13:10, Andres Freund wrote:

Hi,

On 2022-04-06 11:03:37 -0400, Andrew Dunstan wrote:

On 3/30/22 20:26, Andres Freund wrote:

Could you try using dash to invoke configure here, and whether it makes configure faster?

I got weird failures re libxml/parser.h when I tried with dash. See
<https://cirrus-ci.com/task/5963254039052288&gt; (It would be nice if we
could see config.log on failure.)

Since dash won't help us to get the build time down sufficiently, and the
tests don't pass without a separate build tree, I looked at what makes
config/prep_buildtree so slow.

It's largely just bad code. The slowest part are spawning one expr and mkdir
-p for each directory. One 'cmp' for each makefile doesn't help either.

The expr can be replaced with
subdir=${item#$sourcetree}
that's afaics posix syntax ([1]), not bash.

Spawning one mkdir for each directory can be replaced by a single mkdir
invocation with all the directories. On my linux workstation that gets the
time for the first loop down from 1005ms to 38ms, really.

That has the danger of the commandline getting too long. But since we rely on
the final link of the backend to be done in a single command, I don't think
it's making things worse? We could try to use xargs otherwise, iirc that's in
posix as well.

Using parameter substitution in the second loop takes it down from 775ms to
533ms. Not calling cmp when the file doesn't exist cuts it down to 337ms.

I don't know of a way to batch the call to ln. The time with ln replaced with
: is 151ms, fwiw.

AFAIK Msy2s 'ln -s' by default copies a non-directory rather than
actually symlinking it. If we want real symlinks, then we need
MSYS=|winsymlinks:nativestrict set. The is will fail unless the calling
user is an Administrator or has the SeCreateSymbolicLink privilege. See
|

|</messages/by-id/%7Ce05b213c-1257-84d4-f079-5c4d8c79e3ad@dunslane.net&gt;
for more details.

On windows that makes prep_buildtree go from 42.4s to 5.8s for me.

That's pretty good.

I think we can get rid of the CVS pruning, it's only 15 years or so
since we've had that in the tree.

+        if test ! -d "$buildtree/$subdir"; then
+            echo "$buildtree/$subdir"
+        fi

I would probably just write that as

test -d "$buildtree/$subdir' || echo "$buildtree/$subdir"

although it's really just a matter of taste.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#16Andrew Dunstan
andrew@dunslane.net
In reply to: Andrew Dunstan (#15)
Re: Mingw task for Cirrus CI

On 4/7/22 16:48, Andrew Dunstan wrote:

On 4/7/22 13:10, Andres Freund wrote:

Hi,

On 2022-04-06 11:03:37 -0400, Andrew Dunstan wrote:

On 3/30/22 20:26, Andres Freund wrote:

Could you try using dash to invoke configure here, and whether it makes configure faster?

I got weird failures re libxml/parser.h when I tried with dash. See
<https://cirrus-ci.com/task/5963254039052288&gt; (It would be nice if we
could see config.log on failure.)

Since dash won't help us to get the build time down sufficiently, and the
tests don't pass without a separate build tree, I looked at what makes
config/prep_buildtree so slow.

It's largely just bad code. The slowest part are spawning one expr and mkdir
-p for each directory. One 'cmp' for each makefile doesn't help either.

The expr can be replaced with
subdir=${item#$sourcetree}
that's afaics posix syntax ([1]), not bash.

Spawning one mkdir for each directory can be replaced by a single mkdir
invocation with all the directories. On my linux workstation that gets the
time for the first loop down from 1005ms to 38ms, really.

That has the danger of the commandline getting too long. But since we rely on
the final link of the backend to be done in a single command, I don't think
it's making things worse? We could try to use xargs otherwise, iirc that's in
posix as well.

Using parameter substitution in the second loop takes it down from 775ms to
533ms. Not calling cmp when the file doesn't exist cuts it down to 337ms.

I don't know of a way to batch the call to ln. The time with ln replaced with
: is 151ms, fwiw.

AFAIK Msy2s 'ln -s' by default copies a non-directory rather than
actually symlinking it. If we want real symlinks, then we need
MSYS=|winsymlinks:nativestrict set. The is will fail unless the calling
user is an Administrator or has the SeCreateSymbolicLink privilege. See
|

Sometimes I hate Thunderbird. Of course the | is spurious above, we
would need

MSYS=winsymlinks:nativestrict

set.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#17Melih Mutlu
m.melihmutlu@gmail.com
In reply to: Andrew Dunstan (#10)
Re: Mingw task for Cirrus CI
#18Alvaro Herrera
alvherre@alvh.no-ip.org
In reply to: Andres Freund (#13)
Re: Mingw task for Cirrus CI

On 2022-Apr-07, Andres Freund wrote:

Since dash won't help us to get the build time down sufficiently, and the
tests don't pass without a separate build tree, I looked at what makes
config/prep_buildtree so slow.

Maybe we can replace prep_buildtree with a Perl script. Surely that
should be faster.

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"Sallah, I said NO camels! That's FIVE camels; can't you count?"
(Indiana Jones)

#19Melih Mutlu
m.melihmutlu@gmail.com
In reply to: Andres Freund (#13)
Re: Mingw task for Cirrus CI

On windows that makes prep_buildtree go from 42.4s to 5.8s for me.

I applied Andres's faster prep build tree changes and triggered some cirrus
runs

Without these changes, preparing build tree was taking around 42.3s
(sometimes even more) [1]https://cirrus-ci.com/task/6562493345562624
It seems like with these changes it drops to around 8s [2]https://cirrus-ci.com/task/4836843802853376

[1]: https://cirrus-ci.com/task/6562493345562624
[2]: https://cirrus-ci.com/task/4836843802853376

Best,
Melih

#20Andres Freund
andres@anarazel.de
In reply to: Alvaro Herrera (#18)
Re: Mingw task for Cirrus CI

Hi,

On 2022-04-08 17:04:34 +0200, Alvaro Herrera wrote:

Since dash won't help us to get the build time down sufficiently, and the
tests don't pass without a separate build tree, I looked at what makes
config/prep_buildtree so slow.

Maybe we can replace prep_buildtree with a Perl script. Surely that
should be faster.

Currently building doesn't depend on perl :(

I think the improvements that I suggested are big enough that they're worth
doing on their own, particularly for windows, but also other OSs.

I just realized that the second find is pretty expensive compared to the
first.

time find "$sourcetree" -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) | grep -v "$sourcetree/doc/src/sgml/\+" > /dev/null
real 0m0.019s
user 0m0.008s
sys 0m0.017s

second:
time find "$sourcetree" -name Makefile -print -o -name GNUmakefile -print | grep -v "$sourcetree/doc/src/sgml/images/" > /dev/null

real 0m0.118s
user 0m0.071s
sys 0m0.053s

It think we could just obsolete the second find, by checking for the existence
of Makefile / GNUmakefile in the first loop...

The invocation of ln -s is quite measurable - looks like it's mostly the
process startup overhead (on linux, at least). Doing a ln --version > /dev/null
each iteration takes about the same time as actually creating the symlinks.

Greetings,

Andres Freund

#21Justin Pryzby
pryzby@telsasoft.com
In reply to: Andres Freund (#13)
Re: Mingw task for Cirrus CI

On Thu, Apr 07, 2022 at 10:10:21AM -0700, Andres Freund wrote:

Hi,

On 2022-04-06 11:03:37 -0400, Andrew Dunstan wrote:

On 3/30/22 20:26, Andres Freund wrote:

Could you try using dash to invoke configure here, and whether it makes configure faster?

I got weird failures re libxml/parser.h when I tried with dash. See
<https://cirrus-ci.com/task/5963254039052288&gt; (It would be nice if we
could see config.log on failure.)

Since dash won't help us to get the build time down sufficiently, and the
tests don't pass without a separate build tree, I looked at what makes
config/prep_buildtree so slow.

It's largely just bad code. The slowest part are spawning one expr and mkdir
-p for each directory. One 'cmp' for each makefile doesn't help either.

The expr can be replaced with
subdir=${item#$sourcetree}
that's afaics posix syntax ([1]), not bash.

Spawning one mkdir for each directory can be replaced by a single mkdir
invocation with all the directories. On my linux workstation that gets the
time for the first loop down from 1005ms to 38ms, really.

Even better?

(cd "$sourcetree" && find . -print |grep -E '/Makefile$|/GNUmakefile$' |grep -v "$sourcetree/doc/src/sgml/images/" |xargs tar c) |
(cd "$buildtree" && tar x)

#22Andres Freund
andres@anarazel.de
In reply to: Justin Pryzby (#21)
Re: Mingw task for Cirrus CI

Hi,

On 2022-04-08 19:27:58 -0500, Justin Pryzby wrote:

On Thu, Apr 07, 2022 at 10:10:21AM -0700, Andres Freund wrote:

On 2022-04-06 11:03:37 -0400, Andrew Dunstan wrote:

On 3/30/22 20:26, Andres Freund wrote:

Could you try using dash to invoke configure here, and whether it makes configure faster?

I got weird failures re libxml/parser.h when I tried with dash. See
<https://cirrus-ci.com/task/5963254039052288&gt; (It would be nice if we
could see config.log on failure.)

Since dash won't help us to get the build time down sufficiently, and the
tests don't pass without a separate build tree, I looked at what makes
config/prep_buildtree so slow.

It's largely just bad code. The slowest part are spawning one expr and mkdir
-p for each directory. One 'cmp' for each makefile doesn't help either.

The expr can be replaced with
subdir=${item#$sourcetree}
that's afaics posix syntax ([1]), not bash.

Spawning one mkdir for each directory can be replaced by a single mkdir
invocation with all the directories. On my linux workstation that gets the
time for the first loop down from 1005ms to 38ms, really.

Even better?

(cd "$sourcetree" && find . -print |grep -E '/Makefile$|/GNUmakefile$' |grep -v "$sourcetree/doc/src/sgml/images/" |xargs tar c) |
(cd "$buildtree" && tar x)

Don't think we depend on tar for building, at the moment. But yes, it'd be
faster... Tar is certainly a smaller dependency than perl, not sure if there's
any relevant platform without it?

Greetings,

Andres Freund

#23Alvaro Herrera
alvherre@alvh.no-ip.org
In reply to: Andres Freund (#20)
Re: Mingw task for Cirrus CI

On 2022-Apr-08, Andres Freund wrote:

I just realized that the second find is pretty expensive compared to the
first.

time find "$sourcetree" -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) | grep -v "$sourcetree/doc/src/sgml/\+" > /dev/null
real 0m0.019s
user 0m0.008s
sys 0m0.017s

second:
time find "$sourcetree" -name Makefile -print -o -name GNUmakefile -print | grep -v "$sourcetree/doc/src/sgml/images/" > /dev/null

real 0m0.118s
user 0m0.071s
sys 0m0.053s

Hmm, ISTM that time can be reduced a bit with -prune,

time find "$sourcetree" \( -name .git -prune \) -o -name Makefile -print -o -name GNUmakefile -print | grep -v "$sourcetree/doc/src/sgml/images/" > /dev/null

I thought it might work to do away with the grep and use find's -path
instead to prune that subdir, but "time" shows almost no difference for
me:

time find "$sourcetree" \( -name .git -prune \) -o \( -path '*doc/src/sgml/images' -prune \) -o -name Makefile -print -o -name GNUmakefile -print > /dev/null

Maybe find's -path is equally expensive. Still, that seems a good
change anyway. (The times are lower in my system than those you show.)

It think we could just obsolete the second find, by checking for the existence
of Makefile / GNUmakefile in the first loop...

Hmm, if that's going to require one more shell command per dir, it
sounds more expensive. It's worth trying, I guess.

The invocation of ln -s is quite measurable - looks like it's mostly the
process startup overhead (on linux, at least). Doing a ln --version > /dev/null
each iteration takes about the same time as actually creating the symlinks.

Is this running with some locale settings enabled? Maybe we can save
some time by making sure we're under LC_ALL=C or something like that, to
avoid searching for translation files.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Las navajas y los monos deben estar siempre distantes" (Germán Poo)

#24Andrew Dunstan
andrew@dunslane.net
In reply to: Andres Freund (#22)
Re: Mingw task for Cirrus CI

On 4/8/22 21:02, Andres Freund wrote:

Hi,

On 2022-04-08 19:27:58 -0500, Justin Pryzby wrote:

On Thu, Apr 07, 2022 at 10:10:21AM -0700, Andres Freund wrote:

On 2022-04-06 11:03:37 -0400, Andrew Dunstan wrote:

On 3/30/22 20:26, Andres Freund wrote:

Could you try using dash to invoke configure here, and whether it makes configure faster?

I got weird failures re libxml/parser.h when I tried with dash. See
<https://cirrus-ci.com/task/5963254039052288&gt; (It would be nice if we
could see config.log on failure.)

Since dash won't help us to get the build time down sufficiently, and the
tests don't pass without a separate build tree, I looked at what makes
config/prep_buildtree so slow.

It's largely just bad code. The slowest part are spawning one expr and mkdir
-p for each directory. One 'cmp' for each makefile doesn't help either.

The expr can be replaced with
subdir=${item#$sourcetree}
that's afaics posix syntax ([1]), not bash.

Spawning one mkdir for each directory can be replaced by a single mkdir
invocation with all the directories. On my linux workstation that gets the
time for the first loop down from 1005ms to 38ms, really.

Even better?

(cd "$sourcetree" && find . -print |grep -E '/Makefile$|/GNUmakefile$' |grep -v "$sourcetree/doc/src/sgml/images/" |xargs tar c) |
(cd "$buildtree" && tar x)

Don't think we depend on tar for building, at the moment. But yes, it'd be
faster... Tar is certainly a smaller dependency than perl, not sure if there's
any relevant platform without it?

Couple of things here.

1. The second grep should lose "$sourcetree" I think.

2. Isn't this going to be a change in behaviour in that it will copy
rather than symlinking the Makefiles? That is in fact the default
behaviour of msys2's 'ln -s', as I pointed out upthread, but I don't
think it's what we really want, especially in the general case. If you
modify the Makefile and you're using a vpath you want to see the change
reflected in your vpath.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#25Melih Mutlu
m.melihmutlu@gmail.com
In reply to: Andrew Dunstan (#24)
1 attachment(s)
Re: Mingw task for Cirrus CI

Hi hackers,

I'm sharing the rebased version of this patch, if you're still interested.

I would appreciate any feedback or concerns.

Best,
Melih

Andrew Dunstan <andrew@dunslane.net>, 9 Nis 2022 Cmt, 19:34 tarihinde şunu
yazdı:

Show quoted text

On 4/8/22 21:02, Andres Freund wrote:

Hi,

On 2022-04-08 19:27:58 -0500, Justin Pryzby wrote:

On Thu, Apr 07, 2022 at 10:10:21AM -0700, Andres Freund wrote:

On 2022-04-06 11:03:37 -0400, Andrew Dunstan wrote:

On 3/30/22 20:26, Andres Freund wrote:

Could you try using dash to invoke configure here, and whether it

makes configure faster?

I got weird failures re libxml/parser.h when I tried with dash. See
<https://cirrus-ci.com/task/5963254039052288&gt; (It would be nice if we
could see config.log on failure.)

Since dash won't help us to get the build time down sufficiently, and

the

tests don't pass without a separate build tree, I looked at what makes
config/prep_buildtree so slow.

It's largely just bad code. The slowest part are spawning one expr and

mkdir

-p for each directory. One 'cmp' for each makefile doesn't help either.

The expr can be replaced with
subdir=${item#$sourcetree}
that's afaics posix syntax ([1]), not bash.

Spawning one mkdir for each directory can be replaced by a single mkdir
invocation with all the directories. On my linux workstation that gets

the

time for the first loop down from 1005ms to 38ms, really.

Even better?

(cd "$sourcetree" && find . -print |grep -E '/Makefile$|/GNUmakefile$'

|grep -v "$sourcetree/doc/src/sgml/images/" |xargs tar c) |

(cd "$buildtree" && tar x)

Don't think we depend on tar for building, at the moment. But yes, it'd

be

faster... Tar is certainly a smaller dependency than perl, not sure if

there's

any relevant platform without it?

Couple of things here.

1. The second grep should lose "$sourcetree" I think.

2. Isn't this going to be a change in behaviour in that it will copy
rather than symlinking the Makefiles? That is in fact the default
behaviour of msys2's 'ln -s', as I pointed out upthread, but I don't
think it's what we really want, especially in the general case. If you
modify the Makefile and you're using a vpath you want to see the change
reflected in your vpath.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Attachments:

v3-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchapplication/octet-stream; name=v3-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchDownload
From ce4e6984a044dd6b6d8d9f610b553ad2c378473b Mon Sep 17 00:00:00 2001
From: Melih Mutlu <memutlu@microsoft.com>
Date: Mon, 21 Feb 2022 14:46:05 +0300
Subject: [PATCH] Added Windows with MinGW environment in Cirrus CI

---
 .cirrus.yml | 78 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 65 insertions(+), 13 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index f23d6cae55..1a06cdcaad 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -338,13 +338,29 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh macos "${HOME}/cores"
 
 
+WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
+    env:
+      # Half the allowed per-user CPU cores
+      CPUS: 4
+      # The default working dir is in a directory msbuild complains about
+      CIRRUS_WORKING_DIR: "c:/cirrus"
+
+      # Avoids port conflicts between concurrent tap test runs
+      PG_TEST_USE_UNIX_SOCKETS: 1
+
+    only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
+
+    sysinfo_script: |
+      chcp
+      systeminfo
+      powershell -Command get-psdrive -psprovider filesystem
+      set
+
 task:
+  << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, VS 2019
 
   env:
-    # Half the allowed per-user CPU cores
-    CPUS: 4
-
     # Our windows infrastructure doesn't have test concurrency above the level
     # of a single vcregress test target. Due to that, it's useful to run prove
     # with multiple jobs. For the other tasks it isn't, because two sources
@@ -354,15 +370,11 @@ task:
     # likely can be improved upon further.
     PROVE_FLAGS: -j10 --timer
 
-    # The default cirrus working dir is in a directory msbuild complains about
-    CIRRUS_WORKING_DIR: "c:/cirrus"
     # Avoid re-installing over and over
     NO_TEMP_INSTALL: 1
     # git's tar doesn't deal with drive letters, see
     # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
     TAR: "c:/windows/system32/tar.exe"
-    # Avoids port conflicts between concurrent tap test runs
-    PG_TEST_USE_UNIX_SOCKETS: 1
     PG_REGRESS_SOCK_DIR: "c:/cirrus/"
     # -m enables parallelism
     # verbosity:minimal + Summary reduce verbosity, while keeping a summary of
@@ -393,12 +405,6 @@ task:
     cpu: $CPUS
     memory: 4G
 
-  sysinfo_script: |
-    chcp
-    systeminfo
-    powershell -Command get-psdrive -psprovider filesystem
-    set
-
   setup_additional_packages_script: |
     REM choco install -y --no-progress ...
 
@@ -456,6 +462,52 @@ task:
       path: "crashlog-*.txt"
       type: text/plain
 
+task:
+  << : *WINDOWS_ENVIRONMENT_BASE
+  name: Windows - Server 2019, MinGW64
+  windows_container:
+    image: $CONTAINER_REPO/windows_ci_mingw64:latest
+    cpu: $CPUS
+    memory: 4G
+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    BUILD_DIR: "%CIRRUS_WORKING_DIR%/build"
+
+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  mingw_info_script:
+    - C:\msys64\usr\bin\dash.exe -lc "where gcc"
+    - C:\msys64\usr\bin\dash.exe -lc "gcc --version"
+    - C:\msys64\usr\bin\dash.exe -lc "where perl"
+    - C:\msys64\usr\bin\dash.exe -lc "perl --version"
+
+  configure_script:
+    - C:\msys64\usr\bin\dash.exe -lc "mkdir %BUILD_DIR% &&
+      cd %BUILD_DIR% &&
+      %CIRRUS_WORKING_DIR%/configure
+        --enable-cassert
+        --enable-tap-tests
+        --with-icu
+        --with-libxml
+        --with-libxslt
+        --with-lz4
+        --enable-debug
+        CC='ccache gcc'
+        CXX='ccache g++'
+        CFLAGS='-Og -ggdb -pipe'
+        CXXFLAGS='-Og -ggdb'"
+
+  build_script:
+    C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s world-bin -j${CPUS}"
+
+  upload_caches: ccache
+
+  tests_script:
+  - set "NoDefaultCurrentDirectoryInExePath=0"
+  - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
+
+  on_failure: *on_failure
 
 task:
   name: CompilerWarnings
-- 
2.25.1

#26Justin Pryzby
pryzby@telsasoft.com
In reply to: Melih Mutlu (#25)
2 attachment(s)
Re: Mingw task for Cirrus CI

I think the "only_if" should allow separately running one but not both of the
windows instances, like:

+ only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw64'

I'm not sure, but maybe this task should only run "by request", and omit the
first condition:

+ only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw64'

I think it should include something like

+  setup_additional_packages_script: |
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm ...

Let's see what others think about those.

Do you know if this handles logging of crash dumps ?

With tweaks to prep_buildtree, and with ./configure --cache-file, that step
goes down to ~36sec (unless configure needs to be re-run).

I also looked into using busybox to avoid running separate processes for each
"ln", but I think 36sec is good enough.

At one point, I tried setting "CIRRUS_SHELL: bash" to avoid writing "bash -c"
over and over, but never got it working.

--
Justin

Attachments:

0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchtext/x-diff; charset=us-asciiDownload
From ec28354e1e526ddab3a8df90540f9aa127c40193 Mon Sep 17 00:00:00 2001
From: Melih Mutlu <memutlu@microsoft.com>
Date: Mon, 21 Feb 2022 14:46:05 +0300
Subject: [PATCH 1/2] Added Windows with MinGW environment in Cirrus CI

---
 .cirrus.yml | 78 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 65 insertions(+), 13 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index f23d6cae552..1a06cdcaadb 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -338,13 +338,29 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh macos "${HOME}/cores"
 
 
+WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
+    env:
+      # Half the allowed per-user CPU cores
+      CPUS: 4
+      # The default working dir is in a directory msbuild complains about
+      CIRRUS_WORKING_DIR: "c:/cirrus"
+
+      # Avoids port conflicts between concurrent tap test runs
+      PG_TEST_USE_UNIX_SOCKETS: 1
+
+    only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
+
+    sysinfo_script: |
+      chcp
+      systeminfo
+      powershell -Command get-psdrive -psprovider filesystem
+      set
+
 task:
+  << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, VS 2019
 
   env:
-    # Half the allowed per-user CPU cores
-    CPUS: 4
-
     # Our windows infrastructure doesn't have test concurrency above the level
     # of a single vcregress test target. Due to that, it's useful to run prove
     # with multiple jobs. For the other tasks it isn't, because two sources
@@ -354,15 +370,11 @@ task:
     # likely can be improved upon further.
     PROVE_FLAGS: -j10 --timer
 
-    # The default cirrus working dir is in a directory msbuild complains about
-    CIRRUS_WORKING_DIR: "c:/cirrus"
     # Avoid re-installing over and over
     NO_TEMP_INSTALL: 1
     # git's tar doesn't deal with drive letters, see
     # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
     TAR: "c:/windows/system32/tar.exe"
-    # Avoids port conflicts between concurrent tap test runs
-    PG_TEST_USE_UNIX_SOCKETS: 1
     PG_REGRESS_SOCK_DIR: "c:/cirrus/"
     # -m enables parallelism
     # verbosity:minimal + Summary reduce verbosity, while keeping a summary of
@@ -393,12 +405,6 @@ task:
     cpu: $CPUS
     memory: 4G
 
-  sysinfo_script: |
-    chcp
-    systeminfo
-    powershell -Command get-psdrive -psprovider filesystem
-    set
-
   setup_additional_packages_script: |
     REM choco install -y --no-progress ...
 
@@ -456,6 +462,52 @@ task:
       path: "crashlog-*.txt"
       type: text/plain
 
+task:
+  << : *WINDOWS_ENVIRONMENT_BASE
+  name: Windows - Server 2019, MinGW64
+  windows_container:
+    image: $CONTAINER_REPO/windows_ci_mingw64:latest
+    cpu: $CPUS
+    memory: 4G
+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    BUILD_DIR: "%CIRRUS_WORKING_DIR%/build"
+
+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  mingw_info_script:
+    - C:\msys64\usr\bin\dash.exe -lc "where gcc"
+    - C:\msys64\usr\bin\dash.exe -lc "gcc --version"
+    - C:\msys64\usr\bin\dash.exe -lc "where perl"
+    - C:\msys64\usr\bin\dash.exe -lc "perl --version"
+
+  configure_script:
+    - C:\msys64\usr\bin\dash.exe -lc "mkdir %BUILD_DIR% &&
+      cd %BUILD_DIR% &&
+      %CIRRUS_WORKING_DIR%/configure
+        --enable-cassert
+        --enable-tap-tests
+        --with-icu
+        --with-libxml
+        --with-libxslt
+        --with-lz4
+        --enable-debug
+        CC='ccache gcc'
+        CXX='ccache g++'
+        CFLAGS='-Og -ggdb -pipe'
+        CXXFLAGS='-Og -ggdb'"
+
+  build_script:
+    C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s world-bin -j${CPUS}"
+
+  upload_caches: ccache
+
+  tests_script:
+  - set "NoDefaultCurrentDirectoryInExePath=0"
+  - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
+
+  on_failure: *on_failure
 
 task:
   name: CompilerWarnings
-- 
2.17.1

0002-f.patchtext/x-diff; charset=us-asciiDownload
From c8122c49502e9f95df392c41284f5e02819cf2cb Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Thu, 28 Jul 2022 10:57:26 -0500
Subject: [PATCH 2/2] f!

ci-os-only: mingw
---
 .cirrus.yml           | 23 ++++++++++++++++-------
 config/prep_buildtree | 18 ++++++------------
 2 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 1a06cdcaadb..93774485bef 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -348,8 +348,6 @@ WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
       # Avoids port conflicts between concurrent tap test runs
       PG_TEST_USE_UNIX_SOCKETS: 1
 
-    only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
-
     sysinfo_script: |
       chcp
       systeminfo
@@ -360,6 +358,8 @@ task:
   << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, VS 2019
 
+  only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
+
   env:
     # Our windows infrastructure doesn't have test concurrency above the level
     # of a single vcregress test target. Due to that, it's useful to run prove
@@ -465,6 +465,8 @@ task:
 task:
   << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, MinGW64
+  only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw.*'
+
   windows_container:
     image: $CONTAINER_REPO/windows_ci_mingw64:latest
     cpu: $CPUS
@@ -482,21 +484,28 @@ task:
     - C:\msys64\usr\bin\dash.exe -lc "where perl"
     - C:\msys64\usr\bin\dash.exe -lc "perl --version"
 
+  setup_additional_packages_script: |
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm busybox
+
   configure_script:
     - C:\msys64\usr\bin\dash.exe -lc "mkdir %BUILD_DIR% &&
-      cd %BUILD_DIR% &&
+      cd %BUILD_DIR% && for i in 1 2; do
       %CIRRUS_WORKING_DIR%/configure
+        --cache-file=${CCACHE_DIR}/configure.cache
         --enable-cassert
+        --enable-debug
         --enable-tap-tests
         --with-icu
         --with-libxml
         --with-libxslt
         --with-lz4
-        --enable-debug
         CC='ccache gcc'
         CXX='ccache g++'
         CFLAGS='-Og -ggdb -pipe'
-        CXXFLAGS='-Og -ggdb'"
+        CXXFLAGS='-Og -ggdb' && break;
+        rm -v ${CCACHE_DIR}/configure.cache;
+        done
+        "
 
   build_script:
     C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s world-bin -j${CPUS}"
@@ -504,8 +513,8 @@ task:
   upload_caches: ccache
 
   tests_script:
-  - set "NoDefaultCurrentDirectoryInExePath=0"
-  - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
+    - set "NoDefaultCurrentDirectoryInExePath=0"
+    - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
 
   on_failure: *on_failure
 
diff --git a/config/prep_buildtree b/config/prep_buildtree
index a0eabd3dee2..4de30ac28a5 100644
--- a/config/prep_buildtree
+++ b/config/prep_buildtree
@@ -26,20 +26,14 @@ buildtree=`cd ${2:-'.'} && pwd`
 # If we did, it would interfere with installation of prebuilt docs from
 # the source tree, if a VPATH build is done from a distribution tarball.
 # See bug #5595.
-for item in `find "$sourcetree" -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) | grep -v "$sourcetree/doc/src/sgml/\+"`; do
-    subdir=`expr "$item" : "$sourcetree\(.*\)"`
-    if test ! -d "$buildtree/$subdir"; then
-        mkdir -p "$buildtree/$subdir" || exit 1
-    fi
-done
+( cd "$sourcetree" && find . -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) |grep -v "doc/src/sgml/\+" ) |
+	( cd "$buildtree" && xargs mkdir -p )
 
 for item in `find "$sourcetree" -name Makefile -print -o -name GNUmakefile -print | grep -v "$sourcetree/doc/src/sgml/images/"`; do
-    filename=`expr "$item" : "$sourcetree\(.*\)"`
-    if test ! -f "${item}.in"; then
-        if cmp "$item" "$buildtree/$filename" >/dev/null 2>&1; then : ; else
-            ln -fs "$item" "$buildtree/$filename" || exit 1
-        fi
-    fi
+    filename=${item#$sourcetree}
+    [ -e "$buildtree/$filename" ] && continue
+    cmp "$item" "$buildtree/$filename" >/dev/null 2>&1 ||
+        ln -fs "$item" "$buildtree/$filename"
 done
 
 exit 0
-- 
2.17.1

#27Thomas Munro
thomas.munro@gmail.com
In reply to: Justin Pryzby (#26)
Re: Mingw task for Cirrus CI

I noticed that this says:

[01:01:45.657] sqlda.pgc: In function 'dump_sqlda':
[01:01:45.657] sqlda.pgc:45:33: warning: format '%d' expects argument
of type 'int', but argument 3 has type 'long long int' [-Wformat=]
[01:01:45.657] 45 | "name sqlda descriptor: '%s' value %I64d\n",
[01:01:45.657] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[01:01:45.657] ......
[01:01:45.657] 49 | sqlda->sqlvar[i].sqlname.data, *(long long int
*)sqlda->sqlvar[i].sqldata);
[01:01:45.657] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[01:01:45.657] | |
[01:01:45.657] | long long int

... but fairywren doesn't. Why would they disagree on recognising %I64d?

The other warning I'm seeing is present on both, so it's not really
relevant to this thread, just mentioning it... seems kinda like a
worlds-colliding-problem without an elegant fix (POSIX says you have
to declare it yourself exactly like that, but Windows says linkage
ain't going to work the way you want unless you sprinkle the right
linkage dust on it...), so maybe we just want to put #if
!defined(something something mings) around it and to MinGW's header's
declaration...

[00:48:08.925] c:/cirrus/src/backend/postmaster/postmaster.c: In
function 'PostmasterMain':
[00:48:08.925] c:/cirrus/src/backend/postmaster/postmaster.c:973:31:
warning: '__p__environ' redeclared without dllimport attribute:
previous dllimport ignored [-Wattributes]
[00:48:08.925] 973 | extern char **environ;
[00:48:08.925] | ^~~~~~~

#28Thomas Munro
thomas.munro@gmail.com
In reply to: Thomas Munro (#27)
Re: Mingw task for Cirrus CI

On Thu, Aug 4, 2022 at 2:04 PM Thomas Munro <thomas.munro@gmail.com> wrote:

I noticed that this says:

[01:01:45.657] sqlda.pgc: In function 'dump_sqlda':
[01:01:45.657] sqlda.pgc:45:33: warning: format '%d' expects argument
of type 'int', but argument 3 has type 'long long int' [-Wformat=]
[01:01:45.657] 45 | "name sqlda descriptor: '%s' value %I64d\n",
[01:01:45.657] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[01:01:45.657] ......
[01:01:45.657] 49 | sqlda->sqlvar[i].sqlname.data, *(long long int
*)sqlda->sqlvar[i].sqldata);
[01:01:45.657] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[01:01:45.657] | |
[01:01:45.657] | long long int

... but fairywren doesn't. Why would they disagree on recognising %I64d?

Oops, I was looking in the wrong place. fairywren does also shows the warning:

https://buildfarm.postgresql.org/cgi-bin/show_stage_log.pl?nm=fairywren&amp;dt=2022-08-02%2022%3A05%3A30&amp;stg=ecpg-check

Something to fix, but not directly relevant to this patch. Sorry for the noise.

#29Justin Pryzby
pryzby@telsasoft.com
In reply to: Justin Pryzby (#26)
2 attachment(s)
Re: Mingw task for Cirrus CI

Inline notes about changes since the last version.

On Thu, Jul 28, 2022 at 05:44:28PM -0500, Justin Pryzby wrote:

I think the "only_if" should allow separately running one but not both of the
windows instances, like:

+ only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw64'

I'm not sure, but maybe this task should only run "by request", and omit the
first condition:

+ only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw64'

The patch shouldn't say this during development, or else cfbot doesn't run it..
Oops.

I think it should include something like

+  setup_additional_packages_script: |
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm ...

Let's see what others think about those.

Do you know if this handles logging of crash dumps ?

It does now, although I hardcoded "postgres.exe" ...

+  setup_additional_packages_script: |
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm busybox

This should include choco, too.

-        CXXFLAGS='-Og -ggdb'"
+        CXXFLAGS='-Og -ggdb' && break;
+        rm -v ${CCACHE_DIR}/configure.cache;
+        done

I noticed that this doesn't seem to do the right thing with the exit status -
configure can fail without cirrusci noticing, and then the build fails at the
next step.

for item in `find "$sourcetree" -name Makefile -print -o -name GNUmakefile -print | grep -v "$sourcetree/doc/src/sgml/images/"`; do
-    filename=`expr "$item" : "$sourcetree\(.*\)"`
-    if test ! -f "${item}.in"; then
-        if cmp "$item" "$buildtree/$filename" >/dev/null 2>&1; then : ; else
-            ln -fs "$item" "$buildtree/$filename" || exit 1
-        fi
-    fi
+    filename=${item#$sourcetree}
+    [ -e "$buildtree/$filename" ] && continue

I fixed this to check for ".in" files as intended.

It'd be a lot better if the image didn't take so long to start. :(

--
Justin

Attachments:

0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchtext/x-diff; charset=us-asciiDownload
From 32646786299672d333cbf1f49bafac9e90e0d3be Mon Sep 17 00:00:00 2001
From: Melih Mutlu <memutlu@microsoft.com>
Date: Mon, 21 Feb 2022 14:46:05 +0300
Subject: [PATCH 1/2] Added Windows with MinGW environment in Cirrus CI

---
 .cirrus.yml | 78 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 65 insertions(+), 13 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index a9193c2c34f..472661c0936 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -339,13 +339,29 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh macos "${HOME}/cores"
 
 
+WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
+    env:
+      # Half the allowed per-user CPU cores
+      CPUS: 4
+      # The default working dir is in a directory msbuild complains about
+      CIRRUS_WORKING_DIR: "c:/cirrus"
+
+      # Avoids port conflicts between concurrent tap test runs
+      PG_TEST_USE_UNIX_SOCKETS: 1
+
+    only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
+
+    sysinfo_script: |
+      chcp
+      systeminfo
+      powershell -Command get-psdrive -psprovider filesystem
+      set
+
 task:
+  << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, VS 2019
 
   env:
-    # Half the allowed per-user CPU cores
-    CPUS: 4
-
     # Our windows infrastructure doesn't have test concurrency above the level
     # of a single vcregress test target. Due to that, it's useful to run prove
     # with multiple jobs. For the other tasks it isn't, because two sources
@@ -355,15 +371,11 @@ task:
     # likely can be improved upon further.
     PROVE_FLAGS: -j10 --timer
 
-    # The default cirrus working dir is in a directory msbuild complains about
-    CIRRUS_WORKING_DIR: "c:/cirrus"
     # Avoid re-installing over and over
     NO_TEMP_INSTALL: 1
     # git's tar doesn't deal with drive letters, see
     # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
     TAR: "c:/windows/system32/tar.exe"
-    # Avoids port conflicts between concurrent tap test runs
-    PG_TEST_USE_UNIX_SOCKETS: 1
     PG_REGRESS_SOCK_DIR: "c:/cirrus/"
     # -m enables parallelism
     # verbosity:minimal + Summary reduce verbosity, while keeping a summary of
@@ -398,12 +410,6 @@ task:
     cpu: $CPUS
     memory: 4G
 
-  sysinfo_script: |
-    chcp
-    systeminfo
-    powershell -Command get-psdrive -psprovider filesystem
-    set
-
   setup_additional_packages_script: |
     REM 3min
     REM choco install -y --no-progress --version=1.0.0 visualstudio2022-workload-vctools --install-args="--add Microsoft.VisualStudio.Component.VC.CLI.Support"
@@ -475,6 +481,52 @@ task:
       path: "crashlog-*.txt"
       type: text/plain
 
+task:
+  << : *WINDOWS_ENVIRONMENT_BASE
+  name: Windows - Server 2019, MinGW64
+  windows_container:
+    image: $CONTAINER_REPO/windows_ci_mingw64:latest
+    cpu: $CPUS
+    memory: 4G
+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    BUILD_DIR: "%CIRRUS_WORKING_DIR%/build"
+
+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  mingw_info_script:
+    - C:\msys64\usr\bin\dash.exe -lc "where gcc"
+    - C:\msys64\usr\bin\dash.exe -lc "gcc --version"
+    - C:\msys64\usr\bin\dash.exe -lc "where perl"
+    - C:\msys64\usr\bin\dash.exe -lc "perl --version"
+
+  configure_script:
+    - C:\msys64\usr\bin\dash.exe -lc "mkdir %BUILD_DIR% &&
+      cd %BUILD_DIR% &&
+      %CIRRUS_WORKING_DIR%/configure
+        --enable-cassert
+        --enable-tap-tests
+        --with-icu
+        --with-libxml
+        --with-libxslt
+        --with-lz4
+        --enable-debug
+        CC='ccache gcc'
+        CXX='ccache g++'
+        CFLAGS='-Og -ggdb -pipe'
+        CXXFLAGS='-Og -ggdb'"
+
+  build_script:
+    C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s world-bin -j${CPUS}"
+
+  upload_caches: ccache
+
+  tests_script:
+  - set "NoDefaultCurrentDirectoryInExePath=0"
+  - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
+
+  on_failure: *on_failure
 
 task:
   name: CompilerWarnings
-- 
2.17.1

0002-f.patchtext/x-diff; charset=us-asciiDownload
From 49a49939827dde731f513d334e53e1f56be44b5f Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Thu, 28 Jul 2022 10:57:26 -0500
Subject: [PATCH 2/2] f!

ci-os-only: mingw
---
 .cirrus.yml                     | 31 +++++++++++++++++++++++--------
 config/prep_buildtree           | 20 ++++++++------------
 src/tools/ci/cores_backtrace.sh | 17 +++++++++++++++--
 3 files changed, 46 insertions(+), 22 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 472661c0936..b51a625d210 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -34,6 +34,7 @@ on_failure: &on_failure
       - "**/*.log"
       - "**/*.diffs"
       - "**/regress_log_*"
+      - "**/*.stackdump"
     type: text/plain
 
 task:
@@ -349,8 +350,6 @@ WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
       # Avoids port conflicts between concurrent tap test runs
       PG_TEST_USE_UNIX_SOCKETS: 1
 
-    only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
-
     sysinfo_script: |
       chcp
       systeminfo
@@ -361,6 +360,8 @@ task:
   << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, VS 2019
 
+  only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
+
   env:
     # Our windows infrastructure doesn't have test concurrency above the level
     # of a single vcregress test target. Due to that, it's useful to run prove
@@ -484,6 +485,8 @@ task:
 task:
   << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, MinGW64
+  #XXX only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw.*'
+
   windows_container:
     image: $CONTAINER_REPO/windows_ci_mingw64:latest
     cpu: $CPUS
@@ -495,6 +498,10 @@ task:
   ccache_cache:
     folder: ${CCACHE_DIR}
 
+  setup_additional_packages_script: |
+    REM choco install -y --no-progress ...
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm busybox
+
   mingw_info_script:
     - C:\msys64\usr\bin\dash.exe -lc "where gcc"
     - C:\msys64\usr\bin\dash.exe -lc "gcc --version"
@@ -502,20 +509,25 @@ task:
     - C:\msys64\usr\bin\dash.exe -lc "perl --version"
 
   configure_script:
+    # Try to configure with the cache file, and retry without if it fails, in case the flags changed.
     - C:\msys64\usr\bin\dash.exe -lc "mkdir %BUILD_DIR% &&
-      cd %BUILD_DIR% &&
+      cd %BUILD_DIR% && for i in 1 2; do
       %CIRRUS_WORKING_DIR%/configure
+        --cache-file=${CCACHE_DIR}/configure.cache
         --enable-cassert
+        --enable-debug
         --enable-tap-tests
         --with-icu
         --with-libxml
         --with-libxslt
         --with-lz4
-        --enable-debug
         CC='ccache gcc'
         CXX='ccache g++'
         CFLAGS='-Og -ggdb -pipe'
-        CXXFLAGS='-Og -ggdb'"
+        CXXFLAGS='-Og -ggdb' && break;
+        rm -v ${CCACHE_DIR}/configure.cache;
+        done
+        "
 
   build_script:
     C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s world-bin -j${CPUS}"
@@ -523,10 +535,13 @@ task:
   upload_caches: ccache
 
   tests_script:
-  - set "NoDefaultCurrentDirectoryInExePath=0"
-  - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
+    - set "NoDefaultCurrentDirectoryInExePath=0"
+    - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
 
-  on_failure: *on_failure
+  on_failure:
+    <<: *on_failure
+    cores_script:
+      - C:\tools\cygwin\bin\dash.exe --login -c "cd '%cd%' && src/tools/ci/cores_backtrace.sh msys ."
 
 task:
   name: CompilerWarnings
diff --git a/config/prep_buildtree b/config/prep_buildtree
index a0eabd3dee2..97bf65967f1 100644
--- a/config/prep_buildtree
+++ b/config/prep_buildtree
@@ -26,20 +26,16 @@ buildtree=`cd ${2:-'.'} && pwd`
 # If we did, it would interfere with installation of prebuilt docs from
 # the source tree, if a VPATH build is done from a distribution tarball.
 # See bug #5595.
-for item in `find "$sourcetree" -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) | grep -v "$sourcetree/doc/src/sgml/\+"`; do
-    subdir=`expr "$item" : "$sourcetree\(.*\)"`
-    if test ! -d "$buildtree/$subdir"; then
-        mkdir -p "$buildtree/$subdir" || exit 1
-    fi
-done
+( cd "$sourcetree" && find . -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) |grep -v "doc/src/sgml/\+" ) |
+	( cd "$buildtree" && xargs mkdir -p )
 
 for item in `find "$sourcetree" -name Makefile -print -o -name GNUmakefile -print | grep -v "$sourcetree/doc/src/sgml/images/"`; do
-    filename=`expr "$item" : "$sourcetree\(.*\)"`
-    if test ! -f "${item}.in"; then
-        if cmp "$item" "$buildtree/$filename" >/dev/null 2>&1; then : ; else
-            ln -fs "$item" "$buildtree/$filename" || exit 1
-        fi
-    fi
+    [ -e "$item.in" ] && echo "skipping: $item" &&
+        continue
+
+    filename=${item#$sourcetree}
+    cmp "$item" "$buildtree/$filename" >/dev/null 2>&1 ||
+        ln -fs "$item" "$buildtree/$filename"
 done
 
 exit 0
diff --git a/src/tools/ci/cores_backtrace.sh b/src/tools/ci/cores_backtrace.sh
index 28d3cecfc67..93e90f284e6 100755
--- a/src/tools/ci/cores_backtrace.sh
+++ b/src/tools/ci/cores_backtrace.sh
@@ -10,11 +10,24 @@ directory=$2
 
 case $os in
     freebsd|linux|macos)
-    ;;
+        ;;
+
+    msys)
+        # XXX Evidently I don't know how to write two arguments here without pathname expansion later, other than eval.
+        #findargs='-name "*.stackdump"'
+        for corefile in $(find "$directory" -type f -name "*.stackdump") ; do
+            binary=`basename "$corefile" .stackdump`
+            echo;echo;
+            echo "dumping ${corefile} for ${binary}"
+            awk '/^0/{print $2}' $corefile |addr2line -f -i -e ./src/backend/postgres.exe
+        done
+        exit 0
+        ;;
+
     *)
         echo "unsupported operating system ${os}"
         exit 1
-    ;;
+        ;;
 esac
 
 first=1
-- 
2.17.1

#30Melih Mutlu
m.melihmutlu@gmail.com
In reply to: Justin Pryzby (#29)
1 attachment(s)
Re: Mingw task for Cirrus CI

Justin Pryzby <pryzby@telsasoft.com>, 19 Ağu 2022 Cum, 05:34 tarihinde şunu
yazdı:

Inline notes about changes since the last version.

On Thu, Jul 28, 2022 at 05:44:28PM -0500, Justin Pryzby wrote:

I think the "only_if" should allow separately running one but not both

of the

windows instances, like:

+ only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' ||

$CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw64'

I'm not sure, but maybe this task should only run "by request", and omit

the

first condition:

+ only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw64'

The patch shouldn't say this during development, or else cfbot doesn't run
it..
Oops.

Actually, making MinGW task optional for now might make sense. Due to
windows resource limits on Cirrus CI and slow builds on Windows, adding
this task as non-optional may not be an efficient decision
I think that continuing with this patch by changing MinGW to optional for
now, instead of waiting for more resource on Cirrus or faster builds on
Windows, could be better. I don't see any harm.

+ only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-include:[^\n]*mingw.* ||

$CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw.*'

Added this line to allow run only mingw task or run all tasks including
mingw.

What do you all think about this change? Does it make sense?

Thanks for your contributions/reviews Justin!

I think it should include something like

+  setup_additional_packages_script: |
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm ...

Let's see what others think about those.

Do you know if this handles logging of crash dumps ?

It does now, although I hardcoded "postgres.exe" ...

merged this with my patch

+ setup_additional_packages_script: |

+ REM C:\msys64\usr\bin\pacman.exe -S --noconfirm busybox

This should include choco, too.

Added pacman.exe line. Do we really need choco here? I don't think mingw
would require any package via choco.
Also is ending pacman.exe line with busybox intentional? I just added that
line with "..." at the end instead of any package name.

- CXXFLAGS='-Og -ggdb'"

+        CXXFLAGS='-Og -ggdb' && break;
+        rm -v ${CCACHE_DIR}/configure.cache;
+        done

I noticed that this doesn't seem to do the right thing with the exit
status -
configure can fail without cirrusci noticing, and then the build fails at
the
next step.

merged.

for item in `find "$sourcetree" -name Makefile -print -o -name
GNUmakefile -print | grep -v "$sourcetree/doc/src/sgml/images/"`; do

- filename=`expr "$item" : "$sourcetree\(.*\)"`
- if test ! -f "${item}.in"; then
- if cmp "$item" "$buildtree/$filename" >/dev/null 2>&1; then : ;

else

-            ln -fs "$item" "$buildtree/$filename" || exit 1
-        fi
-    fi
+    filename=${item#$sourcetree}
+    [ -e "$buildtree/$filename" ] && continue

I fixed this to check for ".in" files as intended.

It'd be a lot better if the image didn't take so long to start. :(

One question would be that should this patch include "prep_buildtree"? It
doesn't seem to me like it's directly related to adding MinGW into CI but
more like an improvement for builds on Windows.
Maybe we can make it a seperate patch if it's necessary.

What do you think?

TAR: "c:/windows/system32/tar.exe"

Sharing a new version of the patch. It also moves the above line so that it
will apply to mingw task too. Otherwise mingw task was failing.

Thanks,
Melih

Attachments:

v4-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchapplication/octet-stream; name=v4-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchDownload
From 7a8377decffb919f2e82bdc09be32343e8c5b4c1 Mon Sep 17 00:00:00 2001
From: Melih Mutlu <m.melihmutlu@gmail.com>
Date: Fri, 2 Sep 2022 23:10:02 +0300
Subject: [PATCH] Added Windows with MinGW environment in Cirrus CI

CI task on Windows Server with MinGW has been added as optional.
---
 .cirrus.yml                     | 103 ++++++++++++++++++++++++++------
 src/tools/ci/cores_backtrace.sh |  17 +++++-
 2 files changed, 100 insertions(+), 20 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 81eb8a9996..f0883308d3 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -34,6 +34,7 @@ on_failure: &on_failure
       - "**/*.log"
       - "**/*.diffs"
       - "**/regress_log_*"
+      - "**/*.stackdump"
     type: text/plain
 
 task:
@@ -338,13 +339,33 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh macos "${HOME}/cores"
 
 
+WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
+    env:
+      # Half the allowed per-user CPU cores
+      CPUS: 4
+      # The default working dir is in a directory msbuild complains about
+      CIRRUS_WORKING_DIR: "c:/cirrus"
+
+      # Avoids port conflicts between concurrent tap test runs
+      PG_TEST_USE_UNIX_SOCKETS: 1
+
+      # git's tar doesn't deal with drive letters, see
+      # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
+      TAR: "c:/windows/system32/tar.exe"
+
+    sysinfo_script: |
+      chcp
+      systeminfo
+      powershell -Command get-psdrive -psprovider filesystem
+      set
+
 task:
+  << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, VS 2019
 
-  env:
-    # Half the allowed per-user CPU cores
-    CPUS: 4
+  only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
 
+  env:
     # Our windows infrastructure doesn't have test concurrency above the level
     # of a single vcregress test target. Due to that, it's useful to run prove
     # with multiple jobs. For the other tasks it isn't, because two sources
@@ -354,15 +375,9 @@ task:
     # likely can be improved upon further.
     PROVE_FLAGS: -j10 --timer
 
-    # The default cirrus working dir is in a directory msbuild complains about
-    CIRRUS_WORKING_DIR: "c:/cirrus"
     # Avoid re-installing over and over
     NO_TEMP_INSTALL: 1
-    # git's tar doesn't deal with drive letters, see
-    # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
-    TAR: "c:/windows/system32/tar.exe"
-    # Avoids port conflicts between concurrent tap test runs
-    PG_TEST_USE_UNIX_SOCKETS: 1
+
     PG_REGRESS_SOCK_DIR: "c:/cirrus/"
     # -m enables parallelism
     # verbosity:minimal + Summary reduce verbosity, while keeping a summary of
@@ -386,19 +401,11 @@ task:
     # currently have a tool for that...
     CIRRUS_ESCAPING_PROCESSES: 1
 
-  only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
-
   windows_container:
     image: $CONTAINER_REPO/windows_ci_vs_2019:latest
     cpu: $CPUS
     memory: 4G
 
-  sysinfo_script: |
-    chcp
-    systeminfo
-    powershell -Command get-psdrive -psprovider filesystem
-    set
-
   setup_additional_packages_script: |
     REM choco install -y --no-progress ...
 
@@ -456,6 +463,66 @@ task:
       path: "crashlog-*.txt"
       type: text/plain
 
+task:
+  << : *WINDOWS_ENVIRONMENT_BASE
+  name: Windows - Server 2019, MinGW64
+  
+  only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-include:[^\n]*mingw.* || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw.*'
+
+  windows_container:
+    image: $CONTAINER_REPO/windows_ci_mingw64:latest
+    cpu: $CPUS
+    memory: 4G
+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    BUILD_DIR: "%CIRRUS_WORKING_DIR%/build"
+
+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  setup_additional_packages_script: |
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm ...
+
+  mingw_info_script:
+    - C:\msys64\usr\bin\dash.exe -lc "where gcc"
+    - C:\msys64\usr\bin\dash.exe -lc "gcc --version"
+    - C:\msys64\usr\bin\dash.exe -lc "where perl"
+    - C:\msys64\usr\bin\dash.exe -lc "perl --version"
+
+  configure_script:
+    # Try to configure with the cache file, and retry without if it fails, in case the flags changed.
+    - C:\msys64\usr\bin\dash.exe -lc "mkdir %BUILD_DIR% &&
+      cd %BUILD_DIR% && for i in 1 2; do
+      %CIRRUS_WORKING_DIR%/configure
+        --cache-file=${CCACHE_DIR}/configure.cache
+        --enable-cassert
+        --enable-debug
+        --enable-tap-tests
+        --with-icu
+        --with-libxml
+        --with-libxslt
+        --with-lz4
+        CC='ccache gcc'
+        CXX='ccache g++'
+        CFLAGS='-Og -ggdb -pipe'
+        CXXFLAGS='-Og -ggdb' && break;
+        rm -v ${CCACHE_DIR}/configure.cache;
+        done
+        "
+
+  build_script:
+    C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s world-bin -j${CPUS}"
+
+  upload_caches: ccache
+
+  tests_script:
+    - set "NoDefaultCurrentDirectoryInExePath=0"
+    - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
+
+  on_failure:
+    <<: *on_failure
+    cores_script:
+      - C:\tools\cygwin\bin\dash.exe --login -c "cd '%cd%' && src/tools/ci/cores_backtrace.sh msys ."
 
 task:
   name: CompilerWarnings
diff --git a/src/tools/ci/cores_backtrace.sh b/src/tools/ci/cores_backtrace.sh
index 28d3cecfc6..93e90f284e 100755
--- a/src/tools/ci/cores_backtrace.sh
+++ b/src/tools/ci/cores_backtrace.sh
@@ -10,11 +10,24 @@ directory=$2
 
 case $os in
     freebsd|linux|macos)
-    ;;
+        ;;
+
+    msys)
+        # XXX Evidently I don't know how to write two arguments here without pathname expansion later, other than eval.
+        #findargs='-name "*.stackdump"'
+        for corefile in $(find "$directory" -type f -name "*.stackdump") ; do
+            binary=`basename "$corefile" .stackdump`
+            echo;echo;
+            echo "dumping ${corefile} for ${binary}"
+            awk '/^0/{print $2}' $corefile |addr2line -f -i -e ./src/backend/postgres.exe
+        done
+        exit 0
+        ;;
+
     *)
         echo "unsupported operating system ${os}"
         exit 1
-    ;;
+        ;;
 esac
 
 first=1
-- 
2.25.1

#31Justin Pryzby
pryzby@telsasoft.com
In reply to: Melih Mutlu (#30)
2 attachment(s)
Re: Mingw task for Cirrus CI

On Sat, Sep 03, 2022 at 12:52:54AM +0300, Melih Mutlu wrote:

Justin Pryzby <pryzby@telsasoft.com>, 19 Ağu 2022 Cum, 05:34 tarihinde şunu yazdı:

Inline notes about changes since the last version.

On Thu, Jul 28, 2022 at 05:44:28PM -0500, Justin Pryzby wrote:

I think the "only_if" should allow separately running one but not both

of the

windows instances, like:

+ only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw64'

I'm not sure, but maybe this task should only run "by request", and omit the
first condition:

+ only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw64'

The patch shouldn't say this during development, or else cfbot doesn't run it..
Oops.

Actually, making MinGW task optional for now might make sense. Due to
windows resource limits on Cirrus CI and slow builds on Windows, adding
this task as non-optional may not be an efficient decision
I think that continuing with this patch by changing MinGW to optional for
now, instead of waiting for more resource on Cirrus or faster builds on
Windows, could be better. I don't see any harm.

I agree that maybe it should be optional if merged to postgres.

But cfbot should run the Mingw task for this patch's own commitfest
entry. But right now (because cfbot doesn't include the original commit
message/s), it doesn't get run :(

+ only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-include:[^\n]*mingw.* ||
$CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw.*'

Added this line to allow run only mingw task or run all tasks including
mingw.

What do you all think about this change? Does it make sense?

You're allowing to write "ci-os-include: mingw" to "opt-in" to the task,
without opting-out of all the other tasks (and without enumerating all
the tasks by writing "ci-os-only: mingw,windows,macos,freebsd,linux".
That makes sense, and the logic looks right. But that still has to be
commented during development to be run by cfbot.

Also, the first half was missing a closing quote.
https://cirrus-ci.com/build/5874178241855488

+ setup_additional_packages_script: |

+ REM C:\msys64\usr\bin\pacman.exe -S --noconfirm busybox

This should include choco, too.

Added pacman.exe line. Do we really need choco here? I don't think mingw
would require any package via choco.

I guess choco isn't needed.

Also is ending pacman.exe line with busybox intentional? I just added that
line with "..." at the end instead of any package name.

Yeah, the busybox part was unintentional.

for item in `find "$sourcetree" -name Makefile -print -o -name GNUmakefile -print | grep -v "$sourcetree/doc/src/sgml/images/"`; do
-    filename=`expr "$item" : "$sourcetree\(.*\)"`
-    if test ! -f "${item}.in"; then
-        if cmp "$item" "$buildtree/$filename" >/dev/null 2>&1; then : ; else
-            ln -fs "$item" "$buildtree/$filename" || exit 1
-        fi
-    fi
+    filename=${item#$sourcetree}
+    [ -e "$buildtree/$filename" ] && continue

I fixed this to check for ".in" files as intended.

It'd be a lot better if the image didn't take so long to start. :(

One question would be that should this patch include "prep_buildtree"? It
doesn't seem to me like it's directly related to adding MinGW into CI but
more like an improvement for builds on Windows.
Maybe we can make it a seperate patch if it's necessary.

I don't know what direction that idea is going, but it makes working
with this patch a bit easier when configure is less slow. Fine with me
to split it into a separate patch :)

Sharing a new version of the patch. It also moves the above line so that it
will apply to mingw task too. Otherwise mingw task was failing.

I saw that but hadn't tracked it down yet. Do you know if the tar
failures were from a TAP test added since you first posted the mingw
patch, or ??

Also: your original patch said --host=x86_64-w64-mingw32, but the task
is called MinGW64. The most recent patches don't use --host at all, and
were building for a 32 bit environment, even though the OS image says
MSYSTEM=UCRT64.

Also: right now src/test and src/interfaces/*/test aren't being built
during the build phase, which means that they're 1) not compiled in
parallel; and 2) not cached. This isn't specific to MinGW. Other than
compiling those dirs specifically, one option is to put
"always: upload_caches: ccache" after "test_world_script" (in that case,
if the CI instance is rescheduled during tests, the compilation won't be
pushed to cache). Actually, it seems better to compile stuff during
"build" or else any compilation warnings should up in the middle of
"check-world.."

Also: I'm having second thoughts about the loop around ./configure. It
could happen that a cached configure would succeed, but then the build
would later fail, and it wouldn't fix itself. I think a slow configure
is okay for an "opt-in" task.

Also: my backtrace call was using a path to cygwin rather than msys.
This seemed to work before, but doesn't seem to be working now...

--
Justin

Attachments:

0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchtext/x-diff; charset=us-asciiDownload
From 94023eb23329eb53cb0b164487afb85925e89c51 Mon Sep 17 00:00:00 2001
From: Melih Mutlu <m.melihmutlu@gmail.com>
Date: Fri, 2 Sep 2022 23:10:02 +0300
Subject: [PATCH 1/2] Added Windows with MinGW environment in Cirrus CI

CI task on Windows Server with MinGW has been added as optional.
---
 .cirrus.yml                     | 103 ++++++++++++++++++++++++++------
 src/tools/ci/cores_backtrace.sh |  17 +++++-
 2 files changed, 100 insertions(+), 20 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index a9193c2c34f..60f9ae2b65c 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -34,6 +34,7 @@ on_failure: &on_failure
       - "**/*.log"
       - "**/*.diffs"
       - "**/regress_log_*"
+      - "**/*.stackdump"
     type: text/plain
 
 task:
@@ -339,13 +340,33 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh macos "${HOME}/cores"
 
 
+WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
+    env:
+      # Half the allowed per-user CPU cores
+      CPUS: 4
+      # The default working dir is in a directory msbuild complains about
+      CIRRUS_WORKING_DIR: "c:/cirrus"
+
+      # Avoids port conflicts between concurrent tap test runs
+      PG_TEST_USE_UNIX_SOCKETS: 1
+
+      # git's tar doesn't deal with drive letters, see
+      # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
+      TAR: "c:/windows/system32/tar.exe"
+
+    sysinfo_script: |
+      chcp
+      systeminfo
+      powershell -Command get-psdrive -psprovider filesystem
+      set
+
 task:
+  << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, VS 2019
 
-  env:
-    # Half the allowed per-user CPU cores
-    CPUS: 4
+  only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
 
+  env:
     # Our windows infrastructure doesn't have test concurrency above the level
     # of a single vcregress test target. Due to that, it's useful to run prove
     # with multiple jobs. For the other tasks it isn't, because two sources
@@ -355,15 +376,9 @@ task:
     # likely can be improved upon further.
     PROVE_FLAGS: -j10 --timer
 
-    # The default cirrus working dir is in a directory msbuild complains about
-    CIRRUS_WORKING_DIR: "c:/cirrus"
     # Avoid re-installing over and over
     NO_TEMP_INSTALL: 1
-    # git's tar doesn't deal with drive letters, see
-    # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
-    TAR: "c:/windows/system32/tar.exe"
-    # Avoids port conflicts between concurrent tap test runs
-    PG_TEST_USE_UNIX_SOCKETS: 1
+
     PG_REGRESS_SOCK_DIR: "c:/cirrus/"
     # -m enables parallelism
     # verbosity:minimal + Summary reduce verbosity, while keeping a summary of
@@ -387,8 +402,6 @@ task:
     # currently have a tool for that...
     CIRRUS_ESCAPING_PROCESSES: 1
 
-  only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
-
   windows_container:
     #image: $CONTAINER_REPO/windows_ci_vs_2019:latest
     #image: cirrusci/windowsservercore:visualstudio2019-2021.12.07
@@ -398,12 +411,6 @@ task:
     cpu: $CPUS
     memory: 4G
 
-  sysinfo_script: |
-    chcp
-    systeminfo
-    powershell -Command get-psdrive -psprovider filesystem
-    set
-
   setup_additional_packages_script: |
     REM 3min
     REM choco install -y --no-progress --version=1.0.0 visualstudio2022-workload-vctools --install-args="--add Microsoft.VisualStudio.Component.VC.CLI.Support"
@@ -475,6 +482,66 @@ task:
       path: "crashlog-*.txt"
       type: text/plain
 
+task:
+  << : *WINDOWS_ENVIRONMENT_BASE
+  name: Windows - Server 2019, MinGW64
+  
+  only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-include:[^\n]*mingw.* || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw.*'
+
+  windows_container:
+    image: $CONTAINER_REPO/windows_ci_mingw64:latest
+    cpu: $CPUS
+    memory: 4G
+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    BUILD_DIR: "%CIRRUS_WORKING_DIR%/build"
+
+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  setup_additional_packages_script: |
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm ...
+
+  mingw_info_script:
+    - C:\msys64\usr\bin\dash.exe -lc "where gcc"
+    - C:\msys64\usr\bin\dash.exe -lc "gcc --version"
+    - C:\msys64\usr\bin\dash.exe -lc "where perl"
+    - C:\msys64\usr\bin\dash.exe -lc "perl --version"
+
+  configure_script:
+    # Try to configure with the cache file, and retry without if it fails, in case the flags changed.
+    - C:\msys64\usr\bin\dash.exe -lc "mkdir %BUILD_DIR% &&
+      cd %BUILD_DIR% && for i in 1 2; do
+      %CIRRUS_WORKING_DIR%/configure
+        --cache-file=${CCACHE_DIR}/configure.cache
+        --enable-cassert
+        --enable-debug
+        --enable-tap-tests
+        --with-icu
+        --with-libxml
+        --with-libxslt
+        --with-lz4
+        CC='ccache gcc'
+        CXX='ccache g++'
+        CFLAGS='-Og -ggdb -pipe'
+        CXXFLAGS='-Og -ggdb' && break;
+        rm -v ${CCACHE_DIR}/configure.cache;
+        done
+        "
+
+  build_script:
+    C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s world-bin -j${CPUS}"
+
+  upload_caches: ccache
+
+  tests_script:
+    - set "NoDefaultCurrentDirectoryInExePath=0"
+    - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
+
+  on_failure:
+    <<: *on_failure
+    cores_script:
+      - C:\tools\cygwin\bin\dash.exe --login -c "cd '%cd%' && src/tools/ci/cores_backtrace.sh msys ."
 
 task:
   name: CompilerWarnings
diff --git a/src/tools/ci/cores_backtrace.sh b/src/tools/ci/cores_backtrace.sh
index 28d3cecfc67..93e90f284e6 100755
--- a/src/tools/ci/cores_backtrace.sh
+++ b/src/tools/ci/cores_backtrace.sh
@@ -10,11 +10,24 @@ directory=$2
 
 case $os in
     freebsd|linux|macos)
-    ;;
+        ;;
+
+    msys)
+        # XXX Evidently I don't know how to write two arguments here without pathname expansion later, other than eval.
+        #findargs='-name "*.stackdump"'
+        for corefile in $(find "$directory" -type f -name "*.stackdump") ; do
+            binary=`basename "$corefile" .stackdump`
+            echo;echo;
+            echo "dumping ${corefile} for ${binary}"
+            awk '/^0/{print $2}' $corefile |addr2line -f -i -e ./src/backend/postgres.exe
+        done
+        exit 0
+        ;;
+
     *)
         echo "unsupported operating system ${os}"
         exit 1
-    ;;
+        ;;
 esac
 
 first=1
-- 
2.17.1

0002-f.patchtext/x-diff; charset=us-asciiDownload
From 794874a6f0845f3d3a53613e1a6cf326f7ae83f9 Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Thu, 28 Jul 2022 10:57:26 -0500
Subject: [PATCH 2/2] f!

ci-os-only: mingw
---
 .cirrus.yml           | 14 ++++++++++----
 config/prep_buildtree | 20 ++++++++------------
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 60f9ae2b65c..f7cd6de93d1 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -486,7 +486,8 @@ task:
   << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, MinGW64
   
-  only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-include:[^\n]*mingw.* || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw.*'
+  #XXX only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-include:[^\n]*mingw.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw.*'
+  only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-include:[^\n]*mingw.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw.*'
 
   windows_container:
     image: $CONTAINER_REPO/windows_ci_mingw64:latest
@@ -517,6 +518,7 @@ task:
         --enable-cassert
         --enable-debug
         --enable-tap-tests
+        --host=x86_64-w64-mingw64
         --with-icu
         --with-libxml
         --with-libxslt
@@ -530,18 +532,22 @@ task:
         "
 
   build_script:
-    C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s world-bin -j${CPUS}"
+    - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s -j${CPUS} world-bin"
+    - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s -j${CPUS} -C src/test"
+    - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s -j${CPUS} -C src/interfaces/ecpg/test"
+    - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s -j${CPUS} -C src/interfaces/libpq/test"
 
   upload_caches: ccache
 
-  tests_script:
+  test_world_script:
     - set "NoDefaultCurrentDirectoryInExePath=0"
     - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
 
   on_failure:
     <<: *on_failure
     cores_script:
-      - C:\tools\cygwin\bin\dash.exe --login -c "cd '%cd%' && src/tools/ci/cores_backtrace.sh msys ."
+      - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% src/tools/ci/cores_backtrace.sh msys %BUILD_DIR%/tmp_install"
+
 
 task:
   name: CompilerWarnings
diff --git a/config/prep_buildtree b/config/prep_buildtree
index a0eabd3dee2..97bf65967f1 100644
--- a/config/prep_buildtree
+++ b/config/prep_buildtree
@@ -26,20 +26,16 @@ buildtree=`cd ${2:-'.'} && pwd`
 # If we did, it would interfere with installation of prebuilt docs from
 # the source tree, if a VPATH build is done from a distribution tarball.
 # See bug #5595.
-for item in `find "$sourcetree" -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) | grep -v "$sourcetree/doc/src/sgml/\+"`; do
-    subdir=`expr "$item" : "$sourcetree\(.*\)"`
-    if test ! -d "$buildtree/$subdir"; then
-        mkdir -p "$buildtree/$subdir" || exit 1
-    fi
-done
+( cd "$sourcetree" && find . -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) |grep -v "doc/src/sgml/\+" ) |
+	( cd "$buildtree" && xargs mkdir -p )
 
 for item in `find "$sourcetree" -name Makefile -print -o -name GNUmakefile -print | grep -v "$sourcetree/doc/src/sgml/images/"`; do
-    filename=`expr "$item" : "$sourcetree\(.*\)"`
-    if test ! -f "${item}.in"; then
-        if cmp "$item" "$buildtree/$filename" >/dev/null 2>&1; then : ; else
-            ln -fs "$item" "$buildtree/$filename" || exit 1
-        fi
-    fi
+    [ -e "$item.in" ] && echo "skipping: $item" &&
+        continue
+
+    filename=${item#$sourcetree}
+    cmp "$item" "$buildtree/$filename" >/dev/null 2>&1 ||
+        ln -fs "$item" "$buildtree/$filename"
 done
 
 exit 0
-- 
2.17.1

#32Andres Freund
andres@anarazel.de
In reply to: Justin Pryzby (#31)
Re: Mingw task for Cirrus CI

Hi,

On 2022-09-05 06:50:55 -0500, Justin Pryzby wrote:

I saw that but hadn't tracked it down yet. Do you know if the tar
failures were from a TAP test added since you first posted the mingw
patch, or ??

I think it's that msys now includes tar by default, but not sure.

Also: your original patch said --host=x86_64-w64-mingw32, but the task
is called MinGW64. The most recent patches don't use --host at all, and
were building for a 32 bit environment, even though the OS image says
MSYSTEM=UCRT64.

I don't think you should need to use --host, that indicates cross compiling,
which we shouldn't do. I don't think the patch without --host targets 32bit -
the last time CI ran the patch, it built a 64bit PG:

https://cirrus-ci.com/task/5489471041830912?logs=configure#L231
[13:47:54.539] checking size of void *... (cached) 8
[13:47:54.557] checking size of size_t... (cached) 8

and the underlying commit didn't specify --host.

Also: right now src/test and src/interfaces/*/test aren't being built
during the build phase, which means that they're 1) not compiled in
parallel; and 2) not cached. This isn't specific to MinGW. Other than
compiling those dirs specifically, one option is to put
"always: upload_caches: ccache" after "test_world_script" (in that case,
if the CI instance is rescheduled during tests, the compilation won't be
pushed to cache). Actually, it seems better to compile stuff during
"build" or else any compilation warnings should up in the middle of
"check-world.."

I'd tackle that independently of this commit.

Also: I'm having second thoughts about the loop around ./configure. It
could happen that a cached configure would succeed, but then the build
would later fail, and it wouldn't fix itself. I think a slow configure
is okay for an "opt-in" task.

Agreed.

I think we can convert this to meson soon, and that seems a *lot* faster at
configure than autoconf on mingw. Not even close to as fast as on a modern-ish
linux, but not that painful.

Greetings,

Andres Freund

#33Justin Pryzby
pryzby@telsasoft.com
In reply to: Andres Freund (#32)
Re: Mingw task for Cirrus CI

On Mon, Sep 05, 2022 at 04:52:17PM -0700, Andres Freund wrote:

I don't think you should need to use --host, that indicates cross compiling,

This made me consider the idea of cross-compiling for windows under a
new linux task, and then running tests under Windows with a dependent
task. I suppose that use -Og, in addition to CompilerWarnings, which
uses -O2.

cirrusci caches are (or can be) shared between tasks. I got this mostly
working, with a few kludges to compile and install stuff under src/test.
This may be yet another idea that's obsoleted by meson. WDYT?

--
Justin

#34Melih Mutlu
m.melihmutlu@gmail.com
In reply to: Justin Pryzby (#31)
Re: Mingw task for Cirrus CI

Hi hackers,

Justin Pryzby <pryzby@telsasoft.com>, 5 Eyl 2022 Pzt, 14:50 tarihinde şunu
yazdı:

But cfbot should run the Mingw task for this patch's own commitfest
entry. But right now (because cfbot doesn't include the original commit
message/s), it doesn't get run :(

I've been thinking about how to make the mingw task run only for this patch
on cfbot and not for others. TBH, I couldn't come up with a nice way to
achieve this.

Does anyone have any suggestions on this?

Andres Freund <andres@anarazel.de>, 6 Eyl 2022 Sal, 02:52 tarihinde şunu
yazdı:

Hi,

On 2022-09-05 06:50:55 -0500, Justin Pryzby wrote:

I saw that but hadn't tracked it down yet. Do you know if the tar
failures were from a TAP test added since you first posted the mingw
patch, or ??

I think it's that msys now includes tar by default, but not sure.

Seems like msys2 comes with GNU tar now. Previously it was bsd tar under
"/c/Windows/System32/tar.exe " which now we force it to use.

Thanks,
Melih

#35Andres Freund
andres@anarazel.de
In reply to: Melih Mutlu (#34)
Re: Mingw task for Cirrus CI

Hi,

On 2022-09-21 16:18:43 +0300, Melih Mutlu wrote:

I've been thinking about how to make the mingw task run only for this patch
on cfbot and not for others. TBH, I couldn't come up with a nice way to
achieve this.

Does anyone have any suggestions on this?

Add a commented-out trigger-type: manual and note in the commit message that
the committer needs to adjust that piece.

Greetings,

Andres Freund

#36Andres Freund
andres@anarazel.de
In reply to: Andres Freund (#32)
Re: Mingw task for Cirrus CI

Hi Melih,

On 2022-09-05 16:52:17 -0700, Andres Freund wrote:

I think we can convert this to meson soon, and that seems a *lot* faster at
configure than autoconf on mingw. Not even close to as fast as on a modern-ish
linux, but not that painful.

Now that meson has been merged, could you try to adjust this patch so it
builds with meson?

Regards,

Andres

#37Melih Mutlu
m.melihmutlu@gmail.com
In reply to: Andres Freund (#36)
1 attachment(s)
Re: Mingw task for Cirrus CI

Hi hackers.

Andres Freund <andres@anarazel.de>, 22 Eyl 2022 Per, 20:03 tarihinde şunu
yazdı:

Now that meson has been merged, could you try to adjust this patch so it
builds with meson?

Attached patch is the adjusted version to build with meson.

Add a commented-out trigger-type: manual and note in the commit message that

the committer needs to adjust that piece.

Done.

Also: your original patch said --host=x86_64-w64-mingw32, but the task

is called MinGW64. The most recent patches don't use --host at all, and
were building for a 32 bit environment, even though the OS image says
MSYSTEM=UCRT64.

I don't think you should need to use --host, that indicates cross
compiling,
which we shouldn't do. I don't think the patch without --host targets
32bit -
the last time CI ran the patch, it built a 64bit PG:

Also removed this with meson changes. Can confirm that it builds 64bit.

Justin Pryzby <pryzby@telsasoft.com>, 5 Eyl 2022 Pzt, 14:50 tarihinde şunu
yazdı:

I don't know what direction that idea is going, but it makes working
with this patch a bit easier when configure is less slow. Fine with me
to split it into a separate patch :)

If it's okay, then I would suggest not including that piece into this patch
since I don't know what direction this is going either.

The patch has been changed quite a bit due to meson integration.
I would appreciate any feedback.

Best,
Melih

Attachments:

v6-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchapplication/octet-stream; name=v6-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchDownload
From 7e9784adaa7819a63d57a8e38814c58b430c1ada Mon Sep 17 00:00:00 2001
From: Melih Mutlu <m.melihmutlu@gmail.com>
Date: Fri, 2 Sep 2022 23:10:02 +0300
Subject: [PATCH] Added Windows with MinGW environment in Cirrus CI

CI task on Windows Server with MinGW has been added as optional.

Note that trigger_type line for MinGW task has to be uncommented before
merge
---
 .cirrus.yml                     | 97 +++++++++++++++++++++++++--------
 src/tools/ci/cores_backtrace.sh | 17 +++++-
 2 files changed, 90 insertions(+), 24 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 9f2282471a..7e6ebdf7b7 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -35,6 +35,7 @@ on_failure_ac: &on_failure_ac
       - "**/*.log"
       - "**/*.diffs"
       - "**/regress_log_*"
+      - "**/*.stackdump"
     type: text/plain
 
 on_failure_meson: &on_failure_meson
@@ -393,24 +394,37 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh macos "${HOME}/cores"
 
 
+WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
+    env:
+      # Half the allowed per-user CPU cores
+      CPUS: 4
+      TEST_JOBS: 4 # wild guess, data based value welcome
+
+      # The default working dir is in a directory msbuild complains about
+      CIRRUS_WORKING_DIR: "c:/cirrus"
+
+      PG_REGRESS_SOCK_DIR: "c:/cirrus/"
+
+      # Avoids port conflicts between concurrent tap test runs
+      PG_TEST_USE_UNIX_SOCKETS: 1
+
+      # git's tar doesn't deal with drive letters, see
+      # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
+      TAR: "c:/windows/system32/tar.exe"
+
+    sysinfo_script: |
+      chcp
+      systeminfo
+      powershell -Command get-psdrive -psprovider filesystem
+      set
+
 task:
   name: Windows - Server 2019, VS 2019 - Meson & ninja
+  << : *WINDOWS_ENVIRONMENT_BASE
 
   env:
-    # Half the allowed per-user CPU cores
-    CPUS: 4
-    TEST_JOBS: 8 # wild guess, data based value welcome
-
-    # The default cirrus working dir is in a directory msbuild complains about
-    CIRRUS_WORKING_DIR: "c:/cirrus"
     # Avoid re-installing over and over
     NO_TEMP_INSTALL: 1
-    # git's tar doesn't deal with drive letters, see
-    # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
-    TAR: "c:/windows/system32/tar.exe"
-    # Avoids port conflicts between concurrent tap test runs
-    PG_TEST_USE_UNIX_SOCKETS: 1
-    PG_REGRESS_SOCK_DIR: "c:/cirrus/"
 
     # startcreate_script starts a postgres instance that we don't want to get
     # killed at the end of that script (it's stopped in stop_script). Can't
@@ -435,34 +449,73 @@ task:
     cpu: $CPUS
     memory: 4G
 
-  sysinfo_script: |
-    chcp
-    systeminfo
-    powershell -Command get-psdrive -psprovider filesystem
-    set
-
   setup_additional_packages_script: |
     REM choco install -y --no-progress ...
-
   # Use /DEBUG:FASTLINK to avoid high memory usage during linking
   configure_script: |
     vcvarsall x64
-    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
+    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
 
   build_script: |
     vcvarsall x64
     ninja -C build
-
   check_world_script: |
     vcvarsall x64
     meson test %MTEST_ARGS% --num-processes %TEST_JOBS%
-
   on_failure:
     <<: *on_failure_meson
     crashlog_artifacts:
       path: "crashlog-*.txt"
       type: text/plain
 
+task:
+  << : *WINDOWS_ENVIRONMENT_BASE
+  name: Windows - Server 2019, MinGW64 - Meson
+
+  # This task needs to be triggered manually on Cirrus CI.
+  # Otherwise it will not run and be shown as paused
+  # XXX: Below line needs to be uncommented before merge. It's commented for now so that cfbot can run it
+  #trigger_type: manual
+
+  windows_container:
+    image: $CONTAINER_REPO/windows_ci_mingw64:latest
+    cpu: $CPUS
+    memory: 4G
+
+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    BUILD_DIR: "%CIRRUS_WORKING_DIR%/build"
+    PYTHONHOME: C:/msys64/ucrt64
+
+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  setup_additional_packages_script: |
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm ...
+
+  mingw_info_script:
+    - C:\msys64\usr\bin\dash.exe -lc "where gcc"
+    - C:\msys64\usr\bin\dash.exe -lc "gcc --version"
+    - C:\msys64\usr\bin\dash.exe -lc "where perl"
+    - C:\msys64\usr\bin\dash.exe -lc "perl --version"
+
+  configure_script:
+    - C:\msys64\usr\bin\dash.exe -lc "cd %CIRRUS_WORKING_DIR% &&
+      meson setup --buildtype debug -Dcassert=true -Db_pch=true -DTAR=%TAR% build"
+
+  build_script:
+    - C:\msys64\usr\bin\dash.exe -lc "cd %CIRRUS_WORKING_DIR% && ninja -C %BUILD_DIR%"
+
+  upload_caches: ccache
+
+  test_world_script:
+    - C:\msys64\usr\bin\dash.exe -lc "cd %CIRRUS_WORKING_DIR% && meson test --print-errorlogs --num-processes %TEST_JOBS% -C %BUILD_DIR%"
+
+  on_failure:
+    <<: *on_failure_meson
+    cores_script:
+      - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% src/tools/ci/cores_backtrace.sh msys %BUILD_DIR%/tmp_install"
+
 
 task:
   name: CompilerWarnings
diff --git a/src/tools/ci/cores_backtrace.sh b/src/tools/ci/cores_backtrace.sh
index 28d3cecfc6..93e90f284e 100755
--- a/src/tools/ci/cores_backtrace.sh
+++ b/src/tools/ci/cores_backtrace.sh
@@ -10,11 +10,24 @@ directory=$2
 
 case $os in
     freebsd|linux|macos)
-    ;;
+        ;;
+
+    msys)
+        # XXX Evidently I don't know how to write two arguments here without pathname expansion later, other than eval.
+        #findargs='-name "*.stackdump"'
+        for corefile in $(find "$directory" -type f -name "*.stackdump") ; do
+            binary=`basename "$corefile" .stackdump`
+            echo;echo;
+            echo "dumping ${corefile} for ${binary}"
+            awk '/^0/{print $2}' $corefile |addr2line -f -i -e ./src/backend/postgres.exe
+        done
+        exit 0
+        ;;
+
     *)
         echo "unsupported operating system ${os}"
         exit 1
-    ;;
+        ;;
 esac
 
 first=1
-- 
2.25.1

#38Andres Freund
andres@anarazel.de
In reply to: Melih Mutlu (#37)
Re: Mingw task for Cirrus CI

Hi,

On 2022-10-07 20:00:56 +0300, Melih Mutlu wrote:

Attached patch is the adjusted version to build with meson.

Thanks!

diff --git a/.cirrus.yml b/.cirrus.yml
index 9f2282471a..7e6ebdf7b7 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -35,6 +35,7 @@ on_failure_ac: &on_failure_ac
- "**/*.log"
- "**/*.diffs"
- "**/regress_log_*"
+      - "**/*.stackdump"
type: text/plain

I think it might be easier to just set MSYS=winjitdebug
https://www.msys2.org/wiki/JIT-Debugging/#native-windows-processes-started-from-msys2
and then rely on the existing windows crash reporting stuff.

setup_additional_packages_script: |
REM choco install -y --no-progress ...
-
# Use /DEBUG:FASTLINK to avoid high memory usage during linking
configure_script: |

You removed a bunch of newlines here and nearby - I assume that wasn't
intentional?

+  mingw_info_script:
+    - C:\msys64\usr\bin\dash.exe -lc "where gcc"
+    - C:\msys64\usr\bin\dash.exe -lc "gcc --version"
+    - C:\msys64\usr\bin\dash.exe -lc "where perl"
+    - C:\msys64\usr\bin\dash.exe -lc "perl --version"
+
+  configure_script:
+    - C:\msys64\usr\bin\dash.exe -lc "cd %CIRRUS_WORKING_DIR% &&
+      meson setup --buildtype debug -Dcassert=true -Db_pch=true -DTAR=%TAR% build"

There's no need to use dash anymore, the amount of shell script run is
minimal.

+  build_script:
+    - C:\msys64\usr\bin\dash.exe -lc "cd %CIRRUS_WORKING_DIR% && ninja -C %BUILD_DIR%"
+  upload_caches: ccache
+
+  test_world_script:
+    - C:\msys64\usr\bin\dash.exe -lc "cd %CIRRUS_WORKING_DIR% && meson test --print-errorlogs --num-processes %TEST_JOBS% -C %BUILD_DIR%"
+

I think the "cd"s here are superfluous given the ninja -C %BUILD_DIR% etc.

Greetings,

Andres Freund

#39Andres Freund
andres@anarazel.de
In reply to: Andres Freund (#38)
Re: Mingw task for Cirrus CI

Hi,

On 2022-10-11 11:23:36 -0700, Andres Freund wrote:

+  build_script:
+    - C:\msys64\usr\bin\dash.exe -lc "cd %CIRRUS_WORKING_DIR% && ninja -C %BUILD_DIR%"
+  upload_caches: ccache

Only remembered that just after sending my email: When using b_pch=true (which
saves a lot of time on mingw) ccache won't cache much (IIRC just the pch files
themselves) unless you do something like
export CCACHE_SLOPPINESS=pch_defines,time_macros

$ ccache -z -C
Clearing... 100.0% [==============================================================================]

$ ninja clean && ccache -z && CCACHE_SLOPPINESS= time ninja src/bin/pg_test_fsync/pg_test_fsync.exe && ccache -s
[2/2] Cleaning
Cleaning... 200 files.
Statistics zeroed
[124/124] Linking target src/bin/pg_test_fsync/pg_test_fsync.exe
0.00user 0.01system 0:07.60elapsed 0%CPU (0avgtext+0avgdata 4936maxresident)k
0inputs+0outputs (1314major+0minor)pagefaults 0swaps
Summary:
Hits: 0 / 1 (0.00 %)
Direct: 0 / 1 (0.00 %)
Preprocessed: 0 / 1 (0.00 %)
Misses: 1
Direct: 1
Preprocessed: 1
Uncacheable: 110

As you can see, most of the files are determined to be unachable. The build
took 7.6s.

$ ninja clean && ccache -z && CCACHE_SLOPPINESS=pch_defines,time_macros time ninja src/bin/pg_test_fsync/pg_test_fsync.exe && ccache -s
[2/2] Cleaning
Cleaning... 200 files.
Statistics zeroed
[124/124] Linking target src/bin/pg_test_fsync/pg_test_fsync.exe
0.00user 0.01system 0:09.91elapsed 0%CPU (0avgtext+0avgdata 4936maxresident)k
0inputs+0outputs (1313major+0minor)pagefaults 0swaps
Summary:
Hits: 0 / 111 (0.00 %)
Direct: 0 / 111 (0.00 %)
Preprocessed: 0 / 111 (0.00 %)
Misses: 111
Direct: 111
Preprocessed: 111
Primary storage:
Hits: 0 / 216 (0.00 %)
Misses: 216
Cache size (GB): 0.05 / 5.00 (0.98 %)

Files are cachable, but are cache misses (because we cleaned the cache
above). The build took 9.91s.

$ ninja clean && ccache -z && CCACHE_SLOPPINESS=pch_defines,time_macros time ninja src/bin/pg_test_fsync/pg_test_fsync.exe && ccache -s
[2/2] Cleaning
Cleaning... 200 files.
Statistics zeroed
[124/124] Linking target src/bin/pg_test_fsync/pg_test_fsync.exe
0.00user 0.01system 0:02.40elapsed 0%CPU (0avgtext+0avgdata 4936maxresident)k
0inputs+0outputs (1314major+0minor)pagefaults 0swaps
Summary:
Hits: 111 / 111 (100.0 %)
Direct: 111 / 111 (100.0 %)
Preprocessed: 0 / 0
Misses: 0
Direct: 0
Preprocessed: 0
Primary storage:
Hits: 222 / 222 (100.0 %)
Misses: 0
Cache size (GB): 0.05 / 5.00 (0.98 %)

Files are cachable, and hit the cache. The build takes 2.4s.

Using ccache's depend mode reduce the cache-miss case to 7.51s and the cache
hit case to 1.75s. So we should likely export CCACHE_DEPEND=1 as well.

Greetings,

Andres Freund

#40Melih Mutlu
m.melihmutlu@gmail.com
In reply to: Andres Freund (#39)
1 attachment(s)
Re: Mingw task for Cirrus CI

Hi Andres,

Andres Freund <andres@anarazel.de>, 11 Eki 2022 Sal, 21:23 tarihinde şunu
yazdı:

I think it might be easier to just set MSYS=winjitdebug

https://www.msys2.org/wiki/JIT-Debugging/#native-windows-processes-started-from-msys2
and then rely on the existing windows crash reporting stuff.

Done.

You removed a bunch of newlines here and nearby - I assume that wasn't
intentional?

Yes, that was my mistake. Thanks for pointing it out. Fixed.

There's no need to use dash anymore, the amount of shell script run is
minimal.

Switched back to bash.

I think the "cd"s here are superfluous given the ninja -C %BUILD_DIR% etc.

You're right. Those were needed when it was building with autoconf. Not
anymore. Removed.

Only remembered that just after sending my email: When using b_pch=true

(which
saves a lot of time on mingw) ccache won't cache much (IIRC just the pch
files
themselves) unless you do something like
export CCACHE_SLOPPINESS=pch_defines,time_macros

Added CCACHE_SLOPPINESS and CCACHE_SLOPPINESS variables.

You can find the updated patch attached.

Best,
Melih

Attachments:

v7-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchapplication/octet-stream; name=v7-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchDownload
From 00928e9a8df84fc878c1643ca029bf0dce3cd529 Mon Sep 17 00:00:00 2001
From: Melih Mutlu <m.melihmutlu@gmail.com>
Date: Fri, 2 Sep 2022 23:10:02 +0300
Subject: [PATCH] Added Windows with MinGW environment in Cirrus CI

CI task on Windows Server with MinGW has been added as optional.

Note that trigger_type line for MinGW task has to be uncommented before
merge
---
 .cirrus.yml                     | 96 ++++++++++++++++++++++++++-------
 src/tools/ci/cores_backtrace.sh | 17 +++++-
 2 files changed, 92 insertions(+), 21 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 9f2282471a..eae6803970 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -393,24 +393,37 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh macos "${HOME}/cores"
 
 
+WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
+    env:
+      # Half the allowed per-user CPU cores
+      CPUS: 4
+      TEST_JOBS: 4 # wild guess, data based value welcome
+
+      # The default working dir is in a directory msbuild complains about
+      CIRRUS_WORKING_DIR: "c:/cirrus"
+
+      PG_REGRESS_SOCK_DIR: "c:/cirrus/"
+
+      # Avoids port conflicts between concurrent tap test runs
+      PG_TEST_USE_UNIX_SOCKETS: 1
+
+      # git's tar doesn't deal with drive letters, see
+      # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
+      TAR: "c:/windows/system32/tar.exe"
+
+    sysinfo_script: |
+      chcp
+      systeminfo
+      powershell -Command get-psdrive -psprovider filesystem
+      set
+
 task:
   name: Windows - Server 2019, VS 2019 - Meson & ninja
+  << : *WINDOWS_ENVIRONMENT_BASE
 
   env:
-    # Half the allowed per-user CPU cores
-    CPUS: 4
-    TEST_JOBS: 8 # wild guess, data based value welcome
-
-    # The default cirrus working dir is in a directory msbuild complains about
-    CIRRUS_WORKING_DIR: "c:/cirrus"
     # Avoid re-installing over and over
     NO_TEMP_INSTALL: 1
-    # git's tar doesn't deal with drive letters, see
-    # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
-    TAR: "c:/windows/system32/tar.exe"
-    # Avoids port conflicts between concurrent tap test runs
-    PG_TEST_USE_UNIX_SOCKETS: 1
-    PG_REGRESS_SOCK_DIR: "c:/cirrus/"
 
     # startcreate_script starts a postgres instance that we don't want to get
     # killed at the end of that script (it's stopped in stop_script). Can't
@@ -435,19 +448,13 @@ task:
     cpu: $CPUS
     memory: 4G
 
-  sysinfo_script: |
-    chcp
-    systeminfo
-    powershell -Command get-psdrive -psprovider filesystem
-    set
-
   setup_additional_packages_script: |
     REM choco install -y --no-progress ...
 
   # Use /DEBUG:FASTLINK to avoid high memory usage during linking
   configure_script: |
     vcvarsall x64
-    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
+    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
 
   build_script: |
     vcvarsall x64
@@ -463,6 +470,57 @@ task:
       path: "crashlog-*.txt"
       type: text/plain
 
+task:
+  << : *WINDOWS_ENVIRONMENT_BASE
+  name: Windows - Server 2019, MinGW64 - Meson
+
+  # This task needs to be triggered manually on Cirrus CI.
+  # Otherwise it will not run and be shown as paused
+  # XXX: Below line needs to be uncommented before merge. It's commented for now so that cfbot can run it
+  #trigger_type: manual
+
+  windows_container:
+    image: $CONTAINER_REPO/windows_ci_mingw64:latest
+    cpu: $CPUS
+    memory: 4G
+
+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    BUILD_DIR: "%CIRRUS_WORKING_DIR%/build"
+    PYTHONHOME: C:/msys64/ucrt64
+    MSYS: winjitdebug
+    CCACHE_SLOPPINESS: pch_defines,time_macros
+    CCACHE_DEPEND: 1
+
+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  setup_additional_packages_script: |
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm ...
+
+  mingw_info_script:
+    - C:\msys64\usr\bin\bash.exe -lc "where gcc"
+    - C:\msys64\usr\bin\bash.exe -lc "gcc --version"
+    - C:\msys64\usr\bin\bash.exe -lc "where perl"
+    - C:\msys64\usr\bin\bash.exe -lc "perl --version"
+
+  configure_script:
+    - C:\msys64\usr\bin\bash.exe -lc "cd %CIRRUS_WORKING_DIR% &&
+      meson setup --buildtype debug -Dcassert=true -Db_pch=true -DTAR=%TAR% build"
+
+  build_script:
+    - C:\msys64\usr\bin\bash.exe -lc "cd %CIRRUS_WORKING_DIR% && ninja -C %BUILD_DIR%"
+
+  upload_caches: ccache
+
+  test_world_script:
+    - C:\msys64\usr\bin\bash.exe -lc "meson test --print-errorlogs --num-processes %TEST_JOBS% -C %BUILD_DIR%"
+
+  on_failure:
+    <<: *on_failure_meson
+    cores_script:
+      - C:\msys64\usr\bin\bash.exe -lc "cd %BUILD_DIR% src/tools/ci/cores_backtrace.sh msys %BUILD_DIR%/tmp_install"
+
 
 task:
   name: CompilerWarnings
diff --git a/src/tools/ci/cores_backtrace.sh b/src/tools/ci/cores_backtrace.sh
index 28d3cecfc6..93e90f284e 100755
--- a/src/tools/ci/cores_backtrace.sh
+++ b/src/tools/ci/cores_backtrace.sh
@@ -10,11 +10,24 @@ directory=$2
 
 case $os in
     freebsd|linux|macos)
-    ;;
+        ;;
+
+    msys)
+        # XXX Evidently I don't know how to write two arguments here without pathname expansion later, other than eval.
+        #findargs='-name "*.stackdump"'
+        for corefile in $(find "$directory" -type f -name "*.stackdump") ; do
+            binary=`basename "$corefile" .stackdump`
+            echo;echo;
+            echo "dumping ${corefile} for ${binary}"
+            awk '/^0/{print $2}' $corefile |addr2line -f -i -e ./src/backend/postgres.exe
+        done
+        exit 0
+        ;;
+
     *)
         echo "unsupported operating system ${os}"
         exit 1
-    ;;
+        ;;
 esac
 
 first=1
-- 
2.25.1

#41Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Melih Mutlu (#40)
Re: Mingw task for Cirrus CI

Hi,

Thanks for the patch!

On 10/18/22 12:49, Melih Mutlu wrote:

You can find the updated patch attached.

Does it makes sense to set these at 'Windows - Server 2019, MinGW64 -
Meson' task:

env:
    ...
    CHERE_INVOKING: 1
    BASH_EXE: C:\msys64\usr\bin\bash.exe

'CHERE_INVOKING: 1' will cause bash.exe to start from current working
directory(%CIRRUS_WORKING_DIR%).

In this way, there is no need for
'cd %CIRRUS_WORKING_DIR%' when using bash.exe,
also no need for 'BUILD_DIR' environment variable.

i.e:

configure_script: |
    %BASH_EXE% -lc "meson setup --buildtype debug -Dcassert=true
-Db_pch=true -DTAR=%TAR% build"

will work.

Regards,
Nazir Bilal Yavuz

#42Melih Mutlu
m.melihmutlu@gmail.com
In reply to: Nazir Bilal Yavuz (#41)
1 attachment(s)
Re: Mingw task for Cirrus CI

Hi Bilal,

Nazir Bilal Yavuz <byavuz81@gmail.com>, 18 Eki 2022 Sal, 15:37 tarihinde
şunu yazdı:

env:
...
CHERE_INVOKING: 1
BASH_EXE: C:\msys64\usr\bin\bash.exe

'CHERE_INVOKING: 1' will cause bash.exe to start from current working
directory(%CIRRUS_WORKING_DIR%).

In this way, there is no need for
'cd %CIRRUS_WORKING_DIR%' when using bash.exe,
also no need for 'BUILD_DIR' environment variable.

Right, setting CHERE_INVOKING and removing all cd's work and look better.
Thanks for the suggestion.

Here's the updated patch.

Best,
Melih

Attachments:

v8-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchapplication/octet-stream; name=v8-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchDownload
From fa1492dc3f0516aa4e2f6c271ca769d0823527b9 Mon Sep 17 00:00:00 2001
From: Melih Mutlu <m.melihmutlu@gmail.com>
Date: Fri, 2 Sep 2022 23:10:02 +0300
Subject: [PATCH] Added Windows with MinGW environment in Cirrus CI

CI task on Windows Server with MinGW has been added as optional.

Note that trigger_type line for MinGW task has to be uncommented before
merge
---
 .cirrus.yml                     | 98 ++++++++++++++++++++++++++-------
 src/tools/ci/cores_backtrace.sh | 17 +++++-
 2 files changed, 94 insertions(+), 21 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 9f2282471a..07b4c5e268 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -393,24 +393,37 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh macos "${HOME}/cores"
 
 
+WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
+    env:
+      # Half the allowed per-user CPU cores
+      CPUS: 4
+      TEST_JOBS: 4 # wild guess, data based value welcome
+
+      # The default working dir is in a directory msbuild complains about
+      CIRRUS_WORKING_DIR: "c:/cirrus"
+
+      PG_REGRESS_SOCK_DIR: "c:/cirrus/"
+
+      # Avoids port conflicts between concurrent tap test runs
+      PG_TEST_USE_UNIX_SOCKETS: 1
+
+      # git's tar doesn't deal with drive letters, see
+      # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
+      TAR: "c:/windows/system32/tar.exe"
+
+    sysinfo_script: |
+      chcp
+      systeminfo
+      powershell -Command get-psdrive -psprovider filesystem
+      set
+
 task:
   name: Windows - Server 2019, VS 2019 - Meson & ninja
+  << : *WINDOWS_ENVIRONMENT_BASE
 
   env:
-    # Half the allowed per-user CPU cores
-    CPUS: 4
-    TEST_JOBS: 8 # wild guess, data based value welcome
-
-    # The default cirrus working dir is in a directory msbuild complains about
-    CIRRUS_WORKING_DIR: "c:/cirrus"
     # Avoid re-installing over and over
     NO_TEMP_INSTALL: 1
-    # git's tar doesn't deal with drive letters, see
-    # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
-    TAR: "c:/windows/system32/tar.exe"
-    # Avoids port conflicts between concurrent tap test runs
-    PG_TEST_USE_UNIX_SOCKETS: 1
-    PG_REGRESS_SOCK_DIR: "c:/cirrus/"
 
     # startcreate_script starts a postgres instance that we don't want to get
     # killed at the end of that script (it's stopped in stop_script). Can't
@@ -435,19 +448,13 @@ task:
     cpu: $CPUS
     memory: 4G
 
-  sysinfo_script: |
-    chcp
-    systeminfo
-    powershell -Command get-psdrive -psprovider filesystem
-    set
-
   setup_additional_packages_script: |
     REM choco install -y --no-progress ...
 
   # Use /DEBUG:FASTLINK to avoid high memory usage during linking
   configure_script: |
     vcvarsall x64
-    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
+    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
 
   build_script: |
     vcvarsall x64
@@ -463,6 +470,59 @@ task:
       path: "crashlog-*.txt"
       type: text/plain
 
+task:
+  << : *WINDOWS_ENVIRONMENT_BASE
+  name: Windows - Server 2019, MinGW64 - Meson
+
+  # This task needs to be triggered manually on Cirrus CI.
+  # Otherwise it will not run and be shown as paused
+  # XXX: Below line needs to be uncommented before merge. It's commented for now so that cfbot can run it
+  #trigger_type: manual
+
+  windows_container:
+    image: $CONTAINER_REPO/windows_ci_mingw64:latest
+    cpu: $CPUS
+    memory: 4G
+
+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    BUILD_DIR: "%CIRRUS_WORKING_DIR%/build"
+    PYTHONHOME: C:/msys64/ucrt64
+    MSYS: winjitdebug
+    CCACHE_SLOPPINESS: pch_defines,time_macros
+    CCACHE_DEPEND: 1
+    # Start bash in current working directory
+    CHERE_INVOKING: 1
+    BASH_EXE: C:\msys64\usr\bin\bash.exe
+
+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  setup_additional_packages_script: |
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm ...
+
+  mingw_info_script: |
+    %BASH_EXE% -lc "where gcc"
+    %BASH_EXE% -lc "gcc --version"
+    %BASH_EXE% -lc "where perl"
+    %BASH_EXE% -lc "perl --version"
+
+  configure_script: |
+    %BASH_EXE% -lc "meson setup --buildtype debug -Dcassert=true -Db_pch=true -DTAR=%TAR% build"
+
+  build_script: |
+    %BASH_EXE% -lc "cd %CIRRUS_WORKING_DIR% && ninja -C build"
+
+  upload_caches: ccache
+
+  test_world_script: |
+    %BASH_EXE% -lc "meson test --print-errorlogs --num-processes %TEST_JOBS% -C build"
+
+  on_failure:
+    <<: *on_failure_meson
+    cores_script: |
+      %BASH_EXE% -lc "cd build src/tools/ci/cores_backtrace.sh msys build/tmp_install"
+
 
 task:
   name: CompilerWarnings
diff --git a/src/tools/ci/cores_backtrace.sh b/src/tools/ci/cores_backtrace.sh
index 28d3cecfc6..93e90f284e 100755
--- a/src/tools/ci/cores_backtrace.sh
+++ b/src/tools/ci/cores_backtrace.sh
@@ -10,11 +10,24 @@ directory=$2
 
 case $os in
     freebsd|linux|macos)
-    ;;
+        ;;
+
+    msys)
+        # XXX Evidently I don't know how to write two arguments here without pathname expansion later, other than eval.
+        #findargs='-name "*.stackdump"'
+        for corefile in $(find "$directory" -type f -name "*.stackdump") ; do
+            binary=`basename "$corefile" .stackdump`
+            echo;echo;
+            echo "dumping ${corefile} for ${binary}"
+            awk '/^0/{print $2}' $corefile |addr2line -f -i -e ./src/backend/postgres.exe
+        done
+        exit 0
+        ;;
+
     *)
         echo "unsupported operating system ${os}"
         exit 1
-    ;;
+        ;;
 esac
 
 first=1
-- 
2.25.1

#43Andres Freund
andres@anarazel.de
In reply to: Melih Mutlu (#42)
Re: Mingw task for Cirrus CI

Hi,

On 2022-10-19 00:23:46 +0300, Melih Mutlu wrote:

Right, setting CHERE_INVOKING and removing all cd's work and look better.
Thanks for the suggestion.

Agreed, good idea.

+
+  env:
+    CCACHE_DIR: C:/msys64/ccache

It's a bit odd to separate the CCACHE_* variables from each other
(e.g. BUILD_DIR is inbetween them)...

+    BUILD_DIR: "%CIRRUS_WORKING_DIR%/build"
+    PYTHONHOME: C:/msys64/ucrt64

Perhaps add a comment explaining that otherwise plpython tests fail?

+ MSYS: winjitdebug

With this src/tools/ci/cores_backtrace.sh shouldn't need to be modified
anymore afaict?

+    CCACHE_SLOPPINESS: pch_defines,time_macros
+    CCACHE_DEPEND: 1

I experimented a bit and it looks like ccache doesn't yet quite work in CI,
but only because the ccache needs to be larger. Looks like we need about
~400MB.

A fully cached build is ~2min

+  configure_script: |
+    %BASH_EXE% -lc "meson setup --buildtype debug -Dcassert=true -Db_pch=true -DTAR=%TAR% build"

With these buildflags the tests take about 23min37s. Using -Og I saw 18min26s,
with -O1 18m57s and with -O2 18m38s. There's obviously a fair bit of variance,
but it looks like we should use -Og. I think we considered that making compile
times too bad before, but it seems kinda ok now, with 11min. -O2 is 13min,
without providing further benefits.

I'd replace --buildtype debug with -Ddebug=true -Doptimization=g.

+  build_script: |
+    %BASH_EXE% -lc "cd %CIRRUS_WORKING_DIR% && ninja -C build"

Why do we still need this cd?

+  upload_caches: ccache
+
+  test_world_script: |
+    %BASH_EXE% -lc "meson test --print-errorlogs --num-processes %TEST_JOBS% -C build"

Seems like this could use %MTEST_ARGS%?

Greetings,

Andres Freund

#44Melih Mutlu
m.melihmutlu@gmail.com
In reply to: Andres Freund (#43)
1 attachment(s)
Re: Mingw task for Cirrus CI

Hi,

Andres Freund <andres@anarazel.de>, 19 Eki 2022 Çar, 06:19 tarihinde şunu
yazdı:

It's a bit odd to separate the CCACHE_* variables from each other
(e.g. BUILD_DIR is inbetween them)...

Perhaps add a comment explaining that otherwise plpython tests fail?

With this src/tools/ci/cores_backtrace.sh shouldn't need to be modified

anymore afaict?

I'd replace --buildtype debug with -Ddebug=true -Doptimization=g.

Seems like this could use %MTEST_ARGS%?

All the things you mentioned above are done.

+    CCACHE_SLOPPINESS: pch_defines,time_macros
+    CCACHE_DEPEND: 1

I experimented a bit and it looks like ccache doesn't yet quite work in CI,
but only because the ccache needs to be larger. Looks like we need about
~400MB.

A fully cached build is ~2min

Then I should increase CCACHE_MAXSIZE, right? Made it 500MB for MinGW.

Sharing the updated version of the patch.

Thanks,
Melih

Attachments:

v9-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchapplication/octet-stream; name=v9-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchDownload
From e1ec309f78964d0f9fdceb3f1e55c436792f09fd Mon Sep 17 00:00:00 2001
From: Melih Mutlu <m.melihmutlu@gmail.com>
Date: Fri, 2 Sep 2022 23:10:02 +0300
Subject: [PATCH] Added Windows with MinGW environment in Cirrus CI

CI task on Windows Server with MinGW has been added as optional.

Note that trigger_type line for MinGW task has to be uncommented before
merge
---
 .cirrus.yml | 99 +++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 80 insertions(+), 19 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 9f2282471a..c549675fe7 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -393,24 +393,37 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh macos "${HOME}/cores"
 
 
+WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
+    env:
+      # Half the allowed per-user CPU cores
+      CPUS: 4
+      TEST_JOBS: 4 # wild guess, data based value welcome
+
+      # The default working dir is in a directory msbuild complains about
+      CIRRUS_WORKING_DIR: "c:/cirrus"
+
+      PG_REGRESS_SOCK_DIR: "c:/cirrus/"
+
+      # Avoids port conflicts between concurrent tap test runs
+      PG_TEST_USE_UNIX_SOCKETS: 1
+
+      # git's tar doesn't deal with drive letters, see
+      # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
+      TAR: "c:/windows/system32/tar.exe"
+
+    sysinfo_script: |
+      chcp
+      systeminfo
+      powershell -Command get-psdrive -psprovider filesystem
+      set
+
 task:
   name: Windows - Server 2019, VS 2019 - Meson & ninja
+  << : *WINDOWS_ENVIRONMENT_BASE
 
   env:
-    # Half the allowed per-user CPU cores
-    CPUS: 4
-    TEST_JOBS: 8 # wild guess, data based value welcome
-
-    # The default cirrus working dir is in a directory msbuild complains about
-    CIRRUS_WORKING_DIR: "c:/cirrus"
     # Avoid re-installing over and over
     NO_TEMP_INSTALL: 1
-    # git's tar doesn't deal with drive letters, see
-    # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
-    TAR: "c:/windows/system32/tar.exe"
-    # Avoids port conflicts between concurrent tap test runs
-    PG_TEST_USE_UNIX_SOCKETS: 1
-    PG_REGRESS_SOCK_DIR: "c:/cirrus/"
 
     # startcreate_script starts a postgres instance that we don't want to get
     # killed at the end of that script (it's stopped in stop_script). Can't
@@ -435,19 +448,13 @@ task:
     cpu: $CPUS
     memory: 4G
 
-  sysinfo_script: |
-    chcp
-    systeminfo
-    powershell -Command get-psdrive -psprovider filesystem
-    set
-
   setup_additional_packages_script: |
     REM choco install -y --no-progress ...
 
   # Use /DEBUG:FASTLINK to avoid high memory usage during linking
   configure_script: |
     vcvarsall x64
-    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
+    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
 
   build_script: |
     vcvarsall x64
@@ -463,6 +470,60 @@ task:
       path: "crashlog-*.txt"
       type: text/plain
 
+task:
+  << : *WINDOWS_ENVIRONMENT_BASE
+  name: Windows - Server 2019, MinGW64 - Meson
+
+  # This task needs to be triggered manually on Cirrus CI.
+  # Otherwise it will not run and be shown as paused
+  # XXX: Below line needs to be uncommented before merge. It's commented for now so that cfbot can run it
+  #trigger_type: manual
+
+  windows_container:
+    image: $CONTAINER_REPO/windows_ci_mingw64:latest
+    cpu: $CPUS
+    memory: 4G
+
+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    CCACHE_MAXSIZE: "500M"
+    CCACHE_SLOPPINESS: pch_defines,time_macros
+    CCACHE_DEPEND: 1
+    # Need this for plpython tests to pass
+    PYTHONHOME: C:/msys64/ucrt64
+    MSYS: winjitdebug
+    # Start bash in current working directory
+    CHERE_INVOKING: 1
+    BASH_EXE: C:\msys64\usr\bin\bash.exe
+
+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  setup_additional_packages_script: |
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm ...
+
+  mingw_info_script: |
+    %BASH_EXE% -lc "where gcc"
+    %BASH_EXE% -lc "gcc --version"
+    %BASH_EXE% -lc "where perl"
+    %BASH_EXE% -lc "perl --version"
+
+  configure_script: |
+    %BASH_EXE% -lc "meson setup -Ddebug=true -Doptimization=g -Dcassert=true -Db_pch=true -DTAR=%TAR% build"
+
+  build_script: |
+    %BASH_EXE% -lc "ninja -C build"
+
+  upload_caches: ccache
+
+  test_world_script: |
+    %BASH_EXE% -lc "meson test %MTEST_ARGS% --num-processes %TEST_JOBS%"
+
+  on_failure:
+    <<: *on_failure_meson
+    cores_script: |
+      %BASH_EXE% -lc "cd build src/tools/ci/cores_backtrace.sh msys build/tmp_install"
+
 
 task:
   name: CompilerWarnings
-- 
2.25.1

#45Andres Freund
andres@anarazel.de
In reply to: Melih Mutlu (#44)
Re: Mingw task for Cirrus CI

Hi,

On 2022-10-19 17:59:22 +0300, Melih Mutlu wrote:

All the things you mentioned above are done.

Then I should increase CCACHE_MAXSIZE, right? Made it 500MB for MinGW.

Yes.

+
+  on_failure:
+    <<: *on_failure_meson
+    cores_script: |
+      %BASH_EXE% -lc "cd build src/tools/ci/cores_backtrace.sh msys build/tmp_install"
+

This is wrong - it should just archive the same files that the current windows
task does.

Other than that, I think this is basically ready?

Greetings,

Andres Freund

#46Melih Mutlu
m.melihmutlu@gmail.com
In reply to: Andres Freund (#45)
1 attachment(s)
Re: Mingw task for Cirrus CI

Hi,

+
+  on_failure:
+    <<: *on_failure_meson
+    cores_script: |
+      %BASH_EXE% -lc "cd build src/tools/ci/cores_backtrace.sh msys

build/tmp_install"

+

This is wrong - it should just archive the same files that the current
windows
task does.

Changed it with the on_failure from the other windows task.

Other than that, I think this is basically ready?

If you say so, then I think it's ready.

Best,
Melih

Attachments:

v10-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchapplication/octet-stream; name=v10-0001-Added-Windows-with-MinGW-environment-in-Cirrus-CI.patchDownload
From e56687002f2d46f717d0c9dedf0def0541a605d8 Mon Sep 17 00:00:00 2001
From: Melih Mutlu <m.melihmutlu@gmail.com>
Date: Fri, 2 Sep 2022 23:10:02 +0300
Subject: [PATCH] Added Windows with MinGW environment in Cirrus CI

CI task on Windows Server with MinGW has been added as optional.

Note that trigger_type line for MinGW task has to be uncommented before
merge
---
 .cirrus.yml | 100 ++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 81 insertions(+), 19 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 9f2282471a..b3bea5ceac 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -393,24 +393,37 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh macos "${HOME}/cores"
 
 
+WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
+    env:
+      # Half the allowed per-user CPU cores
+      CPUS: 4
+      TEST_JOBS: 4 # wild guess, data based value welcome
+
+      # The default working dir is in a directory msbuild complains about
+      CIRRUS_WORKING_DIR: "c:/cirrus"
+
+      PG_REGRESS_SOCK_DIR: "c:/cirrus/"
+
+      # Avoids port conflicts between concurrent tap test runs
+      PG_TEST_USE_UNIX_SOCKETS: 1
+
+      # git's tar doesn't deal with drive letters, see
+      # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
+      TAR: "c:/windows/system32/tar.exe"
+
+    sysinfo_script: |
+      chcp
+      systeminfo
+      powershell -Command get-psdrive -psprovider filesystem
+      set
+
 task:
   name: Windows - Server 2019, VS 2019 - Meson & ninja
+  << : *WINDOWS_ENVIRONMENT_BASE
 
   env:
-    # Half the allowed per-user CPU cores
-    CPUS: 4
-    TEST_JOBS: 8 # wild guess, data based value welcome
-
-    # The default cirrus working dir is in a directory msbuild complains about
-    CIRRUS_WORKING_DIR: "c:/cirrus"
     # Avoid re-installing over and over
     NO_TEMP_INSTALL: 1
-    # git's tar doesn't deal with drive letters, see
-    # https://postgr.es/m/b6782dc3-a7b0-ed56-175f-f8f54cb08d67%40dunslane.net
-    TAR: "c:/windows/system32/tar.exe"
-    # Avoids port conflicts between concurrent tap test runs
-    PG_TEST_USE_UNIX_SOCKETS: 1
-    PG_REGRESS_SOCK_DIR: "c:/cirrus/"
 
     # startcreate_script starts a postgres instance that we don't want to get
     # killed at the end of that script (it's stopped in stop_script). Can't
@@ -435,19 +448,13 @@ task:
     cpu: $CPUS
     memory: 4G
 
-  sysinfo_script: |
-    chcp
-    systeminfo
-    powershell -Command get-psdrive -psprovider filesystem
-    set
-
   setup_additional_packages_script: |
     REM choco install -y --no-progress ...
 
   # Use /DEBUG:FASTLINK to avoid high memory usage during linking
   configure_script: |
     vcvarsall x64
-    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
+    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
 
   build_script: |
     vcvarsall x64
@@ -463,6 +470,61 @@ task:
       path: "crashlog-*.txt"
       type: text/plain
 
+task:
+  << : *WINDOWS_ENVIRONMENT_BASE
+  name: Windows - Server 2019, MinGW64 - Meson
+
+  # This task needs to be triggered manually on Cirrus CI.
+  # Otherwise it will not run and be shown as paused
+  # XXX: Below line needs to be uncommented before merge. It's commented for now so that cfbot can run it
+  #trigger_type: manual
+
+  windows_container:
+    image: $CONTAINER_REPO/windows_ci_mingw64:latest
+    cpu: $CPUS
+    memory: 4G
+
+  env:
+    CCACHE_DIR: C:/msys64/ccache
+    CCACHE_MAXSIZE: "500M"
+    CCACHE_SLOPPINESS: pch_defines,time_macros
+    CCACHE_DEPEND: 1
+    # Need this for plpython tests to pass
+    PYTHONHOME: C:/msys64/ucrt64
+    MSYS: winjitdebug
+    # Start bash in current working directory
+    CHERE_INVOKING: 1
+    BASH_EXE: C:\msys64\usr\bin\bash.exe
+
+  ccache_cache:
+    folder: ${CCACHE_DIR}
+
+  setup_additional_packages_script: |
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm ...
+
+  mingw_info_script: |
+    %BASH_EXE% -lc "where gcc"
+    %BASH_EXE% -lc "gcc --version"
+    %BASH_EXE% -lc "where perl"
+    %BASH_EXE% -lc "perl --version"
+
+  configure_script: |
+    %BASH_EXE% -lc "meson setup -Ddebug=true -Doptimization=g -Dcassert=true -Db_pch=true -DTAR=%TAR% build"
+
+  build_script: |
+    %BASH_EXE% -lc "ninja -C build"
+
+  upload_caches: ccache
+
+  test_world_script: |
+    %BASH_EXE% -lc "meson test %MTEST_ARGS% --num-processes %TEST_JOBS%"
+
+  on_failure:
+    <<: *on_failure_meson
+    crashlog_artifacts:
+      path: "crashlog-*.txt"
+      type: text/plain
+
 
 task:
   name: CompilerWarnings
-- 
2.25.1

#47Andres Freund
andres@anarazel.de
In reply to: Melih Mutlu (#46)
Re: Mingw task for Cirrus CI

Hi,

On 2022-10-24 14:13:06 +0300, Melih Mutlu wrote:

If you say so, then I think it's ready.

I pushed it with a few changes:

- I added an only_if, otherwise the task shows up (without running) even if
you use ci-os-only: linux
- I added -Dnls=disabled - It seemed to add about 1.5min to the cached build
- Inlined the -l into BASH_EXE and renamed it to BASH
- The indentation of WINDOWS_ENVIRONMENT_BASE was irregular, leading to a
larger diff. Some other similar cleanups.
- I added 'mingw' as a ci-os-only choice. Perhaps not the
be-all-end-all. Perhaps we should use windows-{msvc,mingw,cygwin}? Or add
ci-task-only?

I suspect we can make at least -Dssl=openssl work. Perhaps one of the uuid
implementation is available in msys as well?

Currently we end up with:
External libraries
bonjour : NO
bsd_auth : NO
gss : NO
icu : YES 72.1
ldap : YES
libxml : YES 2.10.3
libxslt : YES 1.1.37
llvm : NO
lz4 : YES 1.9.4
nls : NO
pam : NO
plperl : YES
plpython : YES 3.10
pltcl : YES
readline : YES
selinux : NO
ssl : NO
systemd : NO
uuid : NO
zlib : YES 1.2.13
zstd : YES 1.5.2

gss should also work if the is available in the msys repo.

Bonjour is apple only, bsd_auth bsd specific, selinux and systemd linux
specific and pam unixoid specific.

It could also be interesting to see if llvm works, but that might be more
work.

Greetings,

Andres Freund