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

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

Open
KristianBalaj opened this issue Feb 27, 2024 · 2 comments

Comments

@KristianBalaj
Copy link

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

@gbaz
Copy link
Collaborator

gbaz commented Feb 27, 2024

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"

@KristianBalaj
Copy link
Author

KristianBalaj commented Feb 27, 2024

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 🙌

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

2 participants