commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
4k stars 843 forks source link

Stack for Linux AArch64 (ARM64) #5709

Closed dboreham closed 8 months ago

dboreham commented 2 years ago

Apologies, I see from the history that this has come up again and again. I'd like to understand the state of Stack for ARM64. I'm attempting to use Ubuntu rather than macos.

When I follow the batteries included instructions I get this:

$ curl -sSL https://get.haskellstack.org/ | sh
Detected Linux distribution: ubuntu

Sorry, currently only 64-bit (x86_64) Linux binary is available.

But I can see from various issues and posts that there is a GHC for ARM64, and there's even a CI job for Stack on ARM64: https://github.com/commercialhaskell/stack/actions/workflows/arm64-release.yml and also binary packages shipped in this release : https://github.com/commercialhaskell/stack/releases/tag/v2.7.1 (although internet lore claims they don't work).

I suppose I'm wondering what's the gap between the things that exist and get.haskellstack.org working above? Is there a mailing list, forum or somewhere that I can read to catch up? Also if I can help or contribute to make this happen I'm happy to do that. Thanks, hope this makes sense.

francesquini commented 1 year ago

@mpilgrem Indeed the problem was with RIO, in particular, with the atomic variants of writeBinaryFile....

I executed the following code on my machine:

{-# LANGUAGE NoImplicitPrelude #-}

module Main (main) where

import RIO
import RIO.File
import RIO.ByteString

main :: IO ()
main = do
  writeBinaryFile "writeBinaryFile.txt" bs
  writeBinaryFileAtomic "writeBinaryFileAtomic.txt" bs
  writeBinaryFileDurable "writeBinaryFileDurable.txt" bs
  writeBinaryFileDurableAtomic "writeBinaryFileDurableAtomic.txt" bs
  where
    bs = pack [65 .. 75]

On the 'PRoot' system, I got:

emilio@localhost:~/testrio$ ls -l
total 1312
-rwxr-xr-x. 1 emilio emilio 1334440 Dec 28 15:18 testerio-exe
-rw-rw-r--. 1 emilio emilio      11 Dec 28 15:20 writeBinaryFile.txt
-rw-rw-rw-. 1 emilio emilio       0 Dec 28 15:20 writeBinaryFileAtomic.txt
-rw-rw-r--. 1 emilio emilio      11 Dec 28 15:20 writeBinaryFileDurable.txt
-rw-rw-rw-. 1 emilio emilio       0 Dec 28 15:20 writeBinaryFileDurableAtomic.txt

On the other ARM64 machine, all files have 11 bytes each, as expected.

Fortunately, Stack source code concentrates all calls to writeBinaryFileAtomic to a reexported function from Stack's own prelude: https://github.com/commercialhaskell/stack/blob/503ef2433157ab076f5beba709a15aff10eef923/src/Stack/Prelude.hs#L293-L296

After modifying line 296 to:

withBinaryFile (toFilePath fp) WriteMode (`hPutBuilder` builder)

or to withBinaryFileDurable, everything works as expected.

I'll open an issue for the maintainers of RIO, however, for stack itself some questions remain.

Is the use of atomic really necessary? Wouldn't durable (or even the regular version) be enough?

francesquini commented 1 year ago

Issue regarding the unexpected behavior above: https://github.com/fpco/unliftio/issues/107

mpilgrem commented 8 months ago

I am going to close this 'general' issue, having separated out @francesquini's PRoot-related problem.