well-typed / cborg

Binary serialisation in the CBOR format
https://hackage.haskell.org/package/cborg
191 stars 86 forks source link

Build failure on AArch64 #276

Closed georgefst closed 2 years ago

georgefst commented 2 years ago

Setting -f -optimize-gmp doesn't make any difference. Neither do all the other flags that I usually pass when cross-compiling (--disable-shared, --with-ghc-pkg, --with-gcc etc.). So I've left them all off to keep things simple.

The GHC here was built with ghcup compile ghc -v 9.2.1 -b 8.10.7 -x aarch64-none-linux-gnu -c $(pwd)/build.mk, with a toolchain from https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads, and build.mk containing:

V=0
BUILD_MAN = NO
BUILD_SPHINX_HTML = NO
BUILD_SPHINX_PDF = NO

Stage1Only = YES
HADDOCK_DOCS = NO
BuildFlavour = quick
WITH_TERMINFO = NO

BIGNUM_BACKEND = native

Building cborg fails:

$ cabal build cborg -w aarch64-none-linux-gnu-ghc-9.2.1
Resolving dependencies...
Build profile: -w ghc-9.2.1 -O1
In order, the following will be built (use -v for more details):
 - cborg-0.2.5.0 (lib) (configuration changed)
Configuring library for cborg-0.2.5.0..
Preprocessing library for cborg-0.2.5.0..
Building library for cborg-0.2.5.0..
[ 1 of 14] Compiling Codec.CBOR.ByteArray.Internal ( src/Codec/CBOR/ByteArray/Internal.hs, /home/gthomas/code/cborg/dist-newstyle/build/aarch64-linux/ghc-9.2.1/cborg-0.2.5.0/build/Codec/CBOR/ByteArray/Internal.o ) [flags changed]
[ 2 of 14] Compiling Codec.CBOR.ByteArray.Sliced ( src/Codec/CBOR/ByteArray/Sliced.hs, /home/gthomas/code/cborg/dist-newstyle/build/aarch64-linux/ghc-9.2.1/cborg-0.2.5.0/build/Codec/CBOR/ByteArray/Sliced.o ) [flags changed]

src/Codec/CBOR/ByteArray/Sliced.hs:44:1: warning: [-Wunused-imports]
    The qualified import of ‘Data.ByteString.Short.Internal’ is redundant
      except perhaps to import instances from ‘Data.ByteString.Short.Internal’
    To import instances alone, use: import Data.ByteString.Short.Internal()
   |
44 | import qualified Data.ByteString.Short.Internal as BSS
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ 3 of 14] Compiling Codec.CBOR.ByteArray ( src/Codec/CBOR/ByteArray.hs, /home/gthomas/code/cborg/dist-newstyle/build/aarch64-linux/ghc-9.2.1/cborg-0.2.5.0/build/Codec/CBOR/ByteArray.o ) [flags changed]

src/Codec/CBOR/ByteArray.hs:39:1: warning: [-Wunused-imports]
    The qualified import of ‘Data.ByteString.Short.Internal’ is redundant
      except perhaps to import instances from ‘Data.ByteString.Short.Internal’
    To import instances alone, use: import Data.ByteString.Short.Internal()
   |
39 | import qualified Data.ByteString.Short.Internal as BSS
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ 4 of 14] Compiling Codec.CBOR.Decoding ( src/Codec/CBOR/Decoding.hs, /home/gthomas/code/cborg/dist-newstyle/build/aarch64-linux/ghc-9.2.1/cborg-0.2.5.0/build/Codec/CBOR/Decoding.o ) [flags changed]
[ 5 of 14] Compiling Codec.CBOR.Encoding[boot] ( src/Codec/CBOR/Encoding.hs-boot, /home/gthomas/code/cborg/dist-newstyle/build/aarch64-linux/ghc-9.2.1/cborg-0.2.5.0/build/Codec/CBOR/Encoding.o-boot )
[ 6 of 14] Compiling Codec.CBOR.FlatTerm[boot] ( src/Codec/CBOR/FlatTerm.hs-boot, /home/gthomas/code/cborg/dist-newstyle/build/aarch64-linux/ghc-9.2.1/cborg-0.2.5.0/build/Codec/CBOR/FlatTerm.o-boot )
[ 7 of 14] Compiling Codec.CBOR.Encoding ( src/Codec/CBOR/Encoding.hs, /home/gthomas/code/cborg/dist-newstyle/build/aarch64-linux/ghc-9.2.1/cborg-0.2.5.0/build/Codec/CBOR/Encoding.o ) [flags changed]
[ 8 of 14] Compiling Codec.CBOR.Magic ( src/Codec/CBOR/Magic.hs, /home/gthomas/code/cborg/dist-newstyle/build/aarch64-linux/ghc-9.2.1/cborg-0.2.5.0/build/Codec/CBOR/Magic.o )

src/Codec/CBOR/Magic.hs:194:20: error:
    • Couldn't match expected type ‘Word16#’ with actual type ‘Word8#’
    • In the first argument of ‘W16#’, namely ‘w0#’
      In the first argument of ‘unsafeShiftL’, namely ‘W16# w0#’
      In the first argument of ‘(.|.)’, namely
        ‘W16# w0# `unsafeShiftL` 8’
    |
194 |        w1# -> W16# w0# `unsafeShiftL` 8 .|.
    |                    ^^^

src/Codec/CBOR/Magic.hs:195:20: error:
    • Couldn't match expected type ‘Word16#’ with actual type ‘Word8#’
    • In the first argument of ‘W16#’, namely ‘w1#’
      In the second argument of ‘(.|.)’, namely ‘W16# w1#’
      In the expression: W16# w0# `unsafeShiftL` 8 .|. W16# w1#
    |
195 |               W16# w1#
    |                    ^^^

src/Codec/CBOR/Magic.hs:205:24: error:
    • Couldn't match expected type ‘Word32#’ with actual type ‘Word8#’
    • In the first argument of ‘W32#’, namely ‘w0#’
      In the first argument of ‘unsafeShiftL’, namely ‘W32# w0#’
      In the first argument of ‘(.|.)’, namely
        ‘W32# w0# `unsafeShiftL` 24’
    |
205 |            w3# -> W32# w0# `unsafeShiftL` 24 .|.
    |                        ^^^

src/Codec/CBOR/Magic.hs:206:24: error:
    • Couldn't match expected type ‘Word32#’ with actual type ‘Word8#’
    • In the first argument of ‘W32#’, namely ‘w1#’
      In the first argument of ‘unsafeShiftL’, namely ‘W32# w1#’
      In the second argument of ‘(.|.)’, namely
        ‘W32# w1# `unsafeShiftL` 16’
    |
206 |                   W32# w1# `unsafeShiftL` 16 .|.
    |                        ^^^

src/Codec/CBOR/Magic.hs:207:24: error:
    • Couldn't match expected type ‘Word32#’ with actual type ‘Word8#’
    • In the first argument of ‘W32#’, namely ‘w2#’
      In the first argument of ‘unsafeShiftL’, namely ‘W32# w2#’
      In the second argument of ‘(.|.)’, namely
        ‘W32# w2# `unsafeShiftL` 8’
    |
207 |                   W32# w2# `unsafeShiftL`  8 .|.
    |                        ^^^

src/Codec/CBOR/Magic.hs:208:24: error:
    • Couldn't match expected type ‘Word32#’ with actual type ‘Word8#’
    • In the first argument of ‘W32#’, namely ‘w3#’
      In the second argument of ‘(.|.)’, namely ‘W32# w3#’
      In the expression:
        W32# w0# `unsafeShiftL` 24 .|. W32# w1# `unsafeShiftL` 16
          .|. W32# w2# `unsafeShiftL` 8
          .|. W32# w3#
    |
208 |                   W32# w3#
    |                        ^^^

src/Codec/CBOR/Magic.hs:226:29: error:
    • Couldn't match expected type ‘Word#’ with actual type ‘Word8#’
    • In the first argument of ‘w’, namely ‘w0#’
      In the first argument of ‘unsafeShiftL’, namely ‘w w0#’
      In the first argument of ‘(.|.)’, namely ‘w w0# `unsafeShiftL` 56’
    |
226 |                    w7# -> w w0# `unsafeShiftL` 56 .|.
    |                             ^^^

src/Codec/CBOR/Magic.hs:227:29: error:
    • Couldn't match expected type ‘Word#’ with actual type ‘Word8#’
    • In the first argument of ‘w’, namely ‘w1#’
      In the first argument of ‘unsafeShiftL’, namely ‘w w1#’
      In the second argument of ‘(.|.)’, namely ‘w w1# `unsafeShiftL` 48’
    |
227 |                           w w1# `unsafeShiftL` 48 .|.
    |                             ^^^

src/Codec/CBOR/Magic.hs:228:29: error:
    • Couldn't match expected type ‘Word#’ with actual type ‘Word8#’
    • In the first argument of ‘w’, namely ‘w2#’
      In the first argument of ‘unsafeShiftL’, namely ‘w w2#’
      In the second argument of ‘(.|.)’, namely ‘w w2# `unsafeShiftL` 40’
    |
228 |                           w w2# `unsafeShiftL` 40 .|.
    |                             ^^^

src/Codec/CBOR/Magic.hs:229:29: error:
    • Couldn't match expected type ‘Word#’ with actual type ‘Word8#’
    • In the first argument of ‘w’, namely ‘w3#’
      In the first argument of ‘unsafeShiftL’, namely ‘w w3#’
      In the second argument of ‘(.|.)’, namely ‘w w3# `unsafeShiftL` 32’
    |
229 |                           w w3# `unsafeShiftL` 32 .|.
    |                             ^^^

src/Codec/CBOR/Magic.hs:230:29: error:
    • Couldn't match expected type ‘Word#’ with actual type ‘Word8#’
    • In the first argument of ‘w’, namely ‘w4#’
      In the first argument of ‘unsafeShiftL’, namely ‘w w4#’
      In the second argument of ‘(.|.)’, namely ‘w w4# `unsafeShiftL` 24’
    |
230 |                           w w4# `unsafeShiftL` 24 .|.
    |                             ^^^

src/Codec/CBOR/Magic.hs:231:29: error:
    • Couldn't match expected type ‘Word#’ with actual type ‘Word8#’
    • In the first argument of ‘w’, namely ‘w5#’
      In the first argument of ‘unsafeShiftL’, namely ‘w w5#’
      In the second argument of ‘(.|.)’, namely ‘w w5# `unsafeShiftL` 16’
    |
231 |                           w w5# `unsafeShiftL` 16 .|.
    |                             ^^^

src/Codec/CBOR/Magic.hs:232:29: error:
    • Couldn't match expected type ‘Word#’ with actual type ‘Word8#’
    • In the first argument of ‘w’, namely ‘w6#’
      In the first argument of ‘unsafeShiftL’, namely ‘w w6#’
      In the second argument of ‘(.|.)’, namely ‘w w6# `unsafeShiftL` 8’
    |
232 |                           w w6# `unsafeShiftL`  8 .|.
    |                             ^^^

src/Codec/CBOR/Magic.hs:233:29: error:
    • Couldn't match expected type ‘Word#’ with actual type ‘Word8#’
    • In the first argument of ‘w’, namely ‘w7#’
      In the second argument of ‘(.|.)’, namely ‘w w7#’
      In the expression:
        w w0# `unsafeShiftL` 56 .|. w w1# `unsafeShiftL` 48
          .|. w w2# `unsafeShiftL` 40
          .|. w w3# `unsafeShiftL` 32
          .|. w w4# `unsafeShiftL` 24
          .|. w w5# `unsafeShiftL` 16
          .|. w w6# `unsafeShiftL` 8
          .|. w w7#
    |
233 |                           w w7#
    |                             ^^^
Gabriella439 commented 2 years ago

I also ran into the same issue on AArch64/Darwin when building cborg using GHC 9.2.1 from Nixpkgs. Here is a Nix expression that reproduces the same build failure:

let
  nixpkgs = builtins.fetchTarball {
    url    = "https://github.com/NixOS/nixpkgs/archive/546ad5613314121659966da33efe05681ba24641.tar.gz";
    sha256 = "08hmcwjxipl2n7fj8wvaigh555bqfq2c8aa8yr9am56zh8hcj4lr";
  };

  overlay = pkgsNew: pkgsOld: {
    haskell = pkgsOld.haskell // {
      packages = pkgsOld.haskell.packages // {
        ghc921 = pkgsOld.haskell.packages.ghc921.override (old: {
          overrides =
            pkgsNew.lib.composeExtensions (old.overrides or (_: _: { }))
              (haskellPackagesNew: haskellPackagesOld: {
                mkDerivation = args: haskellPackagesOld.mkDerivation (args // {
                  doCheck = false;

                  doHaddock = false;
                });
              });
        });
      };
    };

  };

  pkgs = import nixpkgs { config = {}; overlays = [ overlay ]; };

in
  pkgs.haskell.packages.ghc921.cborg
georgefst commented 2 years ago

Yep, I've also hit this on an M1 Mac - it seemingly has nothing to do with cross-compiling.

CC-ing @bgamari since he wrote #273.

FinleyMcIlwaine commented 2 years ago

This should now be fixed by #287