rules_haskell icon indicating copy to clipboard operation
rules_haskell copied to clipboard

[WIP] Fix linker error when using haskell_module with TH and local library

Open kozak opened this issue 3 years ago • 3 comments
trafficstars

WIP: not ready for review yet.

The problem:

rules_haskell fix-haskell-module-th-linking % bazel build "//tests/haskell_module/th:lib"
INFO: Analyzed target //tests/haskell_module/th:lib (29 packages loaded, 353 targets configured).
INFO: Found 1 target...
ERROR: /workspace/rules_haskell/tests/haskell_module/th/BUILD.bazel:46:16: HaskellBuildObject //tests/haskell_module/th:lib //tests/haskell_module/th:leaf failed: (Exit 1): ghc_wrapper failed: error executing command bazel-out/host/bin/haskell/ghc_wrapper bazel-out/k8-fastbuild/bin/tests/haskell_module/th/compile_flags_lib_tests_haskell_module_th_leaf_HaskellBuildObject ... (remaining 5 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
/usr/bin/ld.gold: error: cannot find -lphonenumber
collect2: error: ld returned 1 exit status
`cc_wrapper-python' failed in phase `Linker'. (Exit code: 1)
Target //tests/haskell_module/th:lib failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 5.868s, Critical Path: 2.33s
INFO: 3 processes: 3 internal.
FAILED: Build did NOT complete successfully
rules_haskell fix-haskell-module-th-linking %

It seems to fix the problem, but the test case requires a local library which isn't portable.

Co-authored: @zyla

kozak avatar Aug 11 '22 10:08 kozak

I rebased your branch in master and modified your test to be fetching the dependency from nix in https://github.com/tweag/rules_haskell/tree/fix-haskell-module-th-linking. In particular, https://github.com/tweag/rules_haskell/commit/1340c40e218dcb77ae383c10be98eb8b6fb01c0f is the commit which makes the dependency change (and the only new commit there).

Feel free to cherry-pick that or reset your branch to that one (I had to rebase because tests fail on NixOS from where you branched).

Note however that there is still some work to be done regarding the test, as it must be disabled(?) when not running rules_nixpkgs, which I need to dig a bit more to find out how to do.

googleson78 avatar Aug 15 '22 15:08 googleson78

Getting this to work with the bindist route will require some effort, while disabling the test for bindists feels unsatisfying as well. Can you specifically on reproduce the issue with libphonenumber, or is it possible to also do so with any C library? (e.g. reproducing with zlib would be optimal here)

googleson78 avatar Aug 17 '22 08:08 googleson78

Thanks for your help! Unfortunately this issue doesn't manifest itself with zlib, this was the first thing that I tried :). Hard to say about different C libs.

kozak avatar Aug 19 '22 08:08 kozak