Unverified Commit 1a71b7fc authored by Martin Weinelt's avatar Martin Weinelt Committed by GitHub
Browse files

ctranslate2: move to by-name, cleanup, fix CMake 4 compatibility (#449460)

parents d5af3893 127236cb
Loading
Loading
Loading
Loading
+34 −19
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  config,
  fetchFromGitHub,
  cmake,
  llvmPackages, # openmp
  withMkl ? false,
  mkl,
  withCUDA ? false,
  withCuDNN ? false,
  withCUDA ? config.cudaSupport,
  withCuDNN ? withCUDA && (cudaPackages ? cudnn),
  cudaPackages,
  # Enabling both withOneDNN and withOpenblas is broken
  # https://github.com/OpenNMT/CTranslate2/issues/1294
@@ -23,21 +24,33 @@
}:

let
  cmakeBool = b: if b then "ON" else "OFF";
  stdenv' = if withCUDA then cudaPackages.backendStdenv else stdenv;
in
stdenv'.mkDerivation rec {
stdenv'.mkDerivation (finalAttrs: {
  pname = "ctranslate2";
  version = "4.6.0";

  src = fetchFromGitHub {
    owner = "OpenNMT";
    repo = "CTranslate2";
    rev = "v${version}";
    hash = "sha256-EM2kunqtxo0BTIzrEomfaRsdav7sx6QEOhjDtjjSoYY=";
    tag = "v${finalAttrs.version}";
    fetchSubmodules = true;
    hash = "sha256-EM2kunqtxo0BTIzrEomfaRsdav7sx6QEOhjDtjjSoYY=";
  };

  # Fix CMake 4 compatibility
  postPatch = ''
    substituteInPlace third_party/cpu_features/CMakeLists.txt \
      --replace-fail \
        'cmake_minimum_required(VERSION 3.0)' \
        'cmake_minimum_required(VERSION 3.10)'

    substituteInPlace third_party/ruy/third_party/cpuinfo/deps/clog/CMakeLists.txt \
      --replace-fail \
        'CMAKE_MINIMUM_REQUIRED(VERSION 3.1 FATAL_ERROR)' \
        'CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)'
  '';

  nativeBuildInputs = [
    cmake
  ]
@@ -49,15 +62,17 @@ stdenv'.mkDerivation rec {
    # https://opennmt.net/CTranslate2/installation.html#build-options
    # https://github.com/OpenNMT/CTranslate2/blob/54810350e662ebdb01ecbf8e4a746f02aeff1dd7/python/tools/prepare_build_environment_linux.sh#L53
    # https://github.com/OpenNMT/CTranslate2/blob/59d223abcc7e636c1c2956e62482bc3299cc7766/python/tools/prepare_build_environment_macos.sh#L12
    "-DOPENMP_RUNTIME=COMP"
    "-DWITH_CUDA=${cmakeBool withCUDA}"
    "-DWITH_CUDNN=${cmakeBool withCuDNN}"
    "-DWITH_DNNL=${cmakeBool withOneDNN}"
    "-DWITH_OPENBLAS=${cmakeBool withOpenblas}"
    "-DWITH_RUY=${cmakeBool withRuy}"
    "-DWITH_MKL=${cmakeBool withMkl}"
    (lib.cmakeFeature "OPENMP_RUNTIME" "COMP")
    (lib.cmakeBool "WITH_CUDA" withCUDA)
    (lib.cmakeBool "WITH_CUDNN" withCuDNN)
    (lib.cmakeBool "WITH_DNNL" withOneDNN)
    (lib.cmakeBool "WITH_OPENBLAS" withOpenblas)
    (lib.cmakeBool "WITH_RUY" withRuy)
    (lib.cmakeBool "WITH_MKL" withMkl)
  ]
  ++ lib.optional stdenv.hostPlatform.isDarwin "-DWITH_ACCELERATE=ON";
  ++ lib.optionals stdenv.hostPlatform.isDarwin [
    (lib.cmakeBool "WITH_ACCELERATE" true)
  ];

  buildInputs =
    lib.optionals withMkl [
@@ -89,16 +104,16 @@ stdenv'.mkDerivation rec {
      ;
  };

  meta = with lib; {
  meta = {
    description = "Fast inference engine for Transformer models";
    mainProgram = "ct2-translator";
    homepage = "https://github.com/OpenNMT/CTranslate2";
    changelog = "https://github.com/OpenNMT/CTranslate2/blob/${src.rev}/CHANGELOG.md";
    license = licenses.mit;
    maintainers = with maintainers; [
    changelog = "https://github.com/OpenNMT/CTranslate2/blob/${finalAttrs.src.tag}/CHANGELOG.md";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [
      hexa
      misuzu
    ];
    broken = !(withCuDNN -> withCUDA);
  };
}
})
+0 −6
Original line number Diff line number Diff line
@@ -7131,12 +7131,6 @@ with pkgs;

  inherit (cosmopolitan) cosmocc;

  ctranslate2 = callPackage ../development/libraries/ctranslate2 rec {
    withCUDA = pkgs.config.cudaSupport;
    withCuDNN = withCUDA && (cudaPackages ? cudnn);
    cudaPackages = pkgs.cudaPackages;
  };

  ustream-ssl = callPackage ../development/libraries/ustream-ssl { ssl_implementation = openssl; };

  ustream-ssl-wolfssl = callPackage ../development/libraries/ustream-ssl {