From 8add024fabfe8da20fafc9a571eb282cf32363ae Mon Sep 17 00:00:00 2001
From: Sebastian Graf <sgraf1337@gmail.com>
Date: Tue, 16 Jul 2019 16:05:39 +0100
Subject: [PATCH] Make GHC-in-GHCi work on Windows

By not building anything in the dynamic way on Windows, where we don't
have a working story for DLLs yet.

Also the ghcid command needs to call bash on the hadrian/ghci.sh script
explicitly as the path gets interpreted differently otherwise.
---
 .ghcid                                     | 2 +-
 hadrian/ghci.sh                            | 4 ++--
 hadrian/src/Rules.hs                       | 5 ++++-
 hadrian/src/Settings/Flavours/GhcInGhci.hs | 7 +++++--
 4 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/.ghcid b/.ghcid
index 26c2ad2183f7..9ce2eeb73ec4 100644
--- a/.ghcid
+++ b/.ghcid
@@ -1,4 +1,4 @@
---command ./hadrian/ghci.sh
+--command sh ./hadrian/ghci.sh
 --reload compiler
 --reload ghc
 --reload includes
diff --git a/hadrian/ghci.sh b/hadrian/ghci.sh
index 4c9b9c67103c..90727b2d22c3 100755
--- a/hadrian/ghci.sh
+++ b/hadrian/ghci.sh
@@ -1,6 +1,6 @@
-#!/usr/bin/env bash
+#!/usr/bin/env sh
 
 set -e
 
-GHC_FLAGS=$(TERM=dumb CABFLAGS=-v0 . "hadrian/build.cabal.sh" tool-args -q --build-root=.hadrian_ghci --flavour=ghc-in-ghci "$@")
+GHC_FLAGS=$(TERM=dumb CABFLAGS=-v0 "hadrian/build.cabal.sh" tool-args -q --build-root=.hadrian_ghci --flavour=ghc-in-ghci "$@")
 ghci $GHC_FLAGS -fno-code -fwrite-interface -hidir=.hadrian_ghci/interface -O0 ghc/Main.hs
diff --git a/hadrian/src/Rules.hs b/hadrian/src/Rules.hs
index 851ccc05c7c4..61c5211399c5 100644
--- a/hadrian/src/Rules.hs
+++ b/hadrian/src/Rules.hs
@@ -38,7 +38,10 @@ import UserSettings
 toolArgsTarget :: Rules ()
 toolArgsTarget = do
   "tool-args" ~> do
-    let fake_target = target (Context Stage0 compiler dynamic)
+    -- We can't build DLLs on Windows (yet). Actually we should only
+    -- include the dynamic way when we have a dynamic host GHC, but just
+    -- checking for Windows seems simpler for now.
+    let fake_target = target (Context Stage0 compiler (if windowsHost then vanilla else dynamic))
                              (Ghc ToolArgs Stage0) [] ["ignored"]
 
     -- need the autogenerated files so that they are precompiled
diff --git a/hadrian/src/Settings/Flavours/GhcInGhci.hs b/hadrian/src/Settings/Flavours/GhcInGhci.hs
index 82fd0f2411b6..85331720640c 100644
--- a/hadrian/src/Settings/Flavours/GhcInGhci.hs
+++ b/hadrian/src/Settings/Flavours/GhcInGhci.hs
@@ -10,8 +10,11 @@ ghcInGhciFlavour :: Flavour
 ghcInGhciFlavour = defaultFlavour
     { name        = "ghc-in-ghci"
     , args        = defaultBuilderArgs <> ghciArgs <> defaultPackageArgs
-    , libraryWays = pure [vanilla, dynamic]
-    , rtsWays     = pure [vanilla, threaded, dynamic]
+    -- We can't build DLLs on Windows (yet). Actually we should only
+    -- include the dynamic way when we have a dynamic host GHC, but just
+    -- checking for Windows seems simpler for now.
+    , libraryWays = pure [vanilla] <> pure [ dynamic | not windowsHost ]
+    , rtsWays     = pure [vanilla, threaded] <> pure [ dynamic | not windowsHost ]
     , dynamicGhcPrograms = return False }
 
 ghciArgs :: Args
-- 
GitLab