From c9b4998cc9545fa9f968ec29a8a05350dc0e2ed4 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Thu, 9 Mar 2023 00:34:17 -0800 Subject: [PATCH 1/4] qt-5/modules/qtbase.nix: omit --host and --build configureFlags QT's configure script doesn't understand these, so let's not pass them. Co-authored-by: Sandro --- pkgs/development/libraries/qt-5/modules/qtbase.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/libraries/qt-5/modules/qtbase.nix b/pkgs/development/libraries/qt-5/modules/qtbase.nix index de73bcbe2772..edcab1e9c11f 100644 --- a/pkgs/development/libraries/qt-5/modules/qtbase.nix +++ b/pkgs/development/libraries/qt-5/modules/qtbase.nix @@ -208,6 +208,8 @@ stdenv.mkDerivation (finalAttrs: { # To prevent these failures, we need to override PostgreSQL detection. PSQL_LIBS = lib.optionalString (postgresql != null) "-L${postgresql.lib}/lib -lpq"; + # do not pass --host and --build to configureFlags as QT's configure script doesn't understand them + configurePlatforms = [ ]; # TODO Remove obsolete and useless flags once the build will be totally mastered configureFlags = [ "-plugindir $(out)/$(qtPluginPrefix)" From 1430b56362a4719e807568dc38c9b060b118f063 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 23 Apr 2023 17:13:19 -0700 Subject: [PATCH 2/4] qt5.qtbase: fix cross compilation This commit fixes builds of `pkgsCross.*.qt5.qtbase` by: - Adding the buildPlatform compiler to depsBuildBuild in qtbase.nix and qtModule.nix. The `qtbase` build machinery expects to find it in the $PATH in unprefixed form. - Setting the `PKG_CONFIG_SYSROOT_DIR` and `PKG_CONFIG_LIBDIR` environment variables when compiling a cross-targeted `qmake`. This is required; if these environment variables are unset, `qmake` won't even try to use `pkg-config`. - Adding the `-device` and `-device-option` flags necessary for cross compilation to `configureFlags`. - Adding the (one-entry at the moment) Rosetta Stone for QT-5 as a `let`-defined `qtPlatform` function which takes a nixpkgs platform and returns a QT-5 `mkspecs`-string. Co-authored-by: Christoph Neidahl --- .../development/libraries/qt-5/5.15/default.nix | 3 ++- .../libraries/qt-5/hooks/qtbase-setup-hook.sh | 2 ++ .../libraries/qt-5/modules/qtbase.nix | 17 +++++++++++++++++ pkgs/development/libraries/qt-5/qtModule.nix | 12 ++++++++++-- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/pkgs/development/libraries/qt-5/5.15/default.nix b/pkgs/development/libraries/qt-5/5.15/default.nix index 16be29ad529e..6ed5f2b0b1b6 100644 --- a/pkgs/development/libraries/qt-5/5.15/default.nix +++ b/pkgs/development/libraries/qt-5/5.15/default.nix @@ -207,7 +207,8 @@ let import ../qtModule.nix { inherit perl; - inherit lib; + inherit lib stdenv; + inherit buildPackages; # Use a variant of mkDerivation that does not include wrapQtApplications # to avoid cyclic dependencies between Qt modules. mkDerivation = diff --git a/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh b/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh index 1b57d676e1fc..0e23ec143218 100644 --- a/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh +++ b/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh @@ -1,4 +1,5 @@ if [[ -n "${__nix_qtbase-}" ]]; then + if [ -z "${dontWorryAboutQtMismatch-}" ]; then # Throw an error if a different version of Qt was already set up. if [[ "$__nix_qtbase" != "@dev@" ]]; then echo >&2 "Error: detected mismatched Qt dependencies:" @@ -6,6 +7,7 @@ if [[ -n "${__nix_qtbase-}" ]]; then echo >&2 " $__nix_qtbase" exit 1 fi + fi else # Only set up Qt once. __nix_qtbase="@dev@" diff --git a/pkgs/development/libraries/qt-5/modules/qtbase.nix b/pkgs/development/libraries/qt-5/modules/qtbase.nix index edcab1e9c11f..f0cc3950e053 100644 --- a/pkgs/development/libraries/qt-5/modules/qtbase.nix +++ b/pkgs/development/libraries/qt-5/modules/qtbase.nix @@ -28,10 +28,15 @@ , developerBuild ? false , decryptSslTraffic ? false , testers +, buildPackages }: let debugSymbols = debug || developerBuild; + qtPlatformCross = plat: with plat; + if isLinux + then "linux-generic-g++" + else throw "Please add a qtPlatformCross entry for ${plat.config}"; in stdenv.mkDerivation (finalAttrs: { @@ -82,6 +87,11 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ bison flex gperf lndir perl pkg-config which ] ++ lib.optionals stdenv.isDarwin [ xcbuild ]; + # `qtbase` expects to find `cc` (with no prefix) in the + # `$PATH`, so the following is needed even if + # `stdenv.buildPlatform.canExecute stdenv.hostPlatform` + depsBuildBuild = [ buildPackages.stdenv.cc ]; + propagatedNativeBuildInputs = [ lndir ]; # libQt5Core links calls CoreFoundation APIs that call into the system ICU. Binaries linked @@ -161,6 +171,10 @@ stdenv.mkDerivation (finalAttrs: { export MAKEFLAGS+=" -j$NIX_BUILD_CORES" ./bin/syncqt.pl -version $version + '' + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + # QT's configure script will refuse to use pkg-config unless these two environment variables are set + export PKG_CONFIG_SYSROOT_DIR=/ + export PKG_CONFIG_LIBDIR=${lib.getLib pkg-config}/lib ''; postConfigure = '' @@ -236,6 +250,9 @@ stdenv.mkDerivation (finalAttrs: { "-L" "${icu.out}/lib" "-I" "${icu.dev}/include" "-pch" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-device ${qtPlatformCross stdenv.hostPlatform}" + "-device-option CROSS_COMPILE=${stdenv.cc.targetPrefix}" ] ++ lib.optional debugSymbols "-debug" ++ lib.optionals developerBuild [ diff --git a/pkgs/development/libraries/qt-5/qtModule.nix b/pkgs/development/libraries/qt-5/qtModule.nix index 9abd9fabc957..75deee58ea60 100644 --- a/pkgs/development/libraries/qt-5/qtModule.nix +++ b/pkgs/development/libraries/qt-5/qtModule.nix @@ -1,4 +1,8 @@ -{ lib, mkDerivation, perl }: +{ lib +, stdenv +, mkDerivation, perl +, buildPackages +}: let inherit (lib) licenses maintainers platforms; in @@ -17,7 +21,8 @@ mkDerivation (args // { patches = (args.patches or []) ++ (patches.${pname} or []); nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ perl self.qmake ]; - propagatedBuildInputs = args.qtInputs ++ (args.propagatedBuildInputs or []); + propagatedBuildInputs = (args.qtInputs or []) ++ (args.propagatedBuildInputs or []); + depsBuildBuild = [ buildPackages.stdenv.cc ]; outputs = args.outputs or [ "out" "dev" ]; setOutputFlags = args.setOutputFlags or false; @@ -74,4 +79,7 @@ mkDerivation (args // { maintainers = with maintainers; [ qknight ttuegel periklis bkchr ]; platforms = platforms.unix; } // (args.meta or {}); + +} // lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform) { + dontWorryAboutQtMismatch = true; }) From f81e02d9a77194058af95847f22d7db10b555563 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 20 Aug 2023 23:37:47 -0700 Subject: [PATCH 3/4] qt5.qtbase: implement @OPNA2608 suggestion From here: https://github.com/NixOS/nixpkgs/pull/227900#discussion_r1299351842 --- pkgs/development/libraries/qt-5/modules/qtbase.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/development/libraries/qt-5/modules/qtbase.nix b/pkgs/development/libraries/qt-5/modules/qtbase.nix index f0cc3950e053..c86bc70c65f7 100644 --- a/pkgs/development/libraries/qt-5/modules/qtbase.nix +++ b/pkgs/development/libraries/qt-5/modules/qtbase.nix @@ -175,6 +175,7 @@ stdenv.mkDerivation (finalAttrs: { # QT's configure script will refuse to use pkg-config unless these two environment variables are set export PKG_CONFIG_SYSROOT_DIR=/ export PKG_CONFIG_LIBDIR=${lib.getLib pkg-config}/lib + echo "QMAKE_PKG_CONFIG=''$''${CROSS_COMPILE}pkg-config" >> mkspecs/devices/${qtPlatformCross stdenv.hostPlatform}/qmake.conf ''; postConfigure = '' From ba1dcb2e265c800a65649d7f0fbe777920194ed7 Mon Sep 17 00:00:00 2001 From: Adam Joseph <54836058+amjoseph-nixpkgs@users.noreply.github.com> Date: Mon, 21 Aug 2023 20:34:53 +0000 Subject: [PATCH 4/4] Update pkgs/development/libraries/qt-5/modules/qtbase.nix Co-authored-by: Christoph Neidahl --- pkgs/development/libraries/qt-5/modules/qtbase.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/libraries/qt-5/modules/qtbase.nix b/pkgs/development/libraries/qt-5/modules/qtbase.nix index c86bc70c65f7..ed280cc0151a 100644 --- a/pkgs/development/libraries/qt-5/modules/qtbase.nix +++ b/pkgs/development/libraries/qt-5/modules/qtbase.nix @@ -175,7 +175,7 @@ stdenv.mkDerivation (finalAttrs: { # QT's configure script will refuse to use pkg-config unless these two environment variables are set export PKG_CONFIG_SYSROOT_DIR=/ export PKG_CONFIG_LIBDIR=${lib.getLib pkg-config}/lib - echo "QMAKE_PKG_CONFIG=''$''${CROSS_COMPILE}pkg-config" >> mkspecs/devices/${qtPlatformCross stdenv.hostPlatform}/qmake.conf + echo 'QMAKE_PKG_CONFIG=''$''${CROSS_COMPILE}pkg-config' >> mkspecs/devices/${qtPlatformCross stdenv.hostPlatform}/qmake.conf ''; postConfigure = ''