Skip to content
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

Implement --{enable,disable}-executables #4660

Open
hvr opened this issue Aug 3, 2017 · 6 comments
Open

Implement --{enable,disable}-executables #4660

hvr opened this issue Aug 3, 2017 · 6 comments

Comments

@hvr
Copy link
Member

hvr commented Aug 3, 2017

This may have been subsumed by other tickets (e.g. #4087) but I figured it may be worth sketching a more modest enhancement which "completes" cabal's UI (scroll down for rationale):

What?

We already have the ability to enable/disable tests and benchmark, via

    --enable-tests                   Enable dependency checking and compilation
                                     for test suites listed in the package
                                     description file.
    --disable-tests                  Disable dependency checking and
                                     compilation for test suites listed in the
                                     package description file.

    --enable-benchmarks              Enable dependency checking and compilation
                                     for benchmarks listed in the package
                                     description file.
    --disable-benchmarks             Disable dependency checking and
                                     compilation for benchmarks listed in the
                                     package description file.

which translates to cabal.project files as

tests: True
benchmarks: False

package bar
  tests: False
  benchmarks: True

as well as the --constraint syntax to force the solver to enable tests/benchmarks

  --constraint="bar bench"
  --constraint="bar test"

(but I'm not sure this works properly in new-build btw; also I'm missing a no-bench/no-test token for symmetry)

What I'm suggesting now is to extend this logic to executable components, i.e.

    --enable-executables             Enable dependency checking and compilation
                                     for executables listed in the package
                                     description file.
    --disable-executables            Disable dependency checking and
                                     compilation for executables listed in the
                                     package description file.

and

  --constraint="bar exe"
  --constraint="bar no-exe"

as well as the respective executables: <bool> property for cabal.project files

The default settings would be:

  • executables are enabled by default for local packages (i.e. those specified via packages: ...)
  • executables are obviously enabled by default where they're needed to satisfy build-tool-depends goals
  • else, executables are disabled by default (e.g. when only the library of a package is requested via build-depends

Why?

Finally, the rationale for this feature request (beyond improving symmetry of executables w/ tests & benchmark) is the situation that you have packages which bundle libraries + executables to form the unit of distribution. This has become more attractive with new-build's per-component building, where you can depend on the library part of a package w/o cabal building all the executables (& their deps) as well.

However, cabal currently still has to solve for all executables even if all you ever need is the library component.

The library may often have a smaller dependency footprint and would therefore puts less pressure on the constraint solver.

However, the executables often have additional library dependencies, like e.g. optparse-applicative or even heavier dependencies (http libraries, GUI toolkits, terminal UI toolkits, etc).

So having to satisfy the executable's constraints provides no benefit for build-depends dependencies, and can instead result in the cabal solver not finding a solution, even though there would be if executables' constraints would have been ignored.

@grayjay
Copy link
Collaborator

grayjay commented Aug 26, 2017

@hvr #4087 should also allow cabal to skip building executables for non-local packages when they aren't needed as build tools. I was wondering how the two features should interact. Would it make sense for --enable-executables to force executables to be built but for --disable-executables to still allow executables to be built if they are needed as build tools? I'll probably start working on #4087 at the Haskell eXchange hackathon.

boj pushed a commit to alasconnect/servant-auth that referenced this issue Dec 15, 2017
Until something like haskell/cabal#4660 happens or we end up on a nixpkgs with the version we want in it.
@runeksvendsen
Copy link
Collaborator

I'd like to add another reason to the Why section:

Building and linking executables is slow. If I just want to run the test suite of my local library, there should be no need to wait until an otherwise unused executable is done building and linking.

@phadej
Copy link
Collaborator

phadej commented Jan 14, 2022

@runeksvendsen currently cabal solves for all executables, but doesn't build them. So your motivation point doesn't apply.

@runeksvendsen
Copy link
Collaborator

@phadej that's not the behaviour I'm seeing for cabal-install v3.6.2.0:

cabal file:

$ cat *.cabal
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.34.4.
--
-- see: https://github.com/sol/hpack

name:           test-cabal-build-execs
version:        0.1.0.0
description:    Please see the README on GitHub at <https://github.com/githubuser/test-cabal-build-execs#readme>
homepage:       https://github.com/githubuser/test-cabal-build-execs#readme
bug-reports:    https://github.com/githubuser/test-cabal-build-execs/issues
author:         Author name here
maintainer:     [email protected]
copyright:      2022 Author name here
license:        BSD3
license-file:   LICENSE
build-type:     Simple
extra-source-files:
    README.md
    ChangeLog.md

source-repository head
  type: git
  location: https://github.com/githubuser/test-cabal-build-execs

library
  exposed-modules:
      Lib
  other-modules:
      Paths_test_cabal_build_execs
  hs-source-dirs:
      src
  build-depends:
      base >=4.7 && <5
  default-language: Haskell2010

executable test-cabal-build-execs-exe
  main-is: Main.hs
  other-modules:
      Paths_test_cabal_build_execs
  hs-source-dirs:
      app
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , test-cabal-build-execs
  default-language: Haskell2010

test-suite test-cabal-build-execs-test
  type: exitcode-stdio-1.0
  main-is: Spec.hs
  other-modules:
      Paths_test_cabal_build_execs
  hs-source-dirs:
      test
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , test-cabal-build-execs
  default-language: Haskell2010

Building:

$ cabal build --enable-tests
Resolving dependencies...
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
 - test-cabal-build-execs-0.1.0.0 (lib) (first run)
 - test-cabal-build-execs-0.1.0.0 (test:test-cabal-build-execs-test) (first run)
 - test-cabal-build-execs-0.1.0.0 (exe:test-cabal-build-execs-exe) (first run)
Configuring library for test-cabal-build-execs-0.1.0.0..
Preprocessing library for test-cabal-build-execs-0.1.0.0..
Building library for test-cabal-build-execs-0.1.0.0..
[1 of 2] Compiling Lib              ( src/Lib.hs, /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/build/Lib.o, /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/build/Lib.dyn_o )
[2 of 2] Compiling Paths_test_cabal_build_execs ( /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/build/autogen/Paths_test_cabal_build_execs.hs, /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/build/Paths_test_cabal_build_execs.o, /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/build/Paths_test_cabal_build_execs.dyn_o )
Configuring test suite 'test-cabal-build-execs-test' for test-cabal-build-execs-0.1.0.0..
Configuring executable 'test-cabal-build-execs-exe' for test-cabal-build-execs-0.1.0.0..
Preprocessing test suite 'test-cabal-build-execs-test' for test-cabal-build-execs-0.1.0.0..
Building test suite 'test-cabal-build-execs-test' for test-cabal-build-execs-0.1.0.0..
Preprocessing executable 'test-cabal-build-execs-exe' for test-cabal-build-execs-0.1.0.0..
Building executable 'test-cabal-build-execs-exe' for test-cabal-build-execs-0.1.0.0..
[1 of 2] Compiling Main             ( app/Main.hs, /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/x/test-cabal-build-execs-exe/build/test-cabal-build-execs-exe/test-cabal-build-execs-exe-tmp/Main.o )
[1 of 2] Compiling Main             ( test/Spec.hs, /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/t/test-cabal-build-execs-test/build/test-cabal-build-execs-test/test-cabal-build-execs-test-tmp/Main.o )
[2 of 2] Compiling Paths_test_cabal_build_execs ( /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/x/test-cabal-build-execs-exe/build/test-cabal-build-execs-exe/autogen/Paths_test_cabal_build_execs.hs, /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/x/test-cabal-build-execs-exe/build/test-cabal-build-execs-exe/test-cabal-build-execs-exe-tmp/Paths_test_cabal_build_execs.o )
[2 of 2] Compiling Paths_test_cabal_build_execs ( /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/t/test-cabal-build-execs-test/build/test-cabal-build-execs-test/autogen/Paths_test_cabal_build_execs.hs, /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/t/test-cabal-build-execs-test/build/test-cabal-build-execs-test/test-cabal-build-execs-test-tmp/Paths_test_cabal_build_execs.o )
Linking /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/x/test-cabal-build-execs-exe/build/test-cabal-build-execs-exe/test-cabal-build-execs-exe ...
Linking /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/t/test-cabal-build-execs-test/build/test-cabal-build-execs-test/test-cabal-build-execs-test ...

Here's the above log with only lines relevant to the test-cabal-build-execs-exe executable:

Configuring executable 'test-cabal-build-execs-exe' for test-cabal-build-execs-0.1.0.0..
Preprocessing executable 'test-cabal-build-execs-exe' for test-cabal-build-execs-0.1.0.0..
Building executable 'test-cabal-build-execs-exe' for test-cabal-build-execs-0.1.0.0..
[1 of 2] Compiling Main             ( app/Main.hs, /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/x/test-cabal-build-execs-exe/build/test-cabal-build-execs-exe/test-cabal-build-execs-exe-tmp/Main.o )
[2 of 2] Compiling Paths_test_cabal_build_execs ( /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/x/test-cabal-build-execs-exe/build/test-cabal-build-execs-exe/autogen/Paths_test_cabal_build_execs.hs, /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/x/test-cabal-build-execs-exe/build/test-cabal-build-execs-exe/test-cabal-build-execs-exe-tmp/Paths_test_cabal_build_execs.o )
Linking /Users/rune/tmp/test-cabal-build-execs/dist-newstyle/build/x86_64-osx/ghc-8.10.7/test-cabal-build-execs-0.1.0.0/x/test-cabal-build-execs-exe/build/test-cabal-build-execs-exe/test-cabal-build-execs-exe ...

@Mikolaj
Copy link
Member

Mikolaj commented Jan 15, 2022

I thought @phadej meant cabal test or cabal bench?

@phadej
Copy link
Collaborator

phadej commented Jan 15, 2022

I meant dependencies, i.e. libraries on Hackage.

For local packages use cabal build libs etc target selectors to build only what you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants