From 718851b229754c86bb20507404a50ec07719d057 Mon Sep 17 00:00:00 2001 From: Slava Gorbunov Date: Fri, 12 Apr 2024 17:50:59 +0300 Subject: [PATCH] haskellPackages.mkDerivation: use emcc as C compiler for ghcjs We need to set up EM_CACHE correctly so that it works, of course. Note that the solution relies on the assumption that this should only happen when we cross compile, i.e. the extra logic to account for the cc-less stdenv in pkgsCross.ghcjs is only present in crossCabalFlags. Co-authored-by: sternenseemann --- .../haskell-modules/generic-builder.nix | 30 ++++++++++++++----- pkgs/top-level/release-haskell.nix | 10 +++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index 25480044c9ed..f9acdd0f4a27 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -1,13 +1,24 @@ { lib, stdenv, buildPackages, buildHaskellPackages, ghc -, jailbreak-cabal, hscolour, cpphs, nodejs +, jailbreak-cabal, hscolour, cpphs , ghcWithHoogle, ghcWithPackages +, nodejs }: let isCross = stdenv.buildPlatform != stdenv.hostPlatform; + + # 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. + cc = + if stdenv.hasCC then "$CC" + else if stdenv.hostPlatform.isGhcjs then "${emscripten}/bin/emcc" + else "$CC_FOR_BUILD"; + inherit (buildPackages) fetchurl removeReferencesTo - pkg-config coreutils gnugrep glibcLocales; + pkg-config coreutils gnugrep glibcLocales + emscripten; in { pname @@ -40,7 +51,8 @@ in , enableSharedExecutables ? false , enableSharedLibraries ? !stdenv.hostPlatform.isStatic && (ghc.enableShared or false) , enableDeadCodeElimination ? (!stdenv.isDarwin) # TODO: use -dead_strip for darwin -, enableStaticLibraries ? !(stdenv.hostPlatform.isWindows || stdenv.hostPlatform.isWasm) +# Disabling this for ghcjs prevents this crash: https://gitlab.haskell.org/ghc/ghc/-/issues/23235 +, enableStaticLibraries ? !(stdenv.hostPlatform.isWindows || stdenv.hostPlatform.isWasm || stdenv.hostPlatform.isGhcjs) , enableHsc2hsViaAsm ? stdenv.hostPlatform.isWindows , extraLibraries ? [], librarySystemDepends ? [], executableSystemDepends ? [] # On macOS, statically linking against system frameworks is not supported; @@ -188,10 +200,7 @@ let crossCabalFlags = [ "--with-ghc=${ghcCommand}" "--with-ghc-pkg=${ghc.targetPrefix}ghc-pkg" - # 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 "$CC" else "$CC_FOR_BUILD"}" + "--with-gcc=${cc}" ] ++ optionals stdenv.hasCC [ "--with-ld=${stdenv.cc.bintools.targetPrefix}ld" "--with-ar=${stdenv.cc.bintools.targetPrefix}ar" @@ -315,7 +324,7 @@ let optionals doBenchmark benchmarkToolDepends; nativeBuildInputs = [ ghc removeReferencesTo ] ++ optional (allPkgconfigDepends != []) (assert pkg-config != null; pkg-config) ++ - setupHaskellDepends ++ collectedToolDepends; + setupHaskellDepends ++ collectedToolDepends ++ optional stdenv.hostPlatform.isGhcjs nodejs; propagatedBuildInputs = buildDepends ++ libraryHaskellDepends ++ executableHaskellDepends ++ libraryFrameworkDepends; otherBuildInputsHaskell = optionals doCheck (testDepends ++ testHaskellDepends) ++ @@ -442,6 +451,11 @@ stdenv.mkDerivation ({ '' + '' done '' + + (optionalString stdenv.hostPlatform.isGhcjs '' + export EM_CACHE="$(realpath "$(mktemp -d emcache.XXXXXXXXXX)")" + cp -Lr ${emscripten}/share/emscripten/cache/* "$EM_CACHE/" + chmod u+rwX -R "$EM_CACHE" + '') # only use the links hack if we're actually building dylibs. otherwise, the # "dynamic-library-dirs" point to nonexistent paths, and the ln command becomes # "ln -s $out/lib/links", which tries to recreate the links dir and fails diff --git a/pkgs/top-level/release-haskell.nix b/pkgs/top-level/release-haskell.nix index a28c4e8a84ec..5ebc1c78a89f 100644 --- a/pkgs/top-level/release-haskell.nix +++ b/pkgs/top-level/release-haskell.nix @@ -473,6 +473,15 @@ let inherit (packagePlatforms pkgs.pkgsCross.ghcjs.haskellPackages) ghc hello + microlens + ; + }; + + haskell.packages.ghc98 = { + inherit (packagePlatforms pkgs.pkgsCross.ghcjs.haskell.packages.ghc98) + ghc + hello + microlens ; }; @@ -480,6 +489,7 @@ let inherit (packagePlatforms pkgs.pkgsCross.ghcjs.haskell.packages.ghcHEAD) ghc hello + microlens ; }; };