Commit daa829ca authored by Gaetan Lepage's avatar Gaetan Lepage
Browse files

flatcc: fix build, cleanup

parent eae07e1e
Loading
Loading
Loading
Loading
+40 −3
Original line number Diff line number Diff line
@@ -4,17 +4,21 @@
  fetchFromGitHub,
  fetchpatch,
  cmake,
  versionCheckHook,
  nix-update-script,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "flatcc";
  version = "0.6.1";

  strictDeps = true;

  src = fetchFromGitHub {
    owner = "dvidelabs";
    repo = "flatcc";
    rev = "v${finalAttrs.version}";
    sha256 = "sha256-0/IZ7eX6b4PTnlSSdoOH0FsORGK9hrLr1zlr/IHsJFQ=";
    tag = "v${finalAttrs.version}";
    hash = "sha256-0/IZ7eX6b4PTnlSSdoOH0FsORGK9hrLr1zlr/IHsJFQ=";
  };

  patches = [
@@ -42,18 +46,51 @@ stdenv.mkDerivation (finalAttrs: {
        "test/monster_test_cpp/CMakeLists.txt"
      ];
    })
  ]
  ++ lib.optionals stdenv.cc.isClang [
    # Fix clang compilation
    # https://github.com/dvidelabs/flatcc/pull/273
    (fetchpatch {
      name = "fix-c23-fallthrough.patch";
      url = "https://github.com/dvidelabs/flatcc/commit/7c199e3b191a6f714694035f1eba40112e71675c.patch";
      hash = "sha256-kGupiMVa2r+hsQnknatRK+EfscNjJD0T75NY1ELkJ5U=";
    })

    # Fix implicit int conversion on negation for int8/int16
    # https://github.com/dvidelabs/flatcc/commit/5df663837c93eb7516890c27574dcc4b042890cb
    (fetchpatch {
      name = "fix-pprintint-implicit-int-conversion.patch";
      url = "https://github.com/dvidelabs/flatcc/commit/5df663837c93eb7516890c27574dcc4b042890cb.patch";
      hash = "sha256-pntpatUDkZbj5pEViA8jDvXP+9KNdfhUDQCUd598Lxg=";
      excludes = [ "CHANGELOG.md" ];
    })
  ];

  postPatch = ''
    substituteInPlace include/flatcc/portable/grisu3_print.h \
      --replace-fail \
        'static char hexdigits[16] = "0123456789ABCDEF";' \
        "static char hexdigits[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};"
  '';

  nativeBuildInputs = [ cmake ];

  cmakeFlags = [
    "-DFLATCC_INSTALL=on"
    (lib.cmakeBool "FLATCC_INSTALL" true)
  ];

  nativeInstallCheckInputs = [
    versionCheckHook
  ];
  doInstallCheck = true;

  passthru.updateScript = nix-update-script { };

  meta = {
    description = "FlatBuffers Compiler and Library in C for C";
    mainProgram = "flatcc";
    homepage = "https://github.com/dvidelabs/flatcc";
    changelog = "https://github.com/dvidelabs/flatcc/blob/${finalAttrs.src.tag}/CHANGELOG.md";
    license = [ lib.licenses.asl20 ];
    maintainers = with lib.maintainers; [ onny ];
  };