haskell / cabal

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

Alert the user that on Windows, with configuration `executable-dynamic: True` executables (including build-tools) cannot be built #9807

Closed andreasabel closed 1 month ago

andreasabel commented 5 months ago

This issue is singled out from:

Adding executable-dynamic: True to the cabal configuration on Windows will fail executables to build. This include situations where you just want to build a library, but it has build-tool-depends: alex or similar causing the linking of build-tool alex to fail.

Reproduced on a fresh Haskell installation: https://github.com/agda/agda/actions/runs/8213506540/job/22465003537#step:10:233

Building executable 'alex' for alex-3.5.1.0..
[ 1 of 19] Compiling DFS              ( src\DFS.hs, dist\build\alex\alex-tmp\DFS.dyn_o )

src\DFS.hs:24:8: error: [GHC-88719]
Error:     Could not load module ‘Prelude’.
    Perhaps you haven't installed the "dyn" libraries for package ‘base-4.19.1.0’?
jasagredo commented 1 month ago

Dynamic linking in Windows is simply not supported by GHC. This is not a Cabal bug unless you wanted to imply that executable-dynamic: True should crash before even attempting compilation on Windows.

I'm closing this issue, please re-open of you disagree

andreasabel commented 1 month ago

I do disagree.

This is not a Cabal bug unless you wanted to imply that executable-dynamic: True should crash before even attempting compilation on Windows.

I do think it should exit with an error explaining the problem.

Aren't we Haskell programmers? Aren't we proposing strong typing? GHC does not compile ill-typed programs. Cabal should not process ill-formed configurations either.

jasagredo commented 1 month ago

Perfectly understandable!

Could you change the title or description so that just with a glance it is clear that is what you would like to see implemented?

I think the idea is very useful and might be worth adding a specific mechanism for it so that other configurations that are known unusable are also included (such as using rpath on Windows which I think also fails)

jasagredo commented 1 month ago

Note this already exists with relocatable builds:

➜ cabal build --enable-relocatable
Resolving dependencies...
Build profile: -w ghc-9.8.2 -O1
In order, the following will be built (use -v for more details):
 - aa-0.1.0.0 (lib) (configuration changed)
Configuring library for aa-0.1.0.0...
Error: [Cabal-3339]
Operating system: windows, does not support relocatable builds

Error: [Cabal-7125]
Failed to build aa-0.1.0.0. The failure occurred during the configure step.

It should just be a matter of doing a very similar check for shared executables if we are on Windows.

ulysses4ever commented 1 month ago

Sounds like a low-hanging fruit then. I'll put the "newcomer" label on it.

jasagredo commented 1 month ago

Ah actually I did it while waiting for some tests, it was barely a 10 lines change in total