-
Notifications
You must be signed in to change notification settings - Fork 701
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
Cabal ignores hs-source-dirs:
if main-is:
is a C source file
#10168
Comments
Have you checked GHC 9.10/Cabal-3.10? That may be helpful. |
With Cabal-3.10.3.0, Stack-2.15.7, and GHC-9.10.1 the build seems to succeed. With Cabal-3.12.1.0 and GHC-9.6.5 the build fails (Cabal cannot find the |
As the problem is what different versions of Cabal (the library) are, or are not, passing to GHC, I reason that changing GHC version for a given Cabal version has no effect. But I've not tested that empircially. |
I have. The problem is with Cabal. :-( |
I agree with @mouse07410. I was able to try the GHC 9.10.1/Cabal 3.10.2.0 combination by adding to the Cabal file: build-type: Custom
custom-setup
setup-depends: base, Cabal ==3.10.2.0 and to snapshot: nightly-2024-04-04 # GHC 9.8.2
compiler: ghc-9.10.1
extra-deps:
- Cabal-3.10.2.0
- Cabal-syntax-3.10.2.0
# Specifying a boot package as an extra-dep requires its boot package dependencies to be
# specified also
- Win32-2.13.4.0@sha256:6a1299d051c514aa5ac7b77ef5f86be6c0aa6940b00302c6dc246192c7a97d99,5769
- binary-0.8.9.2@sha256:03381e511429c44d13990c6d76281c4fc2468371cede4fe684b0c98d9b7d5f5a,6611
- containers-0.6.8@sha256:bb2bec1bbc6b39a7c97cd95e056a5698ec45beb5d8feb6caae12af64e4bd823c,2670
- directory-1.3.8.5@sha256:fbeec9ec346e5272167f63dcb86af513b457a7b9fc36dc818e4c7b81608d612b,3166
- filepath-1.4.300.2@sha256:345cbb1afe414a09e47737e4d14cbd51891a734e67c0ef3d77a1439518bb81e8,5900
- parsec-3.1.17.0@sha256:8407cbd428d7f640a0fff8891bd2f7aca13cebe70a5e654856f8abec9a648b56,5149
- process-1.6.20.0@sha256:2a9393de33f18415fb8f4826957a87a94ffe8840ca8472a9b69dca6de45aca03,2790
- text-2.1.1@sha256:78c3fb91055d0607a80453327f087b9dc82168d41d0dca3ff410d21033b5e87d,10653
- time-1.12.2@sha256:88e8493d9130038d3b9968a2530a0900141cd3d938483c83dde56e12b875ebc8,6510 |
Actually, things are even more interesting. Below is a proof that the regression is in Cabal 3.12.0.0 library, with which Stack-2.15.7 is built.
|
@mouse07410, the official release of Stack 2.15.7 has a dependency on |
Ok, in that case why does "cabal-install"-v3.10.3.0 build succeeds when "stack" build fails? Does GHC-9.10.1 use boot package with cabal-3.12? |
Thanks everyone for helping to isolate the problem to Cabal-3.12. Next step would be bisect it, perhaps. |
@mouse07410, yes GHC 9.10.1 comes with Cabal-3.12.0.0. This is a handy source: https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/libraries/version-history. This is another: https://www.snoyman.com/base/. |
Good idea, but infeasible for me, as I can't build Cabal locally. :-( |
On isolating the code, my current assumption is that it is something to do with buildCSources =
buildExtraSources
"C Sources"
Internal.componentCcGhcOptions
( \c -> do
let cFiles = cSources (componentBuildInfo c)
case c of
CExe exe
| let mainPath = getSymbolicPath $ modulePath exe
, isC mainPath ->
cFiles ++ [makeSymbolicPath mainPath]
-- NB: Main.hs is relative to hs-source-dirs, but Main.c
-- is relative to the package.
_otherwise -> cFiles
) EDIT: That is, it seems (from the code comment above) to be a deliberate decision to change Cabal's design, but one that was undocumented. EDIT2: The previous corresponding code appears to me to be gbuildSources verbosity pkgId specVer tmpDir bm =
case bm of
GBuildExe exe -> exeSources exe
...
where
exeSources :: Executable -> IO BuildSources
exeSources exe@Executable{buildInfo = bnfo, modulePath = modPath} = do
main <- findFileEx verbosity (tmpDir : map getSymbolicPath (hsSourceDirs bnfo)) modPath
...
if isHaskell main || pkgId == fakePackageId
then
...
else let (csf, cxxsf)
| isCxx main = ( cSources bnfo, main : cxxSources bnfo)
-- if main is not a Haskell source
-- and main is not a C++ source
-- then we assume that it is a C source
| otherwise = (main : cSources bnfo, cxxSources bnfo)
in return BuildSources {
cSourcesFiles = csf,
cxxSourceFiles = cxxsf,
inputSourceFiles = [],
inputSourceModules = exeModules exe
} EDIT3: Some commits of interest:
|
If the design choice is as intended, the 'problem' is that the change in the Package Description Format Specification was not documented in the following places: |
Thanks for investigating @mpilgrem. |
I think this comment simply means that if |
I'm going to look into this. |
If |
Indeed. I've realised that I was being contradictory in saying we should fix this but asserting that C mains should not be found in hs-source-dirs, not realising that this is what the OP literally intended to do. The patch me and @sheaf have put together restores the existing behaviour of looking for non-haskell mains in |
In the 2decb0e refactor we stopped looking for non-Haskell `main-is` files in the hs-source-dirs and other appropriate directories. This commit fixes that oversight. Even if it is not intuitive that main-is-C-sources are searched in the hs-source-dirs, we don't wish to break users relying on this behaviour as there does not exist that strong of a motivation to do so. Fixes haskell#10168 Co-authored-by: sheaf <sam.derbyshire@gmail.com>
What the OP (and I ;) need is a way to specify a directory, other than the package root, for non-Haskell files - but it does not have to be exactly hs- source-dirs. If you replace |
Yes, indeed. But we also don't want to inadvertently break existing packages out there whose maintainers don't follow the latest in Cabal development ;), as this was previously the only way to set a source directory for a C main it seems. I think it would be a welcome feature if someone implemented, say, In the meantime, here's the fix which restores the existing behaviour, once again looking up C main files in hs-source-dirs: #10171 |
In the 2decb0e refactor we stopped looking for non-Haskell `main-is` files in the hs-source-dirs and other appropriate directories. This commit fixes that oversight. Even if it is not intuitive that main-is-C-sources are searched in the hs-source-dirs, we don't wish to break users relying on this behaviour as there does not exist that strong of a motivation to do so. Fixes haskell#10168 Co-authored-by: sheaf <sam.derbyshire@gmail.com>
In the 2decb0e refactor we stopped looking for non-Haskell `main-is` files in the hs-source-dirs and other appropriate directories. This commit fixes that oversight. Even if it is not intuitive that main-is-C-sources are searched in the hs-source-dirs, we don't wish to break users relying on this behaviour as there does not exist that strong of a motivation to do so. Fixes haskell#10168 Co-authored-by: sheaf <sam.derbyshire@gmail.com>
In the 2decb0e refactor we stopped looking for non-Haskell `main-is` files in the hs-source-dirs and other appropriate directories. This commit fixes that oversight. Even if it is not intuitive that main-is-C-sources are searched in the hs-source-dirs, we don't wish to break users relying on this behaviour as there does not exist that strong of a motivation to do so. Fixes haskell#10168 Co-authored-by: sheaf <sam.derbyshire@gmail.com>
In the 2decb0e refactor we stopped looking for non-Haskell `main-is` files in the hs-source-dirs and other appropriate directories. This commit fixes that oversight. Even if it is not intuitive that main-is-C-sources are searched in the hs-source-dirs, we don't wish to break users relying on this behaviour as there does not exist that strong of a motivation to do so. Fixes haskell#10168 Co-authored-by: sheaf <sam.derbyshire@gmail.com>
I first thought: "Umh, we broke something, we should fix it ASAP!" After reading more about it, I've started wondering: do we want to preserve this somewhat unintuitive behavior -- looking into One way to answer this is to first ask: what would you choose if designing Cabal from scratch today? My feeling is that I'd not want that behavior. Now, to the brakages. We probably don't want more brakages than necessary. But, first, we already caused breakage for people who relied on this behavior and are trying to update to cabal-install-3.12.1.0. And second, more importantly, do we understand how much of a breakage this causes? In no way do I want to block #10171, just wanted to make sure that we make an informed choice with some reasoning under it (unlike the initial change that happened by accident). |
The history is:
|
In the 2decb0e refactor we stopped looking for non-Haskell `main-is` files in the hs-source-dirs and other appropriate directories. This commit fixes that oversight. Even if it is not intuitive that main-is-C-sources are searched in the hs-source-dirs, we don't wish to break users relying on this behaviour as there does not exist that strong of a motivation to do so. Fixes haskell#10168 Co-authored-by: sheaf <sam.derbyshire@gmail.com>
In the 2decb0e refactor we stopped looking for non-Haskell `main-is` files in the hs-source-dirs and other appropriate directories. This commit fixes that oversight. Even if it is not intuitive that main-is-C-sources are searched in the hs-source-dirs, we don't wish to break users relying on this behaviour as there does not exist that strong of a motivation to do so. Fixes haskell#10168 Co-authored-by: sheaf <sam.derbyshire@gmail.com>
Thank you for the patch, @alt-romes and @geekosaur ! Would you have any idea when is it likely that we'd see a released version of Cabal with this patch/PR incorporated? |
I'm not involved in cabal release management, but I would suggest to wait a little longer in case there are more regressions coming up, before cutting a new point release. Otherwise you can always downgrade to 3.10.3.0. |
That was our conclusion in our dev meeting yesterday, yes. There's also the complication that this is the Cabal library, and many things will stick to the version that ships with ghc (whether it should is another question) even if we make a minor release. |
In the 2decb0e refactor we stopped looking for non-Haskell `main-is` files in the hs-source-dirs and other appropriate directories. This commit fixes that oversight. Even if it is not intuitive that main-is-C-sources are searched in the hs-source-dirs, we don't wish to break users relying on this behaviour as there does not exist that strong of a motivation to do so. Fixes haskell#10168 Co-authored-by: sheaf <sam.derbyshire@gmail.com>
In the 2decb0e refactor we stopped looking for non-Haskell `main-is` files in the hs-source-dirs and other appropriate directories. This commit fixes that oversight. Even if it is not intuitive that main-is-C-sources are searched in the hs-source-dirs, we don't wish to break users relying on this behaviour as there does not exist that strong of a motivation to do so. Fixes haskell#10168 Co-authored-by: sheaf <sam.derbyshire@gmail.com>
Describe the bug
After GHC 9.8.2/Cabal-3.10.2.0, and by GHC 9.10.1/Cabal-3.12.0.0, Cabal (the library) ignores
hs-source-dirs
ifmain-is
is a C source file. Previously, Cabal respectedhs-source-dirs
.To Reproduce
Imagine a small package. In directory
app
it hasMain.hs
with contents:In directory
src
it hasLib.hs
with contents:In directory
c-app
it hasmain.c
with contents:It has the usual
Setup.hs
:and it has a Cabal file:
With GHC 9.8.2/Cabal-3.10.2.0 all is fine (extracts only):
Note that Cabal has passed
"c-app\main.c"
to GHC 9.8.2 (the second from last argument).However, with GHC 9.10.1/Cabal-3.12.0.0, Cabal passes only
"main.c"
to GHC 9.10.1 and, consequently, fails to findmain.c
:(
stack --stack-yaml stack-ghc-9.10.1.yaml runghc --no-ghc-package-path --
etc runsrunghc
in the correct environment - that is, one that provides the relevant version of GHC and its Cabal boot package. The--no-ghc-package-path
is becauseGHC_PACKAGE_PATH
and Cabal are incompatible.)The text was updated successfully, but these errors were encountered: