From ff2d74b3294f5c5488ddd1aad2d05fbeb045a7af Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 4 Jan 2023 15:19:46 +0100 Subject: [PATCH 1/6] haskellPackages.mkDerivation: use CC_FOR_BUILD if !stdenv.hasCC Previously, we would try to calculate the name of buildPackages.stdenv.cc and then just hope that it is in PATH somehow. This definitely doesn't work in all cases. The new approach is to add buildPackages.stdenv.cc to depsBuildBuild which also populates CC_FOR_BUILD which we can directly re-use. --- pkgs/development/haskell-modules/generic-builder.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index bf1f2c387ad9..a723e56c9e17 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -171,7 +171,7 @@ let # Pass the "wrong" C compiler rather than none at all so packages that just # use the C preproccessor still work, see # https://github.com/haskell/cabal/issues/6466 for details. - "--with-gcc=${(if stdenv.hasCC then stdenv else buildPackages.stdenv).cc.targetPrefix}cc" + "--with-gcc=${if stdenv.hasCC then "$CC" else "$CC_FOR_BUILD"}" ] ++ optionals stdenv.hasCC [ "--with-ld=${stdenv.cc.bintools.targetPrefix}ld" "--with-ar=${stdenv.cc.bintools.targetPrefix}ar" @@ -246,7 +246,10 @@ let allPkgconfigDepends = pkg-configDepends ++ libraryPkgconfigDepends ++ executablePkgconfigDepends ++ optionals doCheck testPkgconfigDepends ++ optionals doBenchmark benchmarkPkgconfigDepends; - depsBuildBuild = [ nativeGhc ]; + depsBuildBuild = [ nativeGhc ] + # CC_FOR_BUILD may be necessary if we have no C preprocessor for the host + # platform. See crossCabalFlags above for more details. + ++ lib.optionals (!stdenv.hasCC) [ buildPackages.stdenv.cc ]; collectedToolDepends = buildTools ++ libraryToolDepends ++ executableToolDepends ++ optionals doCheck testToolDepends ++ From 066591a35960ddb43652935423ceaacf90536ce8 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 4 Jan 2023 15:22:29 +0100 Subject: [PATCH 2/6] haskellPackages.mkDerivation: disable stripping in ghcjs cross set This line may look odd, but we should not set ghc.isGhcjs if we are using the JavaScript backend. It is a normal cross backend and no special code is required to make it work, i.e. everything will be named as it would be normally. Additionally, passing --ghcjs to Cabal will make it do the wrong thing. We need to, of course, stop strip from being thrown at the JS objects in both cases. --- pkgs/development/haskell-modules/generic-builder.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index a723e56c9e17..9bb64bd90298 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -11,7 +11,12 @@ let in { pname -, dontStrip ? (ghc.isGhcjs or false) +# Note that ghc.isGhcjs != stdenv.hostPlatform.isGhcjs. +# ghc.isGhcjs implies that we are using ghcjs, a project separate from GHC. +# (mere) stdenv.hostPlatform.isGhcjs means that we are using GHC's JavaScript +# backend. The latter is a normal cross compilation backend and needs little +# special accomodation. +, dontStrip ? (ghc.isGhcjs or false || stdenv.hostPlatform.isGhcjs) , version, revision ? null , sha256 ? null , src ? fetchurl { url = "mirror://hackage/${pname}-${version}.tar.gz"; inherit sha256; } From d9591db6f648fecabefb2557cfb3fc4212fe72c6 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 4 Jan 2023 15:25:44 +0100 Subject: [PATCH 3/6] haskellPackages.mkDerivation: fix shebangs in JS backend binaries The JavaScript backend emits `#!/usr/bin/env node` shebangs we need to take care off using patchShebangs in fixupPhase. --- pkgs/development/haskell-modules/generic-builder.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index 9bb64bd90298..4b7201bb6ac9 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -324,7 +324,9 @@ stdenv.mkDerivation ({ inherit src; inherit depsBuildBuild nativeBuildInputs; - buildInputs = otherBuildInputs ++ optionals (!isLibrary) propagatedBuildInputs; + buildInputs = otherBuildInputs ++ optionals (!isLibrary) propagatedBuildInputs + # For patchShebangsAuto in fixupPhase + ++ optionals stdenv.hostPlatform.isGhcjs [ nodejs ]; propagatedBuildInputs = optionals isLibrary propagatedBuildInputs; LANG = "en_US.UTF-8"; # GHC needs the locale configured during the Haddock phase. From ac7bc8f358aad901ba2beb4cddefefefa6089cb8 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 5 Jan 2023 15:32:31 +0100 Subject: [PATCH 4/6] pkgsCross.ghcjs.haskellPackages: default to ghcHEAD --- pkgs/top-level/all-packages.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 8e15d2571837..9202cb50281a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14550,10 +14550,13 @@ with pkgs; haskell = callPackage ./haskell-packages.nix { }; haskellPackages = dontRecurseIntoAttrs - # Prefer native-bignum to avoid linking issues with gmp - (if stdenv.hostPlatform.isStatic - then haskell.packages.native-bignum.ghc92 - else haskell.packages.ghc92); + # JS backend is only available for GHC >= 9.6 + (if stdenv.hostPlatform.isGhcjs + then haskell.packages.native-bignum.ghcHEAD + # Prefer native-bignum to avoid linking issues with gmp + else if stdenv.hostPlatform.isStatic + then haskell.packages.native-bignum.ghc92 + else haskell.packages.ghc92); # haskellPackages.ghc is build->host (it exposes the compiler used to build the # set, similarly to stdenv.cc), but pkgs.ghc should be host->target to be more From b931d63bba9277333ffb2ae29272bef5011add22 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 5 Jan 2023 15:34:56 +0100 Subject: [PATCH 5/6] release-haskell.nix: test ghc with JS backend It should be just below the current output limit, but we'll see. If it doesn't fit, we may have to disable profiling objects. --- pkgs/top-level/release-haskell.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/top-level/release-haskell.nix b/pkgs/top-level/release-haskell.nix index 94f835229567..ee7e64f1ffaa 100644 --- a/pkgs/top-level/release-haskell.nix +++ b/pkgs/top-level/release-haskell.nix @@ -345,6 +345,13 @@ let ; }; }; + + pkgsCross.ghcjs.haskellPackages = { + inherit (packagePlatforms pkgs.pkgsCross.ghcjs.haskellPackages) + ghc + hello + ; + }; }) (versionedCompilerJobs { # Packages which should be checked on more than the From 9b9c8edaf55c6e058d63bb409adeace6540fc051 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 5 Jan 2023 15:38:14 +0100 Subject: [PATCH 6/6] release-cross.nix: also test JS backend in ghcjs cross test --- pkgs/top-level/release-cross.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/top-level/release-cross.nix b/pkgs/top-level/release-cross.nix index 6eeda58a6c17..0acd119991b6 100644 --- a/pkgs/top-level/release-cross.nix +++ b/pkgs/top-level/release-cross.nix @@ -159,6 +159,8 @@ in /* Javacript */ ghcjs = mapTestOnCross lib.systems.examples.ghcjs { haskell.packages.ghcjs.hello = nativePlatforms; + haskell.packages.native-bignum.ghcHEAD.hello = nativePlatforms; + haskellPackages.hello = nativePlatforms; }; /* Linux on Raspberrypi */