Merge pull request #74090 from obsidiansystems/ghcjs-cross-without-cc

stdenv, haskell: bonafied GHCJS cross compilation without stdenv.cc
This commit is contained in:
John Ericson 2019-12-30 16:40:43 -08:00 committed by GitHub
commit cfd013813e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 71 additions and 33 deletions

View File

@ -27,6 +27,8 @@ let
"riscv32-linux" "riscv64-linux"
"aarch64-none" "avr-none" "arm-none" "i686-none" "x86_64-none" "powerpc-none" "msp430-none" "riscv64-none" "riscv32-none" "vc4-none"
"js-ghcjs"
];
allParsed = map parse.mkSystemFromString all;
@ -46,6 +48,7 @@ in {
mips = filterDoubles predicates.isMips;
riscv = filterDoubles predicates.isRiscV;
vc4 = filterDoubles predicates.isVc4;
js = filterDoubles predicates.isJavaScript;
cygwin = filterDoubles predicates.isCygwin;
darwin = filterDoubles predicates.isDarwin;

View File

@ -12,7 +12,7 @@ let
expected = lib.sort lib.lessThan y;
};
in with lib.systems.doubles; lib.runTests {
testall = mseteq all (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ wasi ++ windows ++ embedded);
testall = mseteq all (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ wasi ++ windows ++ embedded ++ js);
testarm = mseteq arm [ "armv5tel-linux" "armv6l-linux" "armv7a-linux" "armv7l-linux" "arm-none" "armv7a-darwin" ];
testi686 = mseteq i686 [ "i686-linux" "i686-freebsd" "i686-netbsd" "i686-openbsd" "i686-cygwin" "i686-windows" "i686-none" "i686-darwin" ];

View File

@ -66,7 +66,7 @@ let
else null;
expand-response-params =
if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null"
if buildPackages ? stdenv && buildPackages.stdenv.hasCC && buildPackages.stdenv.cc != "/dev/null"
then import ../expand-response-params { inherit (buildPackages) stdenv; }
else "";

View File

@ -59,7 +59,7 @@ let
infixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;
expand-response-params =
if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null"
if buildPackages.stdenv.hasCC && buildPackages.stdenv.cc != "/dev/null"
then import ../expand-response-params { inherit (buildPackages) stdenv; }
else "";

View File

@ -1,4 +1,5 @@
{ stdenv
, pkgsHostHost
, callPackage
, fetchgit
, ghcjsSrcJson ? null
@ -14,7 +15,6 @@
, pkgconfig
, gcc
, lib
, nodePackages
, ghcjsDepOverrides ? (_:_:{})
, haskell
}:
@ -46,7 +46,7 @@ let
enableShared = true;
socket-io = nodePackages."socket.io";
socket-io = pkgsHostHost.nodePackages."socket.io";
# Relics of the old GHCJS build system
stage1Packages = [];

View File

@ -40,7 +40,7 @@ in
# They must be propagated to the environment of any executable linking with the library
, libraryFrameworkDepends ? [], executableFrameworkDepends ? []
, homepage ? "https://hackage.haskell.org/package/${pname}"
, platforms ? with stdenv.lib.platforms; unix ++ windows # GHC can cross-compile
, platforms ? with stdenv.lib.platforms; all # GHC can cross-compile
, hydraPlatforms ? null
, hyperlinkSource ? true
, isExecutable ? false, isLibrary ? !isExecutable
@ -131,9 +131,13 @@ let
'';
crossCabalFlags = [
"--with-ghc=${ghc.targetPrefix}ghc"
"--with-ghc=${ghcCommand}"
"--with-ghc-pkg=${ghc.targetPrefix}ghc-pkg"
"--with-gcc=${stdenv.cc.targetPrefix}cc"
# Pass the "wrong" C compiler rather than none at all so packages that just
# use the C preproccessor still work, see
# https://github.com/haskell/cabal/issues/6466 for details.
"--with-gcc=${(if stdenv.hasCC then stdenv else buildPackages.stdenv).cc.targetPrefix}cc"
] ++ optionals stdenv.hasCC [
"--with-ld=${stdenv.cc.bintools.targetPrefix}ld"
"--with-ar=${stdenv.cc.bintools.targetPrefix}ar"
# use the one that comes with the cross compiler.
@ -156,7 +160,9 @@ let
"--libsubdir=\\$abi/\\$libname"
(optionalString enableSeparateDataOutput "--datadir=$data/share/${ghc.name}")
(optionalString enableSeparateDocOutput "--docdir=${docdir "$doc"}")
] ++ optionals stdenv.hasCC [
"--with-gcc=$CC" # Clang won't work without that extra information.
] ++ [
"--package-db=$packageConfDir"
(optionalString (enableSharedExecutables && stdenv.isLinux) "--ghc-option=-optl=-Wl,-rpath=$out/lib/${ghc.name}/${pname}-${version}")
(optionalString (enableSharedExecutables && stdenv.isDarwin) "--ghc-option=-optl=-Wl,-headerpad_max_install_names")

View File

@ -23,7 +23,8 @@
# This will build mmorph and monadControl, and have the hoogle installation
# refer to their documentation via symlink so they are not garbage collected.
{ lib, stdenv, hoogle, writeText, ghc
{ lib, stdenv, buildPackages
, hoogle, writeText, ghc
, packages
}:
@ -53,7 +54,7 @@ let
(map (lib.getOutput "doc") packages);
in
stdenv.mkDerivation {
buildPackages.stdenv.mkDerivation {
name = "hoogle-local-0.1";
buildInputs = [ghc hoogle];

View File

@ -144,7 +144,7 @@ let
substituteInPlace "$out"/lib/perl5/*/*/Config_heavy.pl \
--replace "${libcInc}" /no-such-path \
--replace "${
if stdenv.cc.cc or null != null then stdenv.cc.cc else "/no-such-path"
if stdenv.hasCC then stdenv.cc.cc else "/no-such-path"
}" /no-such-path \
--replace "${stdenv.cc}" /no-such-path \
--replace "$man" /no-such-path

View File

@ -121,9 +121,16 @@ stageFuns: let
postStage = buildPackages: {
__raw = true;
stdenv.cc =
if buildPackages.stdenv.cc.isClang or false
then buildPackages.clang
else buildPackages.gcc;
if buildPackages.stdenv.hasCC
then
if buildPackages.stdenv.cc.isClang or false
then buildPackages.clang
else buildPackages.gcc
else
# This will blow up if anything uses it, but that's OK. The `if
# buildPackages.stdenv.cc.isClang then ... else ...` would blow up
# everything, so we make sure to avoid that.
buildPackages.stdenv.cc;
};
in dfold folder postStage (_: {}) withAllowCustomOverrides

View File

@ -51,12 +51,18 @@ in lib.init bootStages ++ [
extraBuildInputs = [ ]; # Old ones run on wrong platform
allowedRequisites = null;
hasCC = !targetPlatform.isGhcjs;
cc = if crossSystem.useiOSPrebuilt or false
then buildPackages.darwin.iosSdkPkgs.clang
else if crossSystem.useAndroidPrebuilt or false
then buildPackages."androidndkPkgs_${crossSystem.ndkVer}".clang
else if targetPlatform.isGhcjs
then null
# Need to use `throw` so tryEval for splicing works, ugh. Using
# `null` or skipping the attribute would cause an eval failure
# `tryEval` wouldn't catch, wrecking accessing previous stages
# when there is a C compiler and everything should be fine.
then throw "no C compiler provided for this platform"
else if crossSystem.useLLVM or false
then buildPackages.llvmPackages_8.lldClang
else buildPackages.gcc;

View File

@ -1,6 +1,15 @@
let lib = import ../../../lib; in lib.makeOverridable (
{ name ? "stdenv", preHook ? "", initialPath, cc, shell
{ name ? "stdenv", preHook ? "", initialPath
, # If we don't have a C compiler, we might either have `cc = null` or `cc =
# throw ...`, but if we do have a C compiler we should definiely have `cc !=
# null`.
#
# TODO(@Ericson2314): Add assert without creating infinite recursion
hasCC ? cc != null, cc
, shell
, allowedRequisites ? null, extraAttrs ? {}, overrides ? (self: super: {}), config
, # The `fetchurl' to use for downloading curl and its dependencies
@ -57,7 +66,8 @@ let
../../build-support/setup-hooks/move-sbin.sh
../../build-support/setup-hooks/move-lib64.sh
../../build-support/setup-hooks/set-source-date-epoch-to-latest.sh
cc
# TODO use lib.optional instead
(if hasCC then cc else null)
];
defaultBuildInputs = extraBuildInputs;
@ -145,7 +155,7 @@ let
inherit overrides;
inherit cc;
inherit cc hasCC;
}
# Propagate any extra attributes. For instance, we use this to

View File

@ -8473,7 +8473,7 @@ in
llvmPackages_35 = callPackage ../development/compilers/llvm/3.5 ({
isl = isl_0_14;
} // stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.cc.isGNU) {
stdenv = gcc6Stdenv;
});
@ -8481,7 +8481,7 @@ in
inherit (stdenvAdapters) overrideCC;
buildLlvmTools = buildPackages.llvmPackages_39.tools;
targetLlvmLibraries = targetPackages.llvmPackages_39.libraries;
} // stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.cc.isGNU) {
stdenv = gcc6Stdenv;
});
@ -8489,7 +8489,7 @@ in
inherit (stdenvAdapters) overrideCC;
buildLlvmTools = buildPackages.llvmPackages_4.tools;
targetLlvmLibraries = targetPackages.llvmPackages_4.libraries;
} // stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.cc.isGNU) {
stdenv = gcc6Stdenv;
});
@ -8497,7 +8497,7 @@ in
inherit (stdenvAdapters) overrideCC;
buildLlvmTools = buildPackages.llvmPackages_5.tools;
targetLlvmLibraries = targetPackages.llvmPackages_5.libraries;
} // stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.cc.isGNU) {
stdenv = gcc6Stdenv; # with gcc-7: undefined reference to `__divmoddi4'
});
@ -8505,7 +8505,7 @@ in
inherit (stdenvAdapters) overrideCC;
buildLlvmTools = buildPackages.llvmPackages_6.tools;
targetLlvmLibraries = targetPackages.llvmPackages_6.libraries;
} // stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.cc.isGNU) {
# with gcc-7 on i686: undefined reference to `__divmoddi4'
# Failing tests with gcc8.
stdenv = overrideCC stdenv (if stdenv.hostPlatform.isi686 then gcc6 else gcc7);
@ -8515,7 +8515,7 @@ in
inherit (stdenvAdapters) overrideCC;
buildLlvmTools = buildPackages.llvmPackages_7.tools;
targetLlvmLibraries = targetPackages.llvmPackages_7.libraries;
} // stdenv.lib.optionalAttrs (buildPackages.stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && buildPackages.stdenv.cc.isGNU) {
stdenv = gcc6Stdenv; # with gcc-7: undefined reference to `__divmoddi4'
});
@ -8523,7 +8523,7 @@ in
inherit (stdenvAdapters) overrideCC;
buildLlvmTools = buildPackages.llvmPackages_8.tools;
targetLlvmLibraries = targetPackages.llvmPackages_8.libraries;
} // stdenv.lib.optionalAttrs (buildPackages.stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && buildPackages.stdenv.cc.isGNU) {
stdenv = gcc6Stdenv; # with gcc-7: undefined reference to `__divmoddi4'
});
@ -8531,7 +8531,7 @@ in
inherit (stdenvAdapters) overrideCC;
buildLlvmTools = buildPackages.llvmPackages_9.tools;
targetLlvmLibraries = targetPackages.llvmPackages_9.libraries;
} // stdenv.lib.optionalAttrs (buildPackages.stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && buildPackages.stdenv.cc.isGNU) {
stdenv = gcc6Stdenv; # with gcc-7: undefined reference to `__divmoddi4'
});
@ -9406,7 +9406,7 @@ in
spidermonkey_1_8_5 = callPackage ../development/interpreters/spidermonkey/1.8.5.nix { };
spidermonkey_38 = callPackage ../development/interpreters/spidermonkey/38.nix ({
inherit (darwin) libobjc;
} // (stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // (stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.cc.isGNU) {
stdenv = gcc6Stdenv; # with gcc-7: undefined reference to `__divmoddi4'
}));
spidermonkey_60 = callPackage ../development/interpreters/spidermonkey/60.nix { };
@ -10787,7 +10787,7 @@ in
arrow-cpp = callPackage ../development/libraries/arrow-cpp ({
gtest = gtest.override { static = true; };
} // stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.cc.isGNU) {
stdenv = overrideCC stdenv buildPackages.gcc6; # hidden symbol `__divmoddi4'
});
@ -11869,27 +11869,27 @@ in
icu58 = callPackage (import ../development/libraries/icu/58.nix fetchurl) ({
nativeBuildRoot = buildPackages.icu58.override { buildRootOnly = true; };
} //
(stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
(stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.cc.isGNU) {
stdenv = gcc6Stdenv; # with gcc-7: undefined reference to `__divmoddi4'
}));
icu59 = callPackage ../development/libraries/icu/59.nix ({
nativeBuildRoot = buildPackages.icu59.override { buildRootOnly = true; };
} // (stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // (stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.cc.isGNU) {
stdenv = gcc6Stdenv; # with gcc-7: undefined reference to `__divmoddi4'
}));
icu60 = callPackage ../development/libraries/icu/60.nix ({
nativeBuildRoot = buildPackages.icu60.override { buildRootOnly = true; };
} // (stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // (stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.cc.isGNU) {
stdenv = gcc6Stdenv; # with gcc-7: undefined reference to `__divmoddi4'
}));
icu63 = callPackage ../development/libraries/icu/63.nix ({
nativeBuildRoot = buildPackages.icu63.override { buildRootOnly = true; };
} // (stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // (stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.cc.isGNU) {
stdenv = gcc6Stdenv; # with gcc-7: undefined reference to `__divmoddi4'
}));
icu64 = callPackage ../development/libraries/icu/64.nix ({
nativeBuildRoot = buildPackages.icu64.override { buildRootOnly = true; };
} // (stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
} // (stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && stdenv.cc.isGNU) {
stdenv = gcc6Stdenv; # with gcc-7: undefined reference to `__divmoddi4'
}));

View File

@ -135,6 +135,11 @@ in
/* Linux on the fuloong */
fuloongminipc = mapTestOnCross lib.systems.examples.fuloongminipc linuxCommon;
/* Javacript */
ghcjs = mapTestOnCross lib.systems.examples.ghcjs {
haskell.packages.ghcjs.hello = nativePlatforms;
};
/* Linux on Raspberrypi */
rpi = mapTestOnCross lib.systems.examples.raspberryPi rpiCommon;
rpi-musl = mapTestOnCross lib.systems.examples.muslpi rpiCommon;