Skip to content

Commit

Permalink
Merge branch 'master' into loong
Browse files Browse the repository at this point in the history
  • Loading branch information
lrzlin authored Sep 6, 2023
2 parents 86b1ec7 + 00bbb66 commit c824cde
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 22 additions & 1 deletion Cabal-tests/tests/UnitTests/Distribution/Simple/Program/GHC.hs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 27 additions & 1 deletion Cabal/src/Distribution/Simple/Program/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Simple/Program/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion cabal-install/src/Distribution/Client/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..))
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions cabal-install/src/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
[]
Expand Down
9 changes: 9 additions & 0 deletions doc/nix-integration.rst
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit c824cde

Please sign in to comment.