executable-hash

Provides the SHA1 hash of the program executable

http://github.com/fpco/executable-hash

Version on this page:0.2.0.0
LTS Haskell 22.14:0.2.0.4
Stackage Nightly 2024-03-28:0.2.0.4
Latest on Hackage:0.2.0.4

See all snapshots executable-hash appears in

MIT licensed by Michael Sloan
Maintained by FP Complete
This version can be pinned in stack with:executable-hash-0.2.0.0@sha256:5904d9eb4e5bc7ff1e0f86c6bf33bb1618c8b2bcd1cb4f99e337d67289aea988,2205

Module documentation for 0.2.0.0

executable-hash

Provides the SHA1 hash of the executable. This hash can either be injected into the executable as a step after compilation, or calculated at runtime.

Usage

The main function expected to be used by the user is System.Executable.Hash.executableHash. When used in a TH splice, like $(executableHash), the resulting expression yields a SHA1 hash determined by the contents of the executable. However, note that this may not be the actual SHA1 of the executable, since the hash can be injected into the executable (which changes its “actual” hash).

Installing this package will also install the inject-executable-hash executable. Running this program on a binary, like inject-executable-hash <binary-name> will replace a dummy ByteString (via the file-embed package) in the binary with its hash.

Alternatively, you can put this in a Setup.hs file, and set build-type: Custom in your .cabal:

import Distribution.Simple
import System.Executable.Hash.Internal (maybeInjectExecutableHash)

main :: IO ()
main = defaultMainWithHooks $ simpleUserHooks
    { postBuild = \_ _ _ _ ->
        maybeInjectExecutableHash "dist/build/path-to/your-executable"
    }

(Note: you’ll need to change the executable path)

Changes

0.2.0.0

In order to support dynamic linking, executableHash and injectedExecutableHash now need to be run in TH splices. Before this change, the library was assuming that it would be statically linked, such that the file-embed dummy bytestring would be present in the executable.

See this github issue.

0.1.1.1

First public version