From eb2764d64d404c6bfd32c354dcd73496cb70cfc4 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 5 Jul 2023 19:21:36 +0200 Subject: [PATCH 1/8] llvmPackages_16.libcxxabi: apply wasm.patch unconditionally This will catch issue like the one that was present: Since we did not make ../llvm writeable, the patch wouldn't apply. --- pkgs/development/compilers/llvm/16/libcxxabi/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/development/compilers/llvm/16/libcxxabi/default.nix b/pkgs/development/compilers/llvm/16/libcxxabi/default.nix index cb5fa44f07009..b90698c6b9a5d 100644 --- a/pkgs/development/compilers/llvm/16/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/16/libcxxabi/default.nix @@ -28,13 +28,13 @@ stdenv.mkDerivation rec { postUnpack = lib.optionalString stdenv.isDarwin '' export TRIPLE=x86_64-apple-darwin - '' + lib.optionalString stdenv.hostPlatform.isWasm '' - patch -p1 -d llvm -i ${./wasm.patch} ''; prePatch = '' - cd ../${pname} + cd ../ chmod -R u+w . + cd ${pname} + patch -p1 -d ../llvm -i ${./wasm.patch} ''; patches = [ From 5e0ab54e714715e9dd803bf048677536b2421ea1 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 5 Jul 2023 19:22:36 +0200 Subject: [PATCH 2/8] llvmPackages_16.libcxx: apply wasm.patch from libcxxabi Seems like sometime between LLVM 12 and 16 the platform check sneaked into libcxx as well. --- pkgs/development/compilers/llvm/16/libcxx/default.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/development/compilers/llvm/16/libcxx/default.nix b/pkgs/development/compilers/llvm/16/libcxx/default.nix index 94374c8a312df..420e7d91f2882 100644 --- a/pkgs/development/compilers/llvm/16/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/16/libcxx/default.nix @@ -41,8 +41,10 @@ stdenv.mkDerivation rec { outputs = [ "out" ] ++ lib.optional (!headersOnly) "dev"; prePatch = '' - cd ../${basename} + cd ../ chmod -R u+w . + cd ${basename} + patch -d ../llvm -p1 -i "${../libcxxabi/wasm.patch}" ''; patches = [ From 6a03c05ffe44b3f21e3c6ab0797a997021caef12 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 5 Jul 2023 20:25:48 +0200 Subject: [PATCH 3/8] llvmPackages_16.libcxxabi: also convince CMake C compiler is working For some reason, this is required now. --- pkgs/development/compilers/llvm/16/libcxxabi/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/development/compilers/llvm/16/libcxxabi/default.nix b/pkgs/development/compilers/llvm/16/libcxxabi/default.nix index b90698c6b9a5d..cbaf69a1897fb 100644 --- a/pkgs/development/compilers/llvm/16/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/16/libcxxabi/default.nix @@ -65,6 +65,7 @@ stdenv.mkDerivation rec { # CMake however checks for this anyways; this flag tells it not to. See: # https://github.com/llvm/llvm-project/blob/4bd3f3759259548e159aeba5c76efb9a0864e6fa/llvm/runtimes/CMakeLists.txt#L243 "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DCMAKE_C_COMPILER_WORKS=ON" ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ "-DLLVM_ENABLE_LIBCXX=ON" "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" From bf5423ce4911996bf9250d78c4bf35f0508a19d7 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 5 Jul 2023 20:01:52 +0200 Subject: [PATCH 4/8] wasilibc: 19 -> 20 pkgsCross.wasi32.llvmPackages: 12 -> 16 * It appears BULK_MEMORY_SOURCES no longer needs to be set to be empty to compile firefox. Without it, the build of wasilibc would fail if enableThreads is true. * Include preliminary support for the experimental threads support in wasilibc which provides pthreads API. If wasilibc is built with support, is exposed via passthru and libcxx / libcxxabi are built with threads support accordingly. See also: - https://github.com/WebAssembly/wasi-sdk/pull/274 - https://github.com/WebAssembly/wasi-sdk/pull/301 - https://github.com/WebAssembly/wasi-sdk/pull/314 wasi-sdk ships it by default, but as a separate variant of libc which would be a hassle for us. Let's just make it optional for now. You can try it out using the following overlay: self: super: { wasilibc = super.wasilibc.override { enableThreads = true; }; } Flags for libc++abi are copied from wasi-sdk. --- .../compilers/llvm/16/libcxx/default.nix | 2 +- .../compilers/llvm/16/libcxxabi/default.nix | 24 +++++++++++++++---- .../libraries/wasilibc/default.nix | 17 ++++++++----- pkgs/top-level/all-packages.nix | 2 +- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/pkgs/development/compilers/llvm/16/libcxx/default.nix b/pkgs/development/compilers/llvm/16/libcxx/default.nix index 420e7d91f2882..de1a9aabf5c2b 100644 --- a/pkgs/development/compilers/llvm/16/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/16/libcxx/default.nix @@ -79,7 +79,7 @@ stdenv.mkDerivation rec { ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_THREADS=${if stdenv.cc.libc.hasThreads then "ON" else "OFF"}" "-DLIBCXX_ENABLE_FILESYSTEM=OFF" "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" diff --git a/pkgs/development/compilers/llvm/16/libcxxabi/default.nix b/pkgs/development/compilers/llvm/16/libcxxabi/default.nix index cbaf69a1897fb..a0e3c805f899e 100644 --- a/pkgs/development/compilers/llvm/16/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/16/libcxxabi/default.nix @@ -69,10 +69,26 @@ stdenv.mkDerivation rec { ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ "-DLLVM_ENABLE_LIBCXX=ON" "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXXABI_ENABLE_THREADS=OFF" - "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ + ] ++ lib.optionals stdenv.hostPlatform.isWasm ( + [ + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + # CMake tests for -fno-exceptions together with -lc++ -lc++abi which fails + # here, without -fno-exceptions, libc++abi is unusable later. + # See also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=260005 + # TODO(@sternenseemann): make this unconditional? + "-DCXX_SUPPORTS_FNO_EXCEPTIONS_FLAG=ON" + ] + ++ (if stdenv.cc.libc.hasThreads then [ + "-DLIBCXXABI_ENABLE_THREADS=ON" + "-DLIBCXXABI_HAS_PTHREAD_API=ON" + "-DLIBCXXABI_HAS_EXTERNAL_THREAD_API=OFF" + "-DLIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY=OFF" + "-DLIBCXXABI_HAS_WIN32_THREAD_API=OFF" + ] else [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + ]) + ) + ++ lib.optionals (!enableShared) [ "-DLIBCXXABI_ENABLE_SHARED=OFF" ]; diff --git a/pkgs/development/libraries/wasilibc/default.nix b/pkgs/development/libraries/wasilibc/default.nix index 0dce309ef5c7c..5cf1733d3d88d 100644 --- a/pkgs/development/libraries/wasilibc/default.nix +++ b/pkgs/development/libraries/wasilibc/default.nix @@ -2,13 +2,16 @@ , buildPackages , fetchFromGitHub , lib +# Enable experimental wasilibc pthread support +, enableThreads ? false +# For tests , firefox-unwrapped , firefox-esr-unwrapped }: let pname = "wasilibc"; - version = "19"; + version = "20"; in stdenv.mkDerivation { inherit pname version; @@ -17,7 +20,7 @@ stdenv.mkDerivation { owner = "WebAssembly"; repo = "wasi-libc"; rev = "refs/tags/wasi-sdk-${version}"; - hash = "sha256-yQSKoSil/C/1lIHwEO9eQKC/ye3PJIFGYjHyNDn61y4="; + sha256 = "0knm5ch499dksmv1k0kh7356pjd9n1gjn0p3vp9bw57mn478zp8z"; fetchSubmodules = true; }; @@ -38,8 +41,7 @@ stdenv.mkDerivation { "SYSROOT_LIB:=$SYSROOT_LIB" "SYSROOT_INC:=$SYSROOT_INC" "SYSROOT_SHARE:=$SYSROOT_SHARE" - # https://bugzilla.mozilla.org/show_bug.cgi?id=1773200 - "BULK_MEMORY_SOURCES:=" + "THREAD_MODEL=${if enableThreads then "posix" else "single"}" ) ''; @@ -53,8 +55,11 @@ stdenv.mkDerivation { ln -s $share/share/undefined-symbols.txt $out/lib/wasi.imports ''; - passthru.tests = { - inherit firefox-unwrapped firefox-esr-unwrapped; + passthru = { + tests = { + inherit firefox-unwrapped firefox-esr-unwrapped; + }; + hasThreads = enableThreads; }; meta = with lib; { diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index cb773146d539f..1bb7106122ddd 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -16125,7 +16125,7 @@ with pkgs; else if platform.isFreeBSD then 12 else if platform.isAndroid then 12 else if platform.isLinux then 11 - else if platform.isWasm then 12 + else if platform.isWasm then 16 else 14; # We take the "max of the mins". Why? Since those are lower bounds of the # supported version set, this is like intersecting those sets and then From 9cc1d4deb57a08e9908dd7041162bbaeb719bd77 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 5 Jul 2023 20:06:05 +0200 Subject: [PATCH 5/8] wasilibc.tests: check compilations of trivial C(++) binaries This is a quicker way than building firefox to see if linking works. --- .../libraries/wasilibc/default.nix | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pkgs/development/libraries/wasilibc/default.nix b/pkgs/development/libraries/wasilibc/default.nix index 5cf1733d3d88d..3ac8c7dc5f754 100644 --- a/pkgs/development/libraries/wasilibc/default.nix +++ b/pkgs/development/libraries/wasilibc/default.nix @@ -7,6 +7,8 @@ # For tests , firefox-unwrapped , firefox-esr-unwrapped +, pkgsCross +, wasmtime }: let @@ -58,6 +60,41 @@ stdenv.mkDerivation { passthru = { tests = { inherit firefox-unwrapped firefox-esr-unwrapped; + simple-c-cxx-binaries = pkgsCross.wasi32.runCommandCC "simple-c-cxx-binaries" { + nativeBuildInputs = [ + wasmtime + ]; + } '' + cat > test.c < + int main(void) { + puts("Hello from C"); + return 0; + } + EOF + cat > test.cpp < + int main(void) { + std::cout<<"Hello from C++\n"; + return 0; + } + EOF + + mkdir -p "$out/bin" + # TODO(@sternenseemann): compile with -pthread if enableThreads + $CC -o "$out/bin/test-c" test.c + $CXX -o "$out/bin/test-cxx" test.cpp -lc++ -lc++abi + + export HOME=$TMPDIR + export WASMTIME_FLAGS=(${ + lib.escapeShellArgs (lib.optionals enableThreads [ + "--wasm-features=threads" + "--wasi-modules=experimental-wasi-threads" + ]) + }) + wasmtime run "''${WASMTIME_FLAGS[@]}" "$out/bin/test-c" + wasmtime run "''${WASMTIME_FLAGS[@]}" "$out/bin/test-cxx" + ''; }; hasThreads = enableThreads; }; From 242c1362e6d47e23461e9f840f772d3de36946df Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 6 Apr 2023 15:51:08 +0200 Subject: [PATCH 6/8] libffi-wasm-ghc: init at unstable-2022-11-10 --- .../haskell-modules/non-hackage-packages.nix | 3 + .../libraries/libffi-wasm-ghc/codegen.nix | 32 ++++++++++ .../libraries/libffi-wasm-ghc/default.nix | 62 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 4 files changed, 99 insertions(+) create mode 100644 pkgs/development/libraries/libffi-wasm-ghc/codegen.nix create mode 100644 pkgs/development/libraries/libffi-wasm-ghc/default.nix diff --git a/pkgs/development/haskell-modules/non-hackage-packages.nix b/pkgs/development/haskell-modules/non-hackage-packages.nix index beb81a58d8638..e805546bb3f5d 100644 --- a/pkgs/development/haskell-modules/non-hackage-packages.nix +++ b/pkgs/development/haskell-modules/non-hackage-packages.nix @@ -38,4 +38,7 @@ self: super: { # Unofficial fork until PRs are merged https://github.com/pcapriotti/optparse-applicative/pulls/roberth # cabal2nix --maintainer roberth https://github.com/hercules-ci/optparse-applicative.git > pkgs/development/misc/haskell/hercules-ci-optparse-applicative.nix hercules-ci-optparse-applicative = self.callPackage ../misc/haskell/hercules-ci-optparse-applicative.nix {}; + + # Codegen tool used by GHC for wasm FFI support + libffi-wasm = self.callPackage ../libraries/libffi-wasm-ghc/codegen.nix { }; } diff --git a/pkgs/development/libraries/libffi-wasm-ghc/codegen.nix b/pkgs/development/libraries/libffi-wasm-ghc/codegen.nix new file mode 100644 index 0000000000000..3147cda8c475f --- /dev/null +++ b/pkgs/development/libraries/libffi-wasm-ghc/codegen.nix @@ -0,0 +1,32 @@ +{ mkDerivation +, fetchFromGitLab +, base +, bytestring +, language-c +, lib +, pretty +, tasty +, unliftio +}: +mkDerivation { + pname = "libffi-wasm"; + version = "unstable-2022-11-10"; + src = fetchFromGitLab { + domain = "gitlab.haskell.org"; + owner = "ghc"; + repo = "libffi-wasm"; + rev = "4914da7d7b8b68abf575a47bf88f64b8e1c47ca7"; + sha256 = "0x06bp1mr977g7w4pinp010rfipg3r4l0h92dc9jplbw2lxswhnm"; + }; + isLibrary = false; + isExecutable = true; + libraryHaskellDepends = [ base bytestring language-c pretty ]; + executableHaskellDepends = [ base bytestring unliftio ]; + testHaskellDepends = [ base tasty ]; + doHaddock = false; + doCheck = true; + license = lib.licenses.bsd3; + maintainers = [ lib.maintainers.sternenseemann ]; + mainProgram = "libffi-wasm"; + homepage = "https://gitlab.haskell.org/ghc/libffi-wasm/"; +} diff --git a/pkgs/development/libraries/libffi-wasm-ghc/default.nix b/pkgs/development/libraries/libffi-wasm-ghc/default.nix new file mode 100644 index 0000000000000..b237d35e8d312 --- /dev/null +++ b/pkgs/development/libraries/libffi-wasm-ghc/default.nix @@ -0,0 +1,62 @@ +{ lib +, stdenv +, buildPackages +}: + +let + # Codegen tool written by GHC upstream to generate the source for their port of + # libffi for wasm + libffi-wasm = buildPackages.haskellPackages.libffi-wasm; +in + +stdenv.mkDerivation (finalAttrs: { + inherit (libffi-wasm) pname version src; + + nativeBuildInputs = [ + libffi-wasm + ]; + + dontConfigure = true; + + CFLAGS = [ + "-Wall" + "-Wextra" + "-DNDEBUG" + "-O3" + "-Icbits" + ]; + + # Based on https://gitlab.haskell.org/ghc/libffi-wasm/-/blob/master/.gitlab-ci.yml + buildPhase = '' + runHook preBuild + + set -x + + libffi-wasm + + for f in cbits/ffi cbits/ffi_call cbits/ffi_closure; do + $CC $CFLAGS -c "$f.c" -o "$f.o" + done + + $AR -rc libffi.a cbits/*.o + + set +x + + runHook postBuild + ''; + + outputs = [ "out" "dev" ]; + installPhase = '' + runHook preInstall + + install -Dm644 -t "$dev/include" cbits/*.h + install -Dm755 -t "$out/lib" libffi.a + + runHook postInstall + ''; + + meta = { + inherit (libffi-wasm.meta) maintainers license homepage; + platforms = lib.platforms.wasi; + }; +}) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 1bb7106122ddd..238a423bcbe4d 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -22328,6 +22328,8 @@ with pkgs; doCheck = false; }; + libffi-wasm-ghc = callPackage ../development/libraries/libffi-wasm-ghc { }; + libfreeaptx = callPackage ../development/libraries/libfreeaptx { }; libfreefare = callPackage ../development/libraries/libfreefare { From 646856e8c48777345b89c291a9f5d7e72d4282ff Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Mon, 13 Mar 2023 01:35:22 +0100 Subject: [PATCH 7/8] pkgsCross.wasi32.haskell.compiler.{ghcHEAD,ghc961}: new wasm backend Closes #220835. --- .../compilers/emscripten/default.nix | 7 +++++- .../compilers/ghc/common-hadrian.nix | 22 +++++++++++++------ pkgs/top-level/all-packages.nix | 4 ++-- pkgs/top-level/haskell-packages.nix | 22 +++++++++++++------ pkgs/top-level/release-cross.nix | 2 ++ pkgs/top-level/release-haskell.nix | 16 ++++++++++++++ 6 files changed, 56 insertions(+), 17 deletions(-) diff --git a/pkgs/development/compilers/emscripten/default.nix b/pkgs/development/compilers/emscripten/default.nix index be74615823038..7575ee833c2a2 100644 --- a/pkgs/development/compilers/emscripten/default.nix +++ b/pkgs/development/compilers/emscripten/default.nix @@ -123,7 +123,12 @@ stdenv.mkDerivation rec { # HACK: Make emscripten look more like a cc-wrapper to GHC # when building the javascript backend. targetPrefix = "em"; - bintools = emscripten; + bintools = emscripten.overrideAttrs (old: { + passthru = old.passthru // { + # emscripten wraps LLVM bintools, GHC checks for this fact + isLLVM = true; + }; + }); }; meta = with lib; { diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index b90a4934fdbad..fb936501dc1d9 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -36,11 +36,15 @@ , # GHC can be built with system libffi or a bundled one. libffi ? null +, # TODO(@sternenseemann): this is ugly as hell + libffiAttr ? "libffi" + , useLLVM ? !(stdenv.targetPlatform.isx86 || stdenv.targetPlatform.isPower || stdenv.targetPlatform.isSparc || (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin) - || stdenv.targetPlatform.isGhcjs) + || stdenv.targetPlatform.isGhcjs + || stdenv.targetPlatform.isWasm) , # LLVM is conceptually a run-time-only dependency, but for # non-x86, we need LLVM to bootstrap later stages, so it becomes a # build-time dependency too. @@ -52,6 +56,7 @@ enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp && lib.meta.availableOn stdenv.targetPlatform gmp) || stdenv.targetPlatform.isGhcjs + || stdenv.targetPlatform.isWasm , gmp , # If enabled, use -fPIC when compiling static libs. @@ -62,11 +67,12 @@ , # Whether to build dynamic libs for the standard library (on the target # platform). Static libs are always built. - enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic && !isGhcjs + enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic && !isGhcjs && !isWasm , # Whether to build terminfo. enableTerminfo ? !(stdenv.targetPlatform.isWindows - || stdenv.targetPlatform.isGhcjs) + || stdenv.targetPlatform.isGhcjs + || stdenv.targetPlatform.isWasm) , # Libdw.c only supports x86_64, i686 and s390x as of 2022-08-04 enableDwarf ? (stdenv.targetPlatform.isx86 || @@ -203,7 +209,7 @@ let # https://gitlab.haskell.org/ghc/ghc/-/issues/22081 ++ lib.optional enableDwarf elfutils ++ lib.optional (!enableNativeBignum) gmp - ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows && !targetPlatform.isGhcjs) libiconv; + ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows && !targetPlatform.isGhcjs && !targetPlatform.isWasm) libiconv; # TODO(@sternenseemann): is buildTarget LLVM unnecessary? # GHC doesn't seem to have {LLC,OPT}_HOST @@ -226,9 +232,11 @@ let then targetCC.bintools else targetCC.bintools.bintools; # Same goes for strip. + # Additionally, if we are using LLVM bintools, they will be always wrapped. strip = # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" - if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin + if (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin) + || targetCC.bintools.isLLVM then targetCC.bintools else targetCC.bintools.bintools; }; @@ -365,8 +373,8 @@ stdenv.mkDerivation ({ "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" ] ++ lib.optionals (libffi != null && !targetPlatform.isGhcjs) [ "--with-system-libffi" - "--with-ffi-includes=${targetPackages.libffi.dev}/include" - "--with-ffi-libraries=${targetPackages.libffi.out}/lib" + "--with-ffi-includes=${targetPackages.${libffiAttr}.dev}/include" + "--with-ffi-libraries=${targetPackages.${libffiAttr}.out}/lib" ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ "--with-gmp-includes=${targetPackages.gmp.dev}/include" "--with-gmp-libraries=${targetPackages.gmp.out}/lib" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 238a423bcbe4d..f9e69a0b361aa 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15740,8 +15740,8 @@ with pkgs; haskell = callPackage ./haskell-packages.nix { }; haskellPackages = dontRecurseIntoAttrs - # JS backend is only available for GHC >= 9.6 - (if stdenv.hostPlatform.isGhcjs + # JS and wasm backends are only available for GHC >= 9.6 + (if stdenv.hostPlatform.isGhcjs || stdenv.hostPlatform.isWasm then haskell.packages.native-bignum.ghc96 # Prefer native-bignum to avoid linking issues with gmp else if stdenv.hostPlatform.isStatic diff --git a/pkgs/top-level/haskell-packages.nix b/pkgs/top-level/haskell-packages.nix index 42867afef83d8..1f94b80b1c9fe 100644 --- a/pkgs/top-level/haskell-packages.nix +++ b/pkgs/top-level/haskell-packages.nix @@ -347,7 +347,7 @@ in { llvmPackages = pkgs.llvmPackages_12; }; ghc94 = compiler.ghc945; - ghc962 = callPackage ../development/compilers/ghc/9.6.2.nix { + ghc962 = callPackage ../development/compilers/ghc/9.6.2.nix ({ bootPkgs = # For GHC 9.2 no armv7l bindists are available. if stdenv.hostPlatform.isAarch32 then @@ -366,9 +366,13 @@ in { # Support range >= 11 && < 16 buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_15; llvmPackages = pkgs.llvmPackages_15; - }; + } // pkgs.lib.optionalAttrs stdenv.targetPlatform.isWasm { + # Use GHC/tweag's custom libffi for wasm + libffi = pkgs.targetPackages.libffi-wasm-ghc; + libffiAttr = "libffi-wasm-ghc"; + }); ghc96 = compiler.ghc962; - ghcHEAD = callPackage ../development/compilers/ghc/head.nix { + ghcHEAD = callPackage ../development/compilers/ghc/head.nix ({ bootPkgs = # For GHC 9.2 no armv7l bindists are available. if stdenv.hostPlatform.isAarch32 then @@ -384,10 +388,14 @@ in { # https://github.com/xattr/xattr/issues/44 and # https://github.com/xattr/xattr/issues/55 are solved. inherit (buildPackages.darwin) xattr autoSignDarwinBinariesHook; - # 2023-01-15: Support range >= 10 && < 15 - buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_14; - llvmPackages = pkgs.llvmPackages_14; - }; + # 2023-07-04: Support range >= 10 && < 16 + buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_15; + llvmPackages = pkgs.llvmPackages_15; + } // pkgs.lib.optionalAttrs stdenv.targetPlatform.isWasm { + # Use GHC/tweag's custom libffi for wasm + libffi = pkgs.targetPackages.libffi-wasm-ghc; + libffiAttr = "libffi-wasm-ghc"; + }); ghcjs = compiler.ghcjs810; ghcjs810 = callPackage ../development/compilers/ghcjs/8.10 { diff --git a/pkgs/top-level/release-cross.nix b/pkgs/top-level/release-cross.nix index 3c6feba6b812f..cd04d31d3e992 100644 --- a/pkgs/top-level/release-cross.nix +++ b/pkgs/top-level/release-cross.nix @@ -75,6 +75,8 @@ let boehmgc = nativePlatforms; hello = nativePlatforms; zlib = nativePlatforms; + haskellPackages.hello = nativePlatforms; + haskell.packages.ghcHEAD.hello = nativePlatforms; }; darwinCommon = { diff --git a/pkgs/top-level/release-haskell.nix b/pkgs/top-level/release-haskell.nix index 6113dcdb121d3..63ff0973445da 100644 --- a/pkgs/top-level/release-haskell.nix +++ b/pkgs/top-level/release-haskell.nix @@ -471,6 +471,22 @@ let ; }; }; + + pkgsCross.wasi32 = { + haskellPackages = { + inherit (packagePlatforms pkgs.pkgsCross.wasi32.haskellPackages) + ghc + hello + ; + }; + + haskell.packages.ghcHEAD = { + inherit (packagePlatforms pkgs.pkgsCross.wasi32.haskell.packages.ghcHEAD) + ghc + hello + ; + }; + }; }) (versionedCompilerJobs { # Packages which should be checked on more than the From 563136d9903b299ea48cf236b9aef140498ca72a Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 5 Jul 2023 17:58:18 +0200 Subject: [PATCH 8/8] haskell.compiler.{ghc96,ghcHEAD}: explicitly provide build->build cc Seems like in a lot of cases the build->build compiler is propagated (?) somehow, but we can also provide it explicitly and have it accompany the stage0 GHC explicitly by setting the *_STAGE0 environment variables. --- pkgs/development/compilers/ghc/common-hadrian.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index fb936501dc1d9..eaac895cb628b 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -10,6 +10,7 @@ { lib , stdenv +, pkgsBuildBuild , pkgsBuildTarget , pkgsHostTarget , targetPackages @@ -295,6 +296,10 @@ stdenv.mkDerivation ({ export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" + # CC_FOR_BUILD etc. become CC_STAGE0 + export CC_STAGE0="$CC_FOR_BUILD" + export AR_STAGE0="$AR_FOR_BUILD" + export LD_STAGE0="$LD_FOR_BUILD" '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" @@ -416,6 +421,10 @@ stdenv.mkDerivation ({ # For building runtime libs depsBuildTarget = toolsForTarget; + depsBuildBuild = [ + pkgsBuildBuild.targetPackages.stdenv.cc + ]; + buildInputs = [ perl bash ] ++ (libDeps hostPlatform); depsTargetTarget = map lib.getDev (libDeps targetPlatform);