Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make nixpkgs GHC 9.6.x work #1921

Merged
merged 10 commits into from
Dec 11, 2023
9 changes: 9 additions & 0 deletions haskell/cabal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ def _prepare_cabal_inputs(
]
extra_args = ["--flags=" + " ".join(flags)]

if hs.toolchain.is_darwin:
# assume `otool` and `install_name_tool` are available at the same location as `ar`
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"))
extra_args.append("--haddock-option=--optghc=-pgmotool=" + paths.join(ar_bindir, "otool"))
extra_args.append("--haddock-option=--optghc=-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
7 changes: 7 additions & 0 deletions haskell/experimental/private/module.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ def _build_haskell_module(
args.add_all(hs.toolchain.ghcopts)
args.add_all(user_ghcopts)

if hs.toolchain.is_darwin:
# assume `otool` and `install_name_tool` are available at the same location as `ar`
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")

if plugins and not enable_th:
# For #1681. These suppresses bogus warnings about missing libraries which
# aren't really needed.
Expand Down
9 changes: 9 additions & 0 deletions haskell/private/actions/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ def _compilation_defaults(
compile_flags += hs.toolchain.ghcopts
compile_flags += user_compile_flags

if hs.toolchain.is_darwin:
# assume `otool` and `install_name_tool` are available at the same location as `ar`
ar_bindir = paths.dirname(cc.tools.ar)

compile_flags += [
"-pgmotool=" + paths.join(ar_bindir, "otool"),
"-pgminstall_name_tool=" + paths.join(ar_bindir, "install_name_tool"),
]
Comment on lines +127 to +134
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this may fail for users that try to use a hermetic bindist cc toolchain like grail's llvm toolchain. I'm fine with this for now as it is an improvement over the status quo. But, from what I understand so far, this may not cover all use-cases, yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we probably will need a better solution to this in the future.


package_ids = []
all_plugins = plugins + non_default_plugins
for plugin in all_plugins:
Expand Down
16 changes: 16 additions & 0 deletions haskell/private/actions/link.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ def link_binary(
args.add_all(cc.linker_flags, format_each = "-optl%s")
if with_profiling:
args.add("-prof")

if hs.toolchain.is_darwin:
# assume `otool` and `install_name_tool` are available at the same location as `ar`
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 @@ -366,6 +374,14 @@ 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:
# assume `otool` and `install_name_tool` are available at the same location as `ar`
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
Loading