Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libiio: disable Python for static builds #248412

Merged
1 commit merged into from
Aug 17, 2023

Conversation

lopsided98
Copy link
Contributor

Description of changes

libiio's Python bindings use ctypes to load the shared library, which obviously can't work with a static build. Recent changes (#240575, #244118) have also started causing eval errors because the package uses stdenv.hostPlatform.extensions.sharedLibrary, which isn't available when building a static library:

 error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'ardupilot-copter-bebop-static-armv7l-unknown-linux-musleabihf-35da15d'
         whose name attribute is located at /nix/store/sralzj4w34v4mwr0sxq417b4ys202in3-source/pkgs/stdenv/generic/make-derivation.nix:300:7

       … while evaluating attribute 'propagatedBuildInputs' of derivation 'ardupilot-copter-bebop-static-armv7l-unknown-linux-musleabihf-35da15d'

         at /nix/store/sralzj4w34v4mwr0sxq417b4ys202in3-source/pkgs/stdenv/generic/make-derivation.nix:354:7:

          353|       depsHostHostPropagated      = lib.elemAt (lib.elemAt propagatedDependencies 1) 0;
          354|       propagatedBuildInputs       = lib.elemAt (lib.elemAt propagatedDependencies 1) 1;
             |       ^
          355|       depsTargetTargetPropagated  = lib.elemAt (lib.elemAt propagatedDependencies 2) 0;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'sharedLibrary' missing

       at /nix/store/sralzj4w34v4mwr0sxq417b4ys202in3-source/pkgs/development/libraries/libiio/default.nix:64:38:

           63|     # Hardcode path to the shared library into the bindings.
           64|     sed "s#@libiio@#$lib/lib/libiio${stdenv.hostPlatform.extensions.sharedLibrary}#g" ${./hardcode-library-path.patch} | patch -p1
             |                                      ^
           65|

This patch adds a flag to disable the Python bindings, and automatically disables them for static builds.

Note that even with this patch, static libiio doesn't build successfully by default. You have to disable avahi and manually disable libxml2 with custom CMake flags. I currently build a custom stripped down static libiio like this:

(pkgsStatic.libiio.override {
  avahiSupport = false;
  libxml2 = null;
  libusb1 = null;
}).overrideAttrs ({
  cmakeFlags ? [], ...
}: {
  cmakeFlags = cmakeFlags ++ [
    "-DWITH_NETWORK_BACKEND=OFF"
    "-DWITH_USB_BACKEND=OFF"
    "-DWITH_XML_BACKEND=OFF"
  ];
})

cc @thoughtpolice @amjoseph-nixpkgs

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@ofborg ofborg bot requested a review from thoughtpolice August 10, 2023 20:23
lopsided98 added a commit to lopsided98/ardupilot-flake that referenced this pull request Aug 12, 2023
pkgs/development/libraries/libiio/default.nix Outdated Show resolved Hide resolved
@lopsided98 lopsided98 force-pushed the libiio-python-static branch 2 times, most recently from 5a6880a to 8324e07 Compare August 16, 2023 16:55
libiio's Python bindings use ctypes to load the shared library, which
obviously can't work with a static build. This has recently started
causing eval errors because the package uses
stdenv.hostPlatform.extensions.sharedLibrary, which isn't available when
building a static library.

This patch adds a flag to disable the Python bindings, and automatically
disables them for static builds.

Note that even with this patch, static libiio doesn't build successfully
by default. You have to disable avahi and manually disable libxml2 with
custom CMake flags.
@ghost ghost merged commit f606e48 into NixOS:master Aug 17, 2023
21 checks passed
@lopsided98 lopsided98 deleted the libiio-python-static branch August 17, 2023 05:05
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant