1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-05-01 08:27:03 +00:00

Merge pull request #66613 from transumption-unstable/201908/rust-win32-cross

buildRustPackage: support cross-compilation to x86_64-pc-mingw32
This commit is contained in:
John Ericson 2019-08-15 09:28:30 -04:00 committed by GitHub
commit d13a1bc93a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 58 deletions

View file

@ -1,4 +1,4 @@
{ stdenv, cacert, git, cargo, rustc, fetchcargo, buildPackages }: { stdenv, cacert, git, cargo, rustc, fetchcargo, buildPackages, windows }:
{ name ? "${args.pname}-${args.version}" { name ? "${args.pname}-${args.version}"
, cargoSha256 ? "unset" , cargoSha256 ? "unset"
@ -41,18 +41,26 @@ let
cargoDepsCopy="$sourceRoot/${cargoVendorDir}" 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"; ccForBuild="${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc";
cxxForBuild="${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}c++"; cxxForBuild="${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}c++";
ccForHost="${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; ccForHost="${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
cxxForHost="${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++"; cxxForHost="${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++";
releaseDir = "target/${stdenv.hostPlatform.config}/${buildType}"; releaseDir = "target/${rustHostConfig}/${buildType}";
in stdenv.mkDerivation (args // { in
stdenv.mkDerivation (args // {
inherit cargoDeps; inherit cargoDeps;
patchRegistryDeps = ./patch-registry-deps; patchRegistryDeps = ./patch-registry-deps;
nativeBuildInputs = [ cargo rustc git cacert ] ++ nativeBuildInputs; nativeBuildInputs = nativeBuildInputs ++ [ cacert git cargo rustc ];
inherit buildInputs; buildInputs = buildInputs ++ stdenv.lib.optional stdenv.hostPlatform.isMinGW windows.pthreads;
patches = cargoPatches ++ patches; patches = cargoPatches ++ patches;
@ -84,7 +92,7 @@ in stdenv.mkDerivation (args // {
[target."${stdenv.buildPlatform.config}"] [target."${stdenv.buildPlatform.config}"]
"linker" = "${ccForBuild}" "linker" = "${ccForBuild}"
${stdenv.lib.optionalString (stdenv.buildPlatform.config != stdenv.hostPlatform.config) '' ${stdenv.lib.optionalString (stdenv.buildPlatform.config != stdenv.hostPlatform.config) ''
[target."${stdenv.hostPlatform.config}"] [target."${rustHostConfig}"]
"linker" = "${ccForHost}" "linker" = "${ccForHost}"
''} ''}
EOF EOF
@ -104,7 +112,7 @@ in stdenv.mkDerivation (args // {
"CXX_${stdenv.hostPlatform.config}"="${cxxForHost}" \ "CXX_${stdenv.hostPlatform.config}"="${cxxForHost}" \
cargo build \ cargo build \
${stdenv.lib.optionalString (buildType == "release") "--release"} \ ${stdenv.lib.optionalString (buildType == "release") "--release"} \
--target ${stdenv.hostPlatform.config} \ --target ${rustHostConfig} \
--frozen ${concatStringsSep " " cargoBuildFlags} --frozen ${concatStringsSep " " cargoBuildFlags}
) )

View file

@ -1,61 +1,29 @@
{ fetchurl, stdenv, mingwrt }: { stdenv, fetchzip }:
# This file is tweaked for cross-compilation only. stdenv.mkDerivation rec {
assert stdenv.hostPlatform != stdenv.buildPlatform; name = "pthreads-w32-${version}";
version = "2.9.1";
stdenv.mkDerivation { src = fetchzip {
name = "pthread-w32-1.10.0"; url = "https://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.tar.gz";
sha256 = "1s8iny7g06z289ahdj0kzaxj0cd3wvjbd8j3bh9xlg7g444lhy9w";
src = fetchurl {
url = "ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-1-10-0-release.tar.gz";
sha256 = "1vllxxfa9a7mssb1x98a2r736vsv5ll3sjizbr7a8hw8j9p18j7n";
}; };
configurePhase = makeFlags = [ "CROSS=${stdenv.cc.targetPrefix}" "GC-static" ];
'' 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 ]; installPhase = ''
runHook preInstall
buildPhase = "make GC"; # to build the GNU C dll with C cleanup code install -D libpthreadGC2.a $out/lib/libpthread.a
installPhase = runHook postInstall
'' 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 = meta = with stdenv.lib; {
# By default `mingw_headers' is propagated. Prevent that, because description = "POSIX threads library for Windows";
# otherwise MinGW headers appear twice in `-I', and thus the homepage = "https://sourceware.org/pthreads-win32";
# "#include_next <float.h>" in MinGW's <float.h> picks up itself instead license = licenses.lgpl21Plus;
# of picking up GCC's (hence, FLT_RADIX is left undefined, for instance.) maintainers = with maintainers; [ yegortimoshenko ];
'' rm -f "$out/nix-support/propagated-build-inputs" platforms = platforms.windows;
'';
meta = {
description = "POSIX threads for Woe32";
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.
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.
'';
homepage = http://sourceware.org/pthreads-win32/;
license = stdenv.lib.licenses.lgpl21Plus;
}; };
} }