@@ -1,4 +1,4 @@
1−{ pkgs, stdenv, buildPackages, ghc, lib, gobject-introspection ? null, haskellLib, makeConfigFiles, haddockBuilder, ghcForComponent, hsPkgs, compiler, runCommand, libffi, gmp, zlib, ncurses, numactl, nodejs }:
1+{ pkgs, stdenv, buildPackages, ghc, lib, gobject-introspection ? null, haskellLib, makeConfigFiles, haddockBuilder, ghcForComponent, hsPkgs, compiler, runCommand, libffi, gmp, zlib, ncurses, numactl, nodejs }@defaults:
22lib.makeOverridable (
33let self =
44{ componentId
@@ -77,6 +77,16 @@ let self =
7777}@drvArgs:
7878
7979let
80+ # Ignore attempts to include DWARF info when it is not possible
81+ enableDWARF = drvArgs.enableDWARF or false
82+ && stdenv.hostPlatform.isLinux
83+ && !haskellLib.isCrossHost
84+ && !stdenv.hostPlatform.isMusl
85+ && builtins.compareVersions defaults.ghc.version "8.10.2" >= 0;
86+
87+ ghc = if enableDWARF then defaults.ghc.dwarf else defaults.ghc;
88+ setup = if enableDWARF then drvArgs.setup.dwarf else drvArgs.setup;
89+
8090 # TODO fix cabal wildcard support so hpack wildcards can be mapped to cabal wildcards
8191 canCleanSource = !(cabal-generator == "hpack" && !(package.cleanHpack or false));
8292 # In order to support relative references to other packages we need to use
@@ -109,7 +119,7 @@ let
109119
110120 configFiles = makeConfigFiles {
111121 inherit (package) identifier;
112− inherit component fullName flags needsProfiling;
122+ inherit component fullName flags needsProfiling enableDWARF;
113123 };
114124
115125 enableFeature = enable: feature:
@@ -178,7 +188,7 @@ let
178188 ++ (ghc.extraConfigureFlags or [])
179189 ++ lib.optional enableDebugRTS "--ghc-option=-debug"
180190 ++ lib.optional enableTSanRTS "--ghc-option=-tsan"
181− ++ lib.optional enableDWARF "--ghc-option=-g"
191+ ++ lib.optional enableDWARF "--ghc-option=-g3"
182192 ++ lib.optionals useLLVM [
183193 "--ghc-option=-fPIC" "--gcc-option=-fPIC"
184194 ]
@@ -195,7 +205,7 @@ let
195205 # work in the nix-shell. See ../doc/removing-with-package-wrapper.md.
196206 shellWrappers = ghcForComponent {
197207 componentName = fullName;
198− inherit configFiles;
208+ inherit configFiles enableDWARF;
199209 };
200210
201211 # In order to let shell hooks make package-specific things like Hoogle databases
@@ -280,10 +290,11 @@ let
280290 config = component;
281291 srcSubDir = cleanSrc.subDir;
282292 srcSubDirPath = cleanSrc.root + cleanSrc.subDir;
283− inherit configFiles executableToolDepends exeName;
293+ inherit configFiles executableToolDepends exeName enableDWARF;
284294 exePath = drv + "/bin/${exeName}";
285295 env = shellWrappers;
286296 profiled = self (drvArgs // { enableLibraryProfiling = true; });
297+ dwarf = self (drvArgs // { enableDWARF = true; });
287298 } // lib.optionalAttrs (haskellLib.isLibrary componentId) ({
288299 inherit haddock;
289300 inherit (haddock) haddockDir; # This is null if `doHaddock = false`