Skip to content

No recompilation when using addDependentFile or -fforce-recomp in a build dependent package (stanza)  #9745

Closed

Description

@KristianBalaj

Describe the bug

Importing a library that is in the package's build-depends doesn't recompile when it should.
The following are the cases when recompilation should happen in a dependent package but it doesn't happen:

  • when using addDependentFile and the file changes
  • when explicitly marking some file using {-# OPTIONS_GHC -fforce-recomp #-}

The only workaround I have is either to do cabal clean and then compile again from scratch....
Or modify one of the library source files.

To Reproduce

Steps to reproduce the behavior:

Create a new cabal project with 2 stanzas

  1. library my-lib
  2. test-suite my-tests

Like the following:

...
test-suite my-tests
  import:         lang
  type:           exitcode-stdio-1.0
  main-is:        Spec.hs
  hs-source-dirs: my-tests
  build-depends:
    , my-lib

library my-lib
  import: lang
  hs-source-dirs:   my-lib
  exposed-modules:
    Foo.hs

The contents of the Foo.hs are the following:

{-# OPTIONS_GHC -fforce-recomp #-}

module Foo where
....

And the contents of the Spec.hs are the following:

module Spec where

import Foo
...

Now when I run cabal test my-tests for the first time everything necessary normally compiles along with the Foo.hs.
And now when I run cabal test my-tests the second time, I expect the Foo.hs to compile again, but it doesn't compile again even though it uses the -fforce-recomp option.

The similar example would be using the addDependentFile and the dependent file changes, it doesn't compile either.

Expected behavior

When there's {-# OPTIONS_GHC -fforce-recomp #-} used in any of the dependent library source files, it should compile again every single time.
Also, when there's addDependentFile used in the dependent library, it should also recompile when the dependent file changes.

System information

OS:
x86-darwin
Cabal and GHC:
cabal-install version 3.6.2.0
The Glorious Glasgow Haskell Compilation System, version 8.10.7

Additional context

I believe this is a related issue - #4746

Activity

  1. gbaz commented on Feb 27, 2024

    @gbaz
    Collaborator

    As discussed in the related issues, you can use extra-source-files, and this is the recommended way. Have you tried doing so, and are there any problems in doing so?

    This also has the advantage that the file in extra-source-files is actually packaged up by sdist properly, which a file added by addDependentFile cannot be.

    Further, I think this is the correct semantics for -fforce-recomp. The flag is intended to say "if you are recompiling the package, then you should recompile the so-flagged files" not "always recompile this package"

  2. KristianBalaj commented on Feb 27, 2024

    @KristianBalaj
    Author

    Further, I think this is the correct semantics for -fforce-recomp. The flag is intended to say "if you are recompiling the package, then you should recompile the so-flagged files" not "always recompile this package"

    I see, I'm okay with that then.

    As discussed in the related issues, you can use extra-source-files, and this is the recommended way. Have you tried doing so, and are there any problems in doing so?

    I haven't yet, but in my use case the dependent file path is based on env variable, so I'm curious whether I can use env variable in the cabal file for the extra-source-files?

    EDIT: Also thanks for a quick response 🙌

  3. andreasabel commented on Feb 23, 2025

    @andreasabel
    Member

    I haven't yet, but in my use case the dependent file path is based on env variable, so I'm curious whether I can use env variable in the cabal file for the extra-source-files?

    I suppose the answer here is "no", but you could have a generation step for the .cabal file that expands the environment variable.

    I am closing this issue now, but feel free to reopen with new information.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions