gobject-introspection and not finding cairo

  • Open
  • quality assurance status badge
Details
3 participants
  • John Kehayias
  • Maxim Cournoyer
  • Raghav Gururajan
Owner
unassigned
Submitted by
John Kehayias
Severity
normal
J
J
John Kehayias wrote on 19 Jun 2021 20:29
(name . bug-guix@gnu.org)(address . bug-guix@gnu.org)
NU1oXuYXmLmLVwBBnwvv_21WrRNCjHFfDC16NAPAg8uzXlw9N0FhL69CwdG2KdPRBpb5YoOEjDr8ZiDagZpJfLTOFXxOJLecW-HlRjZONMo=@protonmail.com
Hello,

I'm trying to build some new packages, one of which is ghc-gi-cairo (from ghc-haskell-gi: https://github.com/haskell-gi/haskell-gi).These depend on gobject-introspection and finding library information from gir. However, it appears the typelib for cairo does not include the absolute path for cairo (though gobject-introspection right now does not depend on cairo, so that makes sense?) and the library cannot be found from this info.

Perhaps the name exposed in the typelib should be something else? I know there are patches for paths in gobject-introspection, and this issue of library path from gobject-introspection is not just in guix (e.g. https://github.com/Cimbali/pympress/issues/58).In building I do see LIBRARY_PATH includes the correct gobject-introspection (it does find the girepository in configure) and cairo, but as far as I can tell the path to cairo must be found via the typelib when using gobject-introspection?

I've tried building gobject-introspection with cairo enabled in meson, which didn't help. I also tried patching the cairo.gir file (as in https://github.com/Cimbali/pympress/issues/58#issuecomment-503174954),but haven't figured out what needs to go in there to make it work. Probably gobject-introspection needs to be build with cairo as an input and correctly get the full path to the library in generating the typelib? But what goes in the gir/cairo-1.0.gir.in file exactly?

From the gobject-introspection package running:

strings /gnu/store/irmw6agiw3adqphw8c3m19g31fw1yf34-gobject-introspection-1.62.0/lib/girepository-1.0/cairo-1.0.typelib | grep lib

has output:

libcairo-gobject.so.2
xlib


End of building ghc-gi-cairo has the following message:

starting phase `configure'
running "runhaskell Setup.hs" with command "configure" and parameters ("--prefix=/gnu/store/w95yciqs7i7aqm6v7qa6fiy6m6f25czb-ghc-gi-cairo-1.0.25" "--libdir=/gnu/store/w95yciqs7i7aqm6v7qa6fiy6m6f25czb-ghc-gi-cairo-1.0.25/lib" "--docdir=/gnu/store/w95yciqs7i7aqm6v7qa6fiy6m6f25czb-ghc-gi-cairo-1.0.25/share/doc/ghc-gi-cairo-1.0.25" "--libsubdir=$compiler/$pkg-$version" "--package-db=/tmp/guix-build-ghc-gi-cairo-1.0.25.drv-0/package.conf.d" "--global" "--enable-tests" "--enable-shared" "--enable-executable-dynamic" "--ghc-option=-fPIC" "--ghc-option=-optl=-Wl,-rpath=/gnu/store/w95yciqs7i7aqm6v7qa6fiy6m6f25czb-ghc-gi-cairo-1.0.25/lib/$compiler/$pkg-$version")

** (process:19): WARNING **: 17:28:36.142: Failed to load shared library 'libcairo-gobject.so.2' referenced by the typelib: libcairo-gobject.so.2: cannot open shared object file: No such file or directory
Could not resolve symbol "cairo_gobject_context_get_type" in namespace "cairo-1.0"

Appreciate any tips, help, or things to try!

John
J
J
John Kehayias wrote on 21 Jun 2021 01:59
(No Subject)
(name . 49122@debbugs.gnu.org)(address . 49122@debbugs.gnu.org)
zUU7RiK8_yvzxLZxIyAIo3cUoO7pKuN4KeRmxwHUN9UYHN9i0TDX0OdXu5-GxRbxgecj3HGwfMF7DEnqS9LF0aKtHcxbSWWJX_9Gn-VFclY=@protonmail.com
I've managed to fix the initial problem I noted, but this would depend on having cairo as an input so that gobject-introspection can find the library to patch the typelib. Unfortunately, this would be a circular dependency. This is a long standing issue with how cairo is handled here (see, e.g., https://gitlab.freedesktop.org/cairo/cairo/-/issues/141).

I don't know how circular dependencies are solved in guix, so I'm not sure what to do to fix this. gobject-introspection doesn't need cairo to build or function, so the build depends is not really needed other than to fix this bug. So this could be done with a separate package or in two steps?
J
J
John Kehayias wrote on 21 Jun 2021 04:04
(name . 49122@debbugs.gnu.org)(address . 49122@debbugs.gnu.org)
S5U-gizfg9KaYJJXAKf2O9DmT33cBTLXMiX6SITY2FPDk6nGwERrd-TmPwsfkduxC-jbwIzhys9-oq1gAW6Bt55wpT5jRovDh2_KIMMUF5o=@protonmail.com
Of course, saw right after my last message that the dependency cycle here is through poppler, and cairo-sans-poppler exists. So I think I've solved this problem and will submit a patch.

I've attached the current changes I've been working on and testing for now.
Toggle diff (26 lines)
diff --git a/gnu/packages/glib.scm b/gnu/packages/glib.scm
index 206222b578..fb3dbdecb5 100644
--- a/gnu/packages/glib.scm
+++ b/gnu/packages/glib.scm
@@ -496,6 +496,13 @@ dynamic loading, and an object system.")
(arguments
`(#:phases
(modify-phases %standard-phases
+ (add-after 'unpack 'patch
+ ;; Patch for cairo library location
+ (lambda* (#:key inputs #:allow-other-keys)
+ (substitute* "gir/cairo-1.0.gir.in"
+ (("shared-library=\"@CAIRO_SHARED_LIBRARY@\"")
+ (string-append "shared-library=\""
+ (assoc-ref inputs "cairo") "/lib/@CAIRO_SHARED_LIBRARY@\"")))))
(add-after 'unpack 'do-not-use-/usr/bin/env
(lambda _
(substitute* "tools/g-ir-tool-template.in"
@@ -507,6 +514,7 @@ dynamic loading, and an object system.")
("pkg-config" ,pkg-config)))
(inputs
`(("bison" ,bison)
+ ("cairo" ,cairo-sans-poppler) ; break dependency loop via poppler
("flex" ,flex)
("glib" ,glib)
("python" ,python-wrapper)
R
R
Raghav Gururajan wrote on 8 Sep 2021 01:06
Re: gobject-introspection and not finding cairo
(address . 49122@debbugs.gnu.org)
5c2f2026-03ed-2e9a-66f2-c428101b68de@raghavgururajan.name
Hi John!

You could try creating a gobject-introspection variant with cairo
enabled and use that variant as native-input for your packages.

Something like this:

```
(define-public gobject-introspection+cairo
(hidden-package
(package
(inherit gobject-introspection)
(arguments
(substitute-keyword-arguments (package-arguments
gobject-introspection)
((#:configure-flags flags ''())
`(cons* "-Dcairo=true" ,flags))))
(inputs
`(("cairo" ,cairo)
,@(package-inputs gobject-introspection))))))
```

Regards,
RG.
Attachment: OpenPGP_signature
R
R
Raghav Gururajan wrote on 8 Sep 2021 02:07
(address . 49122@debbugs.gnu.org)
0f2be41f-b20f-7ffa-fa17-9b51636cd92a@raghavgururajan.name
Hi John!

Toggle quote (17 lines)
> Something like this:
>
> ```
> (define-public gobject-introspection+cairo
>   (hidden-package
>    (package
>      (inherit gobject-introspection)
>      (arguments
>       (substitute-keyword-arguments (package-arguments
> gobject-introspection)
>         ((#:configure-flags flags ''())
>          `(cons* "-Dcairo=true" ,flags))))
>      (inputs
>       `(("cairo" ,cairo)
>         ,@(package-inputs gobject-introspection))))))
> ```

Or, something like this:

```
(define-public gobject-introspection+cairo
(hidden-package
(package
(inherit gobject-introspection)
(arguments
(substitute-keyword-arguments (package-arguments
gobject-introspection)
((#:configure-flags flags ''())
`(append
(list
"-Dcairo=true"
(string-append "-Dcairo_libname="
(assoc-ref %build-inputs "cairo")
"/lib/libcairo-gobject.so"))
,flags))))
(inputs
`(("cairo" ,cairo)
,@(package-inputs gobject-introspection))))))
```

Regards,
RG.
Attachment: OpenPGP_signature
M
M
Maxim Cournoyer wrote on 20 Jan 23:18 +0100
Re: bug#49122: gobject-introspection and not finding cairo
(name . John Kehayias)(address . john.kehayias@protonmail.com)(name . 49122@debbugs.gnu.org)(address . 49122@debbugs.gnu.org)
87edebd4yu.fsf_-_@gmail.com
Hi John,

John Kehayias <john.kehayias@protonmail.com> writes:

Toggle quote (13 lines)
> I've managed to fix the initial problem I noted, but this would depend
> on having cairo as an input so that gobject-introspection can find the
> library to patch the typelib. Unfortunately, this would be a circular
> dependency. This is a long standing issue with how cairo is handled
> here (see, e.g.,
> https://gitlab.freedesktop.org/cairo/cairo/-/issues/141).
>
> I don't know how circular dependencies are solved in guix, so I'm not
> sure what to do to fix this. gobject-introspection doesn't need cairo
> to build or function, so the build depends is not really needed other
> than to fix this bug. So this could be done with a separate package or
> in two steps?

Upstream said:

Toggle snippet (9 lines)
The Cairo API is not really introspectable, because its type system does
not use GObject.

We could generate the introspection data by using a filter script to
turn the snake case cairo_*_t types into the expected CamelCase Cairo*
types, but it's not entirely trivial, and it would still not by usable
by anything.

Introducing an extra dependency to the closure of gobject-introspection,
we'd have applications soft-linking to potentially different versions of
cairo (cairo and cairo-sans-poppler), which seems ugly.

Could we move the cairo.gir file to the cairo package, and this would be
picked up by gobject-introspection if at the right location?

It'd differ from upstream, but that'd be cleaner. Perhaps we could
contribute such fix for inclusion upstream too.

--
Thanks,
Maxim
?