Skip to content

Commit b9ff22d

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 96ce5a8 commit b9ff22d

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
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 = True
302303
}
303304
where
304305
-- When we are compiling a legacy setup script without an explicit

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,14 +1717,18 @@ elaborateInstallPlan
17171717
-- invocation of the same `./configure` script.
17181718
-- See https://github.com/haskell/cabal/issues/4548
17191719
--
1720-
-- Moreover, at this point in time, only non-Custom setup scripts
1721-
-- are supported. Implementing per-component builds with
1722-
-- Custom would require us to create a new 'ElabSetup'
1720+
-- We have to disable per-component at this point in time, only
1721+
-- Simple and Configure build types are supported. Custom and
1722+
-- Hooks are not implemented. Implementing per-component builds
1723+
-- with Custom would require us to create a new 'ElabSetup'
17231724
-- type, and teach all of the code paths how to handle it.
17241725
-- Once you've implemented this, swap it for the code below.
17251726
cuz_buildtype =
17261727
case bt of
1727-
PD.Configure -> [CuzBuildType CuzConfigureBuildType]
1728+
PD.Configure -> []
1729+
-- Configure is supported, but we only support configuring the
1730+
-- main library in cabal. Other components will need to depend
1731+
-- on the main library for configured data.
17281732
PD.Custom -> [CuzBuildType CuzCustomBuildType]
17291733
PD.Hooks -> [CuzBuildType CuzHooksBuildType]
17301734
PD.Make -> [CuzBuildType CuzMakeBuildType]
@@ -3878,6 +3882,16 @@ setupHsScriptOptions
38783882
, forceExternalSetupMethod = isParallelBuild
38793883
, setupCacheLock = Just cacheLock
38803884
, isInteractive = False
3885+
, isMainLibOrExeComponent = case elabPkgOrComp of
3886+
-- if it's a package, it's all together, so we have to assume it's
3887+
-- at least a library or executable.
3888+
ElabPackage _ -> True
3889+
-- if it's a component, we have to check if it's a Main Library or Executable
3890+
-- as opposed to SubLib, FLib, Test, Bench, or Setup component.
3891+
ElabComponent (ElaboratedComponent{compSolverName = CD.ComponentLib}) -> True
3892+
ElabComponent (ElaboratedComponent{compSolverName = CD.ComponentExe _}) -> True
3893+
-- everything else is not a main lib or exe component
3894+
ElabComponent _ -> False
38813895
}
38823896

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

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

Lines changed: 15 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 main
320+
-- library or executable component. This is used to determine if we should
321+
-- use the configure command, if the build-type is 'Configure'. For
322+
-- configure, only the main library and execomponents have 'configure'
323+
-- support, and thus we can 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 = True
342349
}
343350

344351
workingDir :: SetupScriptOptions -> FilePath
@@ -375,7 +382,14 @@ getSetup verbosity options mpkg = do
375382
(useCabalVersion options)
376383
(orLaterVersion (mkVersion (cabalSpecMinimumLibraryVersion (specVersion pkg))))
377384
}
378-
buildType' = buildType pkg
385+
-- We retain Configure only for the main library and executable components.
386+
-- For other components, we rewrite the buildType to Simple to skip the
387+
-- configure step. This is because the configure step is not supported for
388+
-- other components. Configure can only impact MainLib and Exe through
389+
-- .buildinfo files.
390+
buildType' = case (buildType pkg, isMainLibOrExeComponent options) of
391+
(Configure, False) -> Simple
392+
(bt, _) -> bt
379393
(version, method, options'') <-
380394
getSetupMethod verbosity options' pkg buildType'
381395
return

cabal-testsuite/PackageTests/Configure/cabal.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Configuration is affected by the following files:
44
Resolving dependencies...
55
Build profile: -w ghc-<GHCVER> -O1
66
In order, the following will be built:
7-
- zlib-1.1 (lib:zlib) (first run)
8-
Configuring zlib-1.1...
7+
- zlib-1.1 (lib) (first run)
8+
Configuring library for zlib-1.1...
99
Warning: Flags 'con_flict', 'con-flict' all map to the same environment variable 'CABAL_FLAG_con_flict' causing a collision. The value first flag 'con_flict' will be used.
1010
Preprocessing library for zlib-1.1...
1111
Building library for zlib-1.1...

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)