Tuesday, November 22, 2022

Statically linked binaries with Haskell GHC

TL;DR Use AppImage

I am working on a nostr-project Futr written in Haskell. Since I don't want users of the application to install a bunch of dependencies manually upfront in order to use it, I digged deep into statically linking binaries with Haskell. I tried the nix build system, which didn't bring me to success, I only lost many many hours recompiling the same things again and again. My main requirements are secp256k1 (C-lib), glew and SDL2 (for monomer). What should have been "a not too hard task to solve" took me actually several weeks to find out. So I gave AppImage a try and it worked great basically from the first try on.

It'a two-step-process

1) Compile the haskell binary as usual
2) Build the AppImage

The resulting binary can then be shipped to the users. Compilation first (I'm using stack here): `stack build` - that part was easy!

First I need a build directory, my application is called "futr", so I name the directory "futr.AppDir". Within there I need two files:

"AppRun":
#!/bin/sh
SELF=$(readlink -f "$0")
HERE=${SELF%/*}
EXEC="${HERE}/usr/bin/futr"
exec "${EXEC}"
and "futr.desktop":
[Desktop Entry]
Name=futr
Exec=futr
Icon=futr-icon
Type=Application
Categories=Network
X-AppImage-Version=4702f2f


The latter is "only" for the desktop entry. Okay, so my binary requires some assets to live alongside the binary in the same directory, so let's add those:
cp -R assets futr.AppDir/usr/bin
cp assets/icons/futr-icon.png futr.AppDir


And all there is left is to create the final AppImage:
APPIMAGE_EXTRACT_AND_RUN=1 linuxdeploy-x86_64.AppImage --appdir futr.AppDir
ARCH=x86_64 appimagetool-x86_64.AppImage futr.AppDir


My project already uses Github Action, so I can automate the whole process and attach a binary to each release. Check the repository for the configuration: Futr Github Action

9 comments:

  1. As a statistics project helper, I appreciate the in-depth explanation of statically linked binaries with Haskell GHC. This information will undoubtedly be useful to many programmers and developers out there looking to optimize their workflow and improve the efficiency of their projects.

    ReplyDelete
  2. Use Stack, Stack is a popular Haskell build tool that simplifies managing dependencies and building projects like freebase vape. Ensure you have Stack installed on your system.

    ReplyDelete
  3. Apply Stack, A well-liked Haskell build tool called Stack makes it easier to manage dependencies and build projects like come close vr. Make sure Stack is set up on your computer.

    ReplyDelete
  4. It's always frustrating when what seems like a simple task becomes a time-consuming headache. Statically linking binaries with Haskell can be a challenge, but it's great that you found success with AppImage. It's impressive how technology has made it possible to create applications without requiring users to manually install dependencies. On a completely different topic, if you're considering a cosmetic procedure like Buccal Fat Removal Dubai, be sure to do your research and consult with a qualified professional.

    ReplyDelete
  5. Statically linked binaries with Haskell GHC offer enhanced portability and ease of deployment. By eliminating external dependencies, these binaries become self-contained and resilient, resembling waterproof stickers that withstand any environment. This empowers developers to confidently distribute their Haskell applications, ensuring seamless execution across diverse systems. The resulting convenience and reliability make statically linked Haskell GHC binaries a valuable asset for developers and users alike.





    ReplyDelete
  6. Statically linked binaries with Haskell GHC offer a reliable solution for software deployment. By eliminating external dependencies, the resulting executables become portable and efficient, ensuring compatibility across platforms. This advancement could greatly benefit a basement waterproofing company in Farmington Hills, enhancing their software's performance and ease of installation. With statically linked binaries, the company can streamline their operations and focus on delivering exceptional services to their customers without worrying about compatibility issues.





    ReplyDelete
  7. For those seeking efficient and self-contained software deployments, statically linked binaries offer a reliable solution. When using the Haskell GHC compiler, it becomes possible to create such binaries, which contain all necessary libraries and dependencies, eliminating the need for external installations. This blog post explores the advantages and considerations of utilizing statically linked binaries with Haskell GHC, providing valuable insights for developers and enthusiasts. Additionally, if you're in need of professional WordPress web design services, our team of experts can create visually stunning and highly functional websites tailored to your specific needs. From custom themes to responsive layouts, our WordPress web design services ensure a seamless online presence for your business or personal brand.

    ReplyDelete
  8. Statically linked binaries with Haskell GHC provide numerous advantages, including portability and ease of deployment. By eliminating external dependencies, these binaries ensure consistent performance across different environments. Whether it's developing software or delivering reliable services like Basement Waterproofing Services in Clarkston, Haskell GHC's statically linked binaries offer a solid foundation for efficient and secure applications.




    ReplyDelete
  9. IT Solutions provider company in USA
    Esclatech stands as a prominent IT solutions provider company based in the bustling city of Houston, USA. With a dedicated focus on catering to diverse digital needs, we offer an extensive array of services tailored to elevate your online presence and drive business success.

    ReplyDelete