Skip to content

Commit 145730a

Browse files
committed
Do not hard-code /usr/bin/ar on Darwin
When using nix we cannot use the system ar tool since it might have a different interface (ie. is assumed to support response files) than the nix provided one. The bintools packages provides `libtool` and `ar` in its `bin/` folder.
1 parent 31171a5 commit 145730a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

haskell/cabal.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ def _cabal_toolchain_info(hs, cc, workspace_name, runghc):
164164
# TODO: remove this if Bazel fixes its behavior.
165165
# Upstream ticket: https://github.com/bazelbuild/bazel/issues/5127.
166166
ar = cc.tools.ar
167-
if ar.find("libtool") >= 0:
168-
ar = "/usr/bin/ar"
167+
if paths.basename(ar) == "libtool":
168+
# assume `ar` is available at the same place
169+
ar = paths.join(paths.dirname(ar), "ar")
169170

170171
return struct(
171172
ghc = hs.tools.ghc.path,

haskell/cc.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ load(
99
"C_COMPILE_ACTION_NAME",
1010
)
1111
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
12+
load("@bazel_skylib//lib:paths.bzl", "paths")
1213
load(
1314
"//haskell:providers.bzl",
1415
"GhcPluginInfo",
@@ -136,8 +137,10 @@ def cc_interop_info(ctx, override_cc_toolchain = None):
136137
# "/usr/bin/libtool". Since we call ar directly, override it.
137138
# TODO: remove this if Bazel fixes its behavior.
138139
# Upstream ticket: https://github.com/bazelbuild/bazel/issues/5127.
139-
if tools["ar"].find("libtool") >= 0:
140-
tools["ar"] = "/usr/bin/ar"
140+
ar = tools["ar"]
141+
if paths.basename(ar) == "libtool":
142+
# assume `ar` is available at the same place
143+
tools["ar"] = paths.join(paths.dirname(ar), "ar")
141144

142145
env = {}
143146
if hs_toolchain.is_darwin:

0 commit comments

Comments
 (0)