Skip to content

Commit 70d2731

Browse files
committed
Allow build-type Configure to work with Components
When components were introduced, cabal had support for build-type: Configure, which allows to run a `configure` script prior to building the package. Upon the introduction of components, it became obvious that we can't just configure each and every component, as this easily runs into the situation where the `configure` script is run potentially concurrently for all components. However, build-type is a global option for cabal files, and is usually used to produce a <pkg>.buildinfo file. This file is then used to augment the Main Library and Executables only. This change now tracks whether or not we are building a main library or executable component, and if we do, retains only for these components the build-type: Configure from the package description. For all other components, we will fall back to the default build-type: Simple. For end users who want to depend on package configured values, they will need to set their sub libraries, testsuites and benchmark components to depend on the main library, and import any configured values from there. For lib:Cabal, which doesn't know about components when configure is invoked, we will continue to execute configure. There is no impact on lib:Cabal in this change.
1 parent 83a909d commit 70d2731

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

cabal-install/src/Distribution/Client/Configure.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ configureSetupScript
299299
, useDependenciesExclusive = not defaultSetupDeps && isJust explicitSetupDeps
300300
, useVersionMacros = not defaultSetupDeps && isJust explicitSetupDeps
301301
, isInteractive = False
302+
, isMainLibOrExeComponent = False
302303
}
303304
where
304305
-- When we are compiling a legacy setup script without an explicit

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,10 @@ elaborateInstallPlan
17241724
-- Once you've implemented this, swap it for the code below.
17251725
cuz_buildtype =
17261726
case bt of
1727-
PD.Configure -> [CuzBuildType CuzConfigureBuildType]
1727+
PD.Configure -> []
1728+
-- Configure is supported, but we only support configuring the
1729+
-- main library in cabal. Other components will need to depend
1730+
-- on the main library for configured data.
17281731
PD.Custom -> [CuzBuildType CuzCustomBuildType]
17291732
PD.Hooks -> [CuzBuildType CuzHooksBuildType]
17301733
PD.Make -> [CuzBuildType CuzMakeBuildType]
@@ -3878,6 +3881,11 @@ setupHsScriptOptions
38783881
, forceExternalSetupMethod = isParallelBuild
38793882
, setupCacheLock = Just cacheLock
38803883
, isInteractive = False
3884+
, isMainLibOrExeComponent = case elabPkgOrComp of
3885+
ElabPackage _ -> False
3886+
ElabComponent (ElaboratedComponent { compSolverName = CD.ComponentLib}) -> False
3887+
ElabComponent (ElaboratedComponent { compSolverName = CD.ComponentExe _}) -> False
3888+
ElabComponent _ -> True
38813889
}
38823890

38833891
-- | To be used for the input for elaborateInstallPlan.

cabal-install/src/Distribution/Client/SetupWrapper.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ data SetupScriptOptions = SetupScriptOptions
315315
-- ^ Is the task we are going to run an interactive foreground task,
316316
-- or an non-interactive background task? Based on this flag we
317317
-- decide whether or not to delegate ctrl+c to the spawned task
318+
, isMainLibOrExeComponent :: Bool
319+
-- ^ Let the setup script logic know if it is being run to build a component
320+
-- or a package. This is used to determine if we should use the configure
321+
-- command, if the build-type is 'Configure'. For configure, only the
322+
-- main library and execomponents have 'configure' support, and thus we can
323+
-- skip running configure for other components.
318324
}
319325

320326
defaultSetupScriptOptions :: SetupScriptOptions
@@ -339,6 +345,7 @@ defaultSetupScriptOptions =
339345
, forceExternalSetupMethod = False
340346
, setupCacheLock = Nothing
341347
, isInteractive = False
348+
, isMainLibOrExeComponent = False
342349
}
343350

344351
workingDir :: SetupScriptOptions -> FilePath
@@ -375,7 +382,9 @@ getSetup verbosity options mpkg = do
375382
(useCabalVersion options)
376383
(orLaterVersion (mkVersion (cabalSpecMinimumLibraryVersion (specVersion pkg))))
377384
}
378-
buildType' = buildType pkg
385+
buildType' = case (buildType pkg, isMainLibOrExeComponent options) of
386+
(Configure, True) -> Simple
387+
(bt, _) -> bt
379388
(version, method, options'') <-
380389
getSetupMethod verbosity options' pkg buildType'
381390
return

changelog.d/pr-10966.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
synopsis: Allow build-type: Configure
2+
packages: cabal-install
3+
prs: #10966
4+
issues: #4548
5+
significance: significant
6+
7+
description: {
8+
9+
This change allows the `build-type: Configure` field to be used in
10+
Cabal packages in conjunction with components. (E.g. public sublibraries).
11+
This is a significant change as it enables the use of the `Configure` build
12+
type, which cabal bailed on previously.
13+
14+
This does change the behaviour of cabal-install for packages that contain
15+
`build-type: Configure`. We now always build them as components with
16+
cabal-install. Previously we would turn packages with main libraries, and
17+
executables/benchmarks/tests-suites into a single package to be built in a
18+
compatibility mode. This is no longer the case.
19+
20+
}

0 commit comments

Comments
 (0)