nixpkgs/pkgs/development/libraries/glew/default.nix
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00

83 lines
2.8 KiB
Nix

{ lib
, stdenv
, fetchurl
, fetchpatch
, cmake
, libGLU
, libXmu
, libXi
, libXext
, OpenGL
, enableEGL ? (!stdenv.hostPlatform.isDarwin)
, testers
, mesa
}:
stdenv.mkDerivation (finalAttrs: {
pname = "glew";
version = "2.2.0";
src = fetchurl {
url = "mirror://sourceforge/glew/glew-${finalAttrs.version}.tgz";
sha256 = "1qak8f7g1iswgswrgkzc7idk7jmqgwrs58fhg2ai007v7j4q5z6l";
};
outputs = [ "bin" "out" "dev" ];
patches = [
# https://github.com/nigels-com/glew/pull/342
(fetchpatch {
url = "https://github.com/nigels-com/glew/commit/966e53fa153175864e151ec8a8e11f688c3e752d.diff";
hash = "sha256-xsSwdAbdWZA4KVoQhaLlkYvO711i3QlHGtv6v1Omkhw=";
})
# don't make EGL support disable GLX, use the same patch as ArchLinux
# https://gitlab.archlinux.org/archlinux/packaging/packages/glew/-/blob/ca08ff5d4cd3548a593eb1118d0a84b0c3670349/egl+glx.patch
(fetchpatch {
url = "https://gitlab.archlinux.org/archlinux/packaging/packages/glew/-/raw/ca08ff5d4cd3548a593eb1118d0a84b0c3670349/egl+glx.patch?inline=false";
hash = "sha256-IG3FPhhaor1kshEH3Kr8yzIHqBhczRwCqH7ZeDwlzGE=";
})
];
nativeBuildInputs = [ cmake ];
buildInputs = lib.optionals (!stdenv.hostPlatform.isDarwin) [ libXmu libXi libXext ];
propagatedBuildInputs = if stdenv.hostPlatform.isDarwin then [ OpenGL ] else [ libGLU ]; # GL/glew.h includes GL/glu.h
cmakeDir = "cmake";
cmakeFlags = [
"-DBUILD_SHARED_LIBS=ON"
] ++ lib.optional enableEGL "-DGLEW_EGL=ON";
postInstall = ''
moveToOutput lib/cmake "''${!outputDev}"
moveToOutput lib/pkgconfig "''${!outputDev}"
cat >> "''${!outputDev}"/lib/cmake/glew/glew-config.cmake <<EOF
# nixpkg's workaround for a cmake bug
# https://discourse.cmake.org/t/the-findglew-cmake-module-does-not-set-glew-libraries-in-some-cases/989/3
set(GLEW_VERSION "$version")
set(GLEW_LIBRARIES GLEW::glew\''${_glew_target_postfix})
get_target_property(GLEW_INCLUDE_DIRS GLEW::glew\''${_glew_target_postfix} INTERFACE_INCLUDE_DIRECTORIES)
set_target_properties(GLEW::GLEW\''${_glew_target_postfix} PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE ""
IMPORTED_IMPLIB_RELEASE "GLEW"
IMPORTED_IMPLIB_DEBUG "GLEW"
)
EOF
'';
passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
meta = with lib; {
description = "OpenGL extension loading library for C/C++";
homepage = "https://glew.sourceforge.net/";
license = with licenses; [ /* modified bsd */ free mit gpl2Only ]; # For full details, see https://github.com/nigels-com/glew#copyright-and-licensing
pkgConfigModules = [ "glew" ];
platforms = with platforms;
if enableEGL then
subtractLists darwin mesa.meta.platforms
else
mesa.meta.platforms;
};
})