Build GHCi libraries with ghc --merge-objs - #12358
Open
andreabedini wants to merge 3 commits into
Open
andreabedini wants to merge 3 commits into
andreabedini wants to merge 3 commits into
Conversation
Add GhcFeature: each constructor names the flag whose presence in `ghc --show-options` signals it. Configuring ghc queries once and records the answers as program properties; ghcSupports reads them back. This is detection by capability rather than by version, unlike GhcImplInfo. First feature: the --merge-objs mode (GHC >= 9.4). Add the matching GhcMode too. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
We used to run `ld -r` ourselves, finding ld from the ghc settings and probing it for -r and -x. When ghc has --merge-objs, let it do the merging: it uses the tool and flags it was configured with and handles long argument lists. Whether a GHCi library can be built at all then follows from "Merge objects command" being set, not from probing `ld --help`. GHCs without --merge-objs keep the ld path. Revives haskell#9226 with feature detection instead of a version gate. Refs haskell#7828, haskell#9301, haskell#12332. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
With --merge-objs we never run ld, so skip the two probes at configure time: compiling a C file through ghc to test `ld -x` (not always possible, see haskell#10970) and `ld --help` for relocatable output. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
andreabedini
force-pushed
the
andrea/wip/merge-objs
branch
from
September 15, 2026 06:17
2790548 to
7b4e71e
Compare
4 tasks
There was a problem hiding this comment.
🔵 Needs a closer look
Two moderate issues remain around missing merge-tool handling and test coverage.
Pull request overview
This pull request updates Cabal to use ghc --merge-objs for GHCi libraries when supported, while retaining the ld -r fallback.
Changes:
- Adds GHC capability detection and merge-mode support.
- Avoids unnecessary
ldprobing when GHC handles merging. - Adds changelog and integration-test coverage.
File summaries
| File | Summary | Review note |
|---|---|---|
changelog.d/merge-objs.md |
Documents the new merging behavior. | No final comment. |
Cabal/src/Distribution/Simple/Program/GHC.hs |
Detects GHC features and renders merge commands. | No final comment. |
Cabal/src/Distribution/Simple/Program/Builtin.hs |
Detects GHC capabilities during configuration. | No final comment. |
Cabal/src/Distribution/Simple/GHC/Internal.hs |
Avoids ld probing when appropriate. |
No final comment. |
Cabal/src/Distribution/Simple/GHC/Build/Link.hs |
Uses GHC merging with an ld fallback. |
No final comment. |
Cabal/src/Distribution/Simple/Configure.hs |
Determines GHCi library availability. | Moderate (1 vote): A missing Merge objects command can still enable GHCi libraries; it should be treated as unsupported. |
cabal-testsuite/PackageTests/LibraryForGhci/setup.test.hs |
Tests merge and fallback behavior. | Moderate (1 vote): The test skips the platform where the empty-setting case matters; add controlled fixture or Windows coverage. |
cabal-testsuite/PackageTests/LibraryForGhci/p.cabal |
Defines the test package. | No final comment. |
cabal-testsuite/PackageTests/LibraryForGhci/Lib/Other.hs |
Provides an additional test module. | No final comment. |
cabal-testsuite/PackageTests/LibraryForGhci/Lib.hs |
Provides test library code. | No final comment. |
Review details
Suppressed comments (2)
Cabal/src/Distribution/Simple/Configure.hs:963
- When
Merge objects commandis absent, this expression yieldsNothing, and thefromMaybe Trueat line 968 enables GHCi libraries anyway. That lets a GHC advertising--merge-objsproceed without a configured merge tool (the comment above notes that GHC then falls back to an archive), so a missing setting should be treated as unsupported rather than capable.
not . null <$> Map.lookup "Merge objects command" (compilerProperties comp)
cabal-testsuite/PackageTests/LibraryForGhci/setup.test.hs:10
- The test skips exactly the platform where the new empty
Merge objects commandcase is expected to matter, so it never verifies that--enable-library-for-ghciis disabled instead of invokingghc --merge-objswithout a merge tool. Please add a controlled compiler/settings fixture (or Windows coverage) that exercises this branch and checks the resulting configuration/warning.
skipIfWindows "GHCi libraries are not built with GHC's Windows toolchain"
- Files reviewed: 10/10 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This was referenced Sep 15, 2026
Collaborator
|
This looks reasonable. Did Copilot say there’s an issue when no merge tool is available. Is this spurious? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The only thing Cabal does with
ldisld -rto produce the GHCi object. GHC has exposed exactly that asghc --merge-objssince 9.4 (GHC#20712, added so Cabal could drop its copy of the logic). This makes Cabal use it.When ghc advertises
--merge-objs, the GHCi object is produced by ghc with the merge tool and flags it was configured with, and whether a GHCi library can be built at all follows fromMerge objects commandbeing set in the settings (empty on the Windows bindists, so GHCi libs stay off there as today). On those GHCs we also stop probingldat configure time, which is what #10970 wanted rid of. GHCs without the mode keep theld -rpath unchanged.Detection is by capability, not version: a small
GhcFeaturetype inDistribution.Simple.Program.GHCmaps features to the flag that signals them inghc --show-options, queried once when ghc is configured and recorded as program properties.--merge-objsis the first member; other version checks can migrate later. This is what stalled #9226, which this supersedes.Tested with 9.12.2 and with a wrapper ghc that hides
--merge-objsto exercise the fallback; the newLibraryForGhcitest covers both. Not tested on Windows.Refs #7828, #9301, #12332, #10970. Supersedes #9226.
This PR was prepared with the help of an AI agent (Claude Code); I reviewed and tested the result.
🤖 Generated with Claude Code