hfsevents icon indicating copy to clipboard operation
hfsevents copied to clipboard

"c_fsevents.o: No such file or directory" build error with GHC 9.8

Open simonmichael opened this issue 1 year ago • 6 comments

hfsevents builds for me with GHC 9.6 but not with 9.8. Would anyone have ideas on this error ?

$ stack build hfsevents --stack-yaml stack9.8.yaml

Warning: Stack has not been tested with GHC versions 9.8 and above, and using 9.8.1, this may fail.
hfsevents> configure
hfsevents> Configuring hfsevents-0.1.6...
hfsevents> build
hfsevents> Preprocessing library for hfsevents-0.1.6..
hfsevents> Building library for hfsevents-0.1.6..
hfsevents> [1 of 1] Compiling System.OSX.FSEvents
hfsevents> ar: .stack-work/dist/aarch64-osx/ghc-9.8.1/build/cbits/c_fsevents.o: No such file or directory

Error: [S-7282]
       Stack failed to execute the build plan.
       
       While executing the build plan, Stack encountered the error:
       
       [S-7011]
       While building package hfsevents-0.1.6 (scroll up to its section to see the error) using:
       /Users/simon/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_6HauvNHV_3.10.2.0_ghc-9.8.1 --verbose=1 --builddir=.stack-work/dist/aarch64-osx/ghc-9.8.1 build --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1 

simonmichael avatar Jan 04 '24 16:01 simonmichael

Which cabal version are you using? It doesn't appear to fail on my system (macOS 14.2.1):

cabal-install version 3.10.2.0
compiled using version 3.10.2.1 of the Cabal library 

luite avatar Jan 09 '24 08:01 luite

I'm using stack as mentioned. Unfortunately I wasn't smart enough to figure out how to force cabal-install to (re)install the package and verify that it worked.

simonmichael avatar Jan 09 '24 20:01 simonmichael

Maybe I can reproduce it with stack. What's the stack9.8.yaml file you're using?

luite avatar Jan 11 '24 12:01 luite

It was this:

resolver: nightly-2024-01-04

packages:
- hledger-lib
- hledger
# blocked by https://github.com/luite/hfsevents/issues/16
#- hledger-ui
- hledger-web

extra-deps:
- cassava-megaparsec-2.1.0
- email-validate-2.3.2.19
- yesod-1.6.2.1
- yesod-form-1.7.6

# work around https://github.com/stackbuilders/cassava-megaparsec/issues/39
allow-newer: true

nix:
  pure: false
  packages: [perl gmp ncurses zlib]

ghc-options:
  # silence 9.8's new partial warnings for now
  "$locals": -Wno-x-partial

simonmichael avatar Jan 11 '24 18:01 simonmichael

But I should give a better repro. Here it is with no stack.yaml:

$ cd; stack --resolver nightly-2024-01-04 build hfsevents

Warning: Stack has not been tested with GHC versions 9.8 and above, and using 9.8.1,
         this may fail.
cereal   > using precompiled package
hfsevents> configure
hfsevents> Configuring hfsevents-0.1.6...
hfsevents> build
hfsevents> Preprocessing library for hfsevents-0.1.6..
hfsevents> Building library for hfsevents-0.1.6..
hfsevents> [1 of 1] Compiling System.OSX.FSEvents
hfsevents> ar: .stack-work/dist/aarch64-osx/ghc-9.8.1/build/cbits/c_fsevents.o: No such file or directory
Completed 2 action(s).

Error: [S-7282]
       Stack failed to execute the build plan.
       
       While executing the build plan, Stack encountered the error:
       
       [S-7011]
       While building package hfsevents-0.1.6 (scroll up to its section to see the
       error) using:
       /Users/simon/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_6HauvNHV_3.10.2.0_ghc-9.8.1 --verbose=1 --builddir=.stack-work/dist/aarch64-osx/ghc-9.8.1 build --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1 

simonmichael avatar Jan 11 '24 18:01 simonmichael

Thanks I can reproduce it now. It looks like cabal is ignoring the cbits/c_fsevents.m file when building under stack. If I rename it to .c it works again.

But long ago I actually renamed this file from c_fsevents.c to c_fsevents.m because it's using objective C features, which would work incorrectly with a .c file. I'll have to do a bit more digging to see what's going on.

luite avatar Jan 11 '24 20:01 luite

Hi @luite, did you have a chance to look at this again ?

simonmichael avatar Feb 16 '24 19:02 simonmichael

I had a look at this with stack --verbose build --cabal-verbose and Stack 2.15.1. As far as I can see, with lts-22.11 (GHC 9.6.4, Cabal 3.10.1.0) Stack is sending essentially the same configure and build commands to Cabal (the library) as with nightly-2022-02-17 (GHC 9.8.1, Cabal 3.10.2.0). For some reason, Cabal 3.10.2.0 is skipping the "Building C Sources ..." step that is performed by Cabal 3.10.1.0.

mpilgrem avatar Feb 17 '24 13:02 mpilgrem

It may be something to do with this: https://github.com/haskell/cabal/blob/master/release-notes/Cabal-3.10.2.1.md from the change log for Cabal 3.10.2.1.

mpilgrem avatar Feb 17 '24 13:02 mpilgrem

Ah perhaps adding a .c file will give us more information about why it's ignoring the .m

luite avatar Feb 17 '24 23:02 luite

With cabal-install I get the warning

Warning: The following files listed in the main library's c-sources do not
have the expected '.c' extension cbits/c_fsevents.m.
C++ files should be in the 'cxx-sources' stanza.

With stack it still fails

luite avatar Feb 18 '24 01:02 luite

Still broken with stack 2.15.1, and also broken if I rebuild stack 2.15.1 from source bumping the Cabal library dependency to 3.10.2.1

luite avatar Feb 18 '24 01:02 luite

Stack uses the version of Cabal (the library) that is provided with the specified version of GHC. If the version of Cabal (3.10.2.0) that comes with GHC 9.8.1 is broken in this respect, I am not aware of any work-around for any version of Stack other than to specify a version of GHC that comes with a version of Cabal that does not have this feature/bug. EDIT: The version of Cabal that stack uses as a dependency (for types etc) is distinct from the version of Cabal that Stack uses to build.

EDIT2: In this instance, you could edit the package's Cabal file. Assuming you are building hfsevents-0.1.6:

  • specify cabal-version: 2.2
  • specify default-language: Haskell98 in the library stanza
  • specify cxx-sources: cbits/c_fsevents.m, rather than C-sources
  • then, command stack --snapshot nightly init --force to create the GHC 9.8.1 stack.yaml (assuming Stack 2.15.1, --resolver nightly if using an older version of Stack)

mpilgrem avatar Feb 18 '24 08:02 mpilgrem

Just saw @mpilgrem's edit. I confirm that updating hfsevents.cabal this way makes it build cleanly with stack/ghc-9.8/Cabal-3.2.1.0. @luite, perhaps you could accept PR #17 and make a new release on hackage ?

simonmichael avatar Feb 19 '24 02:02 simonmichael

Thank you! hfsevents-0.1.7 is working for me.

simonmichael avatar Feb 19 '24 18:02 simonmichael