rules_haskell icon indicating copy to clipboard operation
rules_haskell copied to clipboard

Compilation of cabal libraries fails using awry cc tools / options

Open avdv opened this issue 2 years ago • 0 comments

Describe the bug Cabal is calling ghc --info to gather information about the cc toolchain, such as if the ar tool is supporting response files.

Some of this information can be overridden using ghc / cabal flags (such as the path to the otool executable), but some information is only available from ghc --info reflecting the information at the time when GHC was installed.

Depending on the configured cc toolchain, the cc tools actually used and the information about these tools from ghc --info might mismatch and cause errors.

To Reproduce

  1. upgrade nixpkgs to nixos-unstable:
diff --git a/nixpkgs/default.nix b/nixpkgs/default.nix
index 7cfe73d8..8ee33a01 100644
--- a/nixpkgs/default.nix
+++ b/nixpkgs/default.nix
@@ -1,8 +1,8 @@
 { ... }@args:
 let
   # 2023-10-20
-  sha256 = "07dv5x236rqf5b718b7bhpqf2yaq43h6w8mrz9fcb0hxwjzsxlpg";
-  rev = "80c1aab725151632ddc2a20caeb914e76dd0673c";
+  sha256 = "sha256:1hf6cgaci1n186kkkjq106ryf8mmlq9vnwgfwh625wa8hfgdn4dm";
+  rev = "91050ea1e57e50388fa87a3302ba12d188ef723a";
 in
 import (fetchTarball {
   inherit sha256;
  1. nix-shell --pure --argstr ghcVersion 9.6.3 --arg docTools false
  2. cd rules_haskell_tests
  3. for i in *9.6.2*; do cp $i ${i/.2/.3}; done
  4. build some stackage library (transitively)
$ bazel build --config macos-nixpkgs -c dbg @//tests/haskell_module/dep-narrowing-th:lib --build_tag_filters "-dont_test_on_darwin,-requires_dynamic,-skip_profiling" --test_tag_filters "-dont_test_on_darwin,-requires_dynamic,-skip_profiling" --verbose_failures 
INFO: Analyzed target //tests/haskell_module/dep-narrowing-th:lib (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /private/var/tmp/_bazel_claudio/424cbf2491690099f756cdd833c2ed97/external/stackage/BUILD.bazel:1152:22: HaskellCabalLibrary @stackage//:splitmix failed: (Exit 1): cabal_wrapper failed: error executing command (from target @stackage//:splitmix) 
  (cd /private/var/tmp/_bazel_claudio/424cbf2491690099f756cdd833c2ed97/sandbox/processwrapper-sandbox/248/execroot/rules_haskell_tests && \
  exec env - \
    CC_WRAPPER_CC_PATH=external/nixpkgs_config_cc/cc_wrapper.sh \
    CC_WRAPPER_CPU=darwin \
    CC_WRAPPER_PLATFORM=darwin \
    LANG=C.UTF-8 \
    PATH=bazel-out/darwin-opt-exec-C7777A24/bin/external/alex/_install/bin:bazel-out/darwin-opt-exec-C7777A24/internal/_middlemen:/nix/store/ghf6nz4pmn1x29hhnbx712sdm832r4rw-posix-toolchain/bin \
    RULES_HASKELL_DOCDIR_PATH=/nix/store/hpv9q9w11p0h4p95xqxcl091r26pdazz-ghc-9.6.3/lib/ghc-9.6.3/lib/../../../../dpnyj1knmbsg4i5xdjjyc5fylzxpjf94-ghc-9.6.3-doc/share/doc/ghc/html/libraries/base-4.18.1.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/hpv9q9w11p0h4p95xqxcl091r26pdazz-ghc-9.6.3/lib/ghc-9.6.3/lib \
    SDKROOT=macosx \
  bazel-out/darwin-opt-exec-C7777A24/bin/external/rules_haskell/haskell/cabal_wrapper bazel-out/darwin-dbg/bin/external/stackage/splitmix_cabal_wrapper_args.json)
# Configuration: 591ebe1526d025c698e572a1cd3e3e55f88b69124fecb5aa2dee825ee9149154
# 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
ar: @../../../bazel-out/darwin-dbg/bin/external/stackage/splitmix-0.1.0.4/splitmix-0.1.0.4/build/objs-39812/ar39812-3.rsp: No such file or directory
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_claudio/424cbf2491690099f756cdd833c2ed97/sandbox/processwrapper-sandbox/248/execroot/rules_haskell_tests/bazel-out/darwin-opt-exec-C7777A24/bin/external/rules_haskell/haskell/runghc.runfiles/rules_haskell/haskell/runghc.py", line 9, in <module>
    subprocess.run([r.Rlocation("rules_haskell_ghc_nixpkgs/bin/runghc")] + sys.argv[1:], check=True)
  File "/nix/store/dc4xnyqi2kh25f1c74dfczxw95anbhhr-python3-3.11.6/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/private/var/tmp/_bazel_claudio/424cbf2491690099f756cdd833c2ed97/sandbox/processwrapper-sandbox/248/execroot/rules_haskell_tests/bazel-out/darwin-opt-exec-C7777A24/bin/external/rules_haskell/haskell/runghc.runfiles/rules_haskell_ghc_nixpkgs/bin/runghc', '/private/var/tmp/_bazel_claudio/424cbf2491690099f756cdd833c2ed97/sandbox/processwrapper-sandbox/248/execroot/rules_haskell_tests/external/stackage/splitmix-0.1.0.4/Setup.hs', 'build', '--verbose=0', '--builddir=/private/var/tmp/_bazel_claudio/424cbf2491690099f756cdd833c2ed97/sandbox/processwrapper-sandbox/248/execroot/rules_haskell_tests/bazel-out/darwin-dbg/bin/external/stackage/splitmix-0.1.0.4/splitmix-0.1.0.4']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_claudio/424cbf2491690099f756cdd833c2ed97/sandbox/processwrapper-sandbox/248/execroot/rules_haskell_tests/bazel-out/darwin-opt-exec-C7777A24/bin/external/rules_haskell/haskell/cabal_wrapper.runfiles/rules_haskell/haskell/private/cabal_wrapper.py", line 345, in <module>
    run([runghc] + runghc_args + [setup, "build", "--verbose=0", "--builddir=" + distdir])
  File "/private/var/tmp/_bazel_claudio/424cbf2491690099f756cdd833c2ed97/sandbox/processwrapper-sandbox/248/execroot/rules_haskell_tests/bazel-out/darwin-opt-exec-C7777A24/bin/external/rules_haskell/haskell/cabal_wrapper.runfiles/rules_haskell/haskell/private/cabal_wrapper.py", line 69, in run
    subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, *args, **kwargs)
  File "/nix/store/dc4xnyqi2kh25f1c74dfczxw95anbhhr-python3-3.11.6/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/private/var/tmp/_bazel_claudio/424cbf2491690099f756cdd833c2ed97/sandbox/processwrapper-sandbox/248/execroot/rules_haskell_tests/bazel-out/darwin-opt-exec-C7777A24/bin/external/rules_haskell/haskell/runghc', '/private/var/tmp/_bazel_claudio/424cbf2491690099f756cdd833c2ed97/sandbox/processwrapper-sandbox/248/execroot/rules_haskell_tests/external/stackage/splitmix-0.1.0.4/Setup.hs', 'build', '--verbose=0', '--builddir=/private/var/tmp/_bazel_claudio/424cbf2491690099f756cdd833c2ed97/sandbox/processwrapper-sandbox/248/execroot/rules_haskell_tests/bazel-out/darwin-dbg/bin/external/stackage/splitmix-0.1.0.4/splitmix-0.1.0.4']' returned non-zero exit status 1.
Target //tests/haskell_module/dep-narrowing-th:lib failed to build
ERROR: /Users/claudio/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): cabal_wrapper failed: error executing command (from target @stackage//:splitmix) 
  (cd /private/var/tmp/_bazel_claudio/424cbf2491690099f756cdd833c2ed97/sandbox/processwrapper-sandbox/248/execroot/rules_haskell_tests && \
  exec env - \
    CC_WRAPPER_CC_PATH=external/nixpkgs_config_cc/cc_wrapper.sh \
    CC_WRAPPER_CPU=darwin \
    CC_WRAPPER_PLATFORM=darwin \
    LANG=C.UTF-8 \
    PATH=bazel-out/darwin-opt-exec-C7777A24/bin/external/alex/_install/bin:bazel-out/darwin-opt-exec-C7777A24/internal/_middlemen:/nix/store/ghf6nz4pmn1x29hhnbx712sdm832r4rw-posix-toolchain/bin \
    RULES_HASKELL_DOCDIR_PATH=/nix/store/hpv9q9w11p0h4p95xqxcl091r26pdazz-ghc-9.6.3/lib/ghc-9.6.3/lib/../../../../dpnyj1knmbsg4i5xdjjyc5fylzxpjf94-ghc-9.6.3-doc/share/doc/ghc/html/libraries/base-4.18.1.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/hpv9q9w11p0h4p95xqxcl091r26pdazz-ghc-9.6.3/lib/ghc-9.6.3/lib \
    SDKROOT=macosx \
  bazel-out/darwin-opt-exec-C7777A24/bin/external/rules_haskell/haskell/cabal_wrapper bazel-out/darwin-dbg/bin/external/stackage/splitmix_cabal_wrapper_args.json)
# Configuration: 591ebe1526d025c698e572a1cd3e3e55f88b69124fecb5aa2dee825ee9149154
# 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
INFO: Elapsed time: 57.002s, Critical Path: 55.30s
INFO: 49 processes: 31 internal, 18 processwrapper-sandbox.
FAILED: Build did NOT complete successfully

ghc info:

$ ghc --info
 [("Project name","The Glorious Glasgow Haskell Compilation System")
 ,("GCC extra via C opts","")
 ,("C compiler command","/nix/store/dgmdis15d7s7vlkfkz5w5b2wnna2syfz-clang-wrapper-16.0.6/bin/cc")
 ,("C compiler flags","--target=x86_64-apple-darwin ")
 ,("C++ compiler command","/nix/store/dgmdis15d7s7vlkfkz5w5b2wnna2syfz-clang-wrapper-16.0.6/bin/c++")
 ,("C++ compiler flags","--target=x86_64-apple-darwin ")
 ,("C compiler link flags","")
 ,("C compiler supports -no-pie","NO")
 ,("Haskell CPP command","/nix/store/dgmdis15d7s7vlkfkz5w5b2wnna2syfz-clang-wrapper-16.0.6/bin/cc")
 ,("Haskell CPP flags","-E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs")
 ,("ld command","/nix/store/dm67kzmf9jscndd56cvxvlx48ksicwsn-cctools-binutils-darwin-wrapper-16.0.6-973.0.1/bin/ld")
 ,("ld flags","")
 ,("ld supports compact unwind","YES")
 ,("ld supports filelist","YES")
 ,("ld is GNU ld","NO")
 ,("Merge objects command","/nix/store/dm67kzmf9jscndd56cvxvlx48ksicwsn-cctools-binutils-darwin-wrapper-16.0.6-973.0.1/bin/ld")
 ,("Merge objects flags","-r")
 ,("ar command","/nix/store/nxzsfcz92w87i838a8p35b0iyc19m796-cctools-binutils-darwin-16.0.6-973.0.1/bin/ar")
 ,("ar flags","qcls")
 ,("ar supports at file","YES")
 ,("ar supports -L","NO")
 ,("ranlib command","/nix/store/nxzsfcz92w87i838a8p35b0iyc19m796-cctools-binutils-darwin-16.0.6-973.0.1/bin/ranlib")
 ,("otool command","otool")
 ,("install_name_tool command","install_name_tool")
 ,("touch command","touch")
 ,("dllwrap command","/bin/false")
 ,("windres command","/bin/false")
 ,("unlit command","/nix/store/hpv9q9w11p0h4p95xqxcl091r26pdazz-ghc-9.6.3/lib/ghc-9.6.3/lib/bin/unlit")
 ,("cross compiling","NO")
 ,("target platform string","x86_64-apple-darwin")
 ,("target os","OSDarwin")
 ,("target arch","ArchX86_64")
 ,("target word size","8")
 ,("target word big endian","NO")
 ,("target has GNU nonexec stack","NO")
 ,("target has .ident directive","YES")
 ,("target has subsections via symbols","YES")
 ,("target has RTS linker","YES")
 ,("target has libm","YES")
 ,("Unregisterised","NO")
 ,("LLVM target","x86_64-apple-darwin")
 ,("LLVM llc command","llc")
 ,("LLVM opt command","opt")
 ,("LLVM clang command","clang")
 ,("Use inplace MinGW toolchain","NO")
 ,("Use interpreter","YES")
 ,("Support SMP","YES")
 ,("RTS ways","debug thr thr_debug thr_p dyn debug_dyn thr_dyn thr_debug_dyn thr_debug_p debug_p")
 ,("Tables next to code","YES")
 ,("Leading underscore","YES")
 ,("Use LibFFI","NO")
 ,("RTS expects libdw","NO")
 ,("Project version","9.6.3")
 ,("Project Git commit id","6819b70a7739205a75f0b4fefcfcc9fdab39cab9")
 ,("Project Version Int","906")
 ,("Project Patch Level","3")
 ,("Project Patch Level1","3")
 ,("Project Patch Level2","0")
 ,("Booter version","9.2.4")
 ,("Stage","2")
 ,("Build platform","x86_64-apple-darwin")
 ,("Host platform","x86_64-apple-darwin")
 ,("Target platform","x86_64-apple-darwin")
 ,("Have interpreter","YES")
 ,("Object splitting supported","NO")
 ,("Have native code generator","YES")
 ,("Target default backend","native code generator")
 ,("Support dynamic-too","YES")
 ,("Support parallel --make","YES")
 ,("Support reexported-modules","YES")
 ,("Support thinning and renaming package flags","YES")
 ,("Support Backpack","YES")
 ,("Requires unified installed package IDs","YES")
 ,("Uses package keys","YES")
 ,("Uses unit IDs","YES")
 ,("GHC Dynamic","YES")
 ,("GHC Profiled","NO")
 ,("Debug on","NO")
 ,("LibDir","/nix/store/hpv9q9w11p0h4p95xqxcl091r26pdazz-ghc-9.6.3/lib/ghc-9.6.3/lib")
 ,("Global Package DB","/nix/store/hpv9q9w11p0h4p95xqxcl091r26pdazz-ghc-9.6.3/lib/ghc-9.6.3/lib/package.conf.d")
 ]

Notice that ghc info says ("ar supports at file","YES"), but the actual ar does not understand it:

ar: @../../../bazel-out/darwin-dbg/bin/external/stackage/splitmix-0.1.0.4/splitmix-0.1.0.4/build/objs-39812/ar39812-3.rsp: No such file or directory

The cc toolchain has tool_paths = {"ar": "/nix/store/pjpnglgh0bx9q0387g4x5sizilscm41z-Toolchains/XcodeDefault.xctoolchain/bin/libtool", ~which we replace with /usr/bin/ar here and here~ (edit: this is no longer true, see https://github.com/tweag/rules_haskell/pull/2063/commits/145730a7df31f4edbdb6476ee21ca20a8a2286e7).

$ ar          
usage:  ar -d [-TLsv] archive file ...
	ar -m [-TLsv] archive file ...
	ar -m [-abiTLsv] position archive file ...
	ar -p [-TLsv] archive [file ...]
	ar -q [-cTLsv] archive file ...
	ar -r [-cuTLsv] archive file ...
	ar -r [-abciuTLsv] position archive file ...
	ar -t [-TLsv] archive [file ...]
	ar -x [-ouTLsv] archive [file ...]

Expected behavior Cabal should use the cc tools from the cc toolchain and should not rely on the information that is given by ghc --info.

We should not rely on /usr/bin/ar on Darwin. (edit: done in https://github.com/tweag/rules_haskell/pull/2063/commits/145730a7df31f4edbdb6476ee21ca20a8a2286e7)

Environment

  • OS name + version: Darwin 21.6.0, macOS 12.7
  • Bazel version: 6.4.0
  • Version of the rules: 0.17 / current HEAD: https://github.com/tweag/rules_haskell/commit/267933e4f0bebbd76742f26477db5b8a397f938e

Additional context

avdv avatar Dec 05 '23 14:12 avdv