From 0fcffe88db6713d67be4847d3727f143d5bf324b Mon Sep 17 00:00:00 2001 From: Yegor Timoshenko Date: Wed, 14 Aug 2019 09:13:19 +0000 Subject: [PATCH 1/3] buildRustPackage: support cross-compilation to x86_64-pc-mingw32 --- pkgs/build-support/rust/default.nix | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 6afe93c7e4c1b..e354bd6710d4d 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -41,12 +41,20 @@ let cargoDepsCopy="$sourceRoot/${cargoVendorDir}" ''; + hostConfig = stdenv.hostPlatform.config; + + rustHostConfig = { + "x86_64-pc-mingw32" = "x86_64-pc-windows-gnu"; + }."${hostConfig}" or hostConfig; + ccForBuild="${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc"; cxxForBuild="${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}c++"; ccForHost="${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; cxxForHost="${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++"; - releaseDir = "target/${stdenv.hostPlatform.config}/${buildType}"; -in stdenv.mkDerivation (args // { + releaseDir = "target/${rustHostConfig}/${buildType}"; +in + +stdenv.mkDerivation (args // { inherit cargoDeps; patchRegistryDeps = ./patch-registry-deps; @@ -84,7 +92,7 @@ in stdenv.mkDerivation (args // { [target."${stdenv.buildPlatform.config}"] "linker" = "${ccForBuild}" ${stdenv.lib.optionalString (stdenv.buildPlatform.config != stdenv.hostPlatform.config) '' - [target."${stdenv.hostPlatform.config}"] + [target."${rustHostConfig}"] "linker" = "${ccForHost}" ''} EOF @@ -104,7 +112,7 @@ in stdenv.mkDerivation (args // { "CXX_${stdenv.hostPlatform.config}"="${cxxForHost}" \ cargo build \ ${stdenv.lib.optionalString (buildType == "release") "--release"} \ - --target ${stdenv.hostPlatform.config} \ + --target ${rustHostConfig} \ --frozen ${concatStringsSep " " cargoBuildFlags} ) From 31d5005cd6aa11e299f9b980968907d874ddf8ee Mon Sep 17 00:00:00 2001 From: Yegor Timoshenko Date: Wed, 14 Aug 2019 09:15:27 +0000 Subject: [PATCH 2/3] pthreads-w32: 1.10.0 -> 2.9.1 --- .../windows/pthread-w32/default.nix | 70 +++++-------------- 1 file changed, 19 insertions(+), 51 deletions(-) diff --git a/pkgs/os-specific/windows/pthread-w32/default.nix b/pkgs/os-specific/windows/pthread-w32/default.nix index 226bbfb16df19..de0f36dac5fab 100644 --- a/pkgs/os-specific/windows/pthread-w32/default.nix +++ b/pkgs/os-specific/windows/pthread-w32/default.nix @@ -1,61 +1,29 @@ -{ fetchurl, stdenv, mingwrt }: +{ stdenv, fetchzip }: -# This file is tweaked for cross-compilation only. -assert stdenv.hostPlatform != stdenv.buildPlatform; +stdenv.mkDerivation rec { + name = "pthreads-w32-${version}"; + version = "2.9.1"; -stdenv.mkDerivation { - name = "pthread-w32-1.10.0"; - - src = fetchurl { - url = "ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-1-10-0-release.tar.gz"; - sha256 = "1vllxxfa9a7mssb1x98a2r736vsv5ll3sjizbr7a8hw8j9p18j7n"; + src = fetchzip { + url = "https://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.tar.gz"; + sha256 = "1s8iny7g06z289ahdj0kzaxj0cd3wvjbd8j3bh9xlg7g444lhy9w"; }; - configurePhase = - '' sed -i GNUmakefile \ - -e 's/CC=gcc/CC=i686-pc-mingw32-gcc/g ; - s/windres/i686-pc-mingw32-windres/g ; - s/dlltool/i686-pc-mingw32-dlltool/g' - ''; - - buildInputs = [ mingwrt ]; - - buildPhase = "make GC"; # to build the GNU C dll with C cleanup code - - installPhase = - '' mkdir -p "$out" "$out/include" "$out/lib" - cp -v *pthread*{dll,a} "$out/lib" - cp -v pthread.h semaphore.h sched.h "$out/include" - ''; - - postFixup = - # By default `mingw_headers' is propagated. Prevent that, because - # otherwise MinGW headers appear twice in `-I', and thus the - # "#include_next " in MinGW's picks up itself instead - # of picking up GCC's (hence, FLT_RADIX is left undefined, for instance.) - '' rm -f "$out/nix-support/propagated-build-inputs" - ''; - - meta = { - description = "POSIX threads for Woe32"; + makeFlags = [ "CROSS=${stdenv.cc.targetPrefix}" "GC-static" ]; - longDescription = - '' The POSIX 1003.1-2001 standard defines an application programming - interface (API) for writing multithreaded applications. This - interface is known more commonly as pthreads. A good number of - modern operating systems include a threading library of some kind: - Solaris (UI) threads, Win32 threads, DCE threads, DECthreads, or any - of the draft revisions of the pthreads standard. The trend is that - most of these systems are slowly adopting the pthreads standard API, - with application developers following suit to reduce porting woes. + installPhase = '' + runHook preInstall - Woe32 does not, and is unlikely to ever, support pthreads natively. - This project seeks to provide a freely available and high-quality - solution to this problem. - ''; + install -D libpthreadGC2.a $out/lib/libpthread.a - homepage = http://sourceware.org/pthreads-win32/; + runHook postInstall + ''; - license = stdenv.lib.licenses.lgpl21Plus; + meta = with stdenv.lib; { + description = "POSIX threads library for Windows"; + homepage = "https://sourceware.org/pthreads-win32"; + license = licenses.lgpl21Plus; + maintainers = with maintainers; [ yegortimoshenko ]; + platforms = platforms.windows; }; } From da3da08cdf3c622bf14a14a70f5da0e6655779d3 Mon Sep 17 00:00:00 2001 From: Yegor Timoshenko Date: Wed, 14 Aug 2019 09:50:05 +0000 Subject: [PATCH 3/3] buildRustPackage: link against pthreads-w32 on x86_64-pc-mingw32 --- pkgs/build-support/rust/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index e354bd6710d4d..49adcb4d301dd 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -1,4 +1,4 @@ -{ stdenv, cacert, git, cargo, rustc, fetchcargo, buildPackages }: +{ stdenv, cacert, git, cargo, rustc, fetchcargo, buildPackages, windows }: { name ? "${args.pname}-${args.version}" , cargoSha256 ? "unset" @@ -59,8 +59,8 @@ stdenv.mkDerivation (args // { patchRegistryDeps = ./patch-registry-deps; - nativeBuildInputs = [ cargo rustc git cacert ] ++ nativeBuildInputs; - inherit buildInputs; + nativeBuildInputs = nativeBuildInputs ++ [ cacert git cargo rustc ]; + buildInputs = buildInputs ++ stdenv.lib.optional stdenv.hostPlatform.isMinGW windows.pthreads; patches = cargoPatches ++ patches;