-
Notifications
You must be signed in to change notification settings - Fork 81
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
Fix static linking with Haskell prebuilt packages #569
Conversation
This issue was not previously triggered by the rules_haskell test cases, because these either don't have indirect dependencies on prebuilt dependencies, or they use the Note, that linker errors due to missing symbols only occur if Haskell code actually references functions from the imported prebuilt dependency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you!
bf2b994
to
8a580ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor things.
Also cc @regnat, is that change relevant for your newer haskell_import
and has to be added there as well?
haskell/private/haskell_impl.bzl
Outdated
inputs = [hs.tools.ghc_pkg], | ||
outputs = [id_file], | ||
command = """ | ||
$1 --simple-output -v1 field $2 id > $3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d add quotes around the variables here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Previously, static linking (linkstatic = True) of Haskell binary targets fails if the target has an indirect dependency on a prebuilt package imported using haskell_import. The reason is that haskell_import has no access to the package id and the package id of prebuilt package dependencies is not inserted into the `depends:` section of the package configuration file of Haskell targets. GHC then does not add linker flags for the corresponding static libraries and liking fails on missing symbols. See FormationAI/hazel#64 . This change fixes that by inserting the package id of prebuilt packages into the depends: section of Haskell targets. The corresponding package id is obtained using `ghc-pkg field id` on the prebuilt package.
Generate the package id file for prebuilt packages in the `haskell_import` implementation and store the file in the `HaskellPrebuiltPackageInfo` provider.
By setting `use_direct = True` on expose_packages when linking.
Indirect dependencies on `haskell_import` targets caused missing symbol linker errors when statically linking. This test-case triggers this issue.
8a580ee
to
d06bd91
Compare
As suggested in #569 (comment)
If you're referring to |
Currently, static linking (
linkstatic = True
) of Haskell binary targets fails if the target has an indirect dependency on a prebuilt package imported usinghaskell_import
. The reason is thathaskell_import
has no access to the package id and the package id of prebuilt package dependencies is not inserted into thedepends:
section of the package configuration file of Haskell targets. GHC then does not add linker flags for the corresponding static libraries and liking fails on missing symbols. See FormationAI/hazel#64 .This PR fixes that by inserting the package id of prebuilt packages into the
depends:
section of Haskell targets.The corresponding package id is obtained using
ghc-pkg field id
on the prebuilt package. The outcome is stored in a file and a reference to that file is stored in theHaskellPrebuiltPackageInfo
provider. This wayghc-pkg
only has to be executed once per prebuilt package.The implementation of
haskell_import
, which is now a little more complex, has been moved intohaskell/private/haskell_impl.bzl
to follow the convention of other more complex rule implementations.This change also allows to only reference direct prebuilt dependencies on linking, resolving an
XXX
comment inhaskell/private/packages.bzl
.Finally, this PR adds a regression test.