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

[DONTMERGE] PR to demonstrate qutebrowser cross compile #265401

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/systems/inspect.nix
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,32 @@ rec {
];
};

# given two patterns, return a pattern which is their logical AND.
# Since a pattern is a list-of-disjuncts, this needs to
patternLogicalAnd = pat1_: pat2_:
let
# patterns can be either a list or a (bare) singleton; turn
# them into singletons for uniform handling
pat1 = lib.toList pat1_;
pat2 = lib.toList pat2_;
in
lib.concatMap (attr1:
map (attr2:
lib.recursiveUpdateUntil
(path: subattr1: subattr2:
if (builtins.intersectAttrs subattr1 subattr2) == {} || subattr1 == subattr2
then true
else throw ''
pattern conflict at path ${toString path}:
${builtins.toJSON subattr1}
${builtins.toJSON subattr2}
'')
attr1
attr2
)
pat2)
pat1;

matchAnyAttrs = patterns:
if builtins.isList patterns then attrs: any (pattern: matchAttrs pattern attrs) patterns
else matchAttrs patterns;
Expand Down
12 changes: 9 additions & 3 deletions pkgs/applications/networking/browsers/qutebrowser/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
, widevine-cdm
, enableVulkan ? stdenv.isLinux
, vulkan-loader
, buildPackages
}:

let
isQt6 = lib.versions.major qtbase.version == "6";
pdfjs = let
version = "3.9.179";
in
Expand Down Expand Up @@ -50,10 +52,14 @@ python3.pkgs.buildPythonApplication {
];

propagatedBuildInputs = with python3.pkgs; ([
pyyaml pyqt6-webengine jinja2 pygments
pyyaml (if isQt6 then pyqt6-webengine else pyqtwebengine) jinja2 pygments
# scripts and userscripts libs
tldextract beautifulsoup4
readability-lxml pykeepass stem
readability-lxml pykeepass
] ++ lib.optionals ((builtins.tryEval stem.outPath).success) [
# error: stem-1.8.2 not supported for interpreter python3.11
stem
] ++ [
pynacl
# extensive ad blocking
adblock
Expand All @@ -80,7 +86,7 @@ python3.pkgs.buildPythonApplication {
runHook preInstall

make -f misc/Makefile \
PYTHON=${python3}/bin/python3 \
PYTHON=${buildPackages.python3}/bin/python3 \
PREFIX=. \
DESTDIR="$out" \
DATAROOTDIR=/share \
Expand Down
3 changes: 3 additions & 0 deletions pkgs/by-name/ja/jasper/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@ stdenv.mkDerivation (finalAttrs: {
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ AndersonTorres ];
platforms = lib.platforms.unix;

# The value of __STDC_VERSION__ cannot be automatically determined when cross-compiling.
broken = stdenv.buildPlatform != stdenv.hostPlatform;
};
})
19 changes: 14 additions & 5 deletions pkgs/development/libraries/qt-5/5.15/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Check for any minor version changes.
, lib, stdenv, fetchurl, fetchgit, fetchpatch, fetchFromGitHub, makeSetupHook, makeWrapper
, bison, cups ? null, harfbuzz, libGL, perl, python3
, gstreamer, gst-plugins-base, gtk3, dconf
, buildPackages
, darwin

# options
Expand Down Expand Up @@ -313,18 +314,20 @@ let

qmake = callPackage ({ qtbase }: makeSetupHook {
name = "qmake-hook";
propagatedBuildInputs = [ qtbase.dev ];
depsTargetTargetPropagated = [ qtbase.dev ];
substitutions = {
inherit debug;
fix_qmake_libtool = ../hooks/fix-qmake-libtool.sh;
};
} ../hooks/qmake-hook.sh) { };

wrapQtAppsHook = callPackage ({ makeBinaryWrapper, qtbase, qtwayland }: makeSetupHook {
wrapQtAppsHook = callPackage ({ makeBinaryWrapper, qtbase, qtwayland }: makeSetupHook ({
name = "wrap-qt5-apps-hook";
propagatedBuildInputs = [ qtbase.dev makeBinaryWrapper ]
propagatedBuildInputs = [ buildPackages.makeBinaryWrapper ];
depsTargetTargetPropagated = [ qtbase.dev ]
++ lib.optional stdenv.isLinux qtwayland.dev;
} ../hooks/wrap-qt-apps-hook.sh) { };
})
../hooks/wrap-qt-apps-hook.sh) { };
};

baseScope = makeScopeWithSplicing' {
Expand All @@ -338,6 +341,12 @@ let
});

finalScope = baseScope.overrideScope(final: prev: {
qttranslations = bootstrapScope.qttranslations;
# qttranslations causes eval-time infinite recursion when
# cross-compiling; disabled for now.
qttranslations =
if stdenv.buildPlatform == stdenv.hostPlatform
then bootstrapScope.qttranslations
else null;
qutebrowser = final.callPackage ../../../../applications/networking/browsers/qutebrowser { };
});
in finalScope
10 changes: 10 additions & 0 deletions pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
if [[ "x$stdenv" != "x@qtbase_stdenv@" ]]; then
echo "skipping qtbase-setup-hook.sh because of mismatch:"
echo " stdenv of current derivation: $stdenv"
echo " stdenv of qtbase.dev dependency: @qtbase_stdenv@"
echo " qtbase = @dev@"
return
fi

echo "running qtbase-setup-hook.sh with hostOffset=$hostOffset targetOffset=$targetOffset: @out@"

if [[ -n "${__nix_qtbase-}" ]]; then
# Throw an error if a different version of Qt was already set up.
if [[ "$__nix_qtbase" != "@dev@" ]]; then
Expand Down
63 changes: 52 additions & 11 deletions pkgs/development/libraries/qt-5/modules/qtbase.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@
, 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: {
stdenv.mkDerivation (finalAttrs: ({
pname = "qtbase";
inherit qtCompatVersion src version;
debug = debugSymbols;
Expand Down Expand Up @@ -83,6 +88,13 @@ stdenv.mkDerivation (finalAttrs: {
nativeBuildInputs = [ bison flex gperf lndir perl pkg-config which ]
++ lib.optionals stdenv.isDarwin [ xcbuild ];

} // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) {
# `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
Expand Down Expand Up @@ -162,6 +174,13 @@ stdenv.mkDerivation (finalAttrs: {
export MAKEFLAGS+=" -j$NIX_BUILD_CORES"

./bin/syncqt.pl -version $version
'' + lib.optionalString (!stdenv.buildPlatform.canExecute 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
echo "QMAKE_LFLAGS=''${LDFLAGS}" >> mkspecs/devices/${qtPlatformCross stdenv.hostPlatform}/qmake.conf
echo "QMAKE_CFLAGS=''${CFLAGS}" >> mkspecs/devices/${qtPlatformCross stdenv.hostPlatform}/qmake.conf
echo "QMAKE_CXXFLAGS=''${CXXFLAGS}" >> mkspecs/devices/${qtPlatformCross stdenv.hostPlatform}/qmake.conf
'';

postConfigure = ''
Expand All @@ -186,21 +205,35 @@ stdenv.mkDerivation (finalAttrs: {
done
'';

env.NIX_CFLAGS_COMPILE = toString ([
"-Wno-error=sign-compare" # freetype-2.5.4 changed signedness of some struct fields
''-DNIXPKGS_QTCOMPOSE="${libX11.out}/share/X11/locale"''
''-DLIBRESOLV_SO="${stdenv.cc.libc.out}/lib/libresolv"''
''-DNIXPKGS_LIBXCURSOR="${libXcursor.out}/lib/libXcursor"''
] ++ lib.optional libGLSupported ''-DNIXPKGS_MESA_GL="${libGL.out}/lib/libGL"''
env = {
qtbase_stdenv = stdenv.outPath;
NIX_CFLAGS_COMPILE = toString ([
"-Wno-error=sign-compare" # freetype-2.5.4 changed signedness of some struct fields
] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
"-Wno-warn=free-nonheap-object"
"-Wno-free-nonheap-object"
"-w"
] ++ [
''-DNIXPKGS_QTCOMPOSE="${libX11.out}/share/X11/locale"''
''-DLIBRESOLV_SO="${stdenv.cc.libc.out}/lib/libresolv"''
''-DNIXPKGS_LIBXCURSOR="${libXcursor.out}/lib/libXcursor"''
] ++ lib.optional libGLSupported ''-DNIXPKGS_MESA_GL="${libGL.out}/lib/libGL"''
++ lib.optional stdenv.isLinux "-DUSE_X11"
++ lib.optionals (stdenv.hostPlatform.system == "x86_64-darwin") [
# ignore "is only available on macOS 10.12.2 or newer" in obj-c code
"-Wno-error=unguarded-availability"
]
++ lib.optionals withGtk3 [
''-DNIXPKGS_QGTK3_XDG_DATA_DIRS="${gtk3}/share/gsettings-schemas/${gtk3.name}"''
''-DNIXPKGS_QGTK3_GIO_EXTRA_MODULES="${dconf.lib}/lib/gio/modules"''
] ++ lib.optional decryptSslTraffic "-DQT_DECRYPT_SSL_TRAFFIC");
''-DNIXPKGS_QGTK3_XDG_DATA_DIRS="${gtk3}/share/gsettings-schemas/${gtk3.name}"''
''-DNIXPKGS_QGTK3_GIO_EXTRA_MODULES="${dconf.lib}/lib/gio/modules"''
] ++ lib.optional decryptSslTraffic "-DQT_DECRYPT_SSL_TRAFFIC");
} // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) {
NIX_CFLAGS_COMPILE_FOR_BUILD = toString ([
"-Wno-warn=free-nonheap-object"
"-Wno-free-nonheap-object"
"-w"
]);
};

prefixKey = "-prefix ";

Expand All @@ -209,6 +242,9 @@ stdenv.mkDerivation (finalAttrs: {
# To prevent these failures, we need to override PostgreSQL detection.
PSQL_LIBS = lib.optionalString (postgresql != null) "-L${postgresql.lib}/lib -lpq";

} // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) {
configurePlatforms = [ ];
} // {
# TODO Remove obsolete and useless flags once the build will be totally mastered
configureFlags = [
"-plugindir $(out)/$(qtPluginPrefix)"
Expand All @@ -235,11 +271,16 @@ 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 [
"-developer-build"
"-no-warnings-are-errors"
] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
"-no-warnings-are-errors"
] ++ (if (!stdenv.hostPlatform.isx86_64) then [
"-no-sse2"
] else [
Expand Down Expand Up @@ -381,4 +422,4 @@ stdenv.mkDerivation (finalAttrs: {
platforms = platforms.unix;
};

})
}))
10 changes: 9 additions & 1 deletion pkgs/development/libraries/qt-5/modules/qtdeclarative.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{ qtModule, lib, python3, qtbase, qtsvg }:
{ lib
, stdenv
, qtModule, python3, qtbase, qtsvg }:

qtModule {
pname = "qtdeclarative";
Expand All @@ -21,4 +23,10 @@ qtModule {
"bin/qmlscene"
"bin/qmltestrunner"
];
postFixup = lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
mv $dev/bin/qmlformat $bin/bin/qmlformat
mv $dev/bin/qmltyperegistrar $bin/bin/qmltyperegistrar
ln -s $bin/bin/qmlformat $dev/bin/qmlformat
ln -s $bin/bin/qmltyperegistrar $dev/bin/qmltyperegistrar
'';
}
12 changes: 10 additions & 2 deletions pkgs/development/libraries/qt-5/modules/qtimageformats.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{ qtModule
{ lib
, stdenv
, qtModule
, qtbase
, libwebp
, jasper
Expand All @@ -8,5 +10,11 @@

qtModule {
pname = "qtimageformats";
propagatedBuildInputs = [ qtbase libwebp jasper libmng libtiff ];
propagatedBuildInputs = [
qtbase libwebp
] ++ lib.optionals (!jasper.meta.broken) [
jasper
] ++ [
libmng libtiff
];
}
9 changes: 7 additions & 2 deletions pkgs/development/libraries/qt-5/modules/qtwebchannel.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{ qtModule, qtbase, qtdeclarative }:
{ lib
, stdenv
, qtModule
, qtbase
, qtdeclarative
}:

qtModule {
pname = "qtwebchannel";
propagatedBuildInputs = [ qtbase qtdeclarative ];
outputs = [ "out" "dev" "bin" ];
outputs = [ "out" "dev" ] ++ lib.optionals (stdenv.hostPlatform == stdenv.buildPlatform) [ "bin" ];
}
Loading