haskell.compiler.ghc*: set stage 0 tools

This is easy in comparison since these tools won't end up in GHC's
settings nor need to be available at runtime, so we can use
the *_FOR_BUILD environment variables.

It is important to add buildCC to depsBuildBuild to engage the
stdenv/wrapper script machinery properly.

Co-authored-by: sternenseemann <sternenseemann@systemli.org>
This commit is contained in:
Alex Tunstall 2023-07-23 09:30:35 +01:00 committed by sternenseemann
parent 08a9878b23
commit cd31b04413
3 changed files with 31 additions and 2 deletions

View File

@ -1,4 +1,4 @@
{ lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, buildPackages, targetPackages
# build-tools # build-tools
, bootPkgs , bootPkgs
@ -134,6 +134,7 @@ let
pkgsBuildTarget.targetPackages.stdenv.cc pkgsBuildTarget.targetPackages.stdenv.cc
] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm;
buildCC = buildPackages.stdenv.cc;
targetCC = builtins.head toolsForTarget; targetCC = builtins.head toolsForTarget;
# toolPath calculates the absolute path to the name tool associated with a # toolPath calculates the absolute path to the name tool associated with a
@ -299,6 +300,10 @@ stdenv.mkDerivation (rec {
# LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm
export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang"
'' + '' '' + ''
# No need for absolute paths since these tools only need to work during the build
export CC_STAGE0="$CC_FOR_BUILD"
export LD_STAGE0="$LD_FOR_BUILD"
export AR_STAGE0="$AR_FOR_BUILD"
echo -n "${buildMK}" > mk/build.mk echo -n "${buildMK}" > mk/build.mk
sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
@ -372,6 +377,10 @@ stdenv.mkDerivation (rec {
sphinx sphinx
]; ];
# Used by the STAGE0 compiler to build stage1
depsBuildBuild = [
buildCC
];
# For building runtime libs # For building runtime libs
depsBuildTarget = toolsForTarget; depsBuildTarget = toolsForTarget;

View File

@ -12,6 +12,7 @@
, stdenv , stdenv
, pkgsBuildTarget , pkgsBuildTarget
, pkgsHostTarget , pkgsHostTarget
, buildPackages
, targetPackages , targetPackages
, fetchpatch , fetchpatch
@ -265,6 +266,7 @@ let
else pkgsBuildTarget.targetPackages.stdenv.cc) else pkgsBuildTarget.targetPackages.stdenv.cc)
] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm;
buildCC = buildPackages.stdenv.cc;
targetCC = builtins.head toolsForTarget; targetCC = builtins.head toolsForTarget;
# toolPath calculates the absolute path to the name tool associated with a # toolPath calculates the absolute path to the name tool associated with a
@ -346,6 +348,10 @@ stdenv.mkDerivation ({
for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
export "''${env#TARGET_}=''${!env}" export "''${env#TARGET_}=''${!env}"
done done
# No need for absolute paths since these tools only need to work during the build
export CC_STAGE0="$CC_FOR_BUILD"
export LD_STAGE0="$LD_FOR_BUILD"
export AR_STAGE0="$AR_FOR_BUILD"
# GHC is a bit confused on its cross terminology, as these would normally be # GHC is a bit confused on its cross terminology, as these would normally be
# the *host* tools. # the *host* tools.
export CC="${toolPath "cc" targetCC}" export CC="${toolPath "cc" targetCC}"
@ -484,6 +490,10 @@ stdenv.mkDerivation ({
# For building runtime libs # For building runtime libs
depsBuildTarget = toolsForTarget; depsBuildTarget = toolsForTarget;
# Used by the STAGE0 compiler to build stage1
depsBuildBuild = [
buildCC
];
buildInputs = [ perl bash ] ++ (libDeps hostPlatform); buildInputs = [ perl bash ] ++ (libDeps hostPlatform);

View File

@ -3,7 +3,7 @@
, url ? "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz" , url ? "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz"
}: }:
{ lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, buildPackages, targetPackages
# build-tools # build-tools
, bootPkgs , bootPkgs
@ -134,6 +134,7 @@ let
pkgsBuildTarget.targetPackages.stdenv.cc pkgsBuildTarget.targetPackages.stdenv.cc
] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm;
buildCC = buildPackages.stdenv.cc;
targetCC = builtins.head toolsForTarget; targetCC = builtins.head toolsForTarget;
# toolPath calculates the absolute path to the name tool associated with a # toolPath calculates the absolute path to the name tool associated with a
@ -305,6 +306,11 @@ stdenv.mkDerivation (rec {
export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang"
'' ''
+ '' + ''
# No need for absolute paths since these tools only need to work during the build
export CC_STAGE0="$CC_FOR_BUILD"
export LD_STAGE0="$LD_FOR_BUILD"
export AR_STAGE0="$AR_FOR_BUILD"
echo -n "${buildMK}" > mk/build.mk echo -n "${buildMK}" > mk/build.mk
'' ''
+ lib.optionalString (lib.versionOlder version "9.2" || lib.versionAtLeast version "9.4") '' + lib.optionalString (lib.versionOlder version "9.2" || lib.versionAtLeast version "9.4") ''
@ -393,6 +399,10 @@ stdenv.mkDerivation (rec {
xattr xattr
]; ];
# Used by the STAGE0 compiler to build stage1
depsBuildBuild = [
buildCC
];
# For building runtime libs # For building runtime libs
depsBuildTarget = toolsForTarget; depsBuildTarget = toolsForTarget;