Skip to content

Commit 97c66f2

Browse files
authored
Merge pull request #4891 from zw3rk/feature/c-only-main
Allow empty set of input modules.
2 parents 831e40c + 60f1f64 commit 97c66f2

File tree

7 files changed

+37
-1
lines changed

7 files changed

+37
-1
lines changed

Cabal/Distribution/Simple/GHC.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,11 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
12681268
runGhcProg compileTHOpts { ghcOptNoLink = toFlag True
12691269
, ghcOptNumJobs = numJobs }
12701270

1271-
unless (gbuildIsRepl bm) $
1271+
-- Do not try to build anything if there are no input files.
1272+
-- This can happen if the cabal file ends up with only cSrcs
1273+
-- but no Haskell modules.
1274+
unless ((null inputFiles && null inputModules)
1275+
|| gbuildIsRepl bm) $
12721276
runGhcProg compileOpts { ghcOptNoLink = toFlag True
12731277
, ghcOptNumJobs = numJobs }
12741278

Cabal/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-*-change-log-*-
22

33
2.2.0.0 (current development version)
4+
* Cabal does not try to build an empty set of `inputModules` (#4890).
45
* Add `HexFloatLiterals` to `KnownExtension`
56
* Added `virtual-module` field, to allow modules that are not built
67
but registered (#4875).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char **argv) {
4+
printf("Hello world!");
5+
return 0;
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: my
2+
version: 0.1
3+
license: BSD3
4+
cabal-version: >= 2.1
5+
build-type: Simple
6+
7+
executable foo
8+
-- default-language is required by cabal-version >= 1.10
9+
default-language: Haskell2010
10+
main-is: foo.c
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Setup configure
2+
Resolving dependencies...
3+
Configuring my-0.1...
4+
# Setup build
5+
Preprocessing executable 'foo' for my-0.1..
6+
Building executable 'foo' for my-0.1..
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Setup configure
2+
Configuring my-0.1...
3+
# Setup build
4+
Preprocessing executable 'foo' for my-0.1..
5+
Building executable 'foo' for my-0.1..
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Test.Cabal.Prelude
2+
-- Test building an executable whose main() function is defined in a C
3+
-- file
4+
main = setupAndCabalTest $ setup_build []

0 commit comments

Comments
 (0)