Skip to content

[glib] fix for macOS dynamic library#9799

Closed
angelmixu wants to merge 23 commits intomicrosoft:masterfrom
angelmixu:glib-fix-for-macOS-dynamic-library
Closed

[glib] fix for macOS dynamic library#9799
angelmixu wants to merge 23 commits intomicrosoft:masterfrom
angelmixu:glib-fix-for-macOS-dynamic-library

Conversation

@angelmixu
Copy link
Copy Markdown
Contributor

This PR fixes the build of a dynamic library on macOS.

The dynamic library suffix was missing, it needs to link with AppKit, it needs the RPATH correctly set.
And also, there's a cyclic dependence on kqueue, so I made it to build staticlly, and lastly, "gnetworkmonitornm.c" was not building at all, so I commented it.
Maybe someone can fix this file, but I didn't know how; although, I have tested glib and it looks like it is not needed in my case.

@@ -1,5 +1,5 @@
Source: glib
Version: 2.52.3-14-5
Version: 2.52.3-14-6
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe some of those fixes are not required if updated to 2.63.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe ported to the official meson build system instead of a custom cmake file... But that's another topic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe some of those fixes are not required if updated to 2.63.0

Oh, I can try!

And maybe ported to the official meson build system instead of a custom cmake file... But that's another topic

As the guidelines say... all ports should use a CMakeFile, isn't it? :/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When multiple buildsystems are available, prefer using CMake. Additionally, when appropriate, it can be easier and more maintainable to rewrite alternative buildsystems into CMake using file(GLOB) directives.

the problem with using a vcpkg internal CMakeLists.txt is that it must be maintained and checked for correctness/equivalence with the ports real build system. Since vcpkg_(configure|build|install)_meson exists I would also rewrite it using these functions instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, thanks!

@PhoebeHui
Copy link
Copy Markdown
Contributor

PhoebeHui commented Feb 3, 2020

@angelmixu, thanks for the PR!

Could you please open an issue for this PR? so others may replicate this problem.

BTW, glib failed on Linux in CI testing, could you have a look?

@angelmixu
Copy link
Copy Markdown
Contributor Author

@angelmixu, thanks for the PR!

Could you please open an issue for this PR? so others may replicate this problem.

BTW, glib failed on Linux in CI testing, could you have a look?

Thanks to you @PhoebeHui :)
Sure, I just took a look at the error and it is this one:

libgio-2.0.a(giomodule.c.o): In function `_g_io_modules_ensure_loaded':
giomodule.c:(.text+0xdf0): undefined reference to `_g_network_monitor_nm_get_type'
collect2: error: ld returned 1 exit status

Looks like "gnetworkmonitornm.c" is still needed in Linux, sorry :/

In some days I hope I can take a look and try to migrate the port to the vcpkg_*_meson way as mentioned before.

Regarding opening an issue for this PR, should I mention that this PR needs help, or someone to consider anything?

@Neumann-A
Copy link
Copy Markdown
Contributor

In some days I hope I can take a look and try to migrate the port to the vcpkg_*_meson way as mentioned before.

for that to work vcpkg_*_meson must be fixed first.

@angelmixu
Copy link
Copy Markdown
Contributor Author

In some days I hope I can take a look and try to migrate the port to the vcpkg_*_meson way as mentioned before.

for that to work vcpkg_*_meson must be fixed first.

Ah, I thought it was working correctly!
Then I'll try to fix this port as I was doing :)

@cenit
Copy link
Copy Markdown
Contributor

cenit commented Feb 3, 2020

Trying to fix vcpkg_build_meson opened an extremely deep rabbit hole which made me decide to abandon (too busy) some time ago. It required fixing pkgconfig (which I saw also @Neumann-A then had to do), expand coverage into many ports, etc etc...
Yeah it's better if you fix the cmakelists.txt for now

@angelmixu
Copy link
Copy Markdown
Contributor Author

I'm trying to update the CMakeLists.txt and the latest version I can use is 2.57.1, because the latter versions doesn't have the vcprojects for parsing the sources.
I had to disable two patches that were not working.
But what I can't get around is that it only fails in release configure and not in debug:

configure: WARNING: *** FAM support will not be built (FAM library not found) ***
CMake Error at /Users/angel/code/vcpkg/scripts/buildsystems/vcpkg.cmake:166 (_add_executable):
  Cannot find source file:

    gobject/glib-genmarshal.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx
Call Stack (most recent call first):
  CMakeLists.txt:293 (add_executable)
  CMakeLists.txt:336 (add_glib_tool)


CMake Error at /Users/angel/code/vcpkg/scripts/buildsystems/vcpkg.cmake:166 (_add_executable):
  No SOURCES given to target: glib-genmarshal
Call Stack (most recent call first):
  CMakeLists.txt:293 (add_executable)
  CMakeLists.txt:336 (add_glib_tool)


CMake Generate step failed.  Build files cannot be regenerated correctly.
buildtrees/glib/config-inedit-osx-rel-err.log (END)

Do you have any suggestion on it?

@JackBoosY
Copy link
Copy Markdown
Contributor

JackBoosY commented Mar 10, 2020

Sorry for late.
The file gobject/glib-genmarshal.c does not exist, but I found gobject/glib-genmarshal.h.
Maybe we should use configure_file to generate it as gobject/glib-genmarshal.c?

@JackBoosY
Copy link
Copy Markdown
Contributor

@angelmixu Okay, please ping me if this PR is ready for review.

@JackBoosY JackBoosY marked this pull request as draft May 8, 2020 04:53
@angelmixu
Copy link
Copy Markdown
Contributor Author

angelmixu commented May 8, 2020

Hi people! I'm trying to use meson, and it's failing and I don't know why :/

I have pushed the changes to this branch, and the error is the following:

  File "/usr/local/bin/meson", line 2
    PYTHONPATH="/usr/local/Cellar/meson/0.54.1_2/lib/python3.8/site-packages" exec "/usr/local/Cellar/meson/0.54.1_2/libexec/bin/meson" "$@"
                                                                                 ^
SyntaxError: invalid syntax

Looks like it should be my macOS meson installation (I used brew install meson), because if I send this command in the terminal:

/usr/local/bin/python3 /usr/local/bin/meson

The same error appears.

The contents of /usr/local/bin/meson is this:

% cat /usr/local/bin/meson 
#!/bin/bash
PYTHONPATH="/usr/local/Cellar/meson/0.54.1_2/lib/python3.8/site-packages" exec "/usr/local/Cellar/meson/0.54.1_2/libexec/bin/meson" "$@"

I have googled for something similar and I haven't found anything :(
Do you have any idea about how to fix this?

EDIT: just thought on installing meson with pip3, and it's working! Maybe vcpkg should change install instructions? Or maybe... brew should fix this?

@angelmixu
Copy link
Copy Markdown
Contributor Author

Ok, the next error is the following, libffi headers are installed in:

vcpkg % ls installed/x64-osx/include                    
ffi.h			libintl.h		pcre_scanner.h		pcrecpp.h		pcreposix.h		zlib.h
ffitarget.h		pcre.h			pcre_stringpiece.h	pcrecpparg.h		zconf.h

And it looks like meson build is looking for it inside include/ffi:

[259/1030] cc -Igobject/6270cfe@@gobject-2.0@sta -Igobject -I../src/2.64.2-69bc94cffa/gobject -I. -I../src/2.64.2-69bc94cffa -Iglib -I../src/2.64.2-69bc94cffa/glib 
-I/Users/angel/code/vcpkg/installed/x64-osx/include/ffi -Xclang -fcolor-diagnostics -pipe -std=gnu99 -D_GNU_SOURCE -fno-strict-aliasing -Wimplicit-fallthrough -Wstr
ict-prototypes -Wunused -Wno-unused-parameter -Wno-bad-function-cast -Wno-pedantic -Werror=declaration-after-statement -Werror=format=2 -Werror=implicit-function-de
claration -Werror=init-self -Werror=missing-include-dirs -Werror=missing-prototypes -Werror=pointer-arith -fPIC '-DG_LOG_DOMAIN="GLib-GObject"' -DGOBJECT_COMPILATIO
N -MD -MQ 'gobject/6270cfe@@gobject-2.0@sta/gclosure.c.o' -MF 'gobject/6270cfe@@gobject-2.0@sta/gclosure.c.o.d' -o 'gobject/6270cfe@@gobject-2.0@sta/gclosure.c.o' -
c ../src/2.64.2-69bc94cffa/gobject/gclosure.c
FAILED: gobject/6270cfe@@gobject-2.0@sta/gclosure.c.o 
cc -Igobject/6270cfe@@gobject-2.0@sta -Igobject -I../src/2.64.2-69bc94cffa/gobject -I. -I../src/2.64.2-69bc94cffa -Iglib -I../src/2.64.2-69bc94cffa/glib -I/Users/an
gel/code/vcpkg/installed/x64-osx/include/ffi -Xclang -fcolor-diagnostics -pipe -std=gnu99 -D_GNU_SOURCE -fno-strict-aliasing -Wimplicit-fallthrough -Wstrict-prototy
pes -Wunused -Wno-unused-parameter -Wno-bad-function-cast -Wno-pedantic -Werror=declaration-after-statement -Werror=format=2 -Werror=implicit-function-declaration -
Werror=init-self -Werror=missing-include-dirs -Werror=missing-prototypes -Werror=pointer-arith -fPIC '-DG_LOG_DOMAIN="GLib-GObject"' -DGOBJECT_COMPILATION -MD -MQ '
gobject/6270cfe@@gobject-2.0@sta/gclosure.c.o' -MF 'gobject/6270cfe@@gobject-2.0@sta/gclosure.c.o.d' -o 'gobject/6270cfe@@gobject-2.0@sta/gclosure.c.o' -c ../src/2.
64.2-69bc94cffa/gobject/gclosure.c
../src/2.64.2-69bc94cffa/gobject/gclosure.c:28:10: fatal error: 'ffi.h' file not found
#include <ffi.h>
         ^~~~~~~
1 error generated.

The only mention of ffi in the meson.build file is this one:
libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
and later in side gobject/meson.build is using it for building as dependency.

Where should this be changed? :/

@Neumann-A
Copy link
Copy Markdown
Contributor

Is there a *.pc while for libffi in lib/pkgconfig?

@Neumann-A
Copy link
Copy Markdown
Contributor

Neumann-A commented May 8, 2020

Try adding to libffi's portfile before the install of the copyright:

set(_file "${SOURCE_PATH}/libffi.pc.in")
file(READ "${_file}" _contents)
string(REPLACE "includedir=\${libdir}/@PACKAGE_NAME@-@PACKAGE_VERSION@/include" "includedir=@includedir@" _contents "${_contents}")
file(WRITE "${_file}" "${_contents}")

set(prefix "${CURRENT_INSTALLED_DIR}")
set(exec_prefix "\${prefix}")
set(libdir "\${prefix}/lib")
set(toolexeclibdir "\${prefix}/lib")
set(includedir "\${prefix}/include")
set(PACKAGE_NAME ffi)
set(PACKAGE_VERSION 3.3)
configure_file("${SOURCE_PATH}/libffi.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/libffi.pc" @ONLY)
set(prefix "${CURRENT_INSTALLED_DIR}/debug")
configure_file("${SOURCE_PATH}/libffi.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/libffi.pc" @ONLY)
vcpkg_fixup_pkgconfig()

taken from https://github.com/microsoft/vcpkg/pull/9966/files#diff-dffa210f772539f6ecaddd8ab285c1ac

@angelmixu
Copy link
Copy Markdown
Contributor Author

Oh thanks, it worked!!! :D

there's a new error about files shouldn't be present in debug/share, I'll take a look next week!

@cenit
Copy link
Copy Markdown
Contributor

cenit commented May 8, 2020

EDIT: just thought on installing meson with pip3, and it's working! Maybe vcpkg should change install instructions? Or maybe... brew should fix this?

in my OpenCV 4.3 PR I fixed the usage of meson for osx. This also made some meson ports work on CI... :)
I hope to be able to finish the testing of OpenCV 4.3 in the weekend so that your port will work in CI too. Otherwise maybe I can just extract that fix from the PR and submit another one

@angelmixu
Copy link
Copy Markdown
Contributor Author

I've uploaded libffi changes for testing if glib is building correctly, later we can create an individual PR with this change.

Now the changes I made to glib port, looks like build correctly on macOS statically and dynamically, although... tools/executables are not correctly placed in the tools/ directory and they are in the bin/ directory.

@angelmixu
Copy link
Copy Markdown
Contributor Author

Hey people, I was trying to build it on windows, and here's the error on meson-log.txt:

Compiler stderr:
 
Checking for function "ngettext" : NO 
Running compile:
Working directory:  C:\src\vcpkg-glib\buildtrees\glib\x86-windows-dbg\meson-private\tmplhfjlbea
Command line:  cl C:\src\vcpkg-glib\buildtrees\glib\x86-windows-dbg\meson-private\tmplhfjlbea\testfile.c /FeC:\src\vcpkg-glib\buildtrees\glib\x86-windows-dbg\meson-private\tmplhfjlbea\output.exe /nologo /showIncludes /MDd /DWIN32 /D_WINDOWS /W3 /MP /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1 /nologo /showIncludes /Od intl.lib /link 

Code:
 int main(void) { return 0; }
Compiler stdout:
 cl : Command line warning D9030 : '/showIncludes' is incompatible with multiprocessing; ignoring /MP switch
testfile.c
LINK : fatal error LNK1104: cannot open file 'intl.lib'

There's also another error for pcre.lib, it's in the debug configuration, intl.lib file is libintl.lib, and the missing pcre.lib is pcred.lib in the disk.

Do any of you know how would it be fixed?

@JackBoosY
Copy link
Copy Markdown
Contributor

glib depends on pcre in vcpkg, so you should use libpcre.a in VCPKG_ROOT/installed/TRIPLET/lib or VCPKG_ROOT/installed/TRIPLET/debug/lib.
You can try to add its path to the link library path list in some way.

@angelmixu
Copy link
Copy Markdown
Contributor Author

@JackBoosY thanks! Do you know if there's any vcpkg_meson_add_include/lib_path or similar?
Or if it would be a parameter for meson, because I can't see any option related.

@JackBoosY
Copy link
Copy Markdown
Contributor

@Neumann-A Do you have any suggestions?

@JackBoosY JackBoosY added the category:port-bug The issue is with a library, which is something the port should already support label Jun 11, 2020
Copy link
Copy Markdown
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this as initially "requires:discussion" because prognosis of dynamic libs on macos was itself in flux; after discussion #17363 (comment) it seems dynamic libs can work there.

There are conflicts, are you interested in continuing @angelmixu ?

configure_file(gobject/glib-mkenums.in ${CMAKE_SOURCE_DIR}/gobject/glib-mkenums @ONLY) # uses GLIB_VERSION
install(FILES gobject/glib-mkenums DESTINATION tools/glib)

#configure_file(gobject/glib-genmarshal.in ${CMAKE_SOURCE_DIR}/gobject/glib-genmarshal @ONLY) # uses GLIB_VERSION
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably shouldn't add commented out code

@angelmixu
Copy link
Copy Markdown
Contributor Author

I believe this as initially "requires:discussion" because prognosis of dynamic libs on macos was itself in flux; after discussion #17363 (comment) it seems dynamic libs can work there.

There are conflicts, are you interested in continuing @angelmixu ?

Hi!
I haven't used vcpkg since quite time ago and no longer have a macOS available, sorry :(
Feel free to get the ownership of the PR, and if I can help in any way, I'll be glad to.

@Neumann-A
Copy link
Copy Markdown
Contributor

this PR can be closed. glib was switched to meson in #13100

@JackBoosY JackBoosY closed this May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category:port-bug The issue is with a library, which is something the port should already support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants