Help with generating versioned release artifacts

Hi,

I am trying to generate release artifacts for my Haskell project as a part of CI using Github Actions.
I’d like the artifacts to have the version number in the file name, e.g.
<mypackage>-<version>.tar.gz, and <mypackage>-<version> (for the exe)

For sources release, cabal sdist works well, it creates <mypackage>-<version>.tar.gz.

However cabal install does not append the version suffix to the target exe.
There is an option to manually specify the suffix using --program-suffix, but I’d like the version of the package to be picked up from the cabal file automatically.

I’ve searched everywhere but have not been able to find a way to do this. It is a bit surprising that cabal sdist is able to append the version suffix, but not so cabal install

Am I missing something?

I don’t think cabal built executable are meant for distribution in that form. And it likely won’t work for dynamically linked executables on Linux well anyway.

For static ones this can work. But then jsut zip them into a pkg-version.zip for distribution. We don’t usually rename executables by version. Your package manager likely doesn’t either. It versioned the container but not the executable itself (at least not in its name).

EDIT: we could hypothetically expect a cabal bindist command to produce a versioned .zip with of a binary distributable thought.

4 Likes

+1 for cabal bindist

1 Like

I would recommend against using cabal install for this. Instead you can do a normal cabal build followed by copying the executable into the right place with the right name. For example on GitHub Actions you might do:

- run: cp "$( cabal list-bin your-executable )" somewhere/your-executable-${{ github.event.release.tag_name }}

The specifics may vary for your use case, but that’s what I do to produce executables for my Rattletrap project.

7 Likes

@taylorfausak, thanks; I did not know about the --list-bin flag. I distribute precompiled binaries so I decided to use this flag in my work flows instead of first installing into ~/.cabal/bin and then copying further from there. Since I used --enable-executable-stripping during install I was wondering if cabal build would accept this flag and it does indeed. However, it does not strip the built executable at the end. While I can see some reasons for not stripping during build but then why accept the flag at all?

I still am going to use the --list-bin flag but thought that my observation could be useful for others.

I tested this with cabal-install version 3.10.1.0.

I haven’t checked to see if Cabal is stripping my executables. I use the svenstaro/upx-action action, which strips the executables and compresses them with UPX.

I think Cabal is supposed to strip executables by default. But you could try passing --enable-executable-stripping to cabal configure just to be sure.