Commit 0c87981c authored by Gaetan Lepage's avatar Gaetan Lepage
Browse files

python312Packages.blis: fallback to generic architecure when needed

parent 1cef6227
Loading
Loading
Loading
Loading
+34 −14
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  buildPythonPackage,
  fetchFromGitHub,

  # build-system
  setuptools,
  cython,
  hypothesis,
  numpy,

  # tests
  hypothesis,
  pytestCheckHook,
  pythonOlder,

  # passthru
  blis,
  numpy_1,
  gitUpdater,
@@ -18,8 +24,6 @@ buildPythonPackage rec {
  version = "1.2.1";
  pyproject = true;

  disabled = pythonOlder "3.9";

  src = fetchFromGitHub {
    owner = "explosion";
    repo = "cython-blis";
@@ -27,25 +31,41 @@ buildPythonPackage rec {
    hash = "sha256-krUqAEPxJXdlolSbV5R0ZqrWaFuXh7IxSeFTsCr6iss=";
  };

  preCheck = ''
    # remove src module, so tests use the installed module instead
    rm -rf ./blis
  '';

  build-system = [
    setuptools
    cython
    numpy
  ];

  env =
    # Fallback to generic architectures when necessary:
    # https://github.com/explosion/cython-blis?tab=readme-ov-file#building-blis-for-alternative-architectures
    lib.optionalAttrs
      (
        # error: [Errno 2] No such file or directory: '/build/source/blis/_src/make/linux-cortexa57.jsonl'
        (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64)

        # clang: error: unknown argument '-mavx512pf'; did you mean '-mavx512f'?
        # Patching blis/_src/config/knl/make_defs.mk to remove the said flag does not work
        || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64)
      )
      {
        BLIS_ARCH = "generic";
      };

  dependencies = [ numpy ];

  pythonImportsCheck = [ "blis" ];

  nativeCheckInputs = [
    hypothesis
    pytestCheckHook
  ];

  pythonImportsCheck = [ "blis" ];
  # remove src module, so tests use the installed module instead
  preCheck = ''
    rm -rf ./blis
  '';

  passthru = {
    tests = {
@@ -58,11 +78,11 @@ buildPythonPackage rec {
    };
  };

  meta = with lib; {
    changelog = "https://github.com/explosion/cython-blis/releases/tag/release-${src.tag}";
  meta = {
    changelog = "https://github.com/explosion/cython-blis/releases/tag/release-${version}";
    description = "BLAS-like linear algebra library";
    homepage = "https://github.com/explosion/cython-blis";
    license = licenses.bsd3;
    maintainers = with maintainers; [ nickcao ];
    license = lib.licenses.bsd3;
    maintainers = with lib.maintainers; [ nickcao ];
  };
}