Skip to content

Wrong ghc-pkg database used for dependencies during stage0 build

Summary

During a stage0 build (in my case, for building a cross-compiler), ghc-pkg is called with a global database, which results in In-Tree libraries being ignored in favour of those from Hackage.

Possibly related to #22870

Steps to reproduce

./boot
./configure --target=<something other than host>
./hadrian/build

This results in the following error:

Error, rule finished running but did not produce file:
  _build/stage0/lib/package.conf.d/filepath-1.4.2.2.conf
Build failed.

Note that the bundled filepath version is 1.4.100.1.

I traced the problem to ./hadrian/src/Builder.hs:266 where the call to ghc-pkg --no-user-package-db field <package name> depends is made. The result depends on the global database instead of whatever is in ./_build. This clause here is only called from copyConf in ./hadrian/src/Rules/Register.hs, so the bug only manifests during stage0 builds.

    askBuilderWith :: Builder -> BuildInfo -> Action String
    askBuilderWith builder BuildInfo {..} = case builder of
        GhcPkg Dependencies _ -> do
            let input  = fromSingleton msgIn buildInputs
                msgIn  = "[askBuilder] Exactly one input file expected."
            needBuilders [builder]
            path <- H.builderPath builder
            -- we do not depend on bare builders. E.g. we won't depend on `clang`
            -- or `ld` or `ar`.  Unless they are provided with fully qualified paths
            -- this is the job of the person invoking ./configure to pass e.g.
            -- CC=$(which clang) if they want the fully qualified clang path!
            when (path /= takeFileName path) $
                need [path]
            Stdout stdout <- cmd' [path] ["--no-user-package-db", "field", input, "depends"]
            return stdout

Expected behavior

Successful build.

Environment

  • GHC version used: GHC 9.4.5
  • GHC version built: GHC 9.6.2

Optional:

  • Operating System: NixOS 23.11
  • System Architecture: x86_64
Edited by Lana Black
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information