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

Always pass ghc-options #8717

Merged
merged 4 commits into from
Aug 19, 2024
Merged

Conversation

9999years
Copy link
Collaborator

@9999years 9999years commented Jan 31, 2023

The documentation for ghc-shared-options states that they are
combined with ghc-options:

Additional options for GHC when the package is built as shared library. The options specified via this field are combined with the ones specified via ghc-options, and are passed to GHC during both the compile and link phases.

However, only ghc-shared-options and not ghc-options are passed in many cases.

This is an issue because it requires setting ghc-shared-options even if the shared (dynamic) parts of the build don't actually need different options; this has the unpleasant side-effect of causing modules to be compiled twice, effectively doubling compile time! See here, where any non-empty ghc-shared-options causes Cabal to not set -dynamic-too:

-- Should we use -dynamic-too instead of compiling twice?
useDynToo = dynamicTooSupported && isGhcDynamic
&& doingTH && withStaticExe
&& null (hcSharedOptions GHC bnfo)

This issue was discovered while integrating the mold linker with a Haskell project; when ghc-shared-options wasn't set to the same value as ghc-options, the gold linker would be used instead of mold for various links during the build.


Please include the following checklist in your PR:

Please also shortly describe how you tested your change. Bonus points for added tests!

I've tested this by using Cabal with this patch applied to build a large commercial Haskell project (the mercury.com backend) and saw that the ghc-options were correctly applied (in this case, that meant observing that no links were performed with gold and all links were correctly performed with mold, as the options requested, with the exception of the single link described in #4439).

Possibly related issues:

@9999years 9999years marked this pull request as ready for review February 1, 2023 00:55
@Kleidukos
Copy link
Member

@9999years would you like my help with fixing the conflicts of the PR?

@9999years
Copy link
Collaborator Author

Rebased against latest master, PTAL

@Kleidukos Kleidukos requested a review from fendor June 2, 2023 19:52
Copy link
Collaborator

@fendor fendor left a comment

Choose a reason for hiding this comment

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

Essentially, this makes sure that wherever we have shared options, we also pass in the ghc-options. I think the implementation makes sense. Ideally, we'd have some kind of test for this... But I wouldn't know how.

LGTM!

Copy link
Collaborator

@geekosaur geekosaur left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -717,7 +717,7 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
, ghcOptFPic = toFlag True
, ghcOptHiSuffix = toFlag "dyn_hi"
, ghcOptObjSuffix = toFlag "dyn_o"
, ghcOptExtra = hcSharedOptions GHC libBi
, ghcOptExtra = hcOptions GHC libBi ++ hcSharedOptions GHC libBi
Copy link
Collaborator

Choose a reason for hiding this comment

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

For consistency shouldn't you do the same thing for ghcOptExtra of profOpts a few line above?

@ners
Copy link

ners commented Jan 9, 2024

@9999years thanks for fixing this. Is there anything blocking this PR from getting merged?

I'm keen on using the solution outlined in https://gitlab.haskell.org/ghc/ghc/-/merge_requests/9908#note_481299

@Kleidukos
Copy link
Member

There are some merge conflicts to solve still

@9999years
Copy link
Collaborator Author

@Kleidukos Are you going to actually merge or review it? I've fixed conflicts multiple times with this PR over the last year and it still hasn't moved.

@Kleidukos Kleidukos self-assigned this Jan 23, 2024
@Kleidukos
Copy link
Member

@9999years Yes, I thought your reviewers would have merged it. I will take personal care of this PR. Thank you again for your patience. 🙇

@Kleidukos
Copy link
Member

@9999years would you mind giving a thought to #8717 (comment) ?

@Gabriella439
Copy link

Is there a reason that this hasn't been merged? This PR got two approvals and then it seemed like people wanted it merged and then nothing happened. Could we get this merged and address any follow-up concerns in a future PR?

@geekosaur
Copy link
Collaborator

geekosaur commented Aug 14, 2024

There are still merge conflicts (see just after the incomplete CI record) that prevent it from being merged. I think we're still waiting on @Kleidukos but I can take a look at them later today if necessary.

@Kleidukos
Copy link
Member

Is there a reason that this hasn't been merged? This PR got two approvals and then it seemed like people wanted it merged and then nothing happened. Could we get this merged and address any follow-up concerns in a future PR?

Maybe GitHub doesn't show you this but this is what I see:
image

I will try and find the time to rebase this PR this week.

The [documentation for `ghc-shared-options`][1] states that they are
combined with `ghc-options`:

> Additional options for GHC when the package is built as shared
> library. The options specified via this field are combined with the
> ones specified via `ghc-options`, and are passed to GHC during both
> the compile and link phases.

However, _only_ `ghc-shared-options` and not `ghc-options` are passed in
many cases.

This is an issue because it requires setting `ghc-shared-options` even
if the shared (dynamic) parts of the build don't actually need different
options; this has the unpleasant side-effect of causing modules to be
compiled twice, effectively doubling compile time! See here, where any
non-empty `ghc-shared-options` causes Cabal to not set `-dynamic-too`:

https://github.com/haskell/cabal/blob/acbc0f3a5cc9faf0913ff3e270196693816cec41/Cabal/src/Distribution/Simple/GHC.hs#L1466-L1469

This issue was discovered while integrating the `mold` linker with a
Haskell project.

[1]: https://cabal.readthedocs.io/en/latest/cabal-package.html#pkg-field-ghc-shared-options
@Kleidukos
Copy link
Member

@9999years Is there a procedure I can follow to ensure that the patch does what it says?

@Kleidukos Kleidukos added squash+merge me Tell Mergify Bot to squash-merge attention: needs-backport 3.12 labels Aug 17, 2024
@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Aug 19, 2024
@mergify mergify bot merged commit 9c775f2 into haskell:master Aug 19, 2024
53 checks passed
@geekosaur
Copy link
Collaborator

@mergify backport 3.12

Copy link
Contributor

mergify bot commented Sep 14, 2024

backport 3.12

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Sep 14, 2024
* Always pass `ghc-options`

The [documentation for `ghc-shared-options`][1] states that they are
combined with `ghc-options`:

> Additional options for GHC when the package is built as shared
> library. The options specified via this field are combined with the
> ones specified via `ghc-options`, and are passed to GHC during both
> the compile and link phases.

However, _only_ `ghc-shared-options` and not `ghc-options` are passed in
many cases.

This is an issue because it requires setting `ghc-shared-options` even
if the shared (dynamic) parts of the build don't actually need different
options; this has the unpleasant side-effect of causing modules to be
compiled twice, effectively doubling compile time! See here, where any
non-empty `ghc-shared-options` causes Cabal to not set `-dynamic-too`:

https://github.com/haskell/cabal/blob/acbc0f3a5cc9faf0913ff3e270196693816cec41/Cabal/src/Distribution/Simple/GHC.hs#L1466-L1469

This issue was discovered while integrating the `mold` linker with a
Haskell project.

[1]: https://cabal.readthedocs.io/en/latest/cabal-package.html#pkg-field-ghc-shared-options

* Add documentation

* Also enhance profArgs and profDynArgs

---------

Co-authored-by: Hécate Moonlight <[email protected]>
Co-authored-by: Hécate <[email protected]>
(cherry picked from commit 9c775f2)

# Conflicts:
#	Cabal/src/Distribution/Simple/GHC.hs
#	doc/cabal-package-description-file.rst
@mergify mergify bot mentioned this pull request Sep 14, 2024
3 tasks
geekosaur pushed a commit that referenced this pull request Sep 14, 2024
* Always pass `ghc-options`

The [documentation for `ghc-shared-options`][1] states that they are
combined with `ghc-options`:

> Additional options for GHC when the package is built as shared
> library. The options specified via this field are combined with the
> ones specified via `ghc-options`, and are passed to GHC during both
> the compile and link phases.

However, _only_ `ghc-shared-options` and not `ghc-options` are passed in
many cases.

This is an issue because it requires setting `ghc-shared-options` even
if the shared (dynamic) parts of the build don't actually need different
options; this has the unpleasant side-effect of causing modules to be
compiled twice, effectively doubling compile time! See here, where any
non-empty `ghc-shared-options` causes Cabal to not set `-dynamic-too`:

https://github.com/haskell/cabal/blob/acbc0f3a5cc9faf0913ff3e270196693816cec41/Cabal/src/Distribution/Simple/GHC.hs#L1466-L1469

This issue was discovered while integrating the `mold` linker with a
Haskell project.

[1]: https://cabal.readthedocs.io/en/latest/cabal-package.html#pkg-field-ghc-shared-options

* Add documentation

* Also enhance profArgs and profDynArgs

---------

Co-authored-by: Hécate Moonlight <[email protected]>
Co-authored-by: Hécate <[email protected]>
(cherry picked from commit 9c775f2)
geekosaur pushed a commit that referenced this pull request Sep 14, 2024
* Always pass `ghc-options`

The [documentation for `ghc-shared-options`][1] states that they are
combined with `ghc-options`:

> Additional options for GHC when the package is built as shared
> library. The options specified via this field are combined with the
> ones specified via `ghc-options`, and are passed to GHC during both
> the compile and link phases.

However, _only_ `ghc-shared-options` and not `ghc-options` are passed in
many cases.

This is an issue because it requires setting `ghc-shared-options` even
if the shared (dynamic) parts of the build don't actually need different
options; this has the unpleasant side-effect of causing modules to be
compiled twice, effectively doubling compile time! See here, where any
non-empty `ghc-shared-options` causes Cabal to not set `-dynamic-too`:

https://github.com/haskell/cabal/blob/acbc0f3a5cc9faf0913ff3e270196693816cec41/Cabal/src/Distribution/Simple/GHC.hs#L1466-L1469

This issue was discovered while integrating the `mold` linker with a
Haskell project.

[1]: https://cabal.readthedocs.io/en/latest/cabal-package.html#pkg-field-ghc-shared-options

* Add documentation

* Also enhance profArgs and profDynArgs

---------

Co-authored-by: Hécate Moonlight <[email protected]>
Co-authored-by: Hécate <[email protected]>
(cherry picked from commit 9c775f2)
geekosaur pushed a commit that referenced this pull request Sep 14, 2024
* Always pass `ghc-options`

The [documentation for `ghc-shared-options`][1] states that they are
combined with `ghc-options`:

> Additional options for GHC when the package is built as shared
> library. The options specified via this field are combined with the
> ones specified via `ghc-options`, and are passed to GHC during both
> the compile and link phases.

However, _only_ `ghc-shared-options` and not `ghc-options` are passed in
many cases.

This is an issue because it requires setting `ghc-shared-options` even
if the shared (dynamic) parts of the build don't actually need different
options; this has the unpleasant side-effect of causing modules to be
compiled twice, effectively doubling compile time! See here, where any
non-empty `ghc-shared-options` causes Cabal to not set `-dynamic-too`:

https://github.com/haskell/cabal/blob/acbc0f3a5cc9faf0913ff3e270196693816cec41/Cabal/src/Distribution/Simple/GHC.hs#L1466-L1469

This issue was discovered while integrating the `mold` linker with a
Haskell project.

[1]: https://cabal.readthedocs.io/en/latest/cabal-package.html#pkg-field-ghc-shared-options

* Add documentation

* Also enhance profArgs and profDynArgs

---------

Co-authored-by: Hécate Moonlight <[email protected]>
Co-authored-by: Hécate <[email protected]>
(cherry picked from commit 9c775f2)
Mikolaj pushed a commit that referenced this pull request Sep 14, 2024
* Always pass `ghc-options`

The [documentation for `ghc-shared-options`][1] states that they are
combined with `ghc-options`:

> Additional options for GHC when the package is built as shared
> library. The options specified via this field are combined with the
> ones specified via `ghc-options`, and are passed to GHC during both
> the compile and link phases.

However, _only_ `ghc-shared-options` and not `ghc-options` are passed in
many cases.

This is an issue because it requires setting `ghc-shared-options` even
if the shared (dynamic) parts of the build don't actually need different
options; this has the unpleasant side-effect of causing modules to be
compiled twice, effectively doubling compile time! See here, where any
non-empty `ghc-shared-options` causes Cabal to not set `-dynamic-too`:

https://github.com/haskell/cabal/blob/acbc0f3a5cc9faf0913ff3e270196693816cec41/Cabal/src/Distribution/Simple/GHC.hs#L1466-L1469

This issue was discovered while integrating the `mold` linker with a
Haskell project.

[1]: https://cabal.readthedocs.io/en/latest/cabal-package.html#pkg-field-ghc-shared-options

* Add documentation

* Also enhance profArgs and profDynArgs

---------

Co-authored-by: Hécate Moonlight <[email protected]>
Co-authored-by: Hécate <[email protected]>
(cherry picked from commit 9c775f2)
mergify bot added a commit that referenced this pull request Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days squash+merge me Tell Mergify Bot to squash-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants