diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9ba09634a15..eb2700d377a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,6 +15,13 @@ If not, you aren't able to build the testsuite, so you need to disable the defau cabal build --project-file=cabal.project.release cabal ``` +> **Note** +> If you're using Nix, you might find it convenient to work within a shell that has all the `Cabal` development dependencies: +> ``` +> $ nix-shell -p cabal-install ghc ghcid haskellPackages.fourmolu_0_12_0_0 pkgconfig zlib.dev +> ``` +> A Nix flake developer shell with these dependencies is also available, supported solely by the community, through the command `nix develop github:yvan-sraka/cabal.nix`. + The location of your build products will vary depending on which version of cabal-install you use to build; see the documentation section [Where are my build products?](http://cabal.readthedocs.io/en/latest/nix-local-build.html#where-are-my-build-products) diff --git a/Cabal-tests/tests/UnitTests/Distribution/Simple/Program/GHC.hs b/Cabal-tests/tests/UnitTests/Distribution/Simple/Program/GHC.hs index 985c91f8eae..8244285915f 100644 --- a/Cabal-tests/tests/UnitTests/Distribution/Simple/Program/GHC.hs +++ b/Cabal-tests/tests/UnitTests/Distribution/Simple/Program/GHC.hs @@ -1,11 +1,16 @@ module UnitTests.Distribution.Simple.Program.GHC (tests) where +import qualified Data.Map as Map import Data.Algorithm.Diff (PolyDiff (..), getDiff) import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit +import Distribution.System (Platform(..), Arch(X86_64), OS(Linux)) +import Distribution.Types.ParStrat +import Distribution.Simple.Flag +import Distribution.Simple.Compiler (Compiler(..), CompilerId(..), CompilerFlavor(..), AbiTag(NoAbiTag)) import Distribution.PackageDescription (emptyPackageDescription) -import Distribution.Simple.Program.GHC (normaliseGhcArgs) +import Distribution.Simple.Program.GHC (normaliseGhcArgs, renderGhcOptions, ghcOptNumJobs) import Distribution.Version (mkVersion) tests :: TestTree @@ -38,6 +43,22 @@ tests = testGroup "Distribution.Simple.Program.GHC" assertListEquals flags options_9_0_affects ] + , testGroup "renderGhcOptions" + [ testCase "options" $ do + let flags :: [String] + flags = renderGhcOptions + (Compiler + { compilerId = CompilerId GHC (mkVersion [9,8,1]) + , compilerAbiTag = NoAbiTag + , compilerCompat = [] + , compilerLanguages = [] + , compilerExtensions = [] + , compilerProperties = Map.singleton "Support parallel --make" "YES" + }) + (Platform X86_64 Linux) + (mempty { ghcOptNumJobs = Flag (NumJobs (Just 4)) }) + assertListEquals flags ["-j4", "-clear-package-db"] + ] ] assertListEquals :: (Eq a, Show a) => [a] -> [a] -> Assertion diff --git a/Cabal/src/Distribution/Simple/Program/Builtin.hs b/Cabal/src/Distribution/Simple/Program/Builtin.hs index 909ecc7e4b6..1f3db0740f3 100644 --- a/Cabal/src/Distribution/Simple/Program/Builtin.hs +++ b/Cabal/src/Distribution/Simple/Program/Builtin.hs @@ -347,7 +347,33 @@ greencardProgram :: Program greencardProgram = simpleProgram "greencard" ldProgram :: Program -ldProgram = simpleProgram "ld" +ldProgram = + (simpleProgram "ld") + { programPostConf = \verbosity ldProg -> do + -- The `lld` linker cannot create merge (relocatable) objects so we + -- want to detect this. + -- If the linker does support relocatable objects, we want to use that + -- to create partially pre-linked objects for GHCi, so we get much + -- faster loading as we do not have to do the separate loading and + -- in-memory linking the static linker in GHC does, but can offload + -- parts of this process to a pre-linking step. + -- However this requires the linker to support this features. Not all + -- linkers do, and notably as of this writing `lld` which is a popular + -- choice for windows linking does not support this feature. However + -- if using binutils ld or another linker that supports --relocatable, + -- we should still be good to generate pre-linked objects. + ldHelpOutput <- + getProgramInvocationOutput + verbosity + (programInvocation ldProg ["--help"]) + -- In case the linker does not support '--help'. Eg the LLVM linker, + -- `lld` only accepts `-help`. + `catchIO` (\_ -> return "") + let k = "Supports relocatable output" + v = if "--relocatable" `isInfixOf` ldHelpOutput then "YES" else "NO" + m = Map.insert k v (programProperties ldProg) + return $ ldProg{programProperties = m} + } tarProgram :: Program tarProgram = diff --git a/Cabal/src/Distribution/Simple/Program/GHC.hs b/Cabal/src/Distribution/Simple/Program/GHC.hs index 1f525fd9f39..537e008c17f 100644 --- a/Cabal/src/Distribution/Simple/Program/GHC.hs +++ b/Cabal/src/Distribution/Simple/Program/GHC.hs @@ -701,7 +701,7 @@ renderGhcOptions comp _platform@(Platform _arch os) opts if jsemSupported comp then ["-jsem " ++ name] else [] - Flag (NumJobs n) -> ["-j" ++ show n] + Flag (NumJobs n) -> ["-j" ++ maybe "" show n] else [] , -------------------- -- Creating libraries diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index d20db6ced51..dfc4a2d9ec5 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -250,9 +250,9 @@ library if flag(lukko) build-depends: lukko >= 0.1 && <0.2 - -- pull in process version with fixed waitForProcess error - if impl(ghc >=8.2) - build-depends: process >= 1.6.15.0 + -- pull in process version with fixed waitForProcess error + if impl(ghc >=8.2) + build-depends: process >= 1.6.15.0 executable cabal diff --git a/cabal-install/src/Distribution/Client/Nix.hs b/cabal-install/src/Distribution/Client/Nix.hs index 34a12f9157b..0a8d6a5c195 100644 --- a/cabal-install/src/Distribution/Client/Nix.hs +++ b/cabal-install/src/Distribution/Client/Nix.hs @@ -47,7 +47,7 @@ import Distribution.Simple.Program , simpleProgram ) import Distribution.Simple.Setup (fromFlagOrDefault) -import Distribution.Simple.Utils (debug, existsAndIsMoreRecentThan) +import Distribution.Simple.Utils (debug, existsAndIsMoreRecentThan, warn) import Distribution.Client.Config (SavedConfig (..)) import Distribution.Client.GlobalFlags (GlobalFlags (..)) @@ -144,6 +144,9 @@ nixShell verb dist globalFlags config go = do findNixExpr globalFlags config >>= \case Nothing -> go Just shellNix -> do + -- Nix integration never worked with cabal-install v2 commands ... + warn verb "Nix integration has been deprecated and will be removed in a future release. You can learn more about it here: https://cabal.readthedocs.io/en/latest/nix-integration.html" + let prog = simpleProgram "nix-shell" progdb <- configureOneProgram verb prog diff --git a/cabal-install/src/Distribution/Client/Setup.hs b/cabal-install/src/Distribution/Client/Setup.hs index 6a96fb54640..44224d9559b 100644 --- a/cabal-install/src/Distribution/Client/Setup.hs +++ b/cabal-install/src/Distribution/Client/Setup.hs @@ -502,17 +502,17 @@ globalCommand commands = ) "" ["nix"] -- Must be empty because we need to return PP.empty from viewAsFieldDescr - "Nix integration: run commands through nix-shell if a 'shell.nix' file exists (default is False)" + "[DEPRECATED] Nix integration: run commands through nix-shell if a 'shell.nix' file exists (default is False)" , noArg (Flag True) [] ["enable-nix"] - "Enable Nix integration: run commands through nix-shell if a 'shell.nix' file exists" + "[DEPRECATED] Enable Nix integration: run commands through nix-shell if a 'shell.nix' file exists" , noArg (Flag False) [] ["disable-nix"] - "Disable Nix integration" + "[DEPRECATED] Disable Nix integration" ] , option [] diff --git a/doc/nix-integration.rst b/doc/nix-integration.rst index 6edf595b6f0..5d4fa695cd4 100644 --- a/doc/nix-integration.rst +++ b/doc/nix-integration.rst @@ -1,6 +1,15 @@ Nix Integration =============== +.. warning:: + + Nix integration has been deprecated and will be removed in a future release. + + The original mechanism can still be easily replicated with the following commands: + + - for a ``shell.nix``: ``nix-shell --run "cabal ..."`` + - for a ``flake.nix``: ``nix develop -c cabal ...`` + .. note:: This functionality doesn't work with nix-style builds.