MyNixOS website logo
Description

Custom Setup to automate package modules discovery.

Custom Setup to automate package modules discovery. See README for more details.

autopack

logo GitHub CI Build status Windows build status

Hackage Stackage Lts Stackage Nightly MPL-2.0 license

Custom Setup to automate package modules discovery.

⚠️ WARNING:autopack is in early beta phase. ⚠️

Motivation

Usually, when working on a Haskell project, you end up having lots of modules. During the development, you can add, remove or rename any of them. And this is fine unless you continuously need remembering to add, remove or rename the corresponding module line in the .cabal file. Sometimes all you want is to make Cabal dealing with it, so you won't need to patch any files when performing any operations on modules. Good news, everyone! This project was created precisely to help to solve this particular issue.

How does autopack work

autopack is a Haskell library that provides custom setup functions that discover all exposed .hs files for your library from the hs-source-dirs folders. It uses this information to prehook the list of identified modules into the exposed-modules field of the library stanza of your package description.

You can use Cabal's custom setup scripts to use this library in your project. In the next section, we are going to give detailed instructions on that.

For now, all you need to keep in mind to use autopack:

  • It uses hs-source-dirs field to establish where to look up for modules.
  • It can work only with .hs extension at the moment.
  • It adds all discovered modules into exposed-modules of the library stanza.
  • If there are already some modules in the exposed-modules, autopack will concatenate lists.

How to use autopack

First, make sure that you are using the Cabal version at least 2.0 in your .cabal file. For example:

cabal-version:       2.4

Now you need to change the build-type field in your package_name.cabal file to Custom instead of the default Simple:

build-type:    Custom

Then you have to add custom-setup section before you defining your library stanza. It should have the autopack dependency so you can use it in your Setup:

custom-setup
    setup-depends: base
                 , autopack

And the final preparation. You should add the Setup.hs module (or replace the default one) in the root directory of the package with the following content:

import Autopack (defaultMainAutoModules)


main :: IO ()
main = defaultMainAutoModules

You are all set up now!

You can remove exposed-module field from your .cabal file completely, and autopack will discover all the .hs modules in your folders for you during the build.

Alternatives

As Cabal does not currently provide the feature of automatic modules discovery, there are some workarounds for this process. One of them is this library — autopack that uses Cabal's Setup feature to discover all modules during the pre-build stage of Cabal. Another tool that provides it out-of-the-box is hpack. It is the wrapper on Cabal syntax via YAML where there is no need to write modules explicitly. They are added to the exposed-modules field of the .cabal file during the YAML to .cabal step of the tool work process.

Acknowledgement

Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY.

Metadata

Version

0.0.0.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows