From 62fae879a82e68ab4cc2e827ac000c3eddba7729 Mon Sep 17 00:00:00 2001 From: wrvsrx Date: Sun, 18 Aug 2024 00:05:34 +0800 Subject: [PATCH] python3Packages.llvmlite: make it statically link to llvm Llvmlite doc says that they link to llvm statically, but it's not. Check - https://github.com/numba/llvmlite/issues/1027. - https://github.com/numba/llvmlite/blob/ca123c3ae2a6f7db865661ae509862277ec5d692/docs/source/faqs.rst#why-static-linking-to-llvm This behavior causes problems when python uses another version of llvm, for example, mesa llvmpipe. This PR force llvmlite statically link to llvm. Besides, this PR also use llvm as buildInputs rather than nativeBuildInputs since it's a library that llvmlite use rather than a part of build system. This PR also cleans outdated patches. --- .../python-modules/llvmlite/default.nix | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/pkgs/development/python-modules/llvmlite/default.nix b/pkgs/development/python-modules/llvmlite/default.nix index 9fdcab6d7534..9d76e64fde35 100644 --- a/pkgs/development/python-modules/llvmlite/default.nix +++ b/pkgs/development/python-modules/llvmlite/default.nix @@ -6,12 +6,14 @@ isPyPy, pythonAtLeast, - # build-system - llvm, setuptools, # tests pytestCheckHook, + llvm, + libxml2, + + withStaticLLVM ? true, }: buildPythonPackage rec { @@ -28,24 +30,19 @@ buildPythonPackage rec { hash = "sha256-5QBSRDb28Bui9IOhGofj+c7Rk7J5fNv5nPksEPY/O5o="; }; - nativeBuildInputs = [ - llvm - setuptools - ]; + build-system = [ setuptools ]; - postPatch = '' - substituteInPlace llvmlite/tests/test_binding.py \ - --replace-fail "test_linux" "nope" + buildInputs = [ llvm ] ++ lib.optionals withStaticLLVM [ libxml2.dev ]; + + postPatch = lib.optionalString withStaticLLVM '' + substituteInPlace ffi/build.py --replace-fail "--system-libs --libs all" "--system-libs --libs --link-static all" ''; # Set directory containing llvm-config binary - preConfigure = '' - export LLVM_CONFIG=${llvm.dev}/bin/llvm-config - ''; + env.LLVM_CONFIG = "${llvm.dev}/bin/llvm-config"; + + nativeCheckInputs = [ pytestCheckHook ]; - nativeCheckInputs = [ - pytestCheckHook - ]; # https://github.com/NixOS/nixpkgs/issues/255262 preCheck = '' cd $out @@ -53,7 +50,7 @@ buildPythonPackage rec { __impureHostDeps = lib.optionals stdenv.isDarwin [ "/usr/lib/libm.dylib" ]; - passthru.llvm = llvm; + passthru = lib.optionalAttrs (!withStaticLLVM) { inherit llvm; }; meta = { changelog = "https://github.com/numba/llvmlite/blob/v${version}/CHANGE_LOG";