Skip to content

Commit

Permalink
Work around otool not set to nix store path in GHC settings
Browse files Browse the repository at this point in the history
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`.

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.
  • Loading branch information
avdv committed Nov 16, 2023
1 parent ca26b4e commit 2e4dd52
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions haskell/cabal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ def _prepare_cabal_inputs(
]
extra_args = ["--flags=" + " ".join(flags)]

if hs.toolchain.is_darwin:
ar_bindir = paths.dirname(cc.tools.ar)

extra_args.append("--ghc-option=-pgmotool=" + paths.join(ar_bindir, "otool"))
extra_args.append("--ghc-option=-pgminstall_name_tool=" + paths.join(ar_bindir, "install_name_tool"))

ghc_version = [int(x) for x in hs.toolchain.version.split(".")]
if dynamic_file:
# See Note [No PIE when linking] in haskell/private/actions/link.bzl
Expand Down
14 changes: 14 additions & 0 deletions haskell/private/actions/link.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ def link_binary(
args.add_all(cc.linker_flags, format_each = "-optl%s")
if with_profiling:
args.add("-prof")

if hs.toolchain.is_darwin:
ar_bindir = paths.dirname(cc.tools.ar)

args.add(paths.join(ar_bindir, "otool"), format = "-pgmotool=%s")
args.add(paths.join(ar_bindir, "install_name_tool"), format = "-pgminstall_name_tool=%s")

args.add_all(hs.toolchain.ghcopts)
args.add_all(compiler_flags)

Expand Down Expand Up @@ -349,6 +356,13 @@ def link_library_dynamic(hs, cc, posix, dep_info, extra_srcs, object_files, my_p
args = hs.actions.args()
args.add_all(cc.linker_flags, format_each = "-optl%s")
args.add_all(["-shared", "-dynamic"])

if hs.toolchain.is_darwin:
ar_bindir = paths.dirname(cc.tools.ar)

args.add(paths.join(ar_bindir, "otool"), format = "-pgmotool=%s")
args.add(paths.join(ar_bindir, "install_name_tool"), format = "-pgminstall_name_tool=%s")

args.add_all(hs.toolchain.ghcopts)
args.add_all(compiler_flags)
extra_prefix = empty_lib_prefix
Expand Down

0 comments on commit 2e4dd52

Please sign in to comment.