Skip to content

Commit

Permalink
Merge pull request NixOS#208947 from sternenseemann/ghc-head-js-backe…
Browse files Browse the repository at this point in the history
…nd-try-1

haskell.compiler.ghcHEAD: support JS backend
  • Loading branch information
Ericson2314 authored Jan 4, 2023
2 parents 91e05c4 + 6392c21 commit b92fb60
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 26 deletions.
8 changes: 8 additions & 0 deletions pkgs/development/compilers/emscripten/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
, llvmPackages
, symlinkJoin, makeWrapper, substituteAll
, mkYarnModules
, emscripten
}:

stdenv.mkDerivation rec {
Expand Down Expand Up @@ -116,6 +117,13 @@ stdenv.mkDerivation rec {
runHook postInstall
'';

passthru = {
# HACK: Make emscripten look more like a cc-wrapper to GHC
# when building the javascript backend.
targetPrefix = "em";
bintools = emscripten;
};

meta = with lib; {
homepage = "https://github.com/emscripten-core/emscripten";
description = "An LLVM-to-JavaScript Compiler";
Expand Down
4 changes: 3 additions & 1 deletion pkgs/development/compilers/ghc/8.10.7.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

, # If enabled, GHC will be built with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
enableIntegerSimple ? !(lib.meta.availableOn stdenv.hostPlatform gmp), gmp
enableIntegerSimple ? !(lib.meta.availableOn stdenv.hostPlatform gmp
&& lib.meta.availableOn stdenv.targetPlatform gmp)
, gmp

, # If enabled, use -fPIC when compiling static libs.
enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform
Expand Down
4 changes: 3 additions & 1 deletion pkgs/development/compilers/ghc/8.8.4.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

, # If enabled, GHC will be built with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
enableIntegerSimple ? !(lib.meta.availableOn stdenv.hostPlatform gmp), gmp
enableIntegerSimple ? !(lib.meta.availableOn stdenv.hostPlatform gmp
&& lib.meta.availableOn stdenv.targetPlatform gmp)
, gmp

, # If enabled, use -fPIC when compiling static libs.
enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform
Expand Down
3 changes: 2 additions & 1 deletion pkgs/development/compilers/ghc/9.0.2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

, # If enabled, GHC will be built with the GPL-free but slightly slower native
# bignum backend instead of the faster but GPLed gmp backend.
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp)
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp
&& lib.meta.availableOn stdenv.targetPlatform gmp)
, gmp

, # If enabled, use -fPIC when compiling static libs.
Expand Down
3 changes: 2 additions & 1 deletion pkgs/development/compilers/ghc/9.2.4.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

, # If enabled, GHC will be built with the GPL-free but slightly slower native
# bignum backend instead of the faster but GPLed gmp backend.
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp)
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp
&& lib.meta.availableOn stdenv.targetPlatform gmp)
, gmp

, # If enabled, use -fPIC when compiling static libs.
Expand Down
3 changes: 2 additions & 1 deletion pkgs/development/compilers/ghc/9.2.5.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

, # If enabled, GHC will be built with the GPL-free but slightly slower native
# bignum backend instead of the faster but GPLed gmp backend.
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp)
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp
&& lib.meta.availableOn stdenv.targetPlatform gmp)
, gmp

, # If enabled, use -fPIC when compiling static libs.
Expand Down
3 changes: 2 additions & 1 deletion pkgs/development/compilers/ghc/9.4.2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

, # If enabled, GHC will be built with the GPL-free but slightly slower native
# bignum backend instead of the faster but GPLed gmp backend.
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp)
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp
&& lib.meta.availableOn stdenv.targetPlatform gmp)
, gmp

, # If enabled, use -fPIC when compiling static libs.
Expand Down
3 changes: 2 additions & 1 deletion pkgs/development/compilers/ghc/9.4.3.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

, # If enabled, GHC will be built with the GPL-free but slightly slower native
# bignum backend instead of the faster but GPLed gmp backend.
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp)
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp
&& lib.meta.availableOn stdenv.targetPlatform gmp)
, gmp

, # If enabled, use -fPIC when compiling static libs.
Expand Down
3 changes: 2 additions & 1 deletion pkgs/development/compilers/ghc/9.4.4.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

, # If enabled, GHC will be built with the GPL-free but slightly slower native
# bignum backend instead of the faster but GPLed gmp backend.
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp)
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp
&& lib.meta.availableOn stdenv.targetPlatform gmp)
, gmp

, # If enabled, use -fPIC when compiling static libs.
Expand Down
36 changes: 27 additions & 9 deletions pkgs/development/compilers/ghc/common-hadrian.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
, useLLVM ? !(stdenv.targetPlatform.isx86
|| stdenv.targetPlatform.isPower
|| stdenv.targetPlatform.isSparc
|| (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin))
|| (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin)
|| stdenv.targetPlatform.isGhcjs)
, # LLVM is conceptually a run-time-only depedendency, but for
# non-x86, we need LLVM to bootstrap later stages, so it becomes a
# build-time dependency too.
Expand All @@ -48,7 +49,9 @@

, # If enabled, GHC will be built with the GPL-free but slightly slower native
# bignum backend instead of the faster but GPLed gmp backend.
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp)
enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp
&& lib.meta.availableOn stdenv.targetPlatform gmp)
|| stdenv.targetPlatform.isGhcjs
, gmp

, # If enabled, use -fPIC when compiling static libs.
Expand All @@ -62,7 +65,8 @@
enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic

, # Whether to build terminfo.
enableTerminfo ? !stdenv.targetPlatform.isWindows
enableTerminfo ? !(stdenv.targetPlatform.isWindows
|| stdenv.targetPlatform.isGhcjs)

, # Libdw.c only supports x86_64, i686 and s390x as of 2022-08-04
enableDwarf ? (stdenv.targetPlatform.isx86 ||
Expand Down Expand Up @@ -195,17 +199,19 @@ let

# Splicer will pull out correct variations
libDeps = platform: lib.optional enableTerminfo ncurses
++ [libffi]
++ lib.optionals (!targetPlatform.isGhcjs) [libffi]
# Bindist configure script fails w/o elfutils in linker search path
# https://gitlab.haskell.org/ghc/ghc/-/issues/22081
++ lib.optional enableDwarf elfutils
++ lib.optional (!enableNativeBignum) gmp
++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows && !targetPlatform.isGhcjs) libiconv;

# TODO(@sternenseemann): is buildTarget LLVM unnecessary?
# GHC doesn't seem to have {LLC,OPT}_HOST
toolsForTarget = [
pkgsBuildTarget.targetPackages.stdenv.cc
(if targetPlatform.isGhcjs
then pkgsBuildTarget.emscripten
else pkgsBuildTarget.targetPackages.stdenv.cc)
] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm;

targetCC = builtins.head toolsForTarget;
Expand Down Expand Up @@ -245,7 +251,7 @@ in
# C compiler, bintools and LLVM are used at build time, but will also leak into
# the resulting GHC's settings file and used at runtime. This means that we are
# currently only able to build GHC if hostPlatform == buildPlatform.
assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc;
assert !targetPlatform.isGhcjs -> targetCC == pkgsHostTarget.targetPackages.stdenv.cc;
assert buildTargetLlvmPackages.llvm == llvmPackages.llvm;
assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang;

Expand Down Expand Up @@ -328,6 +334,13 @@ stdenv.mkDerivation ({
'*-android*|*-gnueabi*|*-musleabi*)'
done
''
# Need to make writable EM_CACHE for emscripten
# https://gitlab.haskell.org/ghc/ghc/-/wikis/javascript-backend#configure-fails-with-sub-word-sized-atomic-operations-not-available
+ lib.optionalString targetPlatform.isGhcjs ''
export EM_CACHE="$(mktemp -d emcache.XXXXXXXXXX)"
cp -Lr ${targetCC /* == emscripten */}/share/emscripten/cache/* "$EM_CACHE/"
chmod u+rwX -R "$EM_CACHE"
''
# Create bash array hadrianFlagsArray for use in buildPhase. Do it in
# preConfigure, so overrideAttrs can be used to modify it effectively.
# hadrianSettings are passed via the command line so they are more visible
Expand All @@ -339,6 +352,8 @@ stdenv.mkDerivation ({
)
'';

${if targetPlatform.isGhcjs then "configureScript" else null} = "emconfigure ./configure";

# TODO(@Ericson2314): Always pass "--target" and always prefix.
configurePlatforms = [ "build" "host" ]
++ lib.optional (targetPlatform != hostPlatform) "target";
Expand All @@ -347,7 +362,7 @@ stdenv.mkDerivation ({
configureFlags = [
"--datadir=$doc/share/doc/ghc"
"--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
] ++ lib.optionals (libffi != null) [
] ++ lib.optionals (libffi != null && !targetPlatform.isGhcjs) [
"--with-system-libffi"
"--with-ffi-includes=${targetPackages.libffi.dev}/include"
"--with-ffi-libraries=${targetPackages.libffi.out}/lib"
Expand Down Expand Up @@ -386,6 +401,9 @@ stdenv.mkDerivation ({
autoSignDarwinBinariesHook
] ++ lib.optionals enableDocs [
sphinx
] ++ lib.optionals targetPlatform.isGhcjs [
# emscripten itself is added via depBuildTarget / targetCC
python3
];

# For building runtime libs
Expand Down Expand Up @@ -444,7 +462,7 @@ stdenv.mkDerivation ({
preInstall = ''
pushd _build/bindist/*
./configure $configureFlags "''${configureFlagsArray[@]}"
$configureScript $configureFlags "''${configureFlagsArray[@]}"
'';

postInstall = ''
Expand Down
4 changes: 3 additions & 1 deletion pkgs/development/compilers/openjdk/19.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
, libXi, libXinerama, libXcursor, libXrandr, fontconfig, openjdk19-bootstrap
, ensureNewerSourcesForZipFilesHook
, setJavaClassPath
, headless ? false
# TODO(@sternenseemann): gtk3 fails to evaluate in pkgsCross.ghcjs.buildPackages
# which should be fixable, this is a no-rebuild workaround for GHC.
, headless ? stdenv.targetPlatform.isGhcjs
, enableJavaFX ? openjfx.meta.available, openjfx
, enableGnome2 ? true, gtk3, gnome_vfs, glib, GConf
}:
Expand Down
4 changes: 3 additions & 1 deletion pkgs/development/compilers/temurin-bin/jdk-linux-base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# runtime dependencies
, cups
# runtime dependencies for GTK+ Look and Feel
, gtkSupport ? true
# TODO(@sternenseemann): gtk3 fails to evaluate in pkgsCross.ghcjs.buildPackages
# which should be fixable, this is a no-rebuild workaround for GHC.
, gtkSupport ? !stdenv.targetPlatform.isGhcjs
, cairo
, glib
, gtk3
Expand Down
15 changes: 11 additions & 4 deletions pkgs/os-specific/linux/systemd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,16 @@

# the (optional) BPF feature requires bpftool, libbpf, clang and llvm-strip to be available during build time.
# Only libbpf should be a runtime dependency.
# Note: llvmPackages is explicitly taken from buildPackages instead of relying
# on splicing. Splicing will evaluate the adjacent (pkgsHostTarget) llvmPackages
# which is sometimes problematic: llvmPackages.clang looks at targetPackages.stdenv.cc
# which, in the unfortunate case of pkgsCross.ghcjs, `throw`s. If we explicitly
# take buildPackages.llvmPackages, this is no problem because
# `buildPackages.targetPackages.stdenv.cc == stdenv.cc` relative to us. Working
# around this is important, because systemd is in the dependency closure of
# GHC via emscripten and jdk.
, bpftools
, libbpf
, llvmPackages

, withAnalyze ? true
, withApparmor ? true
Expand All @@ -86,7 +93,7 @@
, withHostnamed ? true
, withHwdb ? true
, withImportd ? !stdenv.hostPlatform.isMusl
, withLibBPF ? lib.versionAtLeast llvmPackages.clang.version "10.0"
, withLibBPF ? lib.versionAtLeast buildPackages.llvmPackages.clang.version "10.0"
, withLocaled ? true
, withLogind ? true
, withMachined ? true
Expand Down Expand Up @@ -368,8 +375,8 @@ stdenv.mkDerivation {
]
++ lib.optionals withLibBPF [
bpftools
llvmPackages.clang
llvmPackages.libllvm
buildPackages.llvmPackages.clang
buildPackages.llvmPackages.libllvm
]
;

Expand Down
6 changes: 3 additions & 3 deletions pkgs/top-level/haskell-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ in {
# https://github.com/xattr/xattr/issues/44 and
# https://github.com/xattr/xattr/issues/55 are solved.
inherit (buildPackages.darwin) xattr autoSignDarwinBinariesHook;
# 2022-08-04: Support range >= 10 && < 14
buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_12;
llvmPackages = pkgs.llvmPackages_12;
# 2022-08-04: Support range >= 10 && < 15
buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_14;
llvmPackages = pkgs.llvmPackages_14;
};

ghcjs = compiler.ghcjs810;
Expand Down

0 comments on commit b92fb60

Please sign in to comment.