diff options
author | Matthew Bauer <mjbauer95@gmail.com> | 2018-11-13 16:54:08 -0600 |
---|---|---|
committer | Matthew Bauer <mjbauer95@gmail.com> | 2018-11-29 19:15:30 -0600 |
commit | 9c8fd412248ad907eee7547b19bf3f7583d2c411 (patch) | |
tree | 0db9bedd232a22f0c17c4d7c9f101d9ddaeed160 /pkgs | |
parent | ce6d558c4deebf373eae8723cfb7c181be2be9be (diff) |
treewide: add emulator to platform
You can use stdenv.hostPlatform.emulator to get an executable that runs cross-built binaries. This could be any emulator. For instance, we use QEMU to emulate Linux targets and Wine to emulate Windows targets. To work with qemu, we need to support custom targets. I’ve reworked the cross tests in pkgs/test/cross to use this functionality. Also, I’ve used talloc to cross-execute with the emulator. There appears to be a cross-execute for all waf builds. In the future, it would be nice to set this for all waf builds. Adds stdenv.hostPlatform.qemuArch attrbute to get the qemuArch for each platform.
Diffstat (limited to 'pkgs')
-rw-r--r-- | pkgs/applications/virtualization/qemu/default.nix | 24 | ||||
-rw-r--r-- | pkgs/development/libraries/talloc/default.nix | 14 | ||||
-rw-r--r-- | pkgs/test/cross/default.nix | 62 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 2 |
4 files changed, 58 insertions, 44 deletions
diff --git a/pkgs/applications/virtualization/qemu/default.nix b/pkgs/applications/virtualization/qemu/default.nix index d9495bd984ef0..ea330d5955575 100644 --- a/pkgs/applications/virtualization/qemu/default.nix +++ b/pkgs/applications/virtualization/qemu/default.nix @@ -18,6 +18,10 @@ , virglSupport ? openGLSupport, virglrenderer , smbdSupport ? false, samba , hostCpuOnly ? false +, hostCpuTargets ? (if hostCpuOnly + then (stdenv.lib.optional stdenv.isx86_64 "i386-softmmu" + ++ ["${stdenv.hostPlatform.qemuArch}-softmmu"]) + else null) , nixosTestRunner ? false }: @@ -27,11 +31,6 @@ let + optionalString pulseSupport "pa," + optionalString sdlSupport "sdl,"; - hostCpuTargets = if stdenv.isx86_64 then "i386-softmmu,x86_64-softmmu" - else if stdenv.isi686 then "i386-softmmu" - else if stdenv.isAarch32 then "arm-softmmu" - else if stdenv.isAarch64 then "aarch64-softmmu" - else throw "Don't know how to build a 'hostCpuOnly = true' QEMU"; in stdenv.mkDerivation rec { @@ -113,7 +112,7 @@ stdenv.mkDerivation rec { ++ optional smartcardSupport "--enable-smartcard" ++ optional spiceSupport "--enable-spice" ++ optional usbredirSupport "--enable-usb-redir" - ++ optional hostCpuOnly "--target-list=${hostCpuTargets}" + ++ optional (hostCpuTargets != null) "--target-list=${stdenv.lib.concatStringsSep "," hostCpuTargets}" ++ optional stdenv.isDarwin "--enable-cocoa" ++ optional stdenv.isLinux "--enable-linux-aio" ++ optional gtkSupport "--enable-gtk" @@ -135,12 +134,13 @@ stdenv.mkDerivation rec { ''; # Add a ‘qemu-kvm’ wrapper for compatibility/convenience. - postInstall = - if stdenv.isx86_64 then ''makeWrapper $out/bin/qemu-system-x86_64 $out/bin/qemu-kvm --add-flags "\$([ -e /dev/kvm ] && echo -enable-kvm)"'' - else if stdenv.isi686 then ''makeWrapper $out/bin/qemu-system-i386 $out/bin/qemu-kvm --add-flags "\$([ -e /dev/kvm ] && echo -enable-kvm)"'' - else if stdenv.isAarch32 then ''makeWrapper $out/bin/qemu-system-arm $out/bin/qemu-kvm --add-flags "\$([ -e /dev/kvm ] && echo -enable-kvm)"'' - else if stdenv.isAarch64 then ''makeWrapper $out/bin/qemu-system-aarch64 $out/bin/qemu-kvm --add-flags "\$([ -e /dev/kvm ] && echo -enable-kvm)"'' - else ""; + postInstall = '' + if [ -x $out/bin/qemu-system-${stdenv.hostPlatform.qemuArch} ]; then + makeWrapper $out/bin/qemu-system-${stdenv.hostPlatform.qemuArch} \ + $out/bin/qemu-kvm \ + --add-flags "\$([ -e /dev/kvm ] && echo -enable-kvm)" + fi + ''; passthru = { qemu-system-i386 = "bin/qemu-system-i386"; diff --git a/pkgs/development/libraries/talloc/default.nix b/pkgs/development/libraries/talloc/default.nix index 7c758d298357a..7455876093523 100644 --- a/pkgs/development/libraries/talloc/default.nix +++ b/pkgs/development/libraries/talloc/default.nix @@ -1,5 +1,6 @@ { stdenv, fetchurl, python, pkgconfig, readline, libxslt , docbook_xsl, docbook_xml_dtd_42, fixDarwinDylibNames +, buildPackages }: stdenv.mkDerivation rec { @@ -10,10 +11,9 @@ stdenv.mkDerivation rec { sha256 = "1kk76dyav41ip7ddbbf04yfydb4jvywzi2ps0z2vla56aqkn11di"; }; - nativeBuildInputs = [ pkgconfig fixDarwinDylibNames ]; - buildInputs = [ - python readline libxslt docbook_xsl docbook_xml_dtd_42 - ]; + nativeBuildInputs = [ pkgconfig fixDarwinDylibNames python + docbook_xsl docbook_xml_dtd_42 ]; + buildInputs = [ readline libxslt ]; prePatch = '' patchShebangs buildtools/bin/waf @@ -23,10 +23,14 @@ stdenv.mkDerivation rec { "--enable-talloc-compat1" "--bundled-libraries=NONE" "--builtin-libraries=replace" + ] ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "--cross-compile" + "--cross-execute=${stdenv.hostPlatform.emulator buildPackages}" ]; + configurePlatforms = []; postInstall = '' - ar q $out/lib/libtalloc.a bin/default/talloc_[0-9]*.o + ${stdenv.cc.targetPrefix}ar q $out/lib/libtalloc.a bin/default/talloc_[0-9]*.o ''; meta = with stdenv.lib; { diff --git a/pkgs/test/cross/default.nix b/pkgs/test/cross/default.nix index 6f41447ca76af..622799106cd29 100644 --- a/pkgs/test/cross/default.nix +++ b/pkgs/test/cross/default.nix @@ -1,12 +1,11 @@ -{ pkgs, pkgsCross, lib }: +{ pkgs, lib }: let - emulators = { - mingw32 = "WINEDEBUG=-all ${pkgs.winePackages.minimal}/bin/wine"; - mingwW64 = "WINEDEBUG=-all ${pkgs.wineWowPackages.minimal}/bin/wine"; - # TODO: add some qemu-based emulaltors here - }; + testedSystems = lib.filterAttrs (name: value: let + platform = lib.systems.elaborate value; + in platform.isLinux || platform.isWindows + ) lib.systems.examples; getExecutable = pkgs: pkgFun: exec: "${pkgFun pkgs}${exec}${pkgs.hostPlatform.extensions.executable}"; @@ -17,6 +16,10 @@ let in pkgs.runCommand "test-${pkgName}-${crossPkgs.hostPlatform.config}" { nativeBuildInputs = [ pkgs.dos2unix ]; } '' + # Just in case we are using wine, get rid of that annoying extra + # stuff. + export WINEDEBUG=-all + HOME=$(pwd) mkdir -p $out @@ -44,29 +47,29 @@ let fi ''; -in + mapMultiPlatformTest = test: lib.mapAttrs (name: system: test rec { + crossPkgs = import pkgs.path { + localSystem = { inherit (pkgs.hostPlatform) config; }; + crossSystem = system; + }; -lib.mapAttrs (name: emulator: let - crossPkgs = pkgsCross.${name}; + emulator = crossPkgs.hostPlatform.emulator pkgs; - # Apply some transformation on windows to get dlls in the right - # place. Unfortunately mingw doesn’t seem to be able to do linking - # properly. - platformFun = pkg: if crossPkgs.hostPlatform.isWindows then - pkgs.buildEnv { - name = "${pkg.name}-winlinks"; - paths = [pkg] ++ pkg.buildInputs; - } else pkg; -in { + # Apply some transformation on windows to get dlls in the right + # place. Unfortunately mingw doesn’t seem to be able to do linking + # properly. + platformFun = pkg: if crossPkgs.hostPlatform.isWindows then + pkgs.buildEnv { + name = "${pkg.name}-winlinks"; + paths = [pkg] ++ pkg.buildInputs; + } else pkg; + }) testedSystems; - hello = compareTest { - inherit emulator crossPkgs; - hostPkgs = pkgs; - exec = "/bin/hello"; - pkgFun = pkgs: pkgs.hello; - }; +in + +lib.mapAttrs (_: mapMultiPlatformTest) { - file = compareTest { + file = {platformFun, crossPkgs, emulator}: compareTest { inherit emulator crossPkgs; hostPkgs = pkgs; exec = "/bin/file"; @@ -77,4 +80,11 @@ in { pkgFun = pkgs: platformFun pkgs.file; }; -}) emulators + hello = {platformFun, crossPkgs, emulator}: compareTest { + inherit emulator crossPkgs; + hostPkgs = pkgs; + exec = "/bin/hello"; + pkgFun = pkgs: pkgs.hello; + }; + +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index cea917e174b0e..a9db0b499019f 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -12465,7 +12465,7 @@ with pkgs; taglib-sharp = callPackage ../development/libraries/taglib-sharp { }; talloc = callPackage ../development/libraries/talloc { - python = python2; + python = buildPackages.python2; }; tclap = callPackage ../development/libraries/tclap {}; |