Skip to content

Instantly share code, notes, and snippets.

@lspitzner
Created July 24, 2015 13:48
Show Gist options
  • Save lspitzner/57b1ea39fd00a9d1cf5e to your computer and use it in GitHub Desktop.
Save lspitzner/57b1ea39fd00a9d1cf5e to your computer and use it in GitHub Desktop.
cabal-install common subcommands
The most common thing is to install a library (so your project can use it) or
an executable (like when you install `hoogle` so you can search documentation
locally). Behind the scenes, this involves a number of steps:
1. determine package version plan (a consistent Set (Library,Version))
2. download dependencies (i.e. their source)
3. install dependencies (i.e. do steps 1-6a for each dependency)
4. configure (think: what to build in which order, with which compiler flags etc.)
5. build
6a. register (libraries) in package repository
6b. copy the compiled (executables?) to destination directory
You might say: That sounds all reasonable, but why not wrap that in one command
and hide the details? There are two answers: Yes, this is exactly what
`cabal install` does: It includes all the above steps. The seconds answers is
that all steps take time, and during development, you do not need to execute
each step every time you make a change (e.g. when you change a few lines in
your project, you do not need to install new dependencies, or change the
configuration). That is why the user gets access to sub-commands that map
to certain steps above.
Some subcommands even allow different steps:
2c. export the install plan
5d. run directly / load in repl / run tests / run benchmark
The most important subcommands are:
1. `install --only-dependencies`, or `install --dep` for short, or `install --dep --enable-tests`
2. `configure`, optionally with flags such as `configure -ffoo` or `configure --enable-tests`
3. `build`
4. `run`, `test` and `repl`
5. `install` (which is necessary surprisingly rarely; mostly you need only install dependencies).
The table shows how some sub-commands map to the above steps.
> x: always done
> m: maybe; depends on circumstances/flags
> d: this is required as precondition
dl conf reg exp
plan inst build copy run
1 2 3 4 5 6a 6a 2c 5d
freeze x x (after freeze, the Set is constant, thus the `m`s in the 1 column)
fetch m x
install --only-deps m x x (this involves 4 5 6a for deps)
configure d x
build d x
repl/run/bench/test d dm m x (tests/benchmarks might have additional dependencies; sometimes there is auto-reconf, sometimes there is not)
copy d x
register d x
install m x x x x x x
As you can see, the mapping is rather straightforward; only `install` does
a lot more, or less, depending on flags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment