From ad7478c38a59ea7b11bf587ce88b7456b3f3b3e4 Mon Sep 17 00:00:00 2001 From: Judah Jacobson Date: Mon, 30 Apr 2018 15:12:08 -0700 Subject: [PATCH 1/3] Fix build breakage on macOS when XCode is not installed. If the macOS "command-line developer tools" are installed, but XCode is not, then Bazel will make `ar_executable` point to `/usr/bin/libtool` (despite the fact that `ar` and `libtool` are not invoked the same way). https://github.com/bazelbuild/bazel/blob/71932dd4e25d5e755cb8ce12f4dece438c4b5cb1/tools/cpp/unix_cc_configure.bzl#L101 Fix it by checking for that case and overriding it to point to `/usr/bin/ar` (which is a path also hard-coded in the above code). This is not ideal, but I don't know a good way around it. Note that `rules_rust` has done a similar workaround: https://github.com/bazelbuild/rules_rust/blob/df95c3e3cd5afd87a69fa71dc9a56a0d0baa7823/rust/toolchain.bzl#L18 --- haskell/toolchain.bzl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/haskell/toolchain.bzl b/haskell/toolchain.bzl index 973a0d42d..9cfcd1862 100644 --- a/haskell/toolchain.bzl +++ b/haskell/toolchain.bzl @@ -72,6 +72,13 @@ def _haskell_toolchain_impl(ctx): "strip": ctx.host_fragments.cpp.strip_executable, } + ghc_binaries + # If running on darwin but XCode is not installed (i.e., only the Command + # Line Tools are available), then Bazel will make ar_executable point to + # "/usr/bin/libtool". Since we call ar directly, override it. + # TODO: remove this if Bazel fixes its behavior. + if targets_r["ar"].find("libtool"): + targets_r["ar"] = "/usr/bin/ar" + ar_runfiles = [] # "xcrunwrapper.sh" is a Bazel-generated dependency of the `ar` program on macOS. From cd5d40c2d7ffd88e8638eb66638cc2ceaca536bb Mon Sep 17 00:00:00 2001 From: Judah Jacobson Date: Mon, 30 Apr 2018 15:44:00 -0700 Subject: [PATCH 2/3] Fix bug in if logic --- haskell/toolchain.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haskell/toolchain.bzl b/haskell/toolchain.bzl index 9cfcd1862..900f4ccf0 100644 --- a/haskell/toolchain.bzl +++ b/haskell/toolchain.bzl @@ -76,7 +76,7 @@ def _haskell_toolchain_impl(ctx): # Line Tools are available), then Bazel will make ar_executable point to # "/usr/bin/libtool". Since we call ar directly, override it. # TODO: remove this if Bazel fixes its behavior. - if targets_r["ar"].find("libtool"): + if targets_r["ar"].find("libtool") >= 0: targets_r["ar"] = "/usr/bin/ar" ar_runfiles = [] From 32fb4c563aebc690a0b1a510c5df9d5025260dce Mon Sep 17 00:00:00 2001 From: Mathieu Boespflug Date: Tue, 1 May 2018 22:47:26 +0200 Subject: [PATCH 3/3] Add link to upstream ticket in code. --- haskell/toolchain.bzl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/haskell/toolchain.bzl b/haskell/toolchain.bzl index 900f4ccf0..91bc937ce 100644 --- a/haskell/toolchain.bzl +++ b/haskell/toolchain.bzl @@ -74,8 +74,9 @@ def _haskell_toolchain_impl(ctx): # If running on darwin but XCode is not installed (i.e., only the Command # Line Tools are available), then Bazel will make ar_executable point to - # "/usr/bin/libtool". Since we call ar directly, override it. + # "/usr/bin/libtool". Since we call ar directly, override it. # TODO: remove this if Bazel fixes its behavior. + # Upstream ticket: https://github.com/bazelbuild/bazel/issues/5127. if targets_r["ar"].find("libtool") >= 0: targets_r["ar"] = "/usr/bin/ar"