Merge pull request #208947 from sternenseemann/ghc-head-js-backend-try-1
haskell.compiler.ghcHEAD: support JS backend
This commit is contained in:
commit
b92fb601c2
@ -3,6 +3,7 @@
|
||||
, llvmPackages
|
||||
, symlinkJoin, makeWrapper, substituteAll
|
||||
, mkYarnModules
|
||||
, emscripten
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
@ -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";
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
@ -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.
|
||||
@ -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 ||
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
@ -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";
|
||||
@ -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"
|
||||
@ -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
|
||||
@ -444,7 +462,7 @@ stdenv.mkDerivation ({
|
||||
preInstall = ''
|
||||
pushd _build/bindist/*
|
||||
|
||||
./configure $configureFlags "''${configureFlagsArray[@]}"
|
||||
$configureScript $configureFlags "''${configureFlagsArray[@]}"
|
||||
'';
|
||||
|
||||
postInstall = ''
|
||||
|
@ -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
|
||||
}:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -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
|
||||
@ -368,8 +375,8 @@ stdenv.mkDerivation {
|
||||
]
|
||||
++ lib.optionals withLibBPF [
|
||||
bpftools
|
||||
llvmPackages.clang
|
||||
llvmPackages.libllvm
|
||||
buildPackages.llvmPackages.clang
|
||||
buildPackages.llvmPackages.libllvm
|
||||
]
|
||||
;
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user