Unable to build haskell c/c++ dependency

I’m trying to build this project GitHub - piq9117/rocksdb-haskell: Haskell bindings to RocksDB (http://rocksdb.org) with this flake file

{
  description = "Basic haskell cabal template";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/23.05";

  outputs = { self, nixpkgs }:
    let
      forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
      nixpkgsFor = forAllSystems (system: import nixpkgs {
        inherit system;
        overlays = [ self.overlay ];
      });
    in
    {
      overlay = self: super: {
        hsPkgs = super.haskell.packages.ghc944.override {
          overrides = hself: hsuper: {
            ghcid = super.haskell.lib.dontCheck hsuper.ghcid;
          };
        };
      };
      devShells = forAllSystems (system:
        let
          pkgs = nixpkgsFor.${system};
          libs = with pkgs; [
            zlib
            snappy
            gflags
            bzip2
            lz4
            zstd
          ];
        in
        {
          default = pkgs.hsPkgs.shellFor {
            packages = hsPkgs: [ ];
            buildInputs = with pkgs; [
              hsPkgs.cabal-install
              hsPkgs.cabal-fmt
              hsPkgs.ghcid
              hsPkgs.ghc
            ] ++ libs;
            shellHook = "export PS1='[$PWD]\n❄ '";
            LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath libs;
          };
        });
    };
}

but I keep getting these warnings

rocksdb-8.3.2/util/string_util.cc: In function ‘std::string rocksdb::NumberToHumanString(int64_t)’:

rocksdb-8.3.2/util/string_util.cc:121:32: error:
     error: ‘%li’ directive output may be truncated writing between 1 and 20 bytes into a region of size 19 [-Werror=format-truncation=]
      121 |     snprintf(buf, sizeof(buf), "%" PRIi64, num);
          |                                ^
    |
121 |     snprintf(buf, sizeof(buf), "%" PRIi64, num);
    |                                ^

rocksdb-8.3.2/util/string_util.cc:121:32: error:
     note: directive argument in the range [-9223372036854775808, 9999]
    |
121 |     snprintf(buf, sizeof(buf), "%" PRIi64, num);
    |                                ^
In file included from /nix/store/rfw51dqr3qn7b6fjy8hmx6f0x3hfwbx6-glibc-2.37-8-dev/include/stdio.h:906,
                 from /nix/store/dcd1zhv56rk0d2z7akzfjgzr076c4jl9-gcc-12.2.0/include/c++/12.2.0/cstdio:42,
                 from /nix/store/dcd1zhv56rk0d2z7akzfjgzr076c4jl9-gcc-12.2.0/include/c++/12.2.0/ext/string_conversions.h:43,
                 from /nix/store/dcd1zhv56rk0d2z7akzfjgzr076c4jl9-gcc-12.2.0/include/c++/12.2.0/bits/basic_string.h:3960,
                 from /nix/store/dcd1zhv56rk0d2z7akzfjgzr076c4jl9-gcc-12.2.0/include/c++/12.2.0/string:53,
                 from /nix/store/dcd1zhv56rk0d2z7akzfjgzr076c4jl9-gcc-12.2.0/include/c++/12.2.0/bits/locale_classes.h:40,
                 from /nix/store/dcd1zhv56rk0d2z7akzfjgzr076c4jl9-gcc-12.2.0/include/c++/12.2.0/bits/ios_base.h:41,
                 from /nix/store/dcd1zhv56rk0d2z7akzfjgzr076c4jl9-gcc-12.2.0/include/c++/12.2.0/ios:42,
                 from /nix/store/dcd1zhv56rk0d2z7akzfjgzr076c4jl9-gcc-12.2.0/include/c++/12.2.0/istream:38,
                 from /nix/store/dcd1zhv56rk0d2z7akzfjgzr076c4jl9-gcc-12.2.0/include/c++/12.2.0/sstream:38,
                 from rocksdb-8.3.2/util/string_util.h:10,

                 from rocksdb-8.3.2/util/string_util.cc:6:0: error:
    
In function ‘int snprintf(char*, size_t, const char*, ...)’,
    inlined from ‘std::string rocksdb::NumberToHumanString(int64_t)’ at rocksdb-8.3.2/util/string_util.cc:121:13:

/nix/store/rfw51dqr3qn7b6fjy8hmx6f0x3hfwbx6-glibc-2.37-8-dev/include/bits/stdio2.h:54:35: error:
     note: ‘__builtin___snprintf_chk’ output between 2 and 21 bytes into a destination of size 19
       54 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
          |          ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       55 |                                    __glibc_objsize (__s), __fmt,
          |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       56 |                                    __va_arg_pack ());
          |                                    ~~~~~~~~~~~~~~~~~
   |
54 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
   |                                   ^
cc1plus: all warnings being treated as errors
`c++' failed in phase `C++ Compiler'. (Exit code: 1)
Error: cabal: Failed to build rocksdb-haskell-kadena-1.1.0.

I’m not sure how to proceed from here

Appears to be a bug in RocksDB caused by the project using the gcc -Wall flag to enable all warnings, which now causes the build to fail because of a new gcc warning which probably didn’t exist back when the -Wall flag was added to the project.

The issue has been reported before, here: Build failure due to warning treated as error (minor bug in NumberToHumanString) · Issue #11619 · facebook/rocksdb · GitHub.
A workaround is given in the comments (pass -DFAIL_ON_WARNINGS=OFF to cmake).

1 Like