Commit Graph

64 Commits

Author SHA1 Message Date
sternenseemann
0cac1f100d haskell.compiler.*: don't declare stage0 ghc as dep to stdenv
Some GHC bindists have a normal `$out/lib` directory which contains
symlinks to all core libs. Because it is a normal lib directory, the
bintools setup hook will pick up on it and cause ld to pass the
appropriate -L and -rpath flags. We do not want this to happen,
especially in the case of the stage2 compiler. Not only will the final
ghc have an unnecessary reference (and thus increased closure size) to
the binary ghc, but the extra libraries in the rpath mess with the rts
and cause e.g. segfaults in GHCi.

Unfortunately, there is no way to prevent this. It is a fundamental flaw
in the cc and bintools wrappers that they do not actually distinguish
between the roles of dependencies (build, host, target). Instead
the mangleVar* function will translate the dependencies split up by
roles into platforms. This means that the wrappers can't distinguish
between depsBuildBuild and depsHostTarget (== buildInputs) when natively
compiling. As long as we are natively compiling the wrappers will put
the stage0 ghc (be it in depsBuildBuild, nativeBuildInputs etc.) into
the linker flags of the final ghc.

The solution is to sidestep the issue. We just had ghc in depsBuildBuild
to have it added to PATH. GHC itself will pass the appropriate linker
flags if necessary. To avoid the setup hooks picking up on the GHC
libraries we just don't put it into depsBuildBuild or any other
dependency list. Since the GHC build system accepts the GHC binary via
an absolute path, we don't even need to add the stage0 GHC to PATH.
2024-09-23 18:44:43 +02:00
sternenseemann
097aff7aff haskell.compiler.*: move bootPkgs.ghc to depsBuildBuild
The stage0 ghc is build->build since it builds the stage1 compiler which
has build for its host platform (i.e. is build->target relative to the
entire GHC derivation).

Also annotate a bit more around the use of pkgsBuildBuild and the boot
compiler and make it more explicit where it comes from in the
derivation.
2024-09-19 16:26:43 +02:00
sternenseemann
4903ac938b haskell.compiler.*: remove perl from buildInputs
perl is only needed in some situations as a build time dependency to run
build scripts. The final GHC doesn't require perl.
2024-09-19 16:26:04 +02:00
sternenseemann
e04b930173 haskell.compiler.*: check that there are no references to stage0
This is a safeguard against a problem we had with 9.6. Unfortunately,
since the cc wrapper emits `-L` and `-rpath` flags based on platform
config (e.g. aarch64-unknown-linux), not platform role (e.g. build),
stdenv itself doesn't prevent ghc from being linked against the boot
compiler when building a native or cross-compiling GHC (since host ==
build).

With disallowedReferences, the build will fail if such a problem is
re-introduced.
2024-09-19 15:08:12 +02:00
sternenseemann
6c00c676f1 haskell.compiler.ghc96*: use patch for unlit workaround
That's a bit cleaner and more robust in case this will be backported to
9.6.7 (should it happen).
2024-09-19 12:57:19 +02:00
sternenseemann
f716fa5303 haskell.compiler.*: pass --with-curses-* flags again
We reuse the targetLibs logic for this since it is more or less the same
story. However, the terminfo library is only built when GHC is neither a
cross-compiler nor being cross-compiled. Therefore ncurses (if used)
will only ever come from pkgsHostTarget. In the other cases ncurses is
still passed via depsBuildBuild for the stage1 compiler.

This commit tries to resolve the problem that the package-db doesn't
include library and include dirs of ncurses for the terminfo package,
causing library loading and linking problems in downstream packages,
e.g. dhall-docs and dhall-toml. This problem was introduced in
4b00fbf163. With this in mind, not passing
--with-curses-* – as long as the terminfo package isn't built – seems
fine.
2024-09-19 12:52:08 +02:00
sternenseemann
b039994dad haskell.compiler.ghc*: use matching CLANG & CC on Darwin with LLVM
The Darwin LLVM backend of GHC (which is mostly interesting for
GHC < 9.2) uses clang as configured via the CLANG environment variable
as an assembler. Since it processes outputs of clang as configured via
the CC variable, we need to make sure these versions match or risk CLANG
clang not understanding the output of CC clang.

In the past this wasn't really a problem as due to the fairly old
default clang version in the stdenv, clang 11 would be used for CC.
CLANG would always be a newer version and deal with the output without
any problems.

Ever since the upgrade of the default clang version for
darwin (bcbdb800cf), CC would often be a
newer version of clang than CLANG, causing build problems in some
packages like crypton (for GHC 8.10.7 and 9.0.2 on aarch64-darwin where
the darwin LLVM backend was actually used).
2024-09-14 17:52:09 +02:00
sternenseemann
7fff04332d haskell.compiler.ghc{96,98,910}: use emscripten installCC for ghcjs
An oversight in 884a76c5e6: We need to
mirror the isGhcjs condition of targetCC (toolsForTarget) for installCC
as well. (Note that in practice, targetCC == installCC for ghcjs since
it is cross-only (?).)
2024-09-09 12:04:18 +02:00
sternenseemann
2dae22748f haskell.compiler.*: set correct runtime LLVM tools in settings
Note that the clang command should be adapted in the future as done for
CLANG in #338782.
2024-09-08 23:50:05 +02:00
sternenseemann
de13f8f454 haskell.compiler.*: set cctools tools in settings if applicable 2024-09-08 23:50:05 +02:00
sternenseemann
8c08fb1090 haskell.compiler.ghc9{6,8,10}: update comment about stage selection
The build platform doesn't matter for checking which stage is our final
stage! Stage2 means host and target are sufficiently similar, Stage1
means host and target may differ.
2024-09-08 23:50:05 +02:00
sternenseemann
8b6009f852 haskell.compiler.ghc96: fix incorrect unlit path for cross compilers
Hadrian started installing unlit with a targetPrefix (if applicable)
which wasn't the case with make before. Unfortunately, the logic to
generate the settings file wasn't updated, so GHC 9.6.* cross compilers
expect to find an unlit binary without a target prefix.

Upstream issue: https://gitlab.haskell.org/ghc/ghc/-/issues/23317
2024-09-08 23:50:05 +02:00
Alex Tunstall
322bab8284 haskell.compiler.ghc*: allow all platforms
Propagating the supported platforms of the boot compiler doesn't make
much sense when unregistered cross-compilation is possible.
2024-09-08 23:50:05 +02:00
Alex Tunstall
d3bad45240 haskell.compiler.ghc*: assert cross is possible 2024-09-08 23:50:05 +02:00
Alex Tunstall
35d77dde97 haskell.compiler.ghc*: add enableUnregisterised 2024-09-08 23:50:05 +02:00
Alex Tunstall
884a76c5e6 haskell.compiler.ghc*: use host->target CC and tools in settings
GHC's build system assumes that the C compiler, tools etc. discovered
during configure can also be used at runtime. This means that the CC,
LD, AR etc. variables given at runtime are used to populate the settings
file which GHC uses to lookup the tools it needs.

The implicit assumption of this mechanism is that the build and runtime
environment of GHC are similar enough and PATH is used to find the
tools. I. e. if we set CC=clang, we wouldn't need to worry about this as
much. We, however, pass absolute paths which is useful since it allows
GHC to work outside of stdenv (as long as e. g. no FFI is involved).

Even so, until now, we didn't really have any problems stemming from
this, as we used pkgsBuildTarget to get everything we need. The
compiler we'd want to execute would in principle need to come
from pkgsHostTarget.

1. For native compilers, all package sets are the same since
   build == host == target.
2. For cross compilers build == host, so pkgsBuildTarget
   is practically the same as pkgsHostTarget.

When cross-compiling a native compiler, build != host, so we need to
actually ensure that GHC uses different tools at runtime compared to
bootstrapping. There is currently no intended way to achieve this, so we
use a custom tool to edit the settings file. An alternative would be to
patch the build system, but this would be difficult to maintain. We
could go down this route if there's interest from upstream to provide a
proper way to specify the runtime tools.

Co-authored-by: sternenseemann <sternenseemann@systemli.org>
2024-09-08 23:50:05 +02:00
Alex Tunstall
1261fe024f haskell.compiler.ghc*: fall back to host libs for “cross native” ghc
The goal of this commit is basically to eliminate the use of
targetPackages for finding libraries. Instead, we introduce a
`targetLibs` set that can be used instead. The libraries in there
philosophically come from targetPackages since they are used by the core
libs and will be linked against user code. However, when cross compiling
GHC it's always a native compiler, so we can and have to use
pkgsHostTarget (targetPackages would be empty). This is explained more
in the acccompanying comment.

An alternative to this approach is not to pass in the libraries
explicitly via `--with-*` flags and rely on cc-wrapper and splicing to
pick the correct library. This works well for ncurses and probably
merits testing for other libraries as well since it's very simple. It
would need to be verified, however, that configure doesn't discover the
“wrong” library and leaks it somewhere.

Co-authored-by: sternenseemann <sternenseemann@systemli.org>
2024-09-08 23:50:05 +02:00
Alex Tunstall
4b00fbf163 haskell.compiler.ghc*: correctly account for ncurses in cross
1. Explicitly set WITH_TERMINFO. We usually match GHC's behavior well,
   but it is better to tie the Nix option to make explicitly.
   Unfortunately, the same is very complicated to achieve with
   hadrian (iirc).
2. Disable enableTerminfo if we are cross-compiling. This matches
   the behavior of GHC's build system, so we'll have to match it now.
   It also reduces the ncurses-related headache a bit.
3. Stop passing --with-curses* flags. Unfortunately, GHC does not
   account for the fact that different platforms need different ncurses
   libraries. This is somewhat migitated by the fact that ncurses is
   only ever needed for the build platform if we are cross compiling,
   but I seem to remember it leaking into the final GHC somehow.
   A more reliable alternative is relying on the cc/ld wrapper scripts,
   as they'll always pull out the correct ncurses out of the environment
   when GHC's build system passes -lcurses.
4. Unconditionally add ncurses to depsBuildBuild. Stage0 unconditionally
   builds terminfo (maybe the stage1 compiler needs it?), so we need to
   make sure that ncurses for the build platform is available.

Co-authored-by: sternenseemann <sternenseemann@systemli.org>
2024-09-08 23:50:05 +02:00
Alex Tunstall
cd31b04413 haskell.compiler.ghc*: set stage 0 tools
This is easy in comparison since these tools won't end up in GHC's
settings nor need to be available at runtime, so we can use
the *_FOR_BUILD environment variables.

It is important to add buildCC to depsBuildBuild to engage the
stdenv/wrapper script machinery properly.

Co-authored-by: sternenseemann <sternenseemann@systemli.org>
2024-09-08 23:50:05 +02:00
toonn
c3c5870e96
Merge pull request #307880 from reckenrode/ld64
cctools: 973.0.1 -> 1010.6
2024-07-17 08:22:14 +02:00
Randy Eckenrode
79f5f9bf1b
ghc: update Darwin bintools references
- Unconditionally get `install_name_tool` from cc.bintools.bintools since it is no longer wrapped; and
- Use the `strip` wrapper on both Darwin architectures. It’s the default one, and it’s the same between both.
2024-07-13 21:08:29 -04:00
sternenseemann
aadfe3ef2b haskell.compiler.ghc966: init at 9.6.6
https://www.haskell.org/ghc//blog/20240701-ghc-9.6.6-released.html
2024-07-08 12:29:42 +02:00
sternenseemann
8ebd50f67a haskell.compiler.*: calculate tool path using common function
This refactor should simplify the code a little bit and make future
changes easier. I. e. for cross compiling GHC we'll have to update the
tools in the GHC settings file and calculate the host->target tool paths
for later use. Having a ready function for this will make this a lot
easier.
2024-06-13 00:06:49 +02:00
github-actions[bot]
51bd20f7c4
Merge master into haskell-updates 2024-06-10 00:14:27 +00:00
Alexis Hildebrandt
f8c4a98e8e treewide: Remove the definite article from meta.description
nix run nixpkgs#silver-searcher -- -G '\.nix$' -0l 'description.*"([Tt]he)? ' pkgs \
  | xargs -0 nix run nixpkgs#gnused -- -i '' -Ee 's/(description.*")[Tt]he (.)/\1\U\2/'
2024-06-09 23:08:46 +02:00
Tom Sydney Kerckhove
6457cf0c01 haskell.compiler.ghc96: hadrian patch fix for fully_static 2024-06-08 22:10:06 +02:00
sternenseemann
fc1e8093b5 haskell.packages.ghc910: work around aarch64-darwin output cycles
This ports our infamous patch for Cabal that prevents certain parts of
the Paths_* module from being generated in order to prevent unnecessary
references on aarch64-darwin, to GHC >= 9.10.

See also:

- Original issues: #140774
- Patches
  - Original patch for GHC >= 8.10 && < 9.2 / Cabal >= 3.2 && < 3.6:
    https://github.com/nixOS/nixpkgs/commit/b0dcd7fa34377fc0c5ff155de2d07ffbff3
  - Patch for GHC >= 9.2 && < 9.10 / Cabal >= 3.6 && < 3.12: #216857,
    https://github.com/NixOS/nixpkgs/pull/240387/commits/f6f780f129f50df536fb30,
    …
2024-05-31 21:23:09 +02:00
sternenseemann
69bdf62eb6 haskell.compiler.ghc9{6,8}: fix elfutils splicing
elfutils is used in the RTS (rts/Libdw.c), i.e. it will be used on the
target platform.

Tested via pkgsCross.gnu32.haskellPackages.ghc [1], though #304605 needs
to be cherry-picked for elfutils to build.

[1]: nix-shell -E 'with import ./. { crossSystem = "i686-linux"; };
       mkShell { nativeBuildInputs = [haskellPackages.ghc ]; }'
2024-05-26 21:29:11 +02:00
Sigmanificient
203a48ad35 pkgs/development: remove unused fetchpatch arguments 2024-05-24 02:53:57 +02:00
sternenseemann
c93aff17d5 haskell.compiler.ghc9{6,8}: apply hadrian patches to shared ghcSrc
This makes the hadrian expressions much simpler as we no longer need to
thread through extra arguments for special workarounds.
common-hadrian.nix decides in one place which patches we need and
directly applies them to the source used to build everything.
2024-04-27 15:03:02 +02:00
sternenseemann
675bcbb917 haskell.compiler.ghc9{6,8}: pass patched source to hadrian
We'll want to (slowly) unify the source used by the different
derivations we use to build GHC. As a first step, use the same base
source for building GHC and all hadrian related packages. This is
achieved by wrapping the fetcher result in `srcOnly` to apply GHC
patches immediately.

To modify the patches (and source) used by GHC we now have a changed
overriding interface for >= 9.6:

```
oldGhc.override {
  ghcSrc = oldGhc.src.overrideAttrs (oldAttrs: {
    src = …;
    patches = …;
  });
}
```
2024-04-27 15:03:02 +02:00
sternenseemann
1dc7345389 haskell.compiler.ghc981: build stage 2 compiler for “native cross”
When we are building compiler for a platform we can execute ourselves,
we can build a proper stage2 compiler which unlocks some features that
are interesting for e.g. pkgsStatic.

The resulting compiler is technically a native compiler that's prefixed.
2024-04-16 22:16:19 +02:00
sternenseemann
91a91b9ae4 haskell.compiler.ghcHEAD: fix hash mismatch on case insensitive fs
By trying to migitate the conflict between two files on a case
insensitive fs, we will inevitably end up with a different hash than on
case sensitive filesystems. To work around this, we just delete the
directory that contains the offending files — luckily it is not
important to the build of GHC.
2024-04-10 00:29:58 +02:00
Slava Gorbunov
867727144e pkgsCross.ghcjs.ghc: make EM_CACHE absolute
emscripten-3.1.51 fails to compile code (with cache locking problems) if
EM_CACHE is relative.
2024-04-09 22:18:56 +02:00
sternenseemann
f805a39448 pkgsStatic.haskell.packages.ghc96.ghc: mark broken
Reference https://github.com/NixOS/nixpkgs/issues/208959
2024-01-11 14:14:56 +01:00
maralorn
a7baccff6f Merge branch 'master' into haskell-updates 2024-01-01 14:25:26 +01:00
maralorn
0bd0847ecd
Merge pull request #275616 from sternenseemann/ghc-cross-docs
haskell.compiler: also build manual for cross-compilers
2024-01-01 14:22:20 +01:00
sternenseemann
7998143a43 haskell.compiler: also build manual for cross-compilers
The reasoning given for disabling it is flawed: In most cases, sphinx
and its dependencies are already in the binary cache, since we only need
them as build tools—sphinx for the build platform is just the normal
pkgs.sphinx, since it doesn't care about targetPlatform.

We just need to disable it when the buildPlatform is also musl, so we
avoid pulling in sphinx in pkgsMusl.
2023-12-20 14:12:32 +01:00
sternenseemann
ce5cbc4465 haskell.packages.{ghc96,ghc98}: disable haddock for cross
In this situation, haddock would not be built by hadrian, as there is no
stage0:exe:haddock target by default. (We should eventually try adding
one.) If haddock is enabled and the build->host haddock missing, Cabal
tries using the build->build haddock which may fail to load the
documentation from the interface files produced by the build->host
GHC (e.g. due to a mismatch between dynamic and static linking).

Add regression tests to haskell-updates jobset.

Resolves #275304.
2023-12-20 11:09:45 +01:00
Marc Scholten
54fc9f6356 haskell.packages.ghc9{6,8}: work around aarch64-darwin output cycles
This ports our infamous patch for `Cabal` which cheesily prevents an
output cycle for derivations that use separate bin outputs where
references caused by the `Paths_*` module can't be eliminated by the GHC
aarch64-darwin codegen backend.

See also

- the original issue #140774,
- the original patch for GHC 9.2 #216857
- the ported patch for GHC 9.4
  f6f780f129

Co-authored-by: sternenseemann <sternenseemann@systemli.org>
2023-12-13 00:16:18 +01:00
Claudio Bley
2af613b58c haskell.compiler.ghc*: set abs paths for cctools bintools w/ hadrian
Fixes #267250.

Co-authored-by: sternenseemann <sternenseemann@systemli.org>
2023-11-21 18:19:27 +01:00
sternenseemann
2fd7fa6fbe haskell.compiler: link upstream issue for sphinx 7 patch 2023-11-17 12:52:04 +01:00
Alyssa Ross
afabc4a15d
Merge remote-tracking branch 'origin/master' into HEAD
Conflicts:
	pkgs/development/libraries/SDL2/default.nix
2023-11-10 15:18:19 +01:00
sternenseemann
2ec6f63534 haskell.compiler.ghcHEAD: 9.7.20230527 -> 9.9.20231014 2023-11-06 15:26:58 +01:00
Vladimír Čunát
176ccbcda8
ghc*: patch build of docs after sphinx update
The 8.x versions don't seem to need this (and the patch wouldn't apply).
2023-10-28 12:50:03 +02:00
Vaibhav Sagar
a63c085661 haskell.compiler.ghc98: init at 9.8.1
https://www.haskell.org/ghc/blog/20231009-ghc-9.8.1-released.html

- Use source-built GHC 9.4.7, pending packaging of bindist.
- The aarch64-linux space saving strategy via disabling hyperlinked
  source is disabled for now, pending either an updated patch or
  an user defined flavour using
  https://gitlab.haskell.org/ghc/ghc/-/merge_requests/10850.

Co-authored-by: sternenseemann <sternenseemann@systemli.org>
2023-10-15 00:43:20 +02:00
sternenseemann
59ee081663 haskell.compiler.*: don't unnecessarily include LLVM for GHC >= 9.2
When 9.2.1 was [released], I apparently was confused by the wording. The
NCG (-fasm) codegen backend for aarch64 not only works on
aarch64-darwin, but also aarch64-linux. `useLLVM` being enabled on
aarch64-linux had no adverse effect, as GHC used -fasm anyways, but it
did inflate closure size unnecessarily which we can rectify now.

[released]: https://www.haskell.org/ghc/blog/20211029-ghc-9.2.1-released.html
2023-10-04 20:17:17 +02:00
github-actions[bot]
8ad2926229
Merge master into haskell-updates 2023-07-16 00:16:59 +00:00
Randy Eckenrode
6454fb1bc0
haskell.compiler.ghc962: fix build on Darwin after stdenv rework merge
The switch to cctools-llvm made several LLVM tools the default on
Darwin, which includes llvm-ar. GHC will try to use `-L` with `ar` when
it is `llvm-ar`, but that doesn’t work currently on Darwin.

See https://gitlab.haskell.org/ghc/ghc/-/issues/23188.
2023-07-14 10:51:29 -06:00
sternenseemann
1eddb04ac9 haskell.compiler.{ghc962,ghcHEAD}: no rendered src on aarch64-linux
This saves just enough space on aarch64-linux so that the hadrian built
GHCs are under the 3GB Hydra output limit:

| compiler | before     | after      | Δ          |
|----------|------------|------------|------------|
| ghc962   | 3241234736 | 2810740560 | -430494176 |
| ghcHEAD  | 3341288328 | 2902760872 | -438527456 |

The total output size can be calculated using (don't forget to use
aarch64-linux):

```
nix-build -A <compiler> | xargs nix path-info -s | awk '{ s += $2 }; END { print s }'
```
2023-07-10 23:14:54 +02:00