#
# Wayland-satellite Xwayland implementation.
#
# vim: et:ts=2:sw=2:
{
  lib,
  libclang,
  stdenv,
  llvmPackages,
  rustPlatform,
  xcb-util-cursor,
  xorg,
  fetchFromGitHub,
}:
let
  owner = "Supreeeme";
in
rustPlatform.buildRustPackage rec {
  pname = "xwayland-satellite";
  version = "0.2";

  src = fetchFromGitHub {
    owner = owner;
    repo = pname;
    rev = "v${version}";
    hash = "sha256-jeveB4SWPWYuPLi6Dvd3Lyu3obMYcZZmdo356ujp8rA=";
  };

  cargoHash = "sha256-X+4VGmpnwEgTLCvNUF0Kc7CP53tSZteJjr2zolSDfjA=";
  
  buildInputs = [
    libclang
    llvmPackages.clang-unwrapped
    xorg.libxcb
    xcb-util-cursor
  ];

  doCheck = false;
  buildType = "debug";

  # Ensure that the -sys packages can find libclang.
  LIBCLANG_PATH = "${llvmPackages.clang-unwrapped.lib}/lib";

  # Ensure that bindgen can find our headers.
  BINDGEN_EXTRA_CLANG_ARGS = builtins.concatStringsSep " " [
    "-I${xcb-util-cursor.dev}/include"
    "-I${xorg.libxcb.dev}/include"
    "-I${stdenv.cc.libc_dev}/include"
    "-I${libclang.lib}/lib/clang/17/include/"
  ];

  meta = with lib; {
    description = "XWayland without Wayland";
    mainProgram = pname;
    homepage = "https://github.com/${owner}/${pname}";
    license = with licenses; [ mpl20 ];
    #maintainers = with maintainers; [ deprekages ];
  };
}
