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

cabal-install-3.10 fails with header files in 'c-sources' #9190

Closed
hasufell opened this issue Aug 21, 2023 · 48 comments
Closed

cabal-install-3.10 fails with header files in 'c-sources' #9190

hasufell opened this issue Aug 21, 2023 · 48 comments

Comments

@hasufell
Copy link
Member

hasufell commented Aug 21, 2023

Reproduce:

  • git clone -b refactor/vty-crossplatform https://github.com/hasufell/brick.git
  • cd brick
  • ghcup run --cabal 3.10 -- cabal build
  • ghcup run --cabal 3.6 -- cabal build

Originally spotted here: jtdaugherty/vty#260 (comment)

Fixed here by changing the cabal file: jtdaugherty/vty-unix#1

This is a regression.

@angerman
Copy link
Collaborator

I guess it's a change in behavior, but if the underlying cause is really that .h files were listed in c-sources, then if argue, cabal is actually doing the right thing now and was doing the wrong thing before. Putting .h into c-sources seems more like a user error to me.

@angerman
Copy link
Collaborator

Ideally this should be a warning in cabal though, that for now it filtered out .h files from c-sources (did it really?) and that this behavior will cease in a future version; authors are strongly encouraged not to list headers in c-sources; with a reference to a cabal issue to where affected parties can look up the details.

@hasufell
Copy link
Member Author

Yes, it can be considered a bug. But the problem is that cabal will stop accepting cabal files that it previously accepted with no transition period whatsoever. It is a breaking change.

@mouse07410
Copy link
Collaborator

I guess it's a change in behavior, but if the underlying cause is really that .h files were listed in c-sources, then if argue, cabal is actually doing the right thing now and was doing the wrong thing before. Putting .h into c-sources seems more like a user error to me.

I'm afraid you're conflating languages like Haskell they have no concept of separate "code" and "header" files, and C where both .c and .h are very natural - and often (though not always, I concede) reside in the same directory.

The new behavior is an unwelcome undesirable unproductive breaking change.

@jtdaugherty
Copy link
Contributor

Also, for what it's worth, as a user I personally think "C sources" is a reasonable catch-all term to include header files, so I find it confusing that headers would not be valid to include in a "C sources" list just from a terminology standpoint. If I have files foo.c and foo.h in my package, I don't think of the header as some "other" kind of file that needs to be dealt with. If "C sources" literally means "files with a .c extension" then I think it is confusingly named.

@andreabedini
Copy link
Collaborator

andreabedini commented Aug 22, 2023

It looks like cabal-install-3.8 has the same behaviour of 3.6 so this is indeed a change in 3.10. It's also present in cabal-head.

@angerman
Copy link
Collaborator

angerman commented Aug 22, 2023

I still consider this a bug. One that should not have been a breaking change, but come with a proper deprecation cycle (again, including a ticket where this change of behaviour could be debated, and maybe even lead to the acceptance of the old behaviour).

So why do I think this is a bug? C has source files (.c) and header files (.h) these serve distinctly different purposes. Where they reside on the file system is not that important, In the end you'll either import headers relative to the .c file in which you #include them, or relative to some -I (include) prefix usually using angle brackets (<>). The distinction between header (or if you will interface files) and source files is quite pronounced in C. Your C compiler will not compile header files to object files. It will compile c source files to object files, and then feed those to the linker. So I am then confused why I would list header files under c source files? Am I supposed to list c-- files under c-sources as well? Are assembly (.S) file c-source files?

The cabal documentation, also only lists .c file sunder c-sources, and for the others there is includes: install-includes:.

I'll remain that the old behaviour is a bug. The breaking change is a defect, as it abruptly breaks the behaviour, and should be rectified to a warning. Ultimately I consider listing header files under *-sources: to be wrong. Especially as the package description has explicit support (and separation) for header files. Being more descriptive is almost always better than being less descriptive and relying on heuristics.

@mouse07410
Copy link
Collaborator

I'll remain that the old behaviour is a bug.

For you, maybe - but not for the majority of the users. So, I insist that it isn't.

You say that .c and .h must be treated differently. I say that view is wrong, at least in this context where Cabal is supposed to treat them all as a "blob" to pass along for processing.

Not to mention that .h files sometimes do contain actual code rather than just definitions, and they can be compiled - though majority do not split their code that way.

Everybody, please consider; what's the purpose and the (main) use case for c-sources:?

@hasufell
Copy link
Member Author

Not to mention that .h files sometimes do contain actual code rather than just definitions, and they can be compiled - though majority do not split their code that way.

Correct. The standard is somewhat vague on this but also indicates that headers can sometimes be source files. But not always.

So c-sources isn't a particularly good naming scheme if only things shall be included that are to be turned into object files directly.

@andreabedini
Copy link
Collaborator

My uneducated guess would be that c-sources are c source files to compile before linking them to the haskell code.

From what I managed to understand today, cabal does indeed call ghc to compile each file in c-sources.

@mouse07410
Copy link
Collaborator

cabal does indeed call ghc to compile each file in c-sources.

I used to think that cabal invokes C compiler directly for files in c-sources?

@andreabedini
Copy link
Collaborator

These seem to be the relevant lines

buildExtraSources Internal.componentCcGhcOptions True (cSources libBi)

I cannot do that now but this can be easily checked with cabal -v.

@Kleidukos
Copy link
Member

Ok, how do we proceed? Is this just a matter of emitting a warning if a header file is found and not forwarding it to the underlying C compilation process?

@Kleidukos
Copy link
Member

@jtdaugherty I'm trying to compile vty-unix with GHC 9.2.8 and cabal 3.10.1.0 on commit ad31125f but I'm getting an error:

src/Graphics/Vty/Platform/Unix/Output/Color.hs:8:5: error:
    Ambiguous occurrence ‘detectColorMode’
    It could refer to
       either ‘Graphics.Vty.Attributes.Color.detectColorMode’,
              imported from ‘Graphics.Vty.Attributes.Color’ at src/Graphics/Vty/Platform/Unix/Output/Color.hs:18:1-36
           or ‘Graphics.Vty.Platform.Unix.Output.Color.detectColorMode’,
              defined at src/Graphics/Vty/Platform/Unix/Output/Color.hs:21:1
  |
8 |   ( detectColorMode
  |     ^^^^^^^^^^^^^^^

Is this normal? Is there a commit that compiles that I can try the patch on?

Kleidukos added a commit to Kleidukos/cabal that referenced this issue Aug 23, 2023
Kleidukos added a commit to Kleidukos/cabal that referenced this issue Aug 23, 2023
@Mikolaj
Copy link
Member

Mikolaj commented Aug 23, 2023

I'm confused. There's so many aspects to that.

Does cabal fail currently, because it tries to feed a .h file to the compiler and the compiler rejects it or because cabal sees a .h files and aborts?

Is the intention of the user that each listed file should be fed to the compiler, e.g., even a .h file, because it contains actual code? Is that the most reasonable semantics of the field?

Does C-sources: field accept directories? I guess not?

What was cabal doing previously? Just filtering out the .h files?

What about .cxx files?

@angerman
Copy link
Collaborator

I think the first step is to figure out where exactly this broke. There must be a commit to point at, and say this commit changed the previous behavior.

And then go from there.

@Kleidukos
Copy link
Member

This is a release blocker for 3.10.2.0, and unless someone's figuring out the origin in the next couple of days, we'll have to go with the patch at #9200.

@andreabedini
Copy link
Collaborator

The only recent change to that logic seems to be #9061. I am going to read that again.

@andreabedini
Copy link
Collaborator

andreabedini commented Aug 24, 2023

@Kleidukos AFAICT vty-unix master depends on a pre-release version of vty. I can reproduce with similar instructions to what Julian has posted

git clone -b refactor/vty-crossplatform https://github.com/hasufell/brick.git
cd brick
ghcup run --ghc 9.2.8 --cabal 3.10.1.0 -- cabal build vty-unix

EDIT NOTE: vty-unix gets style: global so it will be cached in the store. The cache key will not change so if you get to build it once you will need to remove it from the store.

@Kleidukos
Copy link
Member

@andreabedini Thanks, I ended up stripping the cabal file from most of its content to get faster build times :P

@andreabedini
Copy link
Collaborator

The plot thickens. With a minimal example, I cannot reproduce it:

❯ cat cabal-issue9190.cabal
cabal-version:   3.0
name:            cabal-issue9190
version:         0.1.0.0
build-type:      Simple

executable cabal-issue9190
    main-is:          Main.hs
    build-depends:    base
    c-sources:        cbits/file.c
                      cbits/file.h
    hs-source-dirs:   app
    default-language: Haskell2010
❯ ls -l cbits/
total 4
-rw-r--r-- 1 andrea andrea 1 Aug 24 15:57 file.c
-rw-r--r-- 1 andrea andrea 0 Aug 24 15:57 file.h
❯ ghcup run --ghc 9.2.8 --cabal 3.10.1.0 -- sh -c "cabal clean && cabal build -v"
Project settings changed, reconfiguring...
Running: /home/andrea/.ghcup/tmp/ghcup-ghc-9.2.8_cabal-3.10.1.0/ghc --make -no-link -fbuilding-cabal-package -O -static -outputdir /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -odir /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -hidir /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -stubdir /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -i -i/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -iapp -i/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/autogen -i/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/global-autogen -I/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/autogen -I/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/global-autogen -I/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -optP-include -optP/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/autogen/cabal_macros.h -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /home/andrea/.local/state/cabal/store/ghc-9.2.8/package.db -package-db /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/packagedb/ghc-9.2.8 -package-db /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/package.conf.inplace -package-id base-4.16.4.0 -XHaskell2010 app/Main.hs -Wall -hide-all-packages
[1 of 1] Compiling Main             ( app/Main.hs, /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp/Main.o )
Building C Sources...
creating
/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp
Running: /home/andrea/.ghcup/tmp/ghcup-ghc-9.2.8_cabal-3.10.1.0/ghc -c -fPIC -odir /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -I/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/autogen -I/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/global-autogen -I/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -optc-O2 -pgmc /usr/bin/gcc -hide-all-packages -no-user-package-db -package-db /home/andrea/.local/state/cabal/store/ghc-9.2.8/package.db -package-db /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/packagedb/ghc-9.2.8 -package-db /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/package.conf.inplace -package-id base-4.16.4.0 cbits/file.c -Wall -hide-all-packages
creating
/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp
Linking...
Running: /home/andrea/.ghcup/tmp/ghcup-ghc-9.2.8_cabal-3.10.1.0/ghc --make -fbuilding-cabal-package -O -static -outputdir /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -odir /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -hidir /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -stubdir /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -i -i/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -iapp -i/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/autogen -i/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/global-autogen -I/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/autogen -I/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/global-autogen -I/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp -optP-include -optP/home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/autogen/cabal_macros.h -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /home/andrea/.local/state/cabal/store/ghc-9.2.8/package.db -package-db /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/packagedb/ghc-9.2.8 -package-db /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/package.conf.inplace -package-id base-4.16.4.0 -XHaskell2010 app/Main.hs /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190-tmp/cbits/file.o -o /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190 -Wall -hide-all-packages
Linking /home/andrea/Scratchpad/cabal-issue-9190/dist-newstyle/build/x86_64-linux/ghc-9.2.8/cabal-issue9190-0.1.0.0/x/cabal-issue9190/build/cabal-issue9190/cabal-issue9190 ...

only cbits/file.c is compiled in the Buiding C Sources... step ... back to the original reproducible example.

@Kleidukos
Copy link
Member

Kleidukos commented Aug 24, 2023

ok let me push a reproducible repo: https://github.com/Kleidukos/cabal-9190-repro

@andreabedini
Copy link
Collaborator

@Kleidukos try swapping cbits/gwinsz.h and cbits/gwinsz.c in your repo.

@andreabedini
Copy link
Collaborator

The first bad commit seems to be 6cf9e13 from #8499.

commit 6cf9e1392ad46e8cd302c23ca6565e023fdc685d
Author: gbaz <gershomb@gmail.com>
Date:   Sun Oct 23 20:34:09 2022 -0400

    ordNub for extra stanzas (#8499)

    * ordNub for extra stanzas

    * changelong

    * Update pr-8499

    Co-authored-by: Gershom Bazerman <gershom@arista.com>
    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

 Cabal/src/Distribution/Simple/Build.hs | 29 ++++++-----------------------
 changelog.d/pr-8499                    |  7 +++++++
 2 files changed, 13 insertions(+), 23 deletions(-)
 create mode 100644 changelog.d/pr-8499

Ping @gbaz

@gbaz
Copy link
Collaborator

gbaz commented Aug 24, 2023

Thanks @andreabedini for the sleuthing. In my mind I think this confirms that there's no bug. The files were never supposed to be there, and through a combination of accidents things sometimes worked.

Prior to that PR, files were nubbed by name (not including extension) alphabetically. Subsequent to that PR, files are nubbed by name (not including extension) in an order preserving manner.

So when you have two files with the same name -- say a c and a header file, before the c always came alphabetically first. Now, it depends on the ordering.

But the nubbing is not a "feature" that filters .h files. Its just an accidental artifact that caused .h files to be dropped only when they had a precisely corresponding c file.

So if you had a header file with no c file "masking" it, this would always have been a problem. Putting h files in the c sources field was never supported, never in spec, and only sometimes, accidentally worked.

The only "real" fix in my mind would be to make cabal nub by filename and extension both -- at which point we would uniformly instead of occasionally fail.

(and just to underline: the documentation never said putting header files in c sources was acceptable or correct -- the packages doing this always went against the documentation)

Kleidukos added a commit that referenced this issue Aug 24, 2023
Co-authored-by: Andrea Bedini <andrea.bedini@tweag.io>
fixes #9190
@Kleidukos
Copy link
Member

Incredible set of circumstances, thank you @gbaz for the explanation

@andreabedini
Copy link
Collaborator

andreabedini commented Aug 24, 2023

Thanks @gbaz

files were nubbed by name (not including extension)

I am curious about this, why would we not include the extension?

@gbaz
Copy link
Collaborator

gbaz commented Aug 24, 2023

Oh you're right, its more complicated in fact!

The nubbing wasn't at issue, since its by filepath, which does take into account extension. Its really just the reordering, not the nubbing, that induced this issue. So it must be something with the order of the files passed to the c compiler mattering, but now I'm not sure how...

@andreabedini
Copy link
Collaborator

Leaving some notes here for the future. My minimal reproducible example is:

cabal-version:   3.4
name:            cabal-issue9190
version:         0.1.0.0
build-type:      Simple

library
    -- Lib.hs contains the following single line
    --   module Lib where
    exposed-modules:  Lib
    build-depends:    base
    -- file.h and file.c are empty files
    c-sources:        file.h, file.c

Last night I ran git bisect recompiling cabal-install everytime and it took ages. I realise now I could have been smarter: this is purely a Cabal problem, so we can find a way to use only Cabal.

Use this script (e.g. reproduce-cabal-issue9190.hs)

import Distribution.Simple (defaultMainArgs)
import System.Directory (withCurrentDirectory)

main :: IO ()
main = do
  -- Path to the cabal file above
  withCurrentDirectory "/home/andrea/Scratchpad/cabal-issue9190" $ do
    defaultMainArgs ["clean"]
    defaultMainArgs ["configure"]
    defaultMainArgs ["build", "-v"]

and call it like:

$ cabal build Cabal && cabal exec -- runhaskell reproduce-cabal-issue9190.hs
Up to date
cleaning...
Configuring cabal-issue9190-0.1.0.0...
Loaded package environment from /home/andrea/code/cabal/dist-newstyle/tmp/environment.-7728/.ghc.environment.x86_64-linux-9.4.6
Component build order: library
Running: /home/andrea/.ghcup/ghc/9.4.6/bin/ghc-pkg-9.4.6 init dist/package.conf.inplace
creating dist/build
creating dist/build/autogen
creating dist/build/autogen
creating dist/build/autogen
Preprocessing library for cabal-issue9190-0.1.0.0...
Building library for cabal-issue9190-0.1.0.0...
creating dist/build
Running: /home/andrea/.ghcup/bin/ghc --make -fbuilding-cabal-package -O -static -dynamic-too -dynosuf dyn_o -dynhisuf dyn_hi -outputdir dist/build -odir dist/build -hidir dist/build -hiedir dist/build/extra-compilation-artifacts -stubdir dist/build -i -i. -idist/build -idist/build/autogen -idist/build/global-autogen -Idist/build/autogen -Idist/build/global-autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -this-unit-id cabal-issue9190-0.1.0.0-26abAqpd6Nv9lm8FrHmnhr -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db dist/package.conf.inplace -package-id base-4.17.2.0 -XHaskell98 Lib
Loaded package environment from /home/andrea/code/cabal/dist-newstyle/tmp/environment.-7728/.ghc.environment.x86_64-linux-9.4.6
[1 of 1] Compiling Lib              ( Lib.hs, dist/build/Lib.o, dist/build/Lib.dyn_o )
Building C Sources...
creating dist/build
Running: /home/andrea/.ghcup/bin/ghc -c -fPIC -odir dist/build -Idist/build/autogen -Idist/build/global-autogen -Idist/build -optc-O2 -pgmc /usr/bin/gcc -hide-all-packages -no-user-package-db -package-db dist/package.conf.inplace -package-id base-4.17.2.0 file.h
Loaded package environment from /home/andrea/code/cabal/dist-newstyle/tmp/environment.-7728/.ghc.environment.x86_64-linux-9.4.6
Warning: the following files would be used as linker inputs, but linking is not being done: file.h
ghc-9.4.6: no input files
Usage: For basic information, try the `--help' option.

This only recompiles Cabal so it is much faster.

If you want to pin down ghc and cabal-install versions you can use ghcup run --ghc 9.4.6 --cabal 3.10.1.0 -- ... as Julian suggest above.

@Mikolaj
Copy link
Member

Mikolaj commented Sep 15, 2023

[Edit: nothing to see here, please move along.]

@gbaz
Copy link
Collaborator

gbaz commented Sep 15, 2023

why is this issue still open? i thought it was fixed by #9200 ...

@Mikolaj
Copy link
Member

Mikolaj commented Sep 15, 2023

Oh, hah, and I was the only person to review the PR.

Let me remove the incriminating comment, in that case, and close this issue. :)

The PR is mentioned in this issue, just a bit far from here, so I hope everybody interested had a look. If not, please feel free to comment now and open a new issue, if needed (or re-open, or ask me to re-open).

@Mikolaj
Copy link
Member

Mikolaj commented Oct 4, 2023

@ulysses4ever just noticed that the PRs quick-fixing this issue are not on master. So perhaps I closed this issue prematurely, after all.

However, nobody objected nor asked me to re-open since 3 weeks ago, so perhaps the quick-fix is an acceptable solution, after all? If so, let's forwardport from branch 3.10 to branch master the #9200 fix and it's companion #9285 and be done with it. Thoughts? Objections?

Dretch added a commit to Dretch/monomer-flatpak-example that referenced this issue Oct 8, 2023
@vaibhavsagar
Copy link
Collaborator

I'm trying to build ghc-lib-parser-9.8.1.20231009 with 3.10.2.0 and it's failing with the following error:

Warning: The following files listed in the main library's c-sources will not
be used: libraries/ghc-heap/cbits/HeapPrim.cmm.
Header files should be in the 'include' or 'install-include' stanza.
See https://cabal.readthedocs.io/en/3.10/cabal-package.html#pkg-field-includes
/nix/store/p58l5qmzifl20qmjs3xfpl01f0mqlza2-binutils-2.40/bin/ar: dist/build/libraries/ghc-heap/cbits/HeapPrim.o: No such file or directory

Am I right that this is the same issue?

@Kleidukos
Copy link
Member

@vaibhavsagar yes indeed, would you mind trying with 3.10.2.1 (which has just been published)?

@cho-m
Copy link

cho-m commented Nov 20, 2023

We hit the same issue building ghc-lib-parser-9.8.1.20231009/ghc-lib-parser-9.6.2.20230523 in Homebrew with 3.10.2.1.

  Warning: The following files listed in the main library's c-sources will not
  be used: libraries/ghc-heap/cbits/HeapPrim.cmm.
  Header files should be in the 'include' or 'install-include' stanza.
  See https://cabal.readthedocs.io/en/3.10/cabal-package.html#pkg-field-includes
  ar: dist/build/libraries/ghc-heap/cbits/HeapPrim.o: No such file or directory
  Error: cabal: Failed to build ghc-lib-parser-9.8.1.20231009

And regression when building ghcup which failed on streamly-0.8.3:

  Warning: The following files listed in the main library's c-sources will not
  be used: src/Streamly/Internal/FileSystem/Event/Darwin.m.
  Header files should be in the 'include' or 'install-include' stanza.
  See https://cabal.readthedocs.io/en/3.10/cabal-package.html#pkg-field-includes
  ar: dist/build/src/Streamly/Internal/FileSystem/Event/Darwin.o: No such file or directory
  Error: cabal: Failed to build streamly-0.8.3 (which is required by exe:ghcup
  from ghcup-0.1.20.0). See the build log above for details.

@Kleidukos
Copy link
Member

digital-asset/ghc-lib#495

@hasufell
Copy link
Member Author

ar: dist/build/src/Streamly/Internal/FileSystem/Event/Darwin.o: No such file or directory

This looks suspiciously similar to #9334

@Kleidukos
Copy link
Member

@hasufell no, it's because the linker can't deal with non-C sources that are in the c-sources stanza

@cho-m
Copy link

cho-m commented Nov 21, 2023

Is there supposed to be an option for Obj-C sources (.m)? https://github.com/composewell/streamly/blob/master/streamly.cabal#L459

@Mokosha
Copy link

Mokosha commented Jan 6, 2024

Hi -- bindings-GLFW also depends on Obj-C sources in the c-sources section of the cabal file:

https://github.com/bsl/bindings-GLFW/blob/21b1250459d460ed22c5ecb2969374a4f45ec519/bindings-GLFW.cabal#L182

It is currently broken with the nightly stackage snapshots. Please either allow .m files, or recommend a fix for how to manage this new behavior. Thank you.

@gbaz
Copy link
Collaborator

gbaz commented Jan 6, 2024

I believe this should be fixed by #9285 which changed the filtering logic from only keeping .c files to only excluding .h files.

This change made it into 3.10.2.1 : https://github.com/haskell/cabal/blob/master/release-notes/Cabal-3.10.2.1.md

@hasufell
Copy link
Member Author

hasufell commented Jan 6, 2024

@juhp

@cho-m
Copy link

cho-m commented Jan 6, 2024

I believe this should be fixed by #9285 which changed the filtering logic from only keeping .c files to only excluding .h files.

This change made it into 3.10.2.1 : https://github.com/haskell/cabal/blob/master/release-notes/Cabal-3.10.2.1.md

3.10.2.1 still thinks .m files are headers.

That's the version I've been trying out in Homebrew/homebrew-core#154836 and ended up having to do a dance of using 3.10.2.1 to install 3.10.1.0 in order to build ghcup.

@gbaz
Copy link
Collaborator

gbaz commented Jan 6, 2024

The linked PR should clearly fix the behavior you describe, so this confuses me. Note that it is a PR to Cabal the library, not cabal-install the executable. Is it possible you are using a version 3.10.2.1 of cabal-install, but linked against a prior version of the Cabal library?

@cho-m
Copy link

cho-m commented Jan 6, 2024

Is it possible you are using a version 3.10.2.1 of cabal-install, but linked against a prior version of the Cabal library?

Retrying locally, it may due to bundled Cabal 3.10.2.0 in GHC 9.8. Increasing verbosity, I see:

[_86] trying: Cabal-syntax-3.10.2.0/installed-inplace (dependency of cabal-install)
[_87] trying: Cabal-3.10.2.0/installed-inplace (dependency of cabal-install)

What would be the best way to avoid this? A manual --constraint? Or would rebuilding GHC help?

@juhp
Copy link
Collaborator

juhp commented Jan 7, 2024

What would be the best way to avoid this? A manual --constraint? Or would rebuilding GHC help?

You could just bump the Cabal lowerbound in cabal-install.cabal, or use --constraint sure.

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

No branches or pull requests