cabal icon indicating copy to clipboard operation
cabal copied to clipboard

v2-build does not pass ghc-options in `.cabal/config` to ghc when building custom Setup.hs

Open demokritos opened this issue 5 years ago • 7 comments

Describe the bug

In case that cabal's new-build and new-install compile the package's custom Setup.hs, ghc-options in ~/.cabal/config is not passed to ghc.

To Reproduce Steps to reproduce the behavior:

  1. Put ghc-options: -dynamic in program-default-options section in ~/.cabal/config
  2. Untar cabal-install source tarball
  3. In that directory, cabal v2-build -v
  4. Find the /usr/bin/ghc command-line for cabal-install's setup.hs does not have -dynamic option
$ cabal v2-build -v
...
creating
/home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0
creating
/home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5
creating
/home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux
creating
/home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5
creating
/home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0
creating
/home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0/cache
creating
/home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0/setup
copy /home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/./Setup.hs to
/home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0/setup/setup.hs
/usr/bin/ghc --make -fbuilding-cabal-package -odir /home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0/setup -hidir /home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0/setup -i -i/home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/. -optP-include -optP/home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0/setup/setup_macros.h -hide-all-packages -no-user-package-db -package-db /home/esrevinu/.cabal/store/ghc-8.6.5/package.db -package-db /home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/packagedb/ghc-8.6.5 -package-id Cabal-3.0.0.0-46bddd9dcdb0614f6b3d4b9186e1471e15bdb76d345f3381c71918ee64d5fd9d -package-id base-4.12.0.0 -package-id filepath-1.4.2.1 -package-id process-1.6.5.0 /home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0/setup/setup.hs -o /home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0/setup/setup -threaded
[1 of 1] Compiling Main             ( /home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0/setup/setup.hs, /home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0/setup/Main.o )

/home/esrevinu/tmp/cabal-install/cabal-install-3.0.0.0/dist-newstyle/build/x86_64-linux/ghc-8.6.5/cabal-install-3.0.0.0/setup/setup.hs:1:1: error:
    Could not find module ‘Prelude’
    There are files missing in the ‘base-4.12.0.0’ package,
    try running 'ghc-pkg check'.
    Use -v to see a list of the files searched for.
  |
1 | import Distribution.PackageDescription ( PackageDescription )
  | ^

Expected behavior -dynamic option should be passed to ghc so that ghc can compile that setup.hs on Arch Linux without static library.

System information

  • Operating system: Arch Linux
  • cabal, ghc versions: cabal-install version 3.0.0.0 compiled using version 3.0.0.0 of the Cabal library, ghc 8.6.5; also cabal-install 2.4.0.0 and Cabal 2.4.0.1

Additional context

With cabal-install 3.0.0.0, --ghc-options=-dynamic command-line option passes the option to ghc. Building library package Cabal-3.0.0.0 does not fail. I think that it is because Cabal package is built Using self-exec internal setup method with build-type Simple and args.

demokritos avatar Jan 22 '20 20:01 demokritos

Looks like ghc-options: dynamic in cabal.project is not honored either.

openingnow avatar Feb 19 '21 10:02 openingnow

Isn't -dynamic a special case? Does the same happen with other flags like the -W ones?

fgaz avatar Feb 19 '21 11:02 fgaz

Tested with -Weverything flag and got same results. Non of flags in ~/.cabal/config, project-name.cabal, cabal.project worked with custom build type project. I'm using cabal-install 3.4.0.0 rc7 with GHC 8.10.4.

openingnow avatar Feb 19 '21 13:02 openingnow

#5038 is an old pull request that implements ~~this~~ a related feature

fgaz avatar Feb 19 '21 15:02 fgaz

I just tested program-default-options ghc-options: -dynamic did work in v1- commands. Also having a global option for this is way more useful than having one in the custom-setup stanza (for reasons stated in #5038).

So this is a bug and a regression, and it isn't related to /fixed by #5038. And it's blocking arch linux users...

fgaz avatar Feb 19 '21 15:02 fgaz

I just tried to repro this with cabal-install version 3.2.0.0 as well as with my custom build of the repo with latest commit. In both cases, I tried creating a new repo with cabal init and then just used cabal v2-build -v with them to introspect the command passed to ghc. I was able to find -dynamic just like in my config file.

Just to double check, I added a dummy flag -blabla into my config file, and got a compilation error from those.

Do other people still repro this issue ? Is it some kind of god fix ?

EDIT : ok after some tinkering with it, it's not actually fixed. When I try do install a package I don't have (for example cabal install yesod-bin, I get the prelude missing error...)

rivten avatar Aug 12 '21 21:08 rivten

A pity, In that case we are waiting for volunteers.

BTW, people reading this probably know that, but we encourage everybody to consider switching from using custom setups to alternative ways, inventing and implementing them, if needed. E.g., doctest no longer needs a custom setup.

Mikolaj avatar Aug 13 '21 16:08 Mikolaj