Skip to content

hadrian install creates symlinks pointing to `_build` directory

Summary

When using hadrian/build install --prefix=<prefix>, we end up with absolute symlinks pointing from unversioned executables to versioned ones. These symlinks are created in relation to the _build directory. This makes build outputs dependent on the existence of _build. So, they break when install copies these files elsewhere and the _build directory is later removed.

I encountered this in the context of building ghc with nix using a slightly modified version of https://gitlab.haskell.org/bgamari/ghcs-nix/-/blob/hadrian/hadrian.nix

This seems to be introduced by f481c189

My guess is that the fix is to change https://gitlab.haskell.org/ghc/ghc/-/blob/f481c1890066b4dac78d981ca680fb01cfff9a11/hadrian/src/Rules/BinaryDist.hs#L166 such that we create a relative symlink rather than an absolute one.

Steps to reproduce

  1. Build ghc HEAD using hadrian
  2. Install ghc somewhere using hadrian/build install --prefix=<prefix>
  3. delete _build
  4. try <prefix>/bin/ghc --version. You will get an error that looks like this:
bin/ghc: line 10: /nix/store/bq04dr93g6a87g4wkrxhpwcphpnan4cg-ghc-9.3.0/lib/ghc-9.3.20210802/bin/ghc: No such file or directory

Looking at the ghc exe with ls -l gives:

lrwxrwxrwx  3 teo teo        84 Jan  1  1970 ghc -> /build/ghc/_build/bindist/ghc-9.3.20210802-x86_64-unknown-linux/bin/ghc-9.3.20210802

Expected behavior

ghc --version should run successfully

Environment

  • GHC version used: ghc-9.3.20210802

Optional:

  • Operating System: Linux
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information