Skip to content

Commit 42162d6

Browse files
committed
Add NoImplicitPrelude to buildTypeScript
This allows us to compile Setup.hs without depending on base. In particular, this ensures that a package with `build-type: Hooks` and a custom setup stanza that does not depend on base successfully compiles. Tested in PackageTests/SetupHooks/SetupHooksNoBase.
1 parent fd8020f commit 42162d6

File tree

7 files changed

+43
-3
lines changed

7 files changed

+43
-3
lines changed

cabal-install/src/Distribution/Client/ProjectPlanning/SetupPolicy.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,10 @@ mkDefaultSetupDeps compiler platform pkg =
133133

134134
-- For other build types (like Simple) if we still need to compile an
135135
-- external Setup.hs, it'll be one of the simple ones that only depends
136-
-- on Cabal and base.
136+
-- on Cabal.
137137
SetupNonCustomExternalLib ->
138138
Just
139139
[ Dependency cabalPkgname cabalConstraint mainLibSet
140-
, Dependency basePkgname anyVersion mainLibSet
141140
]
142141
where
143142
cabalConstraint = orLaterVersion (csvToVersion (specVersion pkg))

cabal-install/src/Distribution/Client/SetupWrapper.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ getExternalSetupMethod verbosity options pkg bt = do
858858
rewriteFileLBS verbosity (i setupHs) (buildTypeScript cabalLibVersion)
859859

860860
buildTypeScript :: Version -> BS.ByteString
861-
buildTypeScript cabalLibVersion = case bt of
861+
buildTypeScript cabalLibVersion = "{-# LANGUAGE NoImplicitPrelude #-}\n" <> case bt of
862862
Simple -> "import Distribution.Simple; main = defaultMain\n"
863863
Configure
864864
| cabalLibVersion >= mkVersion [1, 3, 10] -> "import Distribution.Simple; main = defaultMainWithHooks autoconfUserHooks\n"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
module A where {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
3+
module SetupHooks ( setupHooks ) where
4+
5+
import Distribution.Simple.SetupHooks ( SetupHooks, noSetupHooks )
6+
7+
setupHooks :: SetupHooks
8+
setupHooks = noSetupHooks
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Test.Cabal.Prelude
2+
3+
-- Test that we can compile the Setup.hs script for a package with
4+
-- build-type:Hooks without requiring a dependency on 'base'.
5+
--
6+
-- NB: we specifically don't include a 'Setup.hs' file in this package,
7+
-- as we rely on 'cabal-install' generating one that does not incur an extra
8+
-- dependency on base.
9+
main = cabalTest $ do
10+
mpkgdb <- testPackageDbPath <$> getTestEnv
11+
case mpkgdb of
12+
Nothing -> skip "Cabal-hooks library unavailable."
13+
Just _pkgdb -> recordMode DoNotRecord $ do
14+
cabal "v2-build" [ "all" ]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cabal-version: 3.14
2+
name: setup-hooks-no-base-test
3+
version: 0.1.0.0
4+
synopsis: Test that we can build Setup.hs without base
5+
license: BSD-3-Clause
6+
author: NA
7+
maintainer: NA
8+
category: Testing
9+
build-type: Hooks
10+
11+
custom-setup
12+
setup-depends: Cabal-hooks
13+
14+
library
15+
exposed-modules: A
16+
default-language: Haskell2010

0 commit comments

Comments
 (0)