Skip to content
Open
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
2 changes: 2 additions & 0 deletions Cabal-syntax/src/Distribution/Types/InstalledPackageInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ data InstalledPackageInfo = InstalledPackageInfo
, libraryDirs :: [FilePath]
, libraryDirsStatic :: [FilePath]
, libraryDynDirs :: [FilePath]
, libraryBytecodeDirs :: [FilePath]
-- ^ overrides 'libraryDirs'
, dataDir :: FilePath
, hsLibraries :: [String]
Expand Down Expand Up @@ -160,6 +161,7 @@ emptyInstalledPackageInfo =
, hsLibraries = []
, extraLibraries = []
, extraLibrariesStatic = []
, libraryBytecodeDirs = []
, extraGHCiLibraries = []
, includeDirs = []
, includes = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ ipiFieldGrammar =
<@> monoidalFieldAla "library-dirs" (alaList' FSep FilePathNT) L.libraryDirs
<@> monoidalFieldAla "library-dirs-static" (alaList' FSep FilePathNT) L.libraryDirsStatic
<@> monoidalFieldAla "dynamic-library-dirs" (alaList' FSep FilePathNT) L.libraryDynDirs
<@> monoidalFieldAla "bytecode-library-dirs" (alaList' FSep FilePathNT) L.libraryBytecodeDirs
<@> optionalFieldDefAla "data-dir" FilePathNT L.dataDir ""
<@> monoidalFieldAla "hs-libraries" (alaList' FSep Token) L.hsLibraries
<@> monoidalFieldAla "extra-libraries" (alaList' FSep Token) L.extraLibraries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ libraryDynDirs :: Lens' InstalledPackageInfo [FilePath]
libraryDynDirs f s = fmap (\x -> s{T.libraryDynDirs = x}) (f (T.libraryDynDirs s))
{-# INLINE libraryDynDirs #-}

libraryBytecodeDirs :: Lens' InstalledPackageInfo [FilePath]
libraryBytecodeDirs f s = fmap (\x -> s{T.libraryBytecodeDirs = x}) (f (T.libraryBytecodeDirs s))
{-# INLINE libraryBytecodeDirs #-}

dataDir :: Lens' InstalledPackageInfo FilePath
dataDir f s = fmap (\x -> s{T.dataDir = x}) (f (T.dataDir s))
{-# INLINE dataDir #-}
Expand Down
1 change: 1 addition & 0 deletions Cabal-tests/tests/ParserTests/ipi/Includes2.expr
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ InstalledPackageInfo {
libraryDynDirs =
[
"/home/travis/build/haskell/cabal/cabal-testsuite/PackageTests/Backpack/Includes2/cabal-internal.dist/work/./dist/build/x86_64-linux/ghc-8.2.2/Includes2-0.1.0.0/l/mylib/Includes2-0.1.0.0-inplace-mylib+3gY9SyjX86dBypHcOaev1n/build/Includes2-0.1.0.0-inplace-mylib+3gY9SyjX86dBypHcOaev1n"],
libraryBytecodeDirs = [],
dataDir =
"/home/travis/build/haskell/cabal/cabal-testsuite/PackageTests/Backpack/Includes2",
hsLibraries = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ InstalledPackageInfo {
"/home/ogre/Documents/other-haskell/cabal/cabal-testsuite/PackageTests/CustomPreProcess/setup.dist/work/dist/build"],
libraryDirsStatic = [],
libraryDynDirs = [],
libraryBytecodeDirs = [],
dataDir =
"/home/ogre/Documents/other-haskell/cabal/cabal-testsuite/PackageTests/CustomPreProcess",
hsLibraries = [
Expand Down
1 change: 1 addition & 0 deletions Cabal-tests/tests/ParserTests/ipi/issue-2276-ghc-9885.expr
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ InstalledPackageInfo {
libraryDirsStatic = [],
libraryDynDirs = [
"/opt/ghc/8.2.2/lib/ghc-8.2.2/transformers-0.5.2.0"],
libraryBytecodeDirs = [],
dataDir =
"/opt/ghc/8.2.2/share/x86_64-linux-ghc-8.2.2/transformers-0.5.2.0",
hsLibraries = [
Expand Down
1 change: 1 addition & 0 deletions Cabal-tests/tests/ParserTests/ipi/transformers.expr
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ InstalledPackageInfo {
libraryDirsStatic = [],
libraryDynDirs = [
"/opt/ghc/8.2.2/lib/ghc-8.2.2/transformers-0.5.2.0"],
libraryBytecodeDirs = [],
dataDir =
"/opt/ghc/8.2.2/share/x86_64-linux-ghc-8.2.2/transformers-0.5.2.0",
hsLibraries = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ md5CheckGenericPackageDescription proxy = md5Check proxy

md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion
md5CheckLocalBuildInfo proxy = md5Check proxy
0xc35a236a684a15b35690edb21c305eba
0xf46cd0819435850a64242cab0fc7aa4b
4 changes: 4 additions & 0 deletions Cabal/src/Distribution/Simple/BuildPaths.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module Distribution.Simple.BuildPaths
, mkSharedLibName
, mkProfSharedLibName
, mkStaticLibName
, mkBytecodeLibName
, mkGenericSharedBundledLibName
, exeExtension
, objExtension
Expand Down Expand Up @@ -409,6 +410,9 @@ mkStaticLibName platform (CompilerId compilerFlavor compilerVersion) lib =
where
comp = prettyShow compilerFlavor ++ prettyShow compilerVersion

mkBytecodeLibName :: CompilerId -> UnitId -> String
mkBytecodeLibName _comp lib = getHSLibraryName lib <.> ".bytecodelib"

-- | Create a library name for a bundled shared library from a given name.
-- This matches the naming convention for shared libraries as implemented in
-- GHC's packageHsLibs function in the Packages module.
Expand Down
23 changes: 15 additions & 8 deletions Cabal/src/Distribution/Simple/BuildWay.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
{-# LANGUAGE LambdaCase #-}

module Distribution.Simple.BuildWay where
module Distribution.Simple.BuildWay
( BuildWay (..)
, buildWayObjectExtension
, buildWayInterfaceExtension
) where

data BuildWay = StaticWay | DynWay | ProfWay | ProfDynWay
deriving (Eq, Ord, Show, Read, Enum)

-- | Returns the object/interface extension prefix for the given build way (e.g. "dyn_" for 'DynWay')
buildWayPrefix :: BuildWay -> String
buildWayPrefix = \case
StaticWay -> ""
ProfWay -> "p_"
DynWay -> "dyn_"
ProfDynWay -> "p_dyn_"
-- | Returns the object extension for the given build way (e.g. "dyn_o" for 'DynWay' on ELF)
buildWayObjectExtension :: String -> BuildWay -> String
buildWayObjectExtension ext = \case
StaticWay -> ext
ProfWay -> "p_" ++ ext
DynWay -> "dyn_" ++ ext
ProfDynWay -> "p_dyn_" ++ ext

buildWayInterfaceExtension :: BuildWay -> String
buildWayInterfaceExtension = buildWayObjectExtension "hi"
9 changes: 9 additions & 0 deletions Cabal/src/Distribution/Simple/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module Distribution.Simple.Compiler
, profilingVanillaSupported
, profilingVanillaSupportedOrUnknown
, dynamicSupported
, bytecodeArtifactsSupported
, backpackSupported
, arResponseFilesSupported
, arDashLSupported
Expand Down Expand Up @@ -575,6 +576,14 @@ profilingDynamicSupportedOrUnknown comp =
dynamicSupported :: Compiler -> Maybe Bool
dynamicSupported comp = waySupported "dyn" comp

-- | Does the compiler support producing bytecode objects and bytecode libraries?
bytecodeArtifactsSupported :: Compiler -> Bool
bytecodeArtifactsSupported comp
| GHC <- compilerFlavor comp
, compilerVersion comp >= mkVersion [9, 15, 0] =
True
| otherwise = False

-- | Does this compiler support a package database entry with:
-- "visibility"?
libraryVisibilitySupported :: Compiler -> Bool
Expand Down
13 changes: 13 additions & 0 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ computeLocalBuildConfig cfg comp programDb = do
-- into a huge .a archive) via GHCs -staticlib flag.
fromFlagOrDefault False $ configStaticLib cfg

withBytecodeLib_ =
fromFlagOrDefault False $ configBytecodeLib cfg

withDynExe_ = fromFlag $ configDynExe cfg

withFullyStaticExe_ = fromFlag $ configFullyStaticExe cfg
Expand Down Expand Up @@ -778,12 +781,22 @@ computeLocalBuildConfig cfg comp programDb = do
strip_lib <- strip_libexe "library" configStripLibs
strip_exe <- strip_libexe "executable" configStripExes

checkedWithBytecodeLib <-
if bytecodeArtifactsSupported comp
then return withBytecodeLib_
else do
when withBytecodeLib_ $
warn verbosity $
"This compiler does not support bytecode libraries; ignoring --enable-library-bytecode"
return False

let buildOptions =
setCoverage . setProfiling $
LBC.BuildOptions
{ withVanillaLib = fromFlag $ configVanillaLib cfg
, withSharedLib = withSharedLib_
, withStaticLib = withStaticLib_
, withBytecodeLib = checkedWithBytecodeLib
, withDynExe = withDynExe_
, withFullyStaticExe = withFullyStaticExe_
, withProfLib = False
Expand Down
7 changes: 7 additions & 0 deletions Cabal/src/Distribution/Simple/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ data CabalException
| MissingCoveredInstalledLibrary UnitId
| SetupHooksException SetupHooksException
| MultiReplDoesNotSupportComplexReexportedModules PackageName ComponentName
| StandaloneBytecodeNotSupportedYet
deriving (Show)

exceptionCode :: CabalException -> Int
Expand Down Expand Up @@ -304,6 +305,7 @@ exceptionCode e = case e of
SetupHooksException err ->
setupHooksExceptionCode err
MultiReplDoesNotSupportComplexReexportedModules{} -> 9355
StandaloneBytecodeNotSupportedYet -> 9356

versionRequirement :: VersionRange -> String
versionRequirement range
Expand Down Expand Up @@ -804,3 +806,8 @@ exceptionMessage e = case e of
++ prettyShow pname
++ " a module renaming was found.\n"
++ "Multi-repl does not work with complicated reexported-modules until GHC-9.12."
StandaloneBytecodeNotSupportedYet ->
unlines $
[ "The ecosystem doesn't support building packages with just bytecode libraries yet."
, "If you have run into this error, please comment on issue #11471"
]
4 changes: 4 additions & 0 deletions Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,8 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir pkg lib clbi = do

-- copy the built library files over:
when (has_code && hasLib) $ do
whenBytecodeLib $ installOrdinary builtDir targetDir bytecodeLibName

forM_ libWays $ \w -> case w of
StaticWay -> do
sequence_
Expand Down Expand Up @@ -1095,6 +1097,7 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir pkg lib clbi = do
platform = hostPlatform lbi
uid = componentUnitId clbi
profileLibName = mkProfLibName uid
bytecodeLibName = mkBytecodeLibName compiler_id uid
ghciLibName = Internal.mkGHCiLibName uid
ghciProfLibName = Internal.mkGHCiProfLibName uid

Expand All @@ -1111,6 +1114,7 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir pkg lib clbi = do
_ -> False
has_code = not (componentIsIndefinite clbi)
whenGHCi = when (hasLib && withGHCiLib lbi && has_code)
whenBytecodeLib = when (hasLib && withBytecodeLib lbi && has_code)

-- -----------------------------------------------------------------------------
-- Registering
Expand Down
48 changes: 36 additions & 12 deletions Cabal/src/Distribution/Simple/GHC/Build/Link.hs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li
staticLibFilePath =
buildTargetDir
</> makeRelativePathEx (mkStaticLibName (hostPlatform lbi) compiler_id uid)
bytecodeLibFilePath =
buildTargetDir
</> makeRelativePathEx (mkBytecodeLibName compiler_id uid)
ghciLibFilePath = buildTargetDir </> makeRelativePathEx (Internal.mkGHCiLibName uid)
ghciProfLibFilePath = buildTargetDir </> makeRelativePathEx (Internal.mkGHCiProfLibName uid)
libInstallPath =
Expand All @@ -295,23 +298,29 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li
libInstallPath
</> mkProfSharedLibName (hostPlatform lbi) compiler_id uid

getObjFiles :: BuildWay -> IO [SymbolicPath Pkg File]
getObjFiles way =
getObjWayFiles :: BuildWay -> IO [SymbolicPath Pkg File]
getObjWayFiles w = getObjFiles (buildWayObjectExtension objExtension w) (buildWayObjectExtension objExtension w)

getObjBytecodeWayFiles :: BuildWay -> IO [SymbolicPath Pkg File]
getObjBytecodeWayFiles companion_way = getObjFiles "gbc" (buildWayObjectExtension objExtension companion_way)

getObjFiles :: String -> String -> IO [SymbolicPath Pkg File]
getObjFiles hs_ext obj_ext =
mconcat
[ Internal.getHaskellObjects
implInfo
lib
lbi
clbi
buildTargetDir
(buildWayPrefix way ++ objExtension)
hs_ext
True
, pure $ map (srcObjPath way) extraSources
, pure $ map (srcObjPath obj_ext) extraSources
, catMaybes
<$> sequenceA
[ findFileCwdWithExtension
mbWorkDir
[Suffix $ buildWayPrefix way ++ objExtension]
[Suffix $ obj_ext]
[buildTargetDir]
xPath
| ghcVersion < mkVersion [7, 2] -- ghc-7.2+ does not make _stub.o files
Expand All @@ -323,16 +332,16 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li

-- Get the @.o@ path from a source path (e.g. @.hs@),
-- in the library target build directory.
srcObjPath :: BuildWay -> SymbolicPath Pkg File -> SymbolicPath Pkg File
srcObjPath way srcPath =
srcObjPath :: String -> SymbolicPath Pkg File -> SymbolicPath Pkg File
srcObjPath obj_ext srcPath =
case symbolicPathRelative_maybe objPath of
-- Absolute path: should already be in the target build directory
-- (e.g. a preprocessed file)
-- TODO: assert this?
Nothing -> objPath
Just objRelPath -> coerceSymbolicPath buildTargetDir </> objRelPath
where
objPath = srcPath `replaceExtensionSymbolicPath` (buildWayPrefix way ++ objExtension)
objPath = srcPath `replaceExtensionSymbolicPath` obj_ext

-- I'm fairly certain that, just like the executable, we can keep just the
-- module input list, and point to the right sources dir (as is already
Expand All @@ -343,6 +352,7 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li
-- we could more easily merge the two.
--
-- Right now, instead, we pass the path to each object file.
ghcBaseLinkArgs :: GhcOptions
ghcBaseLinkArgs =
mempty
{ -- TODO: This basically duplicates componentGhcOptions.
Expand Down Expand Up @@ -435,11 +445,17 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li
, -- TODO: Shouldn't this use cleanedExtraLibDirsStatic instead?
ghcOptLinkLibPath = toNubListR $ cleanedExtraLibDirs
}
ghcBytecodeLinkArgs objectFiles =
(ghcSharedLinkArgs objectFiles)
{ ghcOptBytecodeLib = toFlag True
, ghcOptInputFiles = toNubListR $ map coerceSymbolicPath objectFiles
, ghcOptOutputFile = toFlag bytecodeLibFilePath
}

staticObjectFiles <- getObjFiles StaticWay
profObjectFiles <- getObjFiles ProfWay
dynamicObjectFiles <- getObjFiles DynWay
profDynamicObjectFiles <- getObjFiles ProfDynWay
staticObjectFiles <- getObjWayFiles StaticWay
profObjectFiles <- getObjWayFiles ProfWay
dynamicObjectFiles <- getObjWayFiles DynWay
profDynamicObjectFiles <- getObjWayFiles ProfDynWay

let
linkWay = \case
Expand All @@ -457,6 +473,10 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li
runGhcProg $ ghcProfSharedLinkArgs profDynamicObjectFiles
DynWay -> do
runGhcProg $ ghcSharedLinkArgs dynamicObjectFiles
-- The .gbc files were built with DynWay if both are enabled.
when (withBytecodeLib lbi) $ do
bytecodeObjectFiles <- getObjBytecodeWayFiles DynWay
runGhcProg $ ghcBytecodeLinkArgs bytecodeObjectFiles
StaticWay -> do
when (withVanillaLib lbi) $ do
Ar.createArLibArchive verbosity lbi vanillaLibFilePath staticObjectFiles
Expand All @@ -470,6 +490,10 @@ linkLibrary buildTargetDir cleanedExtraLibDirs pkg_descr verbosity runGhcProg li
staticObjectFiles
when (withStaticLib lbi) $ do
runGhcProg $ ghcStaticLinkArgs staticObjectFiles
-- The .gbc files were built with DynWay if both are enabled.
when (withBytecodeLib lbi && (DynWay `notElem` wantedWays)) $ do
bytecodeObjectFiles <- getObjBytecodeWayFiles StaticWay
runGhcProg $ ghcBytecodeLinkArgs bytecodeObjectFiles

-- ROMES: Why exactly branch on staticObjectFiles, rather than any other build
-- kind that we might have wanted instead?
Expand Down
Loading
Loading