Merge pull request #48602 from matthewbauer/cmake-cross

Set CMAKE_SYSTEM_* for cross compiling
This commit is contained in:
John Ericson 2018-10-18 15:47:04 -04:00 committed by GitHub
commit d97e5e1115
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 82 additions and 40 deletions

View File

@ -46,6 +46,25 @@ rec {
# Misc boolean options # Misc boolean options
useAndroidPrebuilt = false; useAndroidPrebuilt = false;
useiOSPrebuilt = false; useiOSPrebuilt = false;
# Output from uname
uname = {
# uname -s
system = {
"linux" = "Linux";
"windows" = "Windows";
"darwin" = "Darwin";
"netbsd" = "NetBSD";
"freebsd" = "FreeBSD";
"openbsd" = "OpenBSD";
}.${final.parsed.kernel.name} or null;
# uname -p
processor = final.parsed.cpu.name;
# uname -r
release = null;
};
} // mapAttrs (n: v: v final.parsed) inspect.predicates } // mapAttrs (n: v: v final.parsed) inspect.predicates
// args; // args;
in assert final.useAndroidPrebuilt -> final.isAndroid; in assert final.useAndroidPrebuilt -> final.isAndroid;

View File

@ -15,6 +15,8 @@ let
"x86_64-cygwin" "x86_64-darwin" "x86_64-freebsd" "x86_64-linux" "x86_64-cygwin" "x86_64-darwin" "x86_64-freebsd" "x86_64-linux"
"x86_64-netbsd" "x86_64-openbsd" "x86_64-solaris" "x86_64-netbsd" "x86_64-openbsd" "x86_64-solaris"
"x86_64-windows" "i686-windows"
]; ];
allParsed = map parse.mkSystemFromString all; allParsed = map parse.mkSystemFromString all;
@ -37,12 +39,13 @@ in rec {
darwin = filterDoubles predicates.isDarwin; darwin = filterDoubles predicates.isDarwin;
freebsd = filterDoubles predicates.isFreeBSD; freebsd = filterDoubles predicates.isFreeBSD;
# Should be better, but MinGW is unclear. # Should be better, but MinGW is unclear.
gnu = filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnu; }); gnu = filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnu; }) ++ filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnueabi; }) ++ filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnueabihf; });
illumos = filterDoubles predicates.isSunOS; illumos = filterDoubles predicates.isSunOS;
linux = filterDoubles predicates.isLinux; linux = filterDoubles predicates.isLinux;
netbsd = filterDoubles predicates.isNetBSD; netbsd = filterDoubles predicates.isNetBSD;
openbsd = filterDoubles predicates.isOpenBSD; openbsd = filterDoubles predicates.isOpenBSD;
unix = filterDoubles predicates.isUnix; unix = filterDoubles predicates.isUnix;
windows = filterDoubles predicates.isWindows;
mesaPlatforms = ["i686-linux" "x86_64-linux" "x86_64-darwin" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "aarch64-linux" "powerpc64le-linux"]; mesaPlatforms = ["i686-linux" "x86_64-linux" "x86_64-darwin" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "aarch64-linux" "powerpc64le-linux"];
} }

View File

@ -12,20 +12,21 @@ let
expected = lib.sort lib.lessThan y; expected = lib.sort lib.lessThan y;
}; };
in with lib.systems.doubles; lib.runTests { in with lib.systems.doubles; lib.runTests {
all = assertTrue (mseteq all (linux ++ darwin ++ cygwin ++ freebsd ++ openbsd ++ netbsd ++ illumos)); testall = mseteq all (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ windows);
arm = assertTrue (mseteq arm [ "armv5tel-linux" "armv6l-linux" "armv7l-linux" ]); testarm = mseteq arm [ "armv5tel-linux" "armv6l-linux" "armv7l-linux" ];
i686 = assertTrue (mseteq i686 [ "i686-linux" "i686-freebsd" "i686-netbsd" "i686-openbsd" "i686-cygwin" ]); testi686 = mseteq i686 [ "i686-linux" "i686-freebsd" "i686-netbsd" "i686-openbsd" "i686-cygwin" "i686-windows" ];
mips = assertTrue (mseteq mips [ "mipsel-linux" ]); testmips = mseteq mips [ "mipsel-linux" ];
x86_64 = assertTrue (mseteq x86_64 [ "x86_64-linux" "x86_64-darwin" "x86_64-freebsd" "x86_64-openbsd" "x86_64-netbsd" "x86_64-cygwin" "x86_64-solaris" ]); testx86_64 = mseteq x86_64 [ "x86_64-linux" "x86_64-darwin" "x86_64-freebsd" "x86_64-openbsd" "x86_64-netbsd" "x86_64-cygwin" "x86_64-solaris" "x86_64-windows" ];
cygwin = assertTrue (mseteq cygwin [ "i686-cygwin" "x86_64-cygwin" ]); testcygwin = mseteq cygwin [ "i686-cygwin" "x86_64-cygwin" ];
darwin = assertTrue (mseteq darwin [ "x86_64-darwin" ]); testdarwin = mseteq darwin [ "x86_64-darwin" ];
freebsd = assertTrue (mseteq freebsd [ "i686-freebsd" "x86_64-freebsd" ]); testfreebsd = mseteq freebsd [ "i686-freebsd" "x86_64-freebsd" ];
gnu = assertTrue (mseteq gnu (linux /* ++ kfreebsd ++ ... */)); testgnu = mseteq gnu (linux /* ++ kfreebsd ++ ... */);
illumos = assertTrue (mseteq illumos [ "x86_64-solaris" ]); testillumos = mseteq illumos [ "x86_64-solaris" ];
linux = assertTrue (mseteq linux [ "i686-linux" "x86_64-linux" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "aarch64-linux" "mipsel-linux" ]); testlinux = mseteq linux [ "i686-linux" "x86_64-linux" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "aarch64-linux" "mipsel-linux" ];
netbsd = assertTrue (mseteq netbsd [ "i686-netbsd" "x86_64-netbsd" ]); testnetbsd = mseteq netbsd [ "i686-netbsd" "x86_64-netbsd" ];
openbsd = assertTrue (mseteq openbsd [ "i686-openbsd" "x86_64-openbsd" ]); testopenbsd = mseteq openbsd [ "i686-openbsd" "x86_64-openbsd" ];
unix = assertTrue (mseteq unix (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos)); testwindows = mseteq windows [ "i686-cygwin" "x86_64-cygwin" "i686-windows" "x86_64-windows" ];
testunix = mseteq unix (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ cygwin);
} }

View File

@ -101,21 +101,17 @@ stdenv.mkDerivation {
inherit src; inherit src;
patchFlags = optionalString (stdenv.hostPlatform.libc == "msvcrt") "-p0"; patchFlags = "";
patches = patches patches = patches
++ optional stdenv.isDarwin ./darwin-no-system-python.patch ++ optional stdenv.isDarwin ./darwin-no-system-python.patch;
++ optional (stdenv.hostPlatform.libc == "msvcrt") (fetchurl {
url = "https://svn.boost.org/trac/boost/raw-attachment/tickaet/7262/"
+ "boost-mingw.patch";
sha256 = "0s32kwll66k50w6r5np1y5g907b7lcpsjhfgr7rsw7q5syhzddyj";
});
meta = { meta = {
homepage = http://boost.org/; homepage = http://boost.org/;
description = "Collection of C++ libraries"; description = "Collection of C++ libraries";
license = stdenv.lib.licenses.boost; license = stdenv.lib.licenses.boost;
platforms = (if versionOlder version "1.59" then remove "aarch64-linux" else id) platforms.unix; platforms = (if versionOlder version "1.59" then remove "aarch64-linux" else id) (platforms.unix ++ platforms.windows);
maintainers = with maintainers; [ peti wkennington ]; maintainers = with maintainers; [ peti wkennington ];
}; };
@ -139,7 +135,8 @@ stdenv.mkDerivation {
enableParallelBuilding = true; enableParallelBuilding = true;
nativeBuildInputs = [ which buildPackages.stdenv.cc ]; nativeBuildInputs = [ which ];
depsBuildBuild = [ buildPackages.stdenv.cc ];
buildInputs = [ expat zlib bzip2 libiconv ] buildInputs = [ expat zlib bzip2 libiconv ]
++ optional (stdenv.hostPlatform == stdenv.buildPlatform) icu ++ optional (stdenv.hostPlatform == stdenv.buildPlatform) icu
++ optional stdenv.isDarwin fixDarwinDylibNames ++ optional stdenv.isDarwin fixDarwinDylibNames

View File

@ -9,6 +9,8 @@ stdenv.mkDerivation rec {
sha256 = "0vnwmbvymw677k780kpb6sb8i3szdp89rzy8mz1fwg1657yw3ls5"; sha256 = "0vnwmbvymw677k780kpb6sb8i3szdp89rzy8mz1fwg1657yw3ls5";
}; };
configureFlags = if stdenv.hostPlatform.isWindows then [ "--disable-shared" "--enable-static" ] else null;
# ares_android.h header is missing # ares_android.h header is missing
# see issue https://github.com/c-ares/c-ares/issues/216 # see issue https://github.com/c-ares/c-ares/issues/216
postPatch = if stdenv.hostPlatform.isAndroid then '' postPatch = if stdenv.hostPlatform.isAndroid then ''

View File

@ -15,8 +15,6 @@ stdenv.mkDerivation rec {
cmakeFlags = [] cmakeFlags = []
++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform)
"-DMSGPACK_BUILD_EXAMPLES=OFF" "-DMSGPACK_BUILD_EXAMPLES=OFF"
++ stdenv.lib.optional (stdenv.hostPlatform.libc == "msvcrt")
"-DCMAKE_SYSTEM_NAME=Windows"
; ;
meta = with stdenv.lib; { meta = with stdenv.lib; {

View File

@ -6,6 +6,7 @@
, enableAsioLib ? false, boost ? null , enableAsioLib ? false, boost ? null
, enableGetAssets ? false, libxml2 ? null , enableGetAssets ? false, libxml2 ? null
, enableJemalloc ? false, jemalloc ? null , enableJemalloc ? false, jemalloc ? null
, enableApp ? !stdenv.hostPlatform.isWindows
}: }:
assert enableHpack -> jansson != null; assert enableHpack -> jansson != null;
@ -35,8 +36,12 @@ stdenv.mkDerivation rec {
enableParallelBuilding = true; enableParallelBuilding = true;
configureFlags = [ "--with-spdylay=no" "--disable-examples" "--disable-python-bindings" "--enable-app" ] configureFlags = [
++ optional enableAsioLib "--enable-asio-lib --with-boost-libdir=${boost}/lib"; "--with-spdylay=no"
"--disable-examples"
"--disable-python-bindings"
(stdenv.lib.enableFeature enableApp "app")
] ++ optional enableAsioLib "--enable-asio-lib --with-boost-libdir=${boost}/lib";
#doCheck = true; # requires CUnit ; currently failing at test_util_localtime_date in util_test.cc #doCheck = true; # requires CUnit ; currently failing at test_util_localtime_date in util_test.cc

View File

@ -18,8 +18,6 @@ stdenv.mkDerivation rec {
cmakeFlags = [ cmakeFlags = [
"-DBuildTests=${if doCheck then "ON" else "OFF"}" "-DBuildTests=${if doCheck then "ON" else "OFF"}"
] ++ stdenv.lib.optionals (stdenv.hostPlatform.libc == "msvcrt") [
"-DCMAKE_SYSTEM_NAME=Windows"
]; ];
doCheck = stdenv.hostPlatform == stdenv.buildPlatform; doCheck = stdenv.hostPlatform == stdenv.buildPlatform;

View File

@ -79,6 +79,6 @@ stdenv.mkDerivation rec {
homepage = http://www.sqlite.org/; homepage = http://www.sqlite.org/;
license = licenses.publicDomain; license = licenses.publicDomain;
maintainers = with maintainers; [ eelco np ]; maintainers = with maintainers; [ eelco np ];
platforms = platforms.unix; platforms = platforms.unix ++ platforms.windows;
}; };
} }

View File

@ -82,4 +82,6 @@ stdenv.mkDerivation (rec {
preConfigure = '' preConfigure = ''
export CHOST=${stdenv.hostPlatform.config} export CHOST=${stdenv.hostPlatform.config}
''; '';
} // stdenv.lib.optionalAttrs (stdenv.hostPlatform.libc == "msvcrt") {
configurePhase = ":";
}) })

View File

@ -41,6 +41,7 @@ rec {
# Configure Phase # Configure Phase
, configureFlags ? [] , configureFlags ? []
, cmakeFlags ? []
, # Target is not included by default because most programs don't care. , # Target is not included by default because most programs don't care.
# Including it then would cause needless mass rebuilds. # Including it then would cause needless mass rebuilds.
# #
@ -225,6 +226,17 @@ rec {
inherit doCheck doInstallCheck; inherit doCheck doInstallCheck;
inherit outputs; inherit outputs;
} // lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform) {
cmakeFlags =
(/**/ if lib.isString cmakeFlags then [cmakeFlags]
else if cmakeFlags == null then []
else cmakeFlags)
++ lib.optional (stdenv.hostPlatform.uname.system != null) "-DCMAKE_SYSTEM_NAME=${stdenv.hostPlatform.uname.system}"
++ lib.optional (stdenv.hostPlatform.uname.processor != null) "-DCMAKE_SYSTEM_PROCESSOR=${stdenv.hostPlatform.uname.processor}"
++ lib.optional (stdenv.hostPlatform.uname.release != null) "-DCMAKE_SYSTEM_VERSION=${stdenv.hostPlatform.release}"
++ lib.optional (stdenv.buildPlatform.uname.system != null) "-DCMAKE_HOST_SYSTEM_NAME=${stdenv.buildPlatform.uname.system}"
++ lib.optional (stdenv.buildPlatform.uname.processor != null) "-DCMAKE_HOST_SYSTEM_PROCESSOR=${stdenv.buildPlatform.uname.processor}"
++ lib.optional (stdenv.buildPlatform.uname.release != null) "-DCMAKE_HOST_SYSTEM_VERSION=${stdenv.buildPlatform.uname.release}";
} // lib.optionalAttrs (attrs.enableParallelBuilding or false) { } // lib.optionalAttrs (attrs.enableParallelBuilding or false) {
enableParallelChecking = attrs.enableParallelChecking or true; enableParallelChecking = attrs.enableParallelChecking or true;
} // lib.optionalAttrs (hardeningDisable != [] || hardeningEnable != []) { } // lib.optionalAttrs (hardeningDisable != [] || hardeningEnable != []) {

View File

@ -15,8 +15,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ cmake ]; nativeBuildInputs = [ cmake ];
cmakeFlags = stdenv.lib.optional cmakeFlags = [];
(stdenv.hostPlatform.libc == "msvcrt") "-DCMAKE_SYSTEM_NAME=Windows";
outputs = [ "out" "dev" "lib" ]; outputs = [ "out" "dev" "lib" ];
@ -59,4 +58,3 @@ stdenv.mkDerivation rec {
platforms = platforms.all; platforms = platforms.all;
}; };
} }

View File

@ -77,7 +77,11 @@ stdenv.mkDerivation rec {
++ stdenv.lib.optional gssSupport "--with-gssapi=${kerberos.dev}" ++ stdenv.lib.optional gssSupport "--with-gssapi=${kerberos.dev}"
# For the 'urandom', maybe it should be a cross-system option # For the 'urandom', maybe it should be a cross-system option
++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform)
"--with-random=/dev/urandom"; "--with-random=/dev/urandom"
++ stdenv.lib.optionals stdenv.hostPlatform.isWindows [
"--disable-shared"
"--enable-static"
];
CXX = "${stdenv.cc.targetPrefix}c++"; CXX = "${stdenv.cc.targetPrefix}c++";
CXXCPP = "${stdenv.cc.targetPrefix}c++ -E"; CXXCPP = "${stdenv.cc.targetPrefix}c++ -E";

View File

@ -81,7 +81,11 @@ stdenv.mkDerivation rec {
++ stdenv.lib.optional gssSupport "--with-gssapi=${kerberos.dev}" ++ stdenv.lib.optional gssSupport "--with-gssapi=${kerberos.dev}"
# For the 'urandom', maybe it should be a cross-system option # For the 'urandom', maybe it should be a cross-system option
++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform)
"--with-random=/dev/urandom"; "--with-random=/dev/urandom"
++ stdenv.lib.optionals stdenv.hostPlatform.isWindows [
"--disable-shared"
"--enable-static"
];
CXX = "${stdenv.cc.targetPrefix}c++"; CXX = "${stdenv.cc.targetPrefix}c++";
CXXCPP = "${stdenv.cc.targetPrefix}c++ -E"; CXXCPP = "${stdenv.cc.targetPrefix}c++ -E";

View File

@ -13,8 +13,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ cmake libxslt/*manpage*/ ]; nativeBuildInputs = [ cmake libxslt/*manpage*/ ];
cmakeFlags = stdenv.lib.optional cmakeFlags = [];
(stdenv.hostPlatform.libc or null == "msvcrt") "-DCMAKE_SYSTEM_NAME=Windows";
# ATM bin/tidy is statically linked, as upstream provides no other option yet. # ATM bin/tidy is statically linked, as upstream provides no other option yet.
# https://github.com/htacg/tidy-html5/issues/326#issuecomment-160322107 # https://github.com/htacg/tidy-html5/issues/326#issuecomment-160322107

View File

@ -2077,7 +2077,7 @@ with pkgs;
zlibSupport = true; zlibSupport = true;
sslSupport = zlibSupport; sslSupport = zlibSupport;
scpSupport = zlibSupport && !stdenv.isSunOS && !stdenv.isCygwin; scpSupport = zlibSupport && !stdenv.isSunOS && !stdenv.isCygwin;
gssSupport = true; gssSupport = !stdenv.hostPlatform.isWindows;
}; };
curl = callPackage ../tools/networking/curl rec { curl = callPackage ../tools/networking/curl rec {
@ -2086,7 +2086,7 @@ with pkgs;
zlibSupport = true; zlibSupport = true;
sslSupport = zlibSupport; sslSupport = zlibSupport;
scpSupport = zlibSupport && !stdenv.isSunOS && !stdenv.isCygwin; scpSupport = zlibSupport && !stdenv.isSunOS && !stdenv.isCygwin;
gssSupport = true; gssSupport = !stdenv.hostPlatform.isWindows;
}; };
curl_unix_socket = callPackage ../tools/networking/curl-unix-socket rec { }; curl_unix_socket = callPackage ../tools/networking/curl-unix-socket rec { };