Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kozak
Copy link

@kozak kozak commented Aug 11, 2022

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

@@ -103,6 +103,27 @@ stack_snapshot(
},
)

new_local_repository(
name = "system-libs",
# pkg-config --variable=libdir x11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a leftover?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I am sorry, don't think this is ready for review yet. It fixes the problem, but the test case requires a local library which isn't portable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I converted the PR into a draft, feel free to undo that once it's ready :)

@kozak kozak changed the title Fix linker error when using haskell_module with th and local library [WIP] Fix linker error when using haskell_module with th and local library Aug 11, 2022
@googleson78 googleson78 marked this pull request as draft August 11, 2022 11:18
@kozak kozak changed the title [WIP] Fix linker error when using haskell_module with th and local library [WIP] Fix linker error when using haskell_module with TH and local library Aug 11, 2022
@@ -338,6 +350,7 @@ def _build_haskell_module(
narrowed_deps_info.deps_hs_libraries,
narrowed_deps_info.empty_hs_libraries,
object_inputs,
depset(static_libs + dynamic_libs),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've added this because of the error in PR description. However this problems doesn't happen for zlib so we are not sure if we are correctly including the libphonenumber library. Does adding dependencies to run_ghc here make sense from you perspective @googleson78 ?

@@ -103,6 +103,27 @@ stack_snapshot(
},
)

new_local_repository(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@googleson78 do you have any idea of a better / more portable way to provide the library to the test? Unfortunately it has a bunch of dependencies https://github.com/google/libphonenumber/tree/master/cpp. I don't know much about nix, but maybe there is a nix package for it? (https://github.com/google/libphonenumber/tree/master/cpp)

@googleson78
Copy link
Contributor

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, 1340c40 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
Copy link
Contributor

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)

@kozak
Copy link
Author

kozak commented Aug 19, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants