haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.6k stars 689 forks source link

Using Setup.hs build --with-ghc looses configure --ghc-option #10069

Open wolfgangwalther opened 2 months ago

wolfgangwalther commented 2 months ago

Describe the bug

When using Setup.hs's configure + build steps a GHC option passed in the configure is not applied in the build step, when the build step uses the --with-ghc option.

To Reproduce

Using the hello world package from hackage.

$ runhaskell Setup.hs configure --ghc-options=-j2
$ runhaskell Setup.hs build -v --with-ghc=ghc
[...]
Running: [...]/ghc --make -no-link -fbuilding-cabal-package -O -static -outputdir dist/build/hello/hello-tmp
-odir dist/build/hello/hello-tmp -hidir dist/build/hello/hello-tmp -hiedir dist/build/hello/hello-tmp/extra-compilation-artifacts/hie
-stubdir dist/build/hello/hello-tmp -i -isrc -idist/build/hello/hello-tmp -idist/build/hello/autogen -idist/build/global-autogen
-Idist/build/hello/autogen -Idist/build/global-autogen -Idist/build/hello/hello-tmp -optP-include
-optPdist/build/hello/autogen/cabal_macros.h -this-unit-id hello-1.0.0.2-9svDvC3HZPN7tI0quUyWXf-hello
-hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db dist/package.conf.inplace
-package-id base-4.20.0.0-18ae -XHaskell98 src/hello.hs
[...]

The -j2 is not passed.

Expected behavior

-j2 should be passed to ghc. The same output when running build without --with-ghc:

Running: [...]/ghc --make -no-link -fbuilding-cabal-package -O -static -outputdir dist/build/hello/hello-tmp
-odir dist/build/hello/hello-tmp -hidir dist/build/hello/hello-tmp -hiedir dist/build/hello/hello-tmp/extra-compilation-artifacts/hie
-stubdir dist/build/hello/hello-tmp -i -isrc -idist/build/hello/hello-tmp -idist/build/hello/autogen -idist/build/global-autogen
-Idist/build/hello/autogen -Idist/build/global-autogen -Idist/build/hello/hello-tmp -optP-include
-optPdist/build/hello/autogen/cabal_macros.h -this-unit-id hello-1.0.0.2-9svDvC3HZPN7tI0quUyWXf-hello
-hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db dist/package.conf.inplace
-package-id base-4.20.0.0-18ae -XHaskell98 src/hello.hs -j2

Note the additional -j2 at the end.

System information

Tested with various cabal and GHC versions. Still present in cabal 3.10.3.0, but was also there in 3.8.x.

Additional context

First noticed in nixpkgs when cross-compiling.

Workaround: Remove --with-ghc from build step - it's added in configure anyway.

sternenseemann commented 2 months ago

The documentation lists --with-PROG= as an option specific to Setup.hs configure, so maybe Setup.hs build should just reject it?