summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/yf/yffi/package.nix
blob: b037a0ebd53bbd467858c8e3254c1c7174c6e31c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
  fetchFromGitHub,
  lib,
  rust-cbindgen,
  rustPlatform,
  stdenv,
}:

rustPlatform.buildRustPackage (finalAttrs: {
  pname = "yffi";
  version = "0.27.4";

  src = fetchFromGitHub {
    owner = "y-crdt";
    repo = "y-crdt";
    tag = "v${finalAttrs.version}";
    hash = "sha256-lW6IvPyOsAOZlopLWTxqtHvuCRjGtmdYedmnyFVdQqk=";
  };

  cargoHash = "sha256-r9wT9PIsAaRp2kHvwYB0vJIAKnsVmoqkQrdmoyKtZcs=";

  buildAndTestSubdir = "yffi";

  nativeBuildInputs = [
    rust-cbindgen
  ];

  postBuild = ''
    cbindgen --config yffi/cbindgen.toml --crate yffi --output libyrs.h --lang C
  '';

  postCheck = ''
    $CXX -o yrs-ffi-tests -I . tests-ffi/main.cpp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/libyrs.a
    ./yrs-ffi-tests
  '';

  postInstall = ''
    install -Dm644 libyrs.h $out/include/libyrs.h
  '';

  meta = {
    description = "C foreign function interface for Yrs";
    homepage = "https://github.com/y-crdt/y-crdt/tree/main/yffi";
    downloadPage = "https://github.com/y-crdt/y-crdt/tags";
    changelog = "https://github.com/y-crdt/y-crdt/releases/tag/${finalAttrs.src.tag}";
    license = lib.licenses.mit;
    teams = with lib.teams; [ ngi ];
    platforms = with lib.platforms; linux;
  };
})