Hi,

On Tue, 21 May 2024 at 18:24, Dave Page <dp...@pgadmin.org> wrote:
>
>
>
> On Tue, 21 May 2024 at 16:04, Andres Freund <and...@anarazel.de> wrote:
>>
>> Hi,
>>
>> On 2024-05-20 11:58:05 +0100, Dave Page wrote:
>> > I have very little experience with Meson, and even less interpreting it's
>> > logs, but it seems to me that it's not including the extra lib and include
>> > directories when it runs the test compile, given the command line it's
>> > reporting:
>> >
>> > cl C:\Users\dpage\git\postgresql\build\meson-private\tmpg_h4xcue\testfile.c
>> > /nologo /showIncludes /utf-8 /EP /nologo /showIncludes /utf-8 /EP /Od /Oi-
>> >
>> > Bug, or am I doing something silly?
>>
>> It's a buglet. We rely on meson's internal fallback detection of zlib, if 
>> it's
>> not provided via pkg-config or cmake. But it doesn't know about our
>> extra_include_dirs parameter. We should probably fix that...
>
>
> Oh good, then I'm not going bonkers. I'm still curious about how it works for 
> Andrew but not me, however fixing that buglet should solve my issue, and 
> would be sensible behaviour.
>
> Thanks!

I tried to install your latest zlib artifact (nmake one) to the
Windows CI images (not the official ones) [1]. Then, I used the
default meson.build file to build but meson could not find the zlib.
After that, I modified it like you suggested before; I used a
'cc.find_library()' to find zlib as a fallback method and it seems it
worked [2]. Please see meson setup logs below [3], does something
similar to the attached solve your problem?

The interesting thing is, I also tried this 'cc.find_library' method
with your old artifact (cmake one). It was able to find zlib but all
tests failed [4].

Experimental zlib meson.build diff is attached.

[1] https://cirrus-ci.com/task/6736867247259648
[2] https://cirrus-ci.com/build/5286228755480576
[3]
Run-time dependency zlib found: NO (tried pkgconfig, cmake and system)
Has header "zlib.h" : YES
Library zlib found: YES
...
  External libraries
...
    zlib                   : YES
...
[4] https://cirrus-ci.com/task/5208433811521536

-- 
Regards,
Nazir Bilal Yavuz
Microsoft
diff --git a/meson.build b/meson.build
index f5ca5cfed49..d89a7a3e277 100644
--- a/meson.build
+++ b/meson.build
@@ -1373,20 +1373,23 @@ endif
 zlibopt = get_option('zlib')
 zlib = not_found_dep
 if not zlibopt.disabled()
-  zlib_t = dependency('zlib', required: zlibopt)
+  zlib = dependency('zlib', required: false)
 
-  if zlib_t.type_name() == 'internal'
-    # if fallback was used, we don't need to test if headers are present (they
-    # aren't built yet, so we can't test)
-    zlib = zlib_t
-  elif not zlib_t.found()
-    warning('did not find zlib')
-  elif not cc.has_header('zlib.h',
-      args: test_c_args, include_directories: postgres_inc,
-      dependencies: [zlib_t], required: zlibopt)
-    warning('zlib header not found')
-  else
-    zlib = zlib_t
+  if zlib.found() and zlib.type_name() != 'internal'
+    if not cc.has_header('zlib.h',
+        args: test_c_args, include_directories: postgres_inc,
+        dependencies: zlib, required: false)
+      zlib = not_found_dep
+    endif
+  elif not zlib.found()
+    zlib_lib = cc.find_library('zlib',
+      dirs: test_lib_d,
+      header_include_directories: postgres_inc,
+      has_headers: ['zlib.h'],
+      required: zlibopt)
+    if zlib_lib.found()
+      zlib = declare_dependency(dependencies: zlib_lib, include_directories: postgres_inc)
+    endif
   endif
 
   if zlib.found()

Reply via email to