Unverified Commit f74f40b5 authored by Florian Brandes's avatar Florian Brandes
Browse files

python312Packages.pyside6: allow optional dependencies for darwin



This commit refactors `pyside6` by:

- adding LLVM_INSTALL_DIR environment variable to let
  `pyside6` find the libclang library
- add required darwin frameworks
- use a `symlinkJoin` construct of all qt6 dependencies
  so `pyside6` finds the dependencies on darwin. This is
  necessary, because `pyside6` on macos expects all
  dependencies to be under the same directory
- remove the optional module `Designer` from the darwin python
  bindings, since it causes linker failures.

The benefit of this change is that `pyside6` now includes almost
all the python bindings for Qt (except Designer and qtwebengine)
on darwin.

This also adds the following modules to the `x86_64-linux` binding:

- qtpositioning
- qtlocation
- qtshadertools
- qtserialport
- qtserialbus
- qtgraphs

Signed-off-by: default avatarFlorian Brandes <florian.brandes@posteo.de>
parent 18cb69fb
Loading
Loading
Loading
Loading
+76 −31
Original line number Diff line number Diff line
@@ -2,11 +2,54 @@
  lib,
  stdenv,
  cmake,
  cups,
  ninja,
  python,
  moveBuildTree,
  shiboken6,
  llvmPackages,
  symlinkJoin,
  libGL,
  darwin,
}:
let
  packages = with python.pkgs.qt6; [
    # required
    python.pkgs.ninja
    python.pkgs.packaging
    python.pkgs.setuptools
    qtbase

    # optional
    qt3d
    qtcharts
    qtconnectivity
    qtdatavis3d
    qtdeclarative
    qthttpserver
    qtmultimedia
    qtnetworkauth
    qtquick3d
    qtremoteobjects
    qtscxml
    qtsensors
    qtspeech
    qtsvg
    qtwebchannel
    qtwebsockets
    qtpositioning
    qtlocation
    qtshadertools
    qtserialport
    qtserialbus
    qtgraphs
    qttools
  ];
  qt_linked = symlinkJoin {
    name = "qt_linked";
    paths = packages;
  };
in

stdenv.mkDerivation (finalAttrs: {
  pname = "pyside6";
@@ -15,16 +58,27 @@ stdenv.mkDerivation (finalAttrs: {

  sourceRoot = "pyside-setup-everywhere-src-${finalAttrs.version}/sources/pyside6";

  # FIXME: cmake/Macros/PySideModules.cmake supposes that all Qt frameworks on macOS
  # cmake/Macros/PySideModules.cmake supposes that all Qt frameworks on macOS
  # reside in the same directory as QtCore.framework, which is not true for Nix.
  postPatch = lib.optionalString stdenv.isLinux ''
  # We therefore symLink all required and optional Qt modules in one directory tree ("qt_linked").
  # Also we remove "Designer" from darwin build, due to linking failure
  postPatch =
    ''
    # Don't ignore optional Qt modules
    substituteInPlace cmake/PySideHelpers.cmake \
      --replace-fail \
        'string(FIND "''${_module_dir}" "''${_core_abs_dir}" found_basepath)' \
        'set (found_basepath 0)'
  ''
  + lib.optionalString stdenv.isDarwin ''
    substituteInPlace cmake/PySideHelpers.cmake \
      --replace-fail \
        "Designer" ""
  '';

  # "Couldn't find libclang.dylib You will likely need to add it manually to PATH to ensure the build succeeds."
  env = lib.optionalAttrs stdenv.isDarwin { LLVM_INSTALL_DIR = "${llvmPackages.libclang.lib}/lib"; };

  nativeBuildInputs = [
    cmake
    ninja
@@ -32,34 +86,25 @@ stdenv.mkDerivation (finalAttrs: {
  ] ++ lib.optionals stdenv.isDarwin [ moveBuildTree ];

  buildInputs =
    with python.pkgs.qt6;
    if stdenv.isLinux then
      # qtwebengine fails under darwin
      # see https://github.com/NixOS/nixpkgs/pull/312987
      packages ++ [ python.pkgs.qt6.qtwebengine ]
    else
      with darwin.apple_sdk_11_0.frameworks;
      [
      # required
      qtbase
      python.pkgs.ninja
      python.pkgs.packaging
      python.pkgs.setuptools
    ]
    ++ lib.optionals stdenv.isLinux [
      # optional
      qt3d
      qtcharts
      qtconnectivity
      qtdatavis3d
      qtdeclarative
      qthttpserver
      qtmultimedia
      qtnetworkauth
      qtquick3d
      qtremoteobjects
      qtscxml
      qtsensors
      qtspeech
      qtsvg
      qttools
      qtwebchannel
      qtwebengine
      qtwebsockets
        qt_linked
        libGL
        cups
        # frameworks
        IOKit
        DiskArbitration
        CoreBluetooth
        EventKit
        AVFoundation
        Contacts
        AGL
        AppKit
      ];

  propagatedBuildInputs = [ shiboken6 ];