Skip to content

Allow empty set of input modules. #4891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cabal/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,11 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
runGhcProg compileTHOpts { ghcOptNoLink = toFlag True
, ghcOptNumJobs = numJobs }

unless (gbuildIsRepl bm) $
-- Do not try to build anything if there are no input files.
-- This can happen if the cabal file ends up with only cSrcs
-- but no Haskell modules.
unless ((null inputFiles && null inputModules)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd maybe add an additional check, something along these lines:

let noHaskellSources  = null inputFiles && null inputModules
     noForeignSources = null cSrcs && null cxxSrcs && null asmSrcs && ...
when (noHaskellSources && noForeignSources) $
    die "Component has no source files to compile"

Though perhaps that should be part of cabal check.

BTW, do we allow a .cpp/.asm/.cmm main-is?

|| gbuildIsRepl bm) $
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you run repl on a component that only has C sources? Also, are C-only libraries allowed now?

runGhcProg compileOpts { ghcOptNoLink = toFlag True
, ghcOptNumJobs = numJobs }

Expand Down
1 change: 1 addition & 0 deletions Cabal/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-*-change-log-*-

2.2.0.0 (current development version)
* Cabal does not try to build an empty set of `inputModules` (#4890).
* Add `HexFloatLiterals` to `KnownExtension`
* Added `virtual-module` field, to allow modules that are not built
but registered (#4875).
Expand Down
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/COnlyMain/foo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>

int main(int argc, char **argv) {
printf("Hello world!");
return 0;
}
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/COnlyMain/my.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: my
version: 0.1
license: BSD3
cabal-version: >= 2.1
build-type: Simple

executable foo
-- default-language is required by cabal-version >= 1.10
default-language: Haskell2010
main-is: foo.c
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/COnlyMain/setup.cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Setup configure
Resolving dependencies...
Configuring my-0.1...
# Setup build
Preprocessing executable 'foo' for my-0.1..
Building executable 'foo' for my-0.1..
5 changes: 5 additions & 0 deletions cabal-testsuite/PackageTests/COnlyMain/setup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Setup configure
Configuring my-0.1...
# Setup build
Preprocessing executable 'foo' for my-0.1..
Building executable 'foo' for my-0.1..
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also test that it correctly outputs "hello, world"?

4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/COnlyMain/setup.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Test.Cabal.Prelude
-- Test building an executable whose main() function is defined in a C
-- file
main = setupAndCabalTest $ setup_build []