Skip to content

Commit b7ed37b

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 3666842 commit b7ed37b

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
@@ -300,6 +300,7 @@ configureSetupScript
300300
, useDependenciesExclusive = not defaultSetupDeps && isJust explicitSetupDeps
301301
, useVersionMacros = not defaultSetupDeps && isJust explicitSetupDeps
302302
, isInteractive = False
303+
, isMainLibOrExeComponent = True
303304
}
304305
where
305306
-- 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
@@ -1826,14 +1826,18 @@ elaborateInstallPlan
18261826
-- invocation of the same `./configure` script.
18271827
-- See https://github.com/haskell/cabal/issues/4548
18281828
--
1829-
-- Moreover, at this point in time, only non-Custom setup scripts
1830-
-- are supported. Implementing per-component builds with
1831-
-- Custom would require us to create a new 'ElabSetup'
1829+
-- We have to disable per-component at this point in time, only
1830+
-- Simple and Configure build types are supported. Custom and
1831+
-- Hooks are not implemented. Implementing per-component builds
1832+
-- with Custom would require us to create a new 'ElabSetup'
18321833
-- type, and teach all of the code paths how to handle it.
18331834
-- Once you've implemented this, swap it for the code below.
18341835
cuz_buildtype =
18351836
case bt of
1836-
PD.Configure -> [CuzBuildType CuzConfigureBuildType]
1837+
PD.Configure -> []
1838+
-- Configure is supported, but we only support configuring the
1839+
-- main library in cabal. Other components will need to depend
1840+
-- on the main library for configured data.
18371841
PD.Custom -> [CuzBuildType CuzCustomBuildType]
18381842
PD.Hooks -> [CuzBuildType CuzHooksBuildType]
18391843
PD.Make -> [CuzBuildType CuzMakeBuildType]
@@ -4028,6 +4032,16 @@ setupHsScriptOptions
40284032
, forceExternalSetupMethod = isParallelBuild
40294033
, setupCacheLock = Just cacheLock
40304034
, isInteractive = False
4035+
, isMainLibOrExeComponent = case elabPkgOrComp of
4036+
-- if it's a package, it's all together, so we have to assume it's
4037+
-- at least a library or executable.
4038+
ElabPackage _ -> True
4039+
-- if it's a component, we have to check if it's a Main Library or Executable
4040+
-- as opposed to SubLib, FLib, Test, Bench, or Setup component.
4041+
ElabComponent (ElaboratedComponent{compSolverName = CD.ComponentLib}) -> True
4042+
ElabComponent (ElaboratedComponent{compSolverName = CD.ComponentExe _}) -> True
4043+
-- everything else is not a main lib or exe component
4044+
ElabComponent _ -> False
40314045
}
40324046

40334047
-- | 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
@@ -314,6 +314,12 @@ data SetupScriptOptions = SetupScriptOptions
314314
-- ^ Is the task we are going to run an interactive foreground task,
315315
-- or an non-interactive background task? Based on this flag we
316316
-- decide whether or not to delegate ctrl+c to the spawned task
317+
, isMainLibOrExeComponent :: Bool
318+
-- ^ Let the setup script logic know if it is being run to build a main
319+
-- library or executable component. This is used to determine if we should
320+
-- use the configure command, if the build-type is 'Configure'. For
321+
-- configure, only the main library and execomponents have 'configure'
322+
-- support, and thus we can skip running configure for other components.
317323
}
318324

319325
defaultSetupScriptOptions :: SetupScriptOptions
@@ -338,6 +344,7 @@ defaultSetupScriptOptions =
338344
, forceExternalSetupMethod = False
339345
, setupCacheLock = Nothing
340346
, isInteractive = False
347+
, isMainLibOrExeComponent = True
341348
}
342349

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