meson: mingw: Add -Wl,--disable-auto-import, enable when linking with readline
authorAndres Freund <[email protected]>
Wed, 28 Sep 2022 17:19:00 +0000 (10:19 -0700)
committerAndres Freund <[email protected]>
Sat, 1 Oct 2022 02:14:35 +0000 (19:14 -0700)
I hadn't ported -Wl,--disable-auto-import over from the win32 template as I
had focused on msvc for windows. The flag is desirable as it makes it easier
to find problems one would have with msvc, particularly useful during cross
compilation.

This turned out to be a somewhat happy accident, as it allowed me to realize
that readline actually works on windows these days, as long as auto imports to
enable. Therefore enable auto-import again as part of linking to readline.

We perhaps can come up with a better solution for the readline issue, but this
seems good enough for now.

Discussion: http://postgr.es/m/20220928022724[email protected]

meson.build

index 0cd09ba4308daaf6d0ba5201ebd5dab65515683e..c32cd792db881be53e5aa6911f07c82166c01d67 100644 (file)
@@ -279,6 +279,8 @@ elif host_system == 'windows'
     ldflags += '-Wl,--stack,@0@'.format(cdata.get('WIN32_STACK_RLIMIT'))
     # Need to allow multiple definitions, we e.g. want to override getopt.
     ldflags += '-Wl,--allow-multiple-definition'
+    # Ensure we get MSVC-like linking behavior.
+    ldflags += '-Wl,--disable-auto-import'
   endif
 
   os_deps += cc.find_library('ws2_32', required: true)
@@ -1080,6 +1082,13 @@ Use -Dreadline=false to disable readline support.'''.format(readline_dep))
       readline = declare_dependency(dependencies: readline,
         include_directories: postgres_inc)
     endif
+
+    # On windows with mingw readline requires auto-import to successfully
+    # link, as the headers don't use declspec(dllimport)
+    if host_system == 'windows' and cc.get_id() != 'msvc'
+      readline = declare_dependency(dependencies: readline,
+        link_args: '-Wl,--enable-auto-import')
+    endif
   endif
 
   # XXX: Figure out whether to implement mingw warning equivalent