v2-build does not pass ghc-options in `.cabal/config` to ghc when building custom Setup.hs
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:
- Put
ghc-options: -dynamicinprogram-default-optionssection in~/.cabal/config - Untar cabal-install source tarball
- In that directory, cabal v2-build -v
- Find the
/usr/bin/ghccommand-line for cabal-install'ssetup.hsdoes 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,ghcversions: 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.
Looks like ghc-options: dynamic in cabal.project is not honored either.
Isn't -dynamic a special case? Does the same happen with other flags like the -W ones?
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.
#5038 is an old pull request that implements ~~this~~ a related feature
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...
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...)
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.