From 015ba1e833641a18b6d55c3f97a04bc54db75911 Mon Sep 17 00:00:00 2001 From: Robert Scott Date: Sun, 5 Feb 2023 23:14:44 +0000 Subject: [PATCH 1/2] gtest: add static option --- pkgs/development/libraries/gtest/default.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/development/libraries/gtest/default.nix b/pkgs/development/libraries/gtest/default.nix index 8e60c08d3600..1dd68b077b20 100644 --- a/pkgs/development/libraries/gtest/default.nix +++ b/pkgs/development/libraries/gtest/default.nix @@ -1,4 +1,10 @@ -{ lib, stdenv, cmake, ninja, fetchFromGitHub }: +{ lib +, stdenv +, fetchFromGitHub +, cmake +, ninja +, static ? stdenv.hostPlatform.isStatic, +}: stdenv.mkDerivation rec { pname = "gtest"; @@ -20,7 +26,7 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake ninja ]; cmakeFlags = [ - "-DBUILD_SHARED_LIBS=ON" + "-DBUILD_SHARED_LIBS=${if static then "OFF" else "ON"}" ] ++ lib.optionals (stdenv.cc.isClang && (lib.versionOlder stdenv.cc.version "16.0")) [ # Enable C++17 support # https://github.com/google/googletest/issues/3081 From 1a6b5135e8f91c14aa86892d85dfd1f67208e27d Mon Sep 17 00:00:00 2001 From: Robert Scott Date: Sun, 5 Feb 2023 23:14:52 +0000 Subject: [PATCH 2/2] python3Packages.onnx: use github source & enable many more tests --- .../python-modules/onnx/default.nix | 70 +++++++++++++++---- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/pkgs/development/python-modules/onnx/default.nix b/pkgs/development/python-modules/onnx/default.nix index b21f343db32a..e3cd5bb09239 100644 --- a/pkgs/development/python-modules/onnx/default.nix +++ b/pkgs/development/python-modules/onnx/default.nix @@ -1,35 +1,42 @@ { lib , buildPythonPackage +, python3 , bash , cmake -, fetchPypi +, fetchFromGitHub +, gtest , isPy27 , nbval , numpy , protobuf +, pybind11 , pytestCheckHook , six , tabulate , typing-extensions , pythonRelaxDepsHook -, pytest-runner }: -buildPythonPackage rec { +let + gtestStatic = gtest.override { static = true; }; +in buildPythonPackage rec { pname = "onnx"; version = "1.13.0"; format = "setuptools"; disabled = isPy27; - src = fetchPypi { - inherit pname version; - sha256 = "sha256-QQs5lQNnhX+XtlCTaB/iSVouI9Y3d6is6vlsVqFtFm4="; + src = fetchFromGitHub { + owner = pname; + repo = pname; + rev = "refs/tags/v${version}"; + sha256 = "sha256-D8POBAkZVr0O5i4qsSuYRkDfL8WsDTqzgNACmmkFwGs="; }; nativeBuildInputs = [ cmake pythonRelaxDepsHook + pybind11 ]; pythonRelaxDeps = [ "protobuf" ]; @@ -44,30 +51,36 @@ buildPythonPackage rec { nativeCheckInputs = [ nbval pytestCheckHook - pytest-runner tabulate ]; postPatch = '' chmod +x tools/protoc-gen-mypy.sh.in patchShebangs tools/protoc-gen-mypy.sh.in + + substituteInPlace setup.py \ + --replace 'setup_requires.append("pytest-runner")' "" + + # prevent from fetching & building own gtest + substituteInPlace CMakeLists.txt \ + --replace 'include(googletest)' "" + substituteInPlace cmake/unittest.cmake \ + --replace 'googletest)' ')' ''; - # Set CMAKE_INSTALL_LIBDIR to lib explicitly, because otherwise it gets set - # to lib64 and cmake incorrectly looks for the protobuf library in lib64 preConfigure = '' + # Set CMAKE_INSTALL_LIBDIR to lib explicitly, because otherwise it gets set + # to lib64 and cmake incorrectly looks for the protobuf library in lib64 export CMAKE_ARGS="-DCMAKE_INSTALL_LIBDIR=lib -DONNX_USE_PROTOBUF_SHARED_LIBS=ON" + '' + lib.optionalString doCheck '' + export CMAKE_ARGS+=" -Dgoogletest_STATIC_LIBRARIES=${gtestStatic}/lib/libgtest.a -Dgoogletest_INCLUDE_DIRS=${lib.getDev gtestStatic}/include" + export ONNX_BUILD_TESTS=1 ''; preBuild = '' export MAX_JOBS=$NIX_BUILD_CORES ''; - disabledTestPaths = [ - # Unexpected output fields from running code: {'stderr'} - "onnx/examples/np_array_tensorproto.ipynb" - ]; - # The executables are just utility scripts that aren't too important postInstall = '' rm -r $out/bin @@ -76,6 +89,35 @@ buildPythonPackage rec { # The setup.py does all the configuration dontUseCmakeConfigure = true; + doCheck = true; + preCheck = '' + export HOME=$(mktemp -d) + + # detecting source dir as a python package confuses pytest + mv onnx/__init__.py onnx/__init__.py.hidden + ''; + pytestFlagsArray = [ "onnx/test" "onnx/examples" ]; + disabledTests = [ + # attempts to fetch data from web + "test_bvlc_alexnet_cpu" + "test_densenet121_cpu" + "test_inception_v1_cpu" + "test_inception_v2_cpu" + "test_resnet50_cpu" + "test_shufflenet_cpu" + "test_squeezenet_cpu" + "test_vgg19_cpu" + "test_zfnet512_cpu" + ]; + disabledTestPaths = [ + # Unexpected output fields from running code: {'stderr'} + "onnx/examples/np_array_tensorproto.ipynb" + ]; + postCheck = '' + # run "cpp" tests + .setuptools-cmake-build/onnx_gtests + ''; + pythonImportsCheck = [ "onnx" ];