From f6a48c21d2e7efadeee6c0b65836765b69f65e47 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 4 Feb 2018 10:13:06 +0100 Subject: [PATCH] lgi: Fix cairo bindings search path Since commit e44038bccab0cae, cairo-1.0.typelib contains an absolute path to cairo in the nix store so that no $LD_LIBRARY_PATH hacks are needed. However, this did not yet work for lgi, because lgi does dlopen("libcairo.so.2") without a full path, too. To make this work, this commit ensures that lgi first uses gobject-introspection to load libcairo. This uses the full path provided by the typelib. Afterwards, dlopen("libcairo.so.2") does not hit the filesystem anymore since the library is already loaded. This commit adds a patch that reorders some code in lgi's cairo initialisation. Previously, this started with core.module('cairo', 2), which is where the dlopen happens. Now, this code is moved down and instead core.gi.cairo.resolve is used to load the definitions of some enums first. This part of the code goes through gobject-introspection and causes libcairo to be loaded. Signed-off-by: Uli Schlachter --- .../lgi-find-cairo-through-typelib.patch | 47 +++++++++++++++++++ pkgs/top-level/lua-packages.nix | 2 + 2 files changed, 49 insertions(+) create mode 100644 pkgs/top-level/lgi-find-cairo-through-typelib.patch diff --git a/pkgs/top-level/lgi-find-cairo-through-typelib.patch b/pkgs/top-level/lgi-find-cairo-through-typelib.patch new file mode 100644 index 00000000000..613b2eda0b5 --- /dev/null +++ b/pkgs/top-level/lgi-find-cairo-through-typelib.patch @@ -0,0 +1,47 @@ +Reorder some code so that the cairo-gobject library is used before this tries to +dlopen("libcairo.so.2"). Since cairo-gobject depends (RT_DEPEND) on cairo, this +causes cairo to be used and so the missing search path for the dlopen() call is +not a problem. + +diff --git a/lgi/override/cairo.lua b/lgi/override/cairo.lua +index ca8193f..019239b 100644 +--- a/lgi/override/cairo.lua ++++ b/lgi/override/cairo.lua +@@ -20,18 +20,8 @@ local record = require 'lgi.record' + local enum = require 'lgi.enum' + local ti = ffi.types + +-cairo._module = core.module('cairo', 2) + local module_gobject = core.gi.cairo.resolve + +--- Versioning support. +-function cairo.version_encode(major, minor, micro) +- return 10000 * major + 100 * minor + micro +-end +-cairo.version = core.callable.new { +- addr = cairo._module.cairo_version, ret = ti.int } () +-cairo.version_string = core.callable.new { +- addr = cairo._module.cairo_version_string, ret = ti.utf8 } () +- + -- Load some constants. + cairo._constant = { + MIME_TYPE_JP2 = 'image/jp2', +@@ -58,6 +48,18 @@ for _, name in pairs { + end + end + ++-- Load libcairo.so directly; this has to happen after the typelib was used ++cairo._module = core.module('cairo', 2) ++ ++-- Versioning support. ++function cairo.version_encode(major, minor, micro) ++ return 10000 * major + 100 * minor + micro ++end ++cairo.version = core.callable.new { ++ addr = cairo._module.cairo_version, ret = ti.int } () ++cairo.version_string = core.callable.new { ++ addr = cairo._module.cairo_version_string, ret = ti.utf8 } () ++ + -- Load definitions of all boxed records. + cairo._struct = cairo._struct or {} + for index, struct in pairs { diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix index b91f9dae9f0..d4822b72e24 100644 --- a/pkgs/top-level/lua-packages.nix +++ b/pkgs/top-level/lua-packages.nix @@ -671,6 +671,8 @@ let sed -i "s|/usr/local|$out|" lgi/Makefile ''; + patches = [ ./lgi-find-cairo-through-typelib.patch ]; + meta = with stdenv.lib; { description = "GObject-introspection based dynamic Lua binding to GObject based libraries"; homepage = https://github.com/pavouk/lgi;