From 2051013fc83cf471c809b83382367617ae8911c3 Mon Sep 17 00:00:00 2001 From: Fendor Date: Wed, 16 Aug 2023 19:37:55 +0200 Subject: [PATCH 1/6] Fix inconsistent indentation --- cabal-install/cabal-install.cabal | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 From d737d711bb1a8db07c64e1580c14323d7c7f81a8 Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Fri, 1 Sep 2023 10:08:13 +0200 Subject: [PATCH 2/6] Add Nix developer shell instructions to CONTRIBUTING.md --- CONTRIBUTING.md | 7 +++++++ 1 file changed, 7 insertions(+) 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) From 37f67421e5f60a652dae8b071207853c01c77c16 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sat, 2 Sep 2023 23:30:01 +1200 Subject: [PATCH 3/6] Fix use of NumJobs From `Cabal/src/Distribution/Types/ParStrat.hs` ``` data ParStratX sem = -- | Compile in parallel with the given number of jobs (`-jN` or `-j`). NumJobs (Maybe Int) ... ``` However in `Cabal/src/Distribution/Simple/Program/GHC.hs` show is applied to the `Maybe Int` and we get errors like: ``` ghc-9.9.20230901: on the commandline: malformed integer argument in -jJust 4 ``` This change should correct the behavior in `Simple/Program/GHC.hs` to match the comment in `Types/ParStrat.hs`. --- Cabal/src/Distribution/Simple/Program/GHC.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 7b624afe595d71dee73c42b924d8b68dafe689b6 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Mon, 4 Sep 2023 21:29:30 +1200 Subject: [PATCH 4/6] Add test --- .../Distribution/Simple/Program/GHC.hs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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 From c483a647ae498f589f4f9d8009bb6a1a2cc32045 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Tue, 5 Sep 2023 10:31:17 +1000 Subject: [PATCH 5/6] Detect ability of linker to create relocatable objects --- .../Distribution/Simple/Program/Builtin.hs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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 = From 5581ff52a880d9fb918aecc82fd11b5736ec8247 Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Tue, 29 Aug 2023 09:46:17 +0200 Subject: [PATCH 6/6] Add deprecation warnings to Nix integration https://cabal.readthedocs.io/en/latest/nix-integration.html --- cabal-install/src/Distribution/Client/Nix.hs | 5 ++++- cabal-install/src/Distribution/Client/Setup.hs | 6 +++--- doc/nix-integration.rst | 9 +++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) 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.