nixpkgs/pkgs/development/libraries/libiio/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

86 lines
2.3 KiB
Nix

{ stdenv
, fetchFromGitHub
, cmake
, flex
, bison
, libxml2
, pythonSupport ? stdenv.hostPlatform.hasSharedLibraries, python
, libusb1
, avahiSupport ? true, avahi
, libaio
, runtimeShell
, lib
, pkg-config
, CFNetwork
, CoreServices
}:
stdenv.mkDerivation rec {
pname = "libiio";
version = "0.24";
outputs = [ "out" "lib" "dev" ]
++ lib.optional pythonSupport "python";
src = fetchFromGitHub {
owner = "analogdevicesinc";
repo = "libiio";
rev = "v${version}";
sha256 = "sha256-c5HsxCdp1cv5BGTQ/8dc8J893zk9ntbfAudLpqoQ1ow=";
};
# Revert after https://github.com/NixOS/nixpkgs/issues/125008 is
# fixed properly
patches = [ ./cmake-fix-libxml2-find-package.patch ];
nativeBuildInputs = [
cmake
flex
bison
pkg-config
] ++ lib.optionals pythonSupport ([
python
] ++ lib.optional python.isPy3k python.pkgs.setuptools);
buildInputs = [
libxml2
libusb1
] ++ lib.optional avahiSupport avahi
++ lib.optional stdenv.hostPlatform.isLinux libaio
++ lib.optionals stdenv.hostPlatform.isDarwin [ CFNetwork CoreServices ];
cmakeFlags = [
"-DUDEV_RULES_INSTALL_DIR=${placeholder "out"}/lib/udev/rules.d"
# osx framework is disabled,
# the linux-like directory structure is used for proper output splitting
"-DOSX_PACKAGE=off"
"-DOSX_FRAMEWORK=off"
] ++ lib.optionals pythonSupport [
"-DPython_EXECUTABLE=${python.pythonOnBuildForHost.interpreter}"
"-DPYTHON_BINDINGS=on"
] ++ lib.optionals (!avahiSupport) [
"-DHAVE_DNS_SD=OFF"
];
postPatch = ''
substituteInPlace libiio.rules.cmakein \
--replace /bin/sh ${runtimeShell}
'' + lib.optionalString pythonSupport ''
# 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
'';
postInstall = lib.optionalString pythonSupport ''
# Move Python bindings into a separate output.
moveToOutput ${python.sitePackages} "$python"
'';
meta = with lib; {
description = "API for interfacing with the Linux Industrial I/O Subsystem";
homepage = "https://github.com/analogdevicesinc/libiio";
license = licenses.lgpl21Plus;
platforms = platforms.linux ++ platforms.darwin;
maintainers = with maintainers; [ thoughtpolice ];
};
}