haskell.compiler.*: enable NUMA in rts if supported

Linking against libnuma gives users extra RTS options:
https://downloads.haskell.org/ghc/latest/docs/users_guide/runtime_control.html#rts-flag-numa

Funnily enough, we've already been supporting this for bindists because
it was enabled for some of them.

Resolves #414559.
This commit is contained in:
sternenseemann
2025-07-15 11:16:56 +02:00
parent cc708024f6
commit 59ea7fd277
3 changed files with 51 additions and 7 deletions
+17 -3
View File
@@ -69,6 +69,10 @@ in
|| (stdenv.hostPlatform != stdenv.targetPlatform)
),
# Enable NUMA support in RTS
enableNuma ? lib.meta.availableOn stdenv.targetPlatform numactl,
numactl,
# What flavour to build. An empty string indicates no
# specific flavour and falls back to ghc default values.
ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) (
@@ -265,7 +269,7 @@ let
basePackageSet = if hostPlatform != targetPlatform then targetPackages else pkgsHostTarget;
in
{
inherit (basePackageSet) gmp ncurses;
inherit (basePackageSet) gmp ncurses numactl;
# dynamic inherits are not possible in Nix
libffi = basePackageSet.${libffi_name};
};
@@ -513,6 +517,11 @@ stdenv.mkDerivation (
++ lib.optionals (disableLargeAddressSpace) [
"--disable-large-address-space"
]
++ lib.optionals enableNuma [
"--enable-numa"
"--with-libnuma-includes=${lib.getDev targetLibs.numactl}/include"
"--with-libnuma-libraries=${lib.getLib targetLibs.numactl}/lib"
]
++ lib.optionals enableUnregisterised [
"--enable-unregisterised"
];
@@ -565,8 +574,13 @@ stdenv.mkDerivation (
buildInputs = [ bash ] ++ (libDeps hostPlatform);
depsTargetTarget = map lib.getDev (libDeps targetPlatform);
depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);
# stage1 GHC doesn't need to link against libnuma, so it's target specific
depsTargetTarget = map lib.getDev (
libDeps targetPlatform ++ lib.optionals enableNuma [ targetLibs.numactl ]
);
depsTargetTargetPropagated = map (lib.getOutput "out") (
libDeps targetPlatform ++ lib.optionals enableNuma [ targetLibs.numactl ]
);
# required, because otherwise all symbols from HSffi.o are stripped, and
# that in turn causes GHCi to abort
@@ -91,6 +91,10 @@
&& !stdenv.hostPlatform.isStatic,
elfutils,
# Enable NUMA support in RTS
enableNuma ? lib.meta.availableOn stdenv.targetPlatform numactl,
numactl,
# What flavour to build. Flavour string may contain a flavour and flavour
# transformers as accepted by hadrian.
ghcFlavour ?
@@ -479,6 +483,7 @@ let
gmp
libffi
ncurses
numactl
;
};
@@ -664,6 +669,11 @@ stdenv.mkDerivation (
"--with-libdw-includes=${lib.getDev targetLibs.elfutils}/include"
"--with-libdw-libraries=${lib.getLib targetLibs.elfutils}/lib"
]
++ lib.optionals enableNuma [
"--enable-numa"
"--with-libnuma-includes=${lib.getDev targetLibs.numactl}/include"
"--with-libnuma-libraries=${lib.getLib targetLibs.numactl}/lib"
]
++ lib.optionals targetPlatform.isDarwin [
# Darwin uses llvm-ar. GHC will try to use `-L` with `ar` when it is `llvm-ar`
# but it doesnt currently work because Cabal never uses `-L` on Darwin. See:
@@ -731,8 +741,13 @@ stdenv.mkDerivation (
buildInputs = [ bash ] ++ (libDeps hostPlatform);
depsTargetTarget = map lib.getDev (libDeps targetPlatform);
depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);
# stage0:ghc (i.e. stage1) doesn't need to link against libnuma, so it's target specific
depsTargetTarget = map lib.getDev (
libDeps targetPlatform ++ lib.optionals enableNuma [ targetLibs.numactl ]
);
depsTargetTargetPropagated = map (lib.getOutput "out") (
libDeps targetPlatform ++ lib.optionals enableNuma [ targetLibs.numactl ]
);
hadrianFlags =
[
@@ -68,6 +68,10 @@
|| (stdenv.hostPlatform != stdenv.targetPlatform)
),
# Enable NUMA support in RTS
enableNuma ? lib.meta.availableOn stdenv.targetPlatform numactl,
numactl,
# What flavour to build. An empty string indicates no
# specific flavour and falls back to ghc default values.
ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) (
@@ -261,6 +265,7 @@ let
gmp
libffi
ncurses
numactl
;
};
@@ -565,6 +570,11 @@ stdenv.mkDerivation (
++ lib.optionals (disableLargeAddressSpace) [
"--disable-large-address-space"
]
++ lib.optionals enableNuma [
"--enable-numa"
"--with-libnuma-includes=${lib.getDev targetLibs.numactl}/include"
"--with-libnuma-libraries=${lib.getLib targetLibs.numactl}/lib"
]
++ lib.optionals enableUnregisterised [
"--enable-unregisterised"
];
@@ -621,8 +631,13 @@ stdenv.mkDerivation (
buildInputs = [ bash ] ++ (libDeps hostPlatform);
depsTargetTarget = map lib.getDev (libDeps targetPlatform);
depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);
# stage1 GHC doesn't need to link against libnuma, so it's target specific
depsTargetTarget = map lib.getDev (
libDeps targetPlatform ++ lib.optionals enableNuma [ targetLibs.numactl ]
);
depsTargetTargetPropagated = map (lib.getOutput "out") (
libDeps targetPlatform ++ lib.optionals enableNuma [ targetLibs.numactl ]
);
# required, because otherwise all symbols from HSffi.o are stripped, and
# that in turn causes GHCi to abort