daml/bazel_tools/haskell-ghc-includes.patch

57 lines
2.1 KiB
Diff

diff --git a/haskell/c2hs.bzl b/haskell/c2hs.bzl
index 96dfd503..0fad061c 100644
--- a/haskell/c2hs.bzl
+++ b/haskell/c2hs.bzl
@@ -95,7 +95,8 @@ def _c2hs_library_impl(ctx):
"""
# Include libdir in include path just like hsc2hs does.
libdir=$({ghc} --print-libdir)
- {c2hs} -C-I$libdir/include "$@"
+ # GHC >=9 on Windows stores the includes outside of libdir
+ {c2hs} -C-I$libdir/include -C-I$libdir/../include "$@"
""".format(
ghc = hs.tools.ghc.path,
c2hs = c2hs_exe.path,
diff --git a/haskell/private/actions/process_hsc_file.bzl b/haskell/private/actions/process_hsc_file.bzl
index 07bdec29..76dd195a 100644
--- a/haskell/private/actions/process_hsc_file.bzl
+++ b/haskell/private/actions/process_hsc_file.bzl
@@ -60,17 +60,35 @@ def process_hsc_file(hs, cc, hsc_flags, hsc_inputs, hsc_file):
if hs.env.get("PATH") == None and hs.toolchain.is_windows:
hs.env["PATH"] = ""
- hs.actions.run(
+ hs.actions.run_shell(
inputs = depset(transitive = [
depset(cc.hdrs),
depset([hsc_file]),
depset(cc.files),
depset(hsc_inputs),
+ depset(hs.toolchain.bindir),
]),
input_manifests = cc.manifests,
outputs = [hs_out],
mnemonic = "HaskellHsc2hs",
- executable = hs.tools.hsc2hs,
+ command =
+ # cpp (called via c2hs) gets very unhappy if the mingw bin dir is
+ # not in PATH so we add it to PATH explicitely.
+ (
+ """
+ export PATH=$PATH:{mingw_bin}
+ """.format(mingw_bin = paths.dirname(cc.tools.cc)) if hs.toolchain.is_windows else ""
+ ) +
+ """
+ # Include libdir in include path just like hsc2hs does.
+ libdir=$({ghc} --print-libdir)
+ # GHC >=9 on Windows stores the includes outside of libdir
+ {hsc2hs} -C-I$libdir/include -C-I$libdir/../include "$@"
+ """.format(
+ ghc = hs.tools.ghc.path,
+ hsc2hs = hs.tools.hsc2hs.path,
+ ),
+
arguments = [args],
env = hs.env,
)