about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/libepoxy
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/libepoxy')
-rw-r--r--nixpkgs/pkgs/development/libraries/libepoxy/default.nix79
-rw-r--r--nixpkgs/pkgs/development/libraries/libepoxy/libgl-path.patch24
2 files changed, 103 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/libepoxy/default.nix b/nixpkgs/pkgs/development/libraries/libepoxy/default.nix
new file mode 100644
index 000000000000..3eb1d47c98d1
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/libepoxy/default.nix
@@ -0,0 +1,79 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, meson
+, ninja
+, pkg-config
+, utilmacros
+, python3
+, libGL
+, libX11
+, Carbon
+, OpenGL
+, x11Support ? !stdenv.isDarwin
+}:
+
+let
+  inherit (lib) getLib optional optionalString;
+
+in
+stdenv.mkDerivation rec {
+  pname = "libepoxy";
+  version = "1.5.10";
+
+  src = fetchFromGitHub {
+    owner = "anholt";
+    repo = pname;
+    rev = version;
+    sha256 = "sha256-gZiyPOW2PeTMILcPiUTqPUGRNlMM5mI1z9563v4SgEs=";
+  };
+
+  patches = [ ./libgl-path.patch ];
+
+  postPatch = ''
+    patchShebangs src/*.py
+  ''
+  + optionalString stdenv.isDarwin ''
+    substituteInPlace src/dispatch_common.h --replace "PLATFORM_HAS_GLX 0" "PLATFORM_HAS_GLX 1"
+  '';
+
+  outputs = [ "out" "dev" ];
+
+  nativeBuildInputs = [ meson ninja pkg-config utilmacros python3 ];
+
+  buildInputs = lib.optionals x11Support [
+    libGL
+    libX11
+  ] ++ lib.optionals stdenv.isDarwin [
+    Carbon
+    OpenGL
+  ];
+
+  mesonFlags = [
+    "-Degl=${if (x11Support && !stdenv.isDarwin) then "yes" else "no"}"
+    "-Dglx=${if x11Support then "yes" else "no"}"
+    "-Dtests=${lib.boolToString doCheck}"
+    "-Dx11=${lib.boolToString x11Support}"
+  ];
+
+  env.NIX_CFLAGS_COMPILE = lib.optionalString x11Support ''-DLIBGL_PATH="${getLib libGL}/lib"'';
+
+  # cgl_core and cgl_epoxy_api fail in darwin sandbox and on Hydra (because it's headless?)
+  preCheck = lib.optionalString stdenv.isDarwin ''
+    substituteInPlace ../test/meson.build \
+      --replace "[ 'cgl_epoxy_api', [ 'cgl_epoxy_api.c' ] ]," ""
+  '' + lib.optionalString (stdenv.isDarwin && stdenv.isx86_64) ''
+    substituteInPlace ../test/meson.build \
+      --replace "[ 'cgl_core', [ 'cgl_core.c' ] ]," ""
+  '';
+
+  doCheck = true;
+
+  meta = with lib; {
+    description = "A library for handling OpenGL function pointer management";
+    homepage = "https://github.com/anholt/libepoxy";
+    license = licenses.mit;
+    maintainers = with maintainers; [ goibhniu ];
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/libepoxy/libgl-path.patch b/nixpkgs/pkgs/development/libraries/libepoxy/libgl-path.patch
new file mode 100644
index 000000000000..8f38ee27174b
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/libepoxy/libgl-path.patch
@@ -0,0 +1,24 @@
+diff --git a/src/dispatch_common.c b/src/dispatch_common.c
+index b3e4f5f..303e8f5 100644
+--- a/src/dispatch_common.c
++++ b/src/dispatch_common.c
+@@ -310,6 +310,19 @@ get_dlopen_handle(void **handle, const char *lib_name, bool exit_on_fail, bool l
+             flags |= RTLD_NOLOAD;
+ 
+         *handle = dlopen(lib_name, flags);
++#ifdef LIBGL_PATH
++        if (!*handle) {
++          char pathbuf[sizeof(LIBGL_PATH) + 1 + 1024 + 1];
++          int l = snprintf(pathbuf, sizeof(pathbuf), "%s/%s", LIBGL_PATH, lib_name);
++          if (l < 0 || l >= sizeof(pathbuf)) {
++            // This really shouldn't happen
++            fprintf(stderr, "Error prefixing library pathname\n");
++            exit(1);
++          }
++          *handle = dlopen(pathbuf, flags);
++        }
++#endif
++
+         if (!*handle) {
+             if (exit_on_fail) {
+                 fprintf(stderr, "Couldn't open %s: %s\n", lib_name, dlerror());