From 1e41fc8ded01e5b6c6281df1f3aa400f91ae92ad Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Fri, 20 Jul 2018 13:55:21 -0400 Subject: [PATCH 1/8] dejavu-fonts: supports everything the .ttf file is cross platform. --- pkgs/data/fonts/dejavu-fonts/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/data/fonts/dejavu-fonts/default.nix b/pkgs/data/fonts/dejavu-fonts/default.nix index 251654e2d58..fa877ea6ed5 100644 --- a/pkgs/data/fonts/dejavu-fonts/default.nix +++ b/pkgs/data/fonts/dejavu-fonts/default.nix @@ -20,7 +20,7 @@ let # See http://dejavu-fonts.org/wiki/License for details license = stdenv.lib.licenses.free; - platforms = stdenv.lib.platforms.unix; + platforms = stdenv.lib.platforms.all; }; full-ttf = stdenv.mkDerivation { From 92daacc9b041cf8aff5c03857b9d9d9f46052df5 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Fri, 20 Jul 2018 13:56:15 -0400 Subject: [PATCH 2/8] libxml2: support all platforms Mingw/Windows support works out of the box. --- pkgs/development/libraries/libxml2/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/libraries/libxml2/default.nix b/pkgs/development/libraries/libxml2/default.nix index 8a3d7abdfa5..ce696bca11b 100644 --- a/pkgs/development/libraries/libxml2/default.nix +++ b/pkgs/development/libraries/libxml2/default.nix @@ -70,7 +70,7 @@ in stdenv.mkDerivation rec { homepage = http://xmlsoft.org/; description = "An XML parsing library for C"; license = lib.licenses.mit; - platforms = lib.platforms.unix; + platforms = lib.platforms.all; maintainers = [ lib.maintainers.eelco ]; }; } From ef087554d0fad9f8e20d9c071976ce0fd273d37a Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Fri, 20 Jul 2018 13:57:16 -0400 Subject: [PATCH 3/8] libxslt: runs on all platforms Mingw/Windows support works out of the box. --- pkgs/development/libraries/libxslt/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/libraries/libxslt/default.nix b/pkgs/development/libraries/libxslt/default.nix index 1bb90ee195d..a6cba986769 100644 --- a/pkgs/development/libraries/libxslt/default.nix +++ b/pkgs/development/libraries/libxslt/default.nix @@ -59,7 +59,7 @@ stdenv.mkDerivation rec { homepage = http://xmlsoft.org/XSLT/; description = "A C library and tools to do XSL transformations"; license = licenses.mit; - platforms = platforms.unix; + platforms = platforms.all; maintainers = [ maintainers.eelco ]; }; } From 3530c39b97ac4b587279933c404b64b7d69014f9 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Fri, 20 Jul 2018 21:14:28 -0400 Subject: [PATCH 4/8] ncurses: add windows configure flags these two flags are needed for windows support to work - sp-funcs - term-driver --- pkgs/development/libraries/ncurses/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/ncurses/default.nix b/pkgs/development/libraries/ncurses/default.nix index cf478837b86..042c09fd864 100644 --- a/pkgs/development/libraries/ncurses/default.nix +++ b/pkgs/development/libraries/ncurses/default.nix @@ -34,7 +34,11 @@ stdenv.mkDerivation rec { ] ++ lib.optional unicode "--enable-widec" ++ lib.optional enableStatic "--enable-static" ++ lib.optional (!withCxx) "--without-cxx" - ++ lib.optional (abiVersion == "5") "--with-abi-version=5"; + ++ lib.optional (abiVersion == "5") "--with-abi-version=5" + ++ lib.optionals hostPlatform.isWindows [ + "--enable-sp-funcs" + "--enable-term-driver" + ]; # Only the C compiler, and explicitly not C++ compiler needs this flag on solaris: CFLAGS = lib.optionalString stdenv.isSunOS "-D_XOPEN_SOURCE_EXTENDED"; From 522b61a069b1a856df23c558f780216b38aa5ed9 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Fri, 20 Jul 2018 21:49:53 -0400 Subject: [PATCH 5/8] openssl: work with mingw32 --- pkgs/development/libraries/openssl/default.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/openssl/default.nix b/pkgs/development/libraries/openssl/default.nix index 0251de77d03..47467ce4ede 100644 --- a/pkgs/development/libraries/openssl/default.nix +++ b/pkgs/development/libraries/openssl/default.nix @@ -45,7 +45,9 @@ let if hostPlatform == buildPlatform then "./config" else if hostPlatform.isMinGW - then "./Configure mingw${toString hostPlatform.parsed.cpu.bits}" + then "./Configure mingw${optionalString + (hostPlatform.parsed.cpu.bits != 32) + (toString hostPlatform.parsed.cpu.bits)}" else if hostPlatform.isLinux then "./Configure linux-generic${toString hostPlatform.parsed.cpu.bits}" else if hostPlatform.isiOS From 53cb8dc09e56591fba8db76d3187a99e492f8d56 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Fri, 20 Jul 2018 22:00:58 -0400 Subject: [PATCH 6/8] windows.libgnurx: init --- pkgs/os-specific/windows/libgnurx/default.nix | 11 +++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 13 insertions(+) create mode 100644 pkgs/os-specific/windows/libgnurx/default.nix diff --git a/pkgs/os-specific/windows/libgnurx/default.nix b/pkgs/os-specific/windows/libgnurx/default.nix new file mode 100644 index 00000000000..f50a0d9f503 --- /dev/null +++ b/pkgs/os-specific/windows/libgnurx/default.nix @@ -0,0 +1,11 @@ +{ stdenv, fetchurl }: + +let + version = "2.5.1"; +in stdenv.mkDerivation rec { + name = "libgnurx-${version}"; + src = fetchurl { + url = "mirror://sourceforge/mingw/Other/UserContributed/regex/mingw-regex-${version}/mingw-${name}-src.tar.gz"; + sha256 = "0xjxcxgws3bblybw5zsp9a4naz2v5bs1k3mk8dw00ggc0vwbfivi"; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 91d2d5aaa56..de255678ca2 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14546,6 +14546,8 @@ with pkgs; }; wxMSW = callPackage ../os-specific/windows/wxMSW-2.8 { }; + + libgnurx = callPackage ../os-specific/windows/libgnurx { }; }; wirelesstools = callPackage ../os-specific/linux/wireless-tools { }; From 09fed91ec8e084c4cdfd9e2363d65e8bb7c48091 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Fri, 20 Jul 2018 22:02:00 -0400 Subject: [PATCH 7/8] file: build on windows --- pkgs/tools/misc/file/default.nix | 7 +++++-- pkgs/top-level/all-packages.nix | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkgs/tools/misc/file/default.nix b/pkgs/tools/misc/file/default.nix index aeb43d7c115..485f46d0314 100644 --- a/pkgs/tools/misc/file/default.nix +++ b/pkgs/tools/misc/file/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchurl, file, zlib }: +{ stdenv, fetchurl, file, zlib, libgnurx }: stdenv.mkDerivation rec { name = "file-${version}"; @@ -13,10 +13,13 @@ stdenv.mkDerivation rec { }; nativeBuildInputs = stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) file; - buildInputs = [ zlib ]; + buildInputs = [ zlib ] + ++ stdenv.lib.optional stdenv.hostPlatform.isWindows libgnurx; doCheck = true; + makeFlags = if stdenv.hostPlatform.isWindows then "FILE_COMPILE=file" + else null; meta = with stdenv.lib; { homepage = http://darwinsys.com/file; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index de255678ca2..5c0e1ddb26e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -2387,7 +2387,9 @@ with pkgs; figlet = callPackage ../tools/misc/figlet { }; - file = callPackage ../tools/misc/file { }; + file = callPackage ../tools/misc/file { + inherit (windows) libgnurx; + }; filegive = callPackage ../tools/networking/filegive { }; From b98b4eac71cfb0ccedc6d909fd58058bc1cb85e7 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Fri, 20 Jul 2018 22:43:55 -0400 Subject: [PATCH 8/8] tests: add some cross tests --- pkgs/test/cross/default.nix | 80 +++++++++++++++++++++++++++++++++++++ pkgs/test/default.nix | 2 + 2 files changed, 82 insertions(+) create mode 100644 pkgs/test/cross/default.nix diff --git a/pkgs/test/cross/default.nix b/pkgs/test/cross/default.nix new file mode 100644 index 00000000000..6f41447ca76 --- /dev/null +++ b/pkgs/test/cross/default.nix @@ -0,0 +1,80 @@ +{ pkgs, pkgsCross, 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 + }; + + getExecutable = pkgs: pkgFun: exec: + "${pkgFun pkgs}${exec}${pkgs.hostPlatform.extensions.executable}"; + + compareTest = { emulator, pkgFun, hostPkgs, crossPkgs, exec, args ? [] }: let + pkgName = (pkgFun hostPkgs).name; + args' = lib.concatStringsSep " " args; + in pkgs.runCommand "test-${pkgName}-${crossPkgs.hostPlatform.config}" { + nativeBuildInputs = [ pkgs.dos2unix ]; + } '' + HOME=$(pwd) + mkdir -p $out + + # We need to remove whitespace, unfortunately + # Windows programs use \r but Unix programs use \n + + # find expected value natively + ${getExecutable hostPkgs pkgFun exec} ${args'} \ + | dos2unix > $out/expected + + # run emulator to get actual value + ${emulator} ${getExecutable crossPkgs pkgFun exec} ${args'} \ + | dos2unix > $out/actual + + if [ "$(cat $out/actual)" != "$(cat $out/expected)" ]; then + echo "${pkgName} did not output expected value:" + cat $out/expected + echo "instead it output:" + cat $out/actual + exit 1 + else + echo "${pkgName} test passed" + echo "both produced output:" + cat $out/actual + fi + ''; + +in + +lib.mapAttrs (name: emulator: let + crossPkgs = pkgsCross.${name}; + + # 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 { + + hello = compareTest { + inherit emulator crossPkgs; + hostPkgs = pkgs; + exec = "/bin/hello"; + pkgFun = pkgs: pkgs.hello; + }; + + file = compareTest { + inherit emulator crossPkgs; + hostPkgs = pkgs; + exec = "/bin/file"; + args = [ + "${pkgs.file}/share/man/man1/file.1.gz" + "${pkgs.dejavu_fonts}/share/fonts/truetype/DejaVuMathTeXGyre.ttf" + ]; + pkgFun = pkgs: platformFun pkgs.file; + }; + +}) emulators diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index 38f6cb8e564..d2e8e1c7314 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -23,4 +23,6 @@ with pkgs; cc-multilib-clang = callPackage ./cc-wrapper/multilib.nix { stdenv = clangMultiStdenv; }; macOSSierraShared = callPackage ./macos-sierra-shared {}; + + cross = callPackage ./cross {}; }