Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pkgs/development/compilers/ghc/9.0.2-binary.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
numactl,
libffi,
llvmPackages,
replaceVarsWith,
coreutils,
targetPackages,

Expand Down Expand Up @@ -214,6 +215,20 @@ let
coreutils # for cat
]
++ lib.optionals useLLVM [
# Allow the use of newer LLVM versions; see the script for details.
(replaceVarsWith {
name = "subopt";
src = ./subopt.bash;
dir = "bin";
isExecutable = true;
preBuild = ''
name=opt
'';
replacements = {
inherit (stdenv) shell;
opt = lib.getExe' llvmPackages.llvm "opt";
};
})
(lib.getBin llvmPackages.llvm)
]
# On darwin, we need unwrapped bintools as well (for otool)
Expand Down
10 changes: 3 additions & 7 deletions pkgs/development/compilers/ghc/9.2.4-binary.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
libiconv,
numactl,
libffi,
llvmPackages,
coreutils,
targetPackages,

Expand Down Expand Up @@ -193,8 +192,6 @@ let
) binDistUsed.archSpecificLibraries
)).nixPackage;

useLLVM = !(import ./common-have-ncg.nix { inherit lib stdenv version; });

libPath = lib.makeLibraryPath (
# Add arch-specific libraries.
map ({ nixPackage, ... }: nixPackage) binDistUsed.archSpecificLibraries
Expand All @@ -207,16 +204,15 @@ let
targetPackages.stdenv.cc.bintools
coreutils # for cat
]
++ lib.optionals useLLVM [
(lib.getBin llvmPackages.llvm)
]
# On darwin, we need unwrapped bintools as well (for otool)
++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [
targetPackages.stdenv.cc.bintools.bintools
];

in

assert import ./common-have-ncg.nix { inherit lib stdenv version; };

Comment on lines +214 to +215
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.. these asserts should not be placed at the top-level, otherwise they will prevent evaluating meta.available.

This assert could either be deferred until after meta (by putting in on some derivation argument instead) or the boolean returned by the import could be put in meta.broken instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broken sounds like the way to go. Although frankly I can't imagine when we'd add other architectures for these that need LLVM without noticing that they don't work to do the bootstrap they're intended for, so I'm not sure how much value the check adds.

Can put up a PR in an hour or so.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #441069.

stdenv.mkDerivation {
inherit version;
pname = "ghc-binary${binDistUsed.variantSuffix}";
Expand Down Expand Up @@ -470,7 +466,7 @@ stdenv.mkDerivation {
targetPrefix = "";
enableShared = true;

inherit llvmPackages;
llvmPackages = null;

# Our Cabal compiler name
haskellCompilerName = "ghc-${version}";
Expand Down
10 changes: 3 additions & 7 deletions pkgs/development/compilers/ghc/9.6.3-binary.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
libiconv,
numactl,
libffi,
llvmPackages,
coreutils,
targetPackages,

Expand Down Expand Up @@ -192,8 +191,6 @@ let
) binDistUsed.archSpecificLibraries
)).nixPackage;

useLLVM = !(import ./common-have-ncg.nix { inherit lib stdenv version; });

libPath = lib.makeLibraryPath (
# Add arch-specific libraries.
map ({ nixPackage, ... }: nixPackage) binDistUsed.archSpecificLibraries
Expand All @@ -206,16 +203,15 @@ let
targetPackages.stdenv.cc.bintools
coreutils # for cat
]
++ lib.optionals useLLVM [
(lib.getBin llvmPackages.llvm)
]
# On darwin, we need unwrapped bintools as well (for otool)
++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [
targetPackages.stdenv.cc.bintools.bintools
];

in

assert import ./common-have-ncg.nix { inherit lib stdenv version; };

stdenv.mkDerivation {
inherit version;
pname = "ghc-binary${binDistUsed.variantSuffix}";
Expand Down Expand Up @@ -449,7 +445,7 @@ stdenv.mkDerivation {
targetPrefix = "";
enableShared = true;

inherit llvmPackages;
llvmPackages = null;

# Our Cabal compiler name
haskellCompilerName = "ghc-${version}";
Expand Down
10 changes: 3 additions & 7 deletions pkgs/development/compilers/ghc/9.8.4-binary.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
libiconv,
numactl,
libffi,
llvmPackages,
coreutils,
targetPackages,

Expand Down Expand Up @@ -206,8 +205,6 @@ let
) binDistUsed.archSpecificLibraries
)).nixPackage;

useLLVM = !(import ./common-have-ncg.nix { inherit lib stdenv version; });

libPath = lib.makeLibraryPath (
# Add arch-specific libraries.
map ({ nixPackage, ... }: nixPackage) binDistUsed.archSpecificLibraries
Expand All @@ -220,16 +217,15 @@ let
targetPackages.stdenv.cc.bintools
coreutils # for cat
]
++ lib.optionals useLLVM [
(lib.getBin llvmPackages.llvm)
]
# On darwin, we need unwrapped bintools as well (for otool)
++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [
targetPackages.stdenv.cc.bintools.bintools
];

in

assert import ./common-have-ncg.nix { inherit lib stdenv version; };

stdenv.mkDerivation {
inherit version;
pname = "ghc-binary${binDistUsed.variantSuffix}";
Expand Down Expand Up @@ -464,7 +460,7 @@ stdenv.mkDerivation {
targetPrefix = "";
enableShared = true;

inherit llvmPackages;
llvmPackages = null;

# Our Cabal compiler name
haskellCompilerName = "ghc-${version}";
Expand Down
80 changes: 80 additions & 0 deletions pkgs/development/compilers/ghc/subopt.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!@shell@

# This script wraps the LLVM `opt(1)` executable and maps the options
# passed by old versions of GHC to the equivalents passed by newer
# versions that support recent versions of LLVM.
#
# It achieves the same effect as the following GHC change externally:
# <https://gitlab.haskell.org/ghc/ghc/-/merge_requests/8999>.
#
# This is used solely for bootstrapping newer GHCs from the GHC 9.0.2
# binary on AArch64, as that is the only architecture supported by that
# binary distribution that requires LLVM, and our later binary packages
# all use the native code generator for all supported platforms.
#
# No attempt is made to support custom LLVM optimization flags, or the
# undocumented flag to disable TBAA, or avoid
# <https://gitlab.haskell.org/ghc/ghc/-/issues/23870>, as these are not
# required to bootstrap GHC and at worst will produce an error message.
#
# It is called `subopt` to reflect the fact that it uses `opt(1)` as a
# subprocess, and the fact that the GHC build system situation
# requiring this hack is suboptimal.

set -e

expect() {
if [[ $1 != $2 ]]; then
printf >&2 'subopt: got %q; expected %q\n' "$1" "$2"
return 2
fi
}

if [[ $NIX_DEBUG -ge 1 ]]; then
printf >&2 'subopt: before:'
printf >&2 ' %q' "$@"
printf >&2 '\n'
fi

args=()

while [[ $# -gt 0 ]]; do
case "$1" in
-enable-new-pm=0)
shift 1
;;
-mem2reg)
expect "$2" -globalopt
expect "$3" -lower-expect
expect "$4" -enable-tbaa
expect "$5" -tbaa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lucky that the order of the -tbaa stuff is consistent :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I figured I would just handle the bare minimum the bootstrap needs rather than trying to get smart about arbitrary flag combinations :)

Technically I suspect some of these optimization levels never even get passed during the bootstrap, but no harm to support them.

args+=('-passes=function(require<tbaa>),function(mem2reg),globalopt,function(lower-expect)')
shift 5
;;
-O1)
expect "$2" -globalopt
expect "$3" -enable-tbaa
expect "$4" -tbaa
args+=('-passes=default<O1>')
shift 4
;;
-O2)
expect "$2" -enable-tbaa
expect "$3" -tbaa
args+=('-passes=default<O2>')
shift 3
;;
*)
args+=("$1")
shift 1
;;
esac
done

if [[ $NIX_DEBUG -ge 1 ]]; then
printf >&2 'subopt: after:'
printf >&2 ' %q' "${args[@]}"
printf >&2 '\n'
fi

exec @opt@ "${args[@]}"
15 changes: 5 additions & 10 deletions pkgs/top-level/haskell-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,16 @@ in
bb = pkgsBuildBuild.haskell;
in
{
# Required to bootstrap 9.4.8.
ghc902Binary = callPackage ../development/compilers/ghc/9.0.2-binary.nix {
llvmPackages = pkgs.llvmPackages_12;
llvmPackages = pkgs.llvmPackages_20;
};

ghc924Binary = callPackage ../development/compilers/ghc/9.2.4-binary.nix {
llvmPackages = pkgs.llvmPackages_12;
};
ghc924Binary = callPackage ../development/compilers/ghc/9.2.4-binary.nix { };

ghc963Binary = callPackage ../development/compilers/ghc/9.6.3-binary.nix {
llvmPackages = pkgs.llvmPackages_15;
};
ghc963Binary = callPackage ../development/compilers/ghc/9.6.3-binary.nix { };

ghc984Binary = callPackage ../development/compilers/ghc/9.8.4-binary.nix {
llvmPackages = pkgs.llvmPackages_15;
};
ghc984Binary = callPackage ../development/compilers/ghc/9.8.4-binary.nix { };

ghc948 = callPackage ../development/compilers/ghc/9.4.8.nix {
bootPkgs =
Expand Down
Loading