Skip to content

Commit 745663e

Browse files
committed
Work around otool not set to nix store path in GHC settings
In previous GHC versions from nixpkgs, the `otool` setting was referencing a tool in the nix store, but for GHC 9.6.2 it is just set to "otool" which means it must be in `$PATH`. The same applies to the `install_name_tool`. See NixOS/nixpkgs#267250 and https://gitlab.haskell.org/ghc/ghc/-/issues/24211 We work around by using the location of the `ar` command and assume the other tools (from the bintools package) are also available at the same place.
1 parent b65ebd8 commit 745663e

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

haskell/cabal.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ def _prepare_cabal_inputs(
289289
]
290290
extra_args = ["--flags=" + " ".join(flags)]
291291

292+
if hs.toolchain.is_darwin:
293+
# assume `otool` and `install_name_tool` are available at the same location as `ar`
294+
ar_bindir = paths.dirname(cc.tools.ar)
295+
296+
extra_args.append("--ghc-option=-pgmotool=" + paths.join(ar_bindir, "otool"))
297+
extra_args.append("--ghc-option=-pgminstall_name_tool=" + paths.join(ar_bindir, "install_name_tool"))
298+
extra_args.append("--haddock-option=--optghc=-pgmotool=" + paths.join(ar_bindir, "otool"))
299+
extra_args.append("--haddock-option=--optghc=-pgminstall_name_tool=" + paths.join(ar_bindir, "install_name_tool"))
300+
292301
ghc_version = [int(x) for x in hs.toolchain.version.split(".")]
293302
if dynamic_file:
294303
# See Note [No PIE when linking] in haskell/private/actions/link.bzl

haskell/experimental/private/module.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,13 @@ def _build_haskell_module(
302302
args.add_all(hs.toolchain.ghcopts)
303303
args.add_all(user_ghcopts)
304304

305+
if hs.toolchain.is_darwin:
306+
# assume `otool` and `install_name_tool` are available at the same location as `ar`
307+
ar_bindir = paths.dirname(cc.tools.ar)
308+
309+
args.add(paths.join(ar_bindir, "otool"), format = "-pgmotool=%s")
310+
args.add(paths.join(ar_bindir, "install_name_tool"), format = "-pgminstall_name_tool=%s")
311+
305312
if plugins and not enable_th:
306313
# For #1681. These suppresses bogus warnings about missing libraries which
307314
# aren't really needed.

haskell/private/actions/compile.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ def _compilation_defaults(
124124
compile_flags += hs.toolchain.ghcopts
125125
compile_flags += user_compile_flags
126126

127+
if hs.toolchain.is_darwin:
128+
# assume `otool` and `install_name_tool` are available at the same location as `ar`
129+
ar_bindir = paths.dirname(cc.tools.ar)
130+
131+
compile_flags += [
132+
"-pgmotool=" + paths.join(ar_bindir, "otool"),
133+
"-pgminstall_name_tool=" + paths.join(ar_bindir, "install_name_tool"),
134+
]
135+
127136
package_ids = []
128137
all_plugins = plugins + non_default_plugins
129138
for plugin in all_plugins:

haskell/private/actions/link.bzl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ def link_binary(
133133
args.add_all(cc.linker_flags, format_each = "-optl%s")
134134
if with_profiling:
135135
args.add("-prof")
136+
137+
if hs.toolchain.is_darwin:
138+
# assume `otool` and `install_name_tool` are available at the same location as `ar`
139+
ar_bindir = paths.dirname(cc.tools.ar)
140+
141+
args.add(paths.join(ar_bindir, "otool"), format = "-pgmotool=%s")
142+
args.add(paths.join(ar_bindir, "install_name_tool"), format = "-pgminstall_name_tool=%s")
143+
136144
args.add_all(hs.toolchain.ghcopts)
137145
args.add_all(compiler_flags)
138146

@@ -366,6 +374,14 @@ def link_library_dynamic(hs, cc, posix, dep_info, extra_srcs, object_files, my_p
366374
args = hs.actions.args()
367375
args.add_all(cc.linker_flags, format_each = "-optl%s")
368376
args.add_all(["-shared", "-dynamic"])
377+
378+
if hs.toolchain.is_darwin:
379+
# assume `otool` and `install_name_tool` are available at the same location as `ar`
380+
ar_bindir = paths.dirname(cc.tools.ar)
381+
382+
args.add(paths.join(ar_bindir, "otool"), format = "-pgmotool=%s")
383+
args.add(paths.join(ar_bindir, "install_name_tool"), format = "-pgminstall_name_tool=%s")
384+
369385
args.add_all(hs.toolchain.ghcopts)
370386
args.add_all(compiler_flags)
371387

0 commit comments

Comments
 (0)