From 0b0b74367f15cf7a0f17b4ee99cc5668c2499b74 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Mon, 6 Jul 2020 06:26:21 +0200 Subject: [PATCH] libiio: 0.20 -> 0.21 * Format with nixpkgs-format. * Reorder the attribute to be more in line with convention. * Use simpler git ref. * Hardcode paths within bindings using patch (the replaced value actually changed in this version and without this clean-up, it would have gone unnoticed.) * Let the build script install the python bindings instead of doing it manually (required the same hardcoding as above in the setup.py.) * Use cmakeFlags attribute with placeholder instead of doing that in preConfigure. * Move udev rules to lib since etc is meant for admins. * License is actually lgpl2.1+. --- pkgs/development/libraries/libiio/default.nix | 69 +++++++++++-------- .../libiio/hardcode-library-path.patch | 38 ++++++++++ 2 files changed, 79 insertions(+), 28 deletions(-) create mode 100644 pkgs/development/libraries/libiio/hardcode-library-path.patch diff --git a/pkgs/development/libraries/libiio/default.nix b/pkgs/development/libraries/libiio/default.nix index 03324c15d8f7..c4136428035c 100644 --- a/pkgs/development/libraries/libiio/default.nix +++ b/pkgs/development/libraries/libiio/default.nix @@ -1,49 +1,62 @@ -{ stdenv, fetchFromGitHub -, cmake, flex, bison -, libxml2, python -, libusb1, runtimeShell +{ stdenv +, fetchFromGitHub +, cmake +, flex +, bison +, libxml2 +, python +, libusb1 +, runtimeShell }: stdenv.mkDerivation rec { pname = "libiio"; - version = "0.20"; - - src = fetchFromGitHub { - owner = "analogdevicesinc"; - repo = "libiio"; - rev = "refs/tags/v${version}"; - sha256 = "1929gvizkqmm9cwh3vihxxszfxvgcp5saq9q6chdk3fpdhzajc00"; - }; + version = "0.21"; outputs = [ "out" "lib" "dev" "python" ]; - nativeBuildInputs = [ cmake flex bison ]; - buildInputs = [ libxml2 libusb1 ]; + src = fetchFromGitHub { + owner = "analogdevicesinc"; + repo = "libiio"; + rev = "v${version}"; + sha256 = "0psw67mzysdb8fkh8xpcwicm7z94k8plkcc8ymxyvl6inshq0mc7"; + }; + + nativeBuildInputs = [ + cmake + flex + bison + ]; + + buildInputs = [ + python + libxml2 + libusb1 + ]; + + cmakeFlags = [ + "-DUDEV_RULES_INSTALL_DIR=${placeholder "out"}/lib/udev/rules.d" + "-DPYTHON_BINDINGS=on" + ]; postPatch = '' + # Hardcode path to the shared library into the bindings. + sed "s#@libiio@#$lib/lib/libiio${stdenv.hostPlatform.extensions.sharedLibrary}#g" ${./hardcode-library-path.patch} | patch -p1 + substituteInPlace libiio.rules.cmakein \ --replace /bin/sh ${runtimeShell} ''; - # since we can't expand $out in cmakeFlags - preConfigure = '' - cmakeFlags="$cmakeFlags -DUDEV_RULES_INSTALL_DIR=$out/etc/udev/rules.d" - ''; - postInstall = '' - mkdir -p $python/lib/${python.libPrefix}/site-packages/ - touch $python/lib/${python.libPrefix}/site-packages/ - cp ../bindings/python/iio.py $python/lib/${python.libPrefix}/site-packages/ - - substitute ../bindings/python/iio.py $python/lib/${python.libPrefix}/site-packages/iio.py \ - --replace 'libiio.so.0' $lib/lib/libiio.so.0 + # Move Python bindings into a separate output. + moveToOutput ${python.sitePackages} "$python" ''; meta = with stdenv.lib; { description = "API for interfacing with the Linux Industrial I/O Subsystem"; - homepage = "https://github.com/analogdevicesinc/libiio"; - license = licenses.lgpl21; - platforms = platforms.linux; + homepage = "https://github.com/analogdevicesinc/libiio"; + license = licenses.lgpl21Plus; + platforms = platforms.linux; maintainers = with maintainers; [ thoughtpolice ]; }; } diff --git a/pkgs/development/libraries/libiio/hardcode-library-path.patch b/pkgs/development/libraries/libiio/hardcode-library-path.patch new file mode 100644 index 000000000000..dad35851cdc6 --- /dev/null +++ b/pkgs/development/libraries/libiio/hardcode-library-path.patch @@ -0,0 +1,38 @@ +diff --git a/bindings/python/iio.py b/bindings/python/iio.py +index 5306daa..f8962ee 100644 +--- a/bindings/python/iio.py ++++ b/bindings/python/iio.py +@@ -229,9 +229,9 @@ if "Windows" in _system(): + _iiolib = "libiio.dll" + else: + # Non-windows, possibly Posix system +- _iiolib = "iio" ++ _iiolib = "@libiio@" + +-_lib = _cdll(find_library(_iiolib), use_errno=True, use_last_error=True) ++_lib = _cdll(_iiolib, use_errno=True, use_last_error=True) + + _get_backends_count = _lib.iio_get_backends_count + _get_backends_count.restype = c_uint +diff --git a/bindings/python/setup.py.cmakein b/bindings/python/setup.py.cmakein +index cd14e2e..516c409 100644 +--- a/bindings/python/setup.py.cmakein ++++ b/bindings/python/setup.py.cmakein +@@ -62,7 +62,7 @@ class InstallWrapper(install): + _iiolib = "libiio.dll" + else: + # Non-windows, possibly Posix system +- _iiolib = "iio" ++ _iiolib = "@libiio@" + try: + import os + +@@ -72,7 +72,7 @@ class InstallWrapper(install): + fulllibpath = find_recursive(destdir, "libiio.so") + _lib = _cdll(fulllibpath, use_errno=True, use_last_error=True) + else: +- _lib = _cdll(find_library(_iiolib), use_errno=True, use_last_error=True) ++ _lib = _cdll(_iiolib, use_errno=True, use_last_error=True) + if not _lib._name: + raise OSError + except OSError: