Skip to content

Add s/cmm-sources + extra-bundled-libraries #4857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 3, 2017
Merged
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
4 changes: 3 additions & 1 deletion Cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,9 @@ checkPaths pkg =
++ [ (path, "data-dir") | path <- [dataDir pkg]]
++ [ (path, "license-file") | path <- licenseFiles pkg ]
++ concat
[ [ (path, "c-sources") | path <- cSources bi ]
[ [ (path, "asm-sources") | path <- asmSources bi ]
++ [ (path, "cmm-sources") | path <- cmmSources bi ]
++ [ (path, "c-sources") | path <- cSources bi ]
++ [ (path, "cxx-sources") | path <- cxxSources bi ]
++ [ (path, "js-sources") | path <- jsSources bi ]
++ [ (path, "install-includes") | path <- installIncludes bi ]
Expand Down
6 changes: 6 additions & 0 deletions Cabal/Distribution/PackageDescription/FieldGrammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,16 @@ buildInfoFieldGrammar = BuildInfo
<*> monoidalFieldAla "build-tool-depends" (alaList CommaFSep) L.buildToolDepends
^^^ availableSince [2,0]
<*> monoidalFieldAla "cpp-options" (alaList' NoCommaFSep Token') L.cppOptions
<*> monoidalFieldAla "asm-options" (alaList' NoCommaFSep Token') L.asmOptions
<*> monoidalFieldAla "cmm-options" (alaList' NoCommaFSep Token') L.cmmOptions
<*> monoidalFieldAla "cc-options" (alaList' NoCommaFSep Token') L.ccOptions
<*> monoidalFieldAla "cxx-options" (alaList' NoCommaFSep Token') L.cxxOptions
<*> monoidalFieldAla "ld-options" (alaList' NoCommaFSep Token') L.ldOptions
<*> monoidalFieldAla "pkgconfig-depends" (alaList CommaFSep) L.pkgconfigDepends
<*> monoidalFieldAla "frameworks" (alaList' FSep Token) L.frameworks
<*> monoidalFieldAla "extra-framework-dirs" (alaList' FSep FilePathNT) L.extraFrameworkDirs
<*> monoidalFieldAla "asm-sources" (alaList' VCat FilePathNT) L.asmSources
<*> monoidalFieldAla "cmm-sources" (alaList' VCat FilePathNT) L.cmmSources
<*> monoidalFieldAla "c-sources" (alaList' VCat FilePathNT) L.cSources
<*> monoidalFieldAla "cxx-sources" (alaList' VCat FilePathNT) L.cxxSources
<*> monoidalFieldAla "js-sources" (alaList' VCat FilePathNT) L.jsSources
Expand All @@ -380,6 +384,8 @@ buildInfoFieldGrammar = BuildInfo
^^^ deprecatedSince [1,12] "Please use 'default-extensions' or 'other-extensions' fields."
<*> monoidalFieldAla "extra-libraries" (alaList' VCat Token) L.extraLibs
<*> monoidalFieldAla "extra-ghci-libraries" (alaList' VCat Token) L.extraGHCiLibs
<*> monoidalFieldAla "extra-bundled-libraries" (alaList' VCat Token) L.extraBundledLibs
<*> monoidalFieldAla "extra-library-flavours" (alaList' VCat Token) L.extraLibFlavours
<*> monoidalFieldAla "extra-lib-dirs" (alaList' FSep FilePathNT) L.extraLibDirs
<*> monoidalFieldAla "include-dirs" (alaList' FSep FilePathNT) L.includeDirs
<*> monoidalFieldAla "includes" (alaList' FSep FilePathNT) L.includes
Expand Down
26 changes: 22 additions & 4 deletions Cabal/Distribution/PackageDescription/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,20 @@ binfoFieldDescrs =
disp parse
buildToolDepends (\xs binfo -> binfo{buildToolDepends=xs})
, commaListFieldWithSep vcat "build-depends"
disp parse
disp parse
targetBuildDepends (\xs binfo -> binfo{targetBuildDepends=xs})
, commaListFieldWithSep vcat "mixins"
disp parse
mixins (\xs binfo -> binfo{mixins=xs})
disp parse
mixins (\xs binfo -> binfo{mixins=xs})
, spaceListField "cpp-options"
showToken parseTokenQ'
cppOptions (\val binfo -> binfo{cppOptions=val})
cppOptions (\val binfo -> binfo{cppOptions=val})
, spaceListField "asm-options"
showToken parseTokenQ'
asmOptions (\val binfo -> binfo{asmOptions=val})
, spaceListField "cmm-options"
showToken parseTokenQ'
cmmOptions (\val binfo -> binfo{cmmOptions=val})
, spaceListField "cc-options"
showToken parseTokenQ'
ccOptions (\val binfo -> binfo{ccOptions=val})
Expand All @@ -456,6 +462,12 @@ binfoFieldDescrs =
, listField "extra-framework-dirs"
showToken parseFilePathQ
extraFrameworkDirs (\val binfo -> binfo{extraFrameworkDirs=val})
, listFieldWithSep vcat "asm-sources"
showFilePath parseFilePathQ
asmSources (\paths binfo -> binfo{asmSources=paths})
, listFieldWithSep vcat "cmm-sources"
showFilePath parseFilePathQ
cmmSources (\paths binfo -> binfo{cmmSources=paths})
, listFieldWithSep vcat "c-sources"
showFilePath parseFilePathQ
cSources (\paths binfo -> binfo{cSources=paths})
Expand Down Expand Up @@ -487,6 +499,12 @@ binfoFieldDescrs =
, listFieldWithSep vcat "extra-ghci-libraries"
showToken parseTokenQ
extraGHCiLibs (\xs binfo -> binfo{extraGHCiLibs=xs})
, listFieldWithSep vcat "extra-bundled-libraries"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will see to this and the haddocks tomorrow. Thanks for the review!

showToken parseTokenQ
extraBundledLibs (\xs binfo -> binfo{extraBundledLibs=xs})
, listFieldWithSep vcat "extra-library-flavours"
showToken parseTokenQ
extraLibFlavours (\xs binfo -> binfo{extraLibFlavours=xs})
, listField "extra-lib-dirs"
showFilePath parseFilePathQ
extraLibDirs (\xs binfo -> binfo{extraLibDirs=xs})
Expand Down
2 changes: 2 additions & 0 deletions Cabal/Distribution/ParseUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ ppField name fielddoc
, "extra-source-files"
, "extra-tmp-files"
, "exposed-modules"
, "asm-sources"
, "cmm-sources"
, "c-sources"
, "js-sources"
, "extra-libraries"
Expand Down
26 changes: 19 additions & 7 deletions Cabal/Distribution/Simple/BuildPaths.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ module Distribution.Simple.BuildPaths (
cppHeaderName,
haddockName,

mkGenericStaticLibName,
mkLibName,
mkProfLibName,
mkGenericSharedLibName,
mkSharedLibName,
mkStaticLibName,

Expand Down Expand Up @@ -183,21 +185,31 @@ flibBuildDir lbi flib = buildDir lbi </> nm </> nm ++ "-tmp"
-- ---------------------------------------------------------------------------
-- Library file names

-- TODO: Should this use staticLibExtension?
-- | Create a library name for a static library from a given name.
-- Prepends 'lib' and appends the static library extension ('.a').
mkGenericStaticLibName :: String -> String
mkGenericStaticLibName lib = "lib" ++ lib <.> "a"

mkLibName :: UnitId -> String
mkLibName lib = "lib" ++ getHSLibraryName lib <.> "a"
mkLibName lib = mkGenericStaticLibName (getHSLibraryName lib)

-- TODO: Should this use staticLibExtension?
mkProfLibName :: UnitId -> String
mkProfLibName lib = "lib" ++ getHSLibraryName lib ++ "_p" <.> "a"
mkProfLibName lib = mkGenericStaticLibName (getHSLibraryName lib ++ "_p")

-- | Create a library name for a shared lirbary from a given name.
-- Prepends 'lib' and appends the '-<compilerFlavour><compilerVersion>'
-- as well as the shared library extension.
mkGenericSharedLibName :: CompilerId -> String -> String
mkGenericSharedLibName (CompilerId compilerFlavor compilerVersion) lib
= mconcat [ "lib", lib, "-", comp <.> dllExtension ]
where comp = display compilerFlavor ++ display compilerVersion

-- Implement proper name mangling for dynamical shared objects
-- libHS<packagename>-<compilerFlavour><compilerVersion>
-- e.g. libHSbase-2.1-ghc6.6.1.so
mkSharedLibName :: CompilerId -> UnitId -> String
mkSharedLibName (CompilerId compilerFlavor compilerVersion) lib
= "lib" ++ getHSLibraryName lib ++ "-" ++ comp <.> dllExtension
where comp = display compilerFlavor ++ display compilerVersion
mkSharedLibName comp lib
= mkGenericSharedLibName comp (getHSLibraryName lib)

-- Static libs are named the same as shared libraries, only with
-- a different extension.
Expand Down
4 changes: 4 additions & 0 deletions Cabal/Distribution/Simple/BuildTarget.hs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ data ComponentInfo = ComponentInfo {
cinfoSrcDirs :: [FilePath],
cinfoModules :: [ModuleName],
cinfoHsFiles :: [FilePath], -- other hs files (like main.hs)
cinfoAsmFiles:: [FilePath],
cinfoCmmFiles:: [FilePath],
cinfoCFiles :: [FilePath],
cinfoJsFiles :: [FilePath]
}
Expand All @@ -464,6 +466,8 @@ pkgComponentInfo pkg =
cinfoSrcDirs = hsSourceDirs bi,
cinfoModules = componentModules c,
cinfoHsFiles = componentHsFiles c,
cinfoAsmFiles= asmSources bi,
cinfoCmmFiles= cmmSources bi,
cinfoCFiles = cSources bi,
cinfoJsFiles = jsSources bi
}
Expand Down
9 changes: 7 additions & 2 deletions Cabal/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
ifReplLib (runGhcProg replOpts)

-- build any C sources
-- TODO: Add support for S and CMM files.
unless (not has_code || null (cSources libBi)) $ do
info verbosity "Building C Sources..."
sequence_
Expand Down Expand Up @@ -1705,7 +1706,11 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir _pkg lib clbi = do

-- copy the built library files over:
whenHasCode $ do
whenVanilla $ installOrdinary builtDir targetDir vanillaLibName
whenVanilla $ do
sequence_ [ installOrdinary builtDir targetDir (mkGenericStaticLibName (l ++ f))
| l <- getHSLibraryName (componentUnitId clbi):(extraBundledLibs (libBuildInfo lib))
, f <- "":extraLibFlavours (libBuildInfo lib)
]
whenProf $ installOrdinary builtDir targetDir profileLibName
whenGHCi $ installOrdinary builtDir targetDir ghciLibName
whenShared $ installShared builtDir dynlibTargetDir sharedLibName
Expand All @@ -1716,6 +1721,7 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir _pkg lib clbi = do
install isShared srcDir dstDir name = do
let src = srcDir </> name
dst = dstDir </> name

createDirectoryIfMissingVerbose verbosity True dstDir

if isShared
Expand All @@ -1734,7 +1740,6 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir _pkg lib clbi = do

compiler_id = compilerId (compiler lbi)
uid = componentUnitId clbi
vanillaLibName = mkLibName uid
profileLibName = mkProfLibName uid
ghciLibName = Internal.mkGHCiLibName uid
sharedLibName = (mkSharedLibName compiler_id) uid
Expand Down
10 changes: 7 additions & 3 deletions Cabal/Distribution/Simple/Register.hs
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,10 @@ generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDi
IPI.libraryDirs = libdirs,
IPI.libraryDynDirs = dynlibdirs,
IPI.dataDir = datadir installDirs,
IPI.hsLibraries = if hasLibrary
then [getHSLibraryName (componentUnitId clbi)]
else [],
IPI.hsLibraries = extraBundledLibs bi
++ if hasLibrary
then [getHSLibraryName (componentUnitId clbi)]
else [],
IPI.extraLibraries = extraLibs bi,
IPI.extraGHCiLibraries = extraGHCiLibs bi,
IPI.includeDirs = absinc ++ adjustRelIncDirs relinc,
Expand Down Expand Up @@ -462,6 +463,9 @@ generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDi
hasModules = not $ null (allLibModules lib clbi)
comp = compiler lbi
hasLibrary = (hasModules || not (null (cSources bi))
|| not (null (asmSources bi))
|| not (null (cmmSources bi))
|| not (null (cxxSources bi))
|| (not (null (jsSources bi)) &&
compilerFlavor comp == GHCJS))
&& not (componentIsIndefinite clbi)
Expand Down
27 changes: 27 additions & 0 deletions Cabal/Distribution/Types/BuildInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ data BuildInfo = BuildInfo {
-- field directly.
buildToolDepends :: [ExeDependency],
cppOptions :: [String], -- ^ options for pre-processing Haskell code
asmOptions :: [String], -- ^ options for assmebler
cmmOptions :: [String], -- ^ options for C-- compiler
ccOptions :: [String], -- ^ options for C compiler
cxxOptions :: [String], -- ^ options for C++ compiler
ldOptions :: [String], -- ^ options for linker
pkgconfigDepends :: [PkgconfigDependency], -- ^ pkg-config packages that are used
frameworks :: [String], -- ^support frameworks for Mac OS X
extraFrameworkDirs:: [String], -- ^ extra locations to find frameworks.
asmSources :: [FilePath], -- ^ Assembly files.
cmmSources :: [FilePath], -- ^ C-- files.
cSources :: [FilePath],
cxxSources :: [FilePath],
jsSources :: [FilePath],
Expand All @@ -72,6 +76,17 @@ data BuildInfo = BuildInfo {

extraLibs :: [String], -- ^ what libraries to link with when compiling a program that uses your package
extraGHCiLibs :: [String], -- ^ if present, overrides extraLibs when package is loaded with GHCi.
extraBundledLibs :: [String], -- ^ if present, adds libs to hs-lirbaries, which become part of the package.
-- Example: the Cffi library shipping with the rts, alognside the HSrts-1.0.a,.o,...
-- Example 2: a library that is being built by a foreing tool (e.g. rust)
-- and copied and registered together with this library. The
-- logic on how this library is built will have to be encoded in a
-- custom Setup for now. Oherwise cabal would need to lear how to
-- call arbitary lirbary builders.
extraLibFlavours :: [String], -- ^ Hidden Flag. This set of strings, will be appended to all lirbaries when
-- copying. E.g. [libHS<name>_<flavour> | flavour <- extraLibFlavours]. This
-- should only be needed in very specific cases, e.g. the `rts` package, where
-- there are multiple copies of slightly differently built libs.
extraLibDirs :: [String],
includeDirs :: [FilePath], -- ^directories to find .h files
includes :: [FilePath], -- ^ The .h files to be found in includeDirs
Expand All @@ -96,12 +111,16 @@ instance Monoid BuildInfo where
buildTools = [],
buildToolDepends = [],
cppOptions = [],
asmOptions = [],
cmmOptions = [],
ccOptions = [],
cxxOptions = [],
ldOptions = [],
pkgconfigDepends = [],
frameworks = [],
extraFrameworkDirs = [],
asmSources = [],
cmmSources = [],
cSources = [],
cxxSources = [],
jsSources = [],
Expand All @@ -115,6 +134,8 @@ instance Monoid BuildInfo where
oldExtensions = [],
extraLibs = [],
extraGHCiLibs = [],
extraBundledLibs = [],
extraLibFlavours = [],
extraLibDirs = [],
includeDirs = [],
includes = [],
Expand All @@ -135,12 +156,16 @@ instance Semigroup BuildInfo where
buildTools = combine buildTools,
buildToolDepends = combine buildToolDepends,
cppOptions = combine cppOptions,
asmOptions = combine asmOptions,
cmmOptions = combine cmmOptions,
ccOptions = combine ccOptions,
cxxOptions = combine cxxOptions,
ldOptions = combine ldOptions,
pkgconfigDepends = combine pkgconfigDepends,
frameworks = combineNub frameworks,
extraFrameworkDirs = combineNub extraFrameworkDirs,
asmSources = combineNub asmSources,
cmmSources = combineNub cmmSources,
cSources = combineNub cSources,
cxxSources = combineNub cxxSources,
jsSources = combineNub jsSources,
Expand All @@ -154,6 +179,8 @@ instance Semigroup BuildInfo where
oldExtensions = combineNub oldExtensions,
extraLibs = combine extraLibs,
extraGHCiLibs = combine extraGHCiLibs,
extraBundledLibs = combine extraBundledLibs,
extraLibFlavours = combine extraLibFlavours,
extraLibDirs = combineNub extraLibDirs,
includeDirs = combineNub includeDirs,
includes = combineNub includes,
Expand Down
42 changes: 42 additions & 0 deletions Cabal/Distribution/Types/BuildInfo/Lens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class HasBuildInfo a where
cppOptions = buildInfo . cppOptions
{-# INLINE cppOptions #-}

asmOptions :: Lens' a [String]
asmOptions = buildInfo . asmOptions
{-# INLINE asmOptions #-}

cmmOptions :: Lens' a [String]
cmmOptions = buildInfo . cmmOptions
{-# INLINE cmmOptions #-}

ccOptions :: Lens' a [String]
ccOptions = buildInfo . ccOptions
{-# INLINE ccOptions #-}
Expand All @@ -63,6 +71,14 @@ class HasBuildInfo a where
extraFrameworkDirs = buildInfo . extraFrameworkDirs
{-# INLINE extraFrameworkDirs #-}

asmSources :: Lens' a [FilePath]
asmSources = buildInfo . asmSources
{-# INLINE asmSources #-}

cmmSources :: Lens' a [FilePath]
cmmSources = buildInfo . cmmSources
{-# INLINE cmmSources #-}

cSources :: Lens' a [FilePath]
cSources = buildInfo . cSources
{-# INLINE cSources #-}
Expand Down Expand Up @@ -115,6 +131,14 @@ class HasBuildInfo a where
extraGHCiLibs = buildInfo . extraGHCiLibs
{-# INLINE extraGHCiLibs #-}

extraBundledLibs :: Lens' a [String]
extraBundledLibs = buildInfo . extraBundledLibs
{-# INLINE extraBundledLibs #-}

extraLibFlavours :: Lens' a [String]
extraLibFlavours = buildInfo . extraLibFlavours
{-# INLINE extraLibFlavours #-}

extraLibDirs :: Lens' a [String]
extraLibDirs = buildInfo . extraLibDirs
{-# INLINE extraLibDirs #-}
Expand Down Expand Up @@ -176,6 +200,12 @@ instance HasBuildInfo BuildInfo where
cppOptions f s = fmap (\x -> s { T.cppOptions = x }) (f (T.cppOptions s))
{-# INLINE cppOptions #-}

asmOptions f s = fmap (\x -> s { T.asmOptions = x }) (f (T.asmOptions s))
{-# INLINE asmOptions #-}

cmmOptions f s = fmap (\x -> s { T.cmmOptions = x }) (f (T.cmmOptions s))
{-# INLINE cmmOptions #-}

ccOptions f s = fmap (\x -> s { T.ccOptions = x }) (f (T.ccOptions s))
{-# INLINE ccOptions #-}

Expand All @@ -194,6 +224,12 @@ instance HasBuildInfo BuildInfo where
extraFrameworkDirs f s = fmap (\x -> s { T.extraFrameworkDirs = x }) (f (T.extraFrameworkDirs s))
{-# INLINE extraFrameworkDirs #-}

asmSources f s = fmap (\x -> s { T.asmSources = x }) (f (T.asmSources s))
{-# INLINE asmSources #-}

cmmSources f s = fmap (\x -> s { T.cmmSources = x }) (f (T.cmmSources s))
{-# INLINE cmmSources #-}

cSources f s = fmap (\x -> s { T.cSources = x }) (f (T.cSources s))
{-# INLINE cSources #-}

Expand Down Expand Up @@ -233,6 +269,12 @@ instance HasBuildInfo BuildInfo where
extraGHCiLibs f s = fmap (\x -> s { T.extraGHCiLibs = x }) (f (T.extraGHCiLibs s))
{-# INLINE extraGHCiLibs #-}

extraBundledLibs f s = fmap (\x -> s { T.extraBundledLibs = x }) (f (T.extraBundledLibs s))
{-# INLINE extraBundledLibs #-}

extraLibFlavours f s = fmap (\x -> s { T.extraLibFlavours = x }) (f (T.extraLibFlavours s))
{-# INLINE extraLibFlavours #-}

extraLibDirs f s = fmap (\x -> s { T.extraLibDirs = x }) (f (T.extraLibDirs s))
{-# INLINE extraLibDirs #-}

Expand Down
Loading