Skip to content

Commit

Permalink
Do not rely on /usr/bin/ar on Darwin
Browse files Browse the repository at this point in the history
For nixpkgs GHC 9.6.2, this caused a bus error with ghc-iserv:
```
ERROR: /Users/runner/work/rules_haskell/rules_haskell/rules_haskell_tests/tests/haskell_module/dep-narrowing-th/BUILD.bazel:88:16: HaskellBuildObject @//tests/haskell_module/dep-narrowing-th:lib @//tests/haskell_module/dep-narrowing-th:TestModule2 failed: (Exit 1): ghc_wrapper failed: error executing command (from target //tests/haskell_module/dep-narrowing-th:lib)
         (cd /private/var/tmp/_bazel_runner/6f93c0710d32c05eb86fd5414239ece6/sandbox/processwrapper-sandbox/2954/execroot/rules_haskell_tests && \
         exec env - \
           LANG=C.UTF-8 \
           MUST_EXTRACT_ABI=true \
           PATH=/nix/store/f0hpls21prmic0kg5b4yz5wgg1jdradr-posix-toolchain/bin:/nix/store/f0hpls21prmic0kg5b4yz5wgg1jdradr-posix-toolchain/bin \
           RULES_HASKELL_DOCDIR_PATH=/nix/store/slndd05yb65viiv9g7b05fb9y38rj0kq-ghc-9.6.2/lib/ghc-9.6.2/lib/../../../../qpzm6rba12ifz005ksjx302vyrzri7rq-ghc-9.6.2-doc/share/doc/ghc/html/libraries/base-4.18.0.0 \
           RULES_HASKELL_GHC_PATH=external/rules_haskell_ghc_nixpkgs/bin/ghc \
           RULES_HASKELL_GHC_PKG_PATH=external/rules_haskell_ghc_nixpkgs/bin/ghc-pkg \
           RULES_HASKELL_LIBDIR_PATH=/nix/store/slndd05yb65viiv9g7b05fb9y38rj0kq-ghc-9.6.2/lib/ghc-9.6.2/lib \
         bazel-out/darwin-opt-exec-C7777A24/bin/external/rules_haskell/haskell/ghc_wrapper bazel-out/darwin-dbg/bin/tests/haskell_module/dep-narrowing-th/compile_flags_lib_tests_haskell_module_dep-narrowing-th_TestModule2_HaskellBuildObjectProf bazel-out/darwin-dbg/bin/tests/haskell_module/dep-narrowing-th/extra_args_lib_tests_haskell_module_dep-narrowing-th_TestModule2_HaskellBuildObjectProf bazel-out/darwin-dbg/bin/tests/haskell_module/dep-narrowing-th/show_iface_lib_tests_haskell_module_dep-narrowing-th_TestModule2 bazel-out/darwin-dbg/bin/tests/haskell_module/dep-narrowing-th/testsZShaskellZUmoduleZSdep-narrowing-thZSlib/_iface/TestModule2.p_abi bazel-out/darwin-dbg/bin/tests/haskell_module/dep-narrowing-th/interfaces_lib_tests_haskell_module_dep-narrowing-th_TestModule2 bazel-out/darwin-dbg/bin/tests/haskell_module/dep-narrowing-th/unused_lib_tests_haskell_module_dep-narrowing-th_TestModule2)
       # Configuration: b90e686f7362f222f0a77fdd18c7cd52adae6ac6c043bbfd99dd47bb206c3ee8
       # Execution platform: @rules_nixpkgs_core//platforms:host

       Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging

       tests/haskell_module/dep-narrowing-th/TestModule2.hs:1:1: error: [GHC-87897]
           Exception when trying to run compile-time code:
             ghc-iserv terminated (-10)
           Code: runIO foo >> return []
         |
       1 | {-# LANGUAGE TemplateHaskell #-}
         | ^
       INFO: Elapsed time: 99.464s, Critical Path: 41.26s
```
See also #2070
  • Loading branch information
avdv committed Dec 6, 2023
1 parent 745663e commit 489d242
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions haskell/cabal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ def _cabal_toolchain_info(hs, cc, workspace_name, runghc):
# TODO: remove this if Bazel fixes its behavior.
# Upstream ticket: https://github.com/bazelbuild/bazel/issues/5127.
ar = cc.tools.ar
if ar.find("libtool") >= 0:
ar = "/usr/bin/ar"
if paths.basename(ar) == "libtool":
# assume `ar` is available at the same place as `libtool`
ar = paths.join(paths.dirname(ar), "ar")

return struct(
ghc = hs.tools.ghc.path,
Expand Down
7 changes: 5 additions & 2 deletions haskell/cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load(
"C_COMPILE_ACTION_NAME",
)
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
load("@bazel_skylib//lib:paths.bzl", "paths")
load(
"//haskell:providers.bzl",
"GhcPluginInfo",
Expand Down Expand Up @@ -136,8 +137,10 @@ def cc_interop_info(ctx, override_cc_toolchain = None):
# "/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 tools["ar"].find("libtool") >= 0:
tools["ar"] = "/usr/bin/ar"
ar_tool = tools["ar"]
if paths.basename(ar_tool) == "libtool":
# assume `ar` is available at the same place as `libtool`
tools["ar"] = paths.join(paths.dirname(ar_tool), "ar")

env = {}
if hs_toolchain.is_darwin:
Expand Down

0 comments on commit 489d242

Please sign in to comment.