lol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

python3Packages.dm-tree: refactor to build from sources (#152971)

* python3Packages.dm-tree: refactor to build from sources

* Addressed review comments

authored by

Alexander Tsvyashchenko and committed by
GitHub
08322e6c a68e6c37

+180 -30
+141
pkgs/development/python-modules/dm-tree/cmake.patch
··· 1 + diff --git a/tree/CMakeLists.txt b/tree/CMakeLists.txt 2 + index 8f9946c..b9d6e9b 100644 3 + --- a/tree/CMakeLists.txt 4 + +++ b/tree/CMakeLists.txt 5 + @@ -50,70 +50,80 @@ if(APPLE) 6 + set (CMAKE_FIND_FRAMEWORK LAST) 7 + endif() 8 + 9 + -# Fetch pybind to be able to use pybind11_add_module symbol. 10 + -set(PYBIND_VER v2.6.2) 11 + -include(FetchContent) 12 + -FetchContent_Declare( 13 + - pybind11 14 + - GIT_REPOSITORY https://github.com/pybind/pybind11 15 + - GIT_TAG ${PYBIND_VER} 16 + -) 17 + -if(NOT pybind11_POPULATED) 18 + - FetchContent_Populate(pybind11) 19 + - add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR}) 20 + - include_directories(${pybind11_INCLUDE_DIR}) 21 + -endif() 22 + - 23 + -# Needed to disable Abseil tests. 24 + -set (BUILD_TESTING OFF) 25 + - 26 + -# Include abseil-cpp. 27 + -set(ABSEIL_VER 20210324.2) 28 + -include(ExternalProject) 29 + -set(ABSEIL_CMAKE_ARGS 30 + - "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}/abseil-cpp" 31 + - "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" 32 + - "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" 33 + - "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}" 34 + - "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" 35 + - "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}" 36 + - "-DLIBRARY_OUTPUT_PATH=${CMAKE_SOURCE_DIR}/abseil-cpp/lib") 37 + -if(DEFINED CMAKE_OSX_ARCHITECTURES) 38 + - set(ABSEIL_CMAKE_ARGS 39 + - ${ABSEIL_CMAKE_ARGS} 40 + - "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}") 41 + +find_package(pybind11 CONFIG) 42 + + 43 + +if (NOT pybind11_FOUND) 44 + + # Fetch pybind to be able to use pybind11_add_module symbol. 45 + + set(PYBIND_VER v2.6.2) 46 + + include(FetchContent) 47 + + FetchContent_Declare( 48 + + pybind11 49 + + GIT_REPOSITORY https://github.com/pybind/pybind11 50 + + GIT_TAG ${PYBIND_VER} 51 + + ) 52 + + if(NOT pybind11_POPULATED) 53 + + FetchContent_Populate(pybind11) 54 + + add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR}) 55 + + include_directories(${pybind11_INCLUDE_DIR}) 56 + + endif() 57 + endif() 58 + -ExternalProject_Add(abseil-cpp 59 + - GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git 60 + - GIT_TAG ${ABSEIL_VER} 61 + - PREFIX ${CMAKE_SOURCE_DIR}/abseil-cpp 62 + - CMAKE_ARGS ${ABSEIL_CMAKE_ARGS} 63 + -) 64 + -ExternalProject_Get_Property(abseil-cpp install_dir) 65 + -set(abseil_install_dir ${install_dir}) 66 + -include_directories (${abseil_install_dir}/include) 67 + - 68 + 69 + # Define pybind11 tree module. 70 + pybind11_add_module(_tree tree.h tree.cc) 71 + -add_dependencies(_tree abseil-cpp) 72 + 73 + -if (WIN32 OR MSVC) 74 + - set(ABSEIL_LIB_PREF "absl") 75 + - set(LIB_SUFF "lib") 76 + +find_package(absl) 77 + + 78 + +if (NOT absl_FOUND) 79 + + # Needed to disable Abseil tests. 80 + + set (BUILD_TESTING OFF) 81 + + 82 + + # Include abseil-cpp. 83 + + set(ABSEIL_VER 20210324.2) 84 + + include(ExternalProject) 85 + + set(ABSEIL_CMAKE_ARGS 86 + + "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}/abseil-cpp" 87 + + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" 88 + + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" 89 + + "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}" 90 + + "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" 91 + + "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}" 92 + + "-DLIBRARY_OUTPUT_PATH=${CMAKE_SOURCE_DIR}/abseil-cpp/lib") 93 + + if(DEFINED CMAKE_OSX_ARCHITECTURES) 94 + + set(ABSEIL_CMAKE_ARGS 95 + + ${ABSEIL_CMAKE_ARGS} 96 + + "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}") 97 + + endif() 98 + + ExternalProject_Add(abseil-cpp 99 + + GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git 100 + + GIT_TAG ${ABSEIL_VER} 101 + + PREFIX ${CMAKE_SOURCE_DIR}/abseil-cpp 102 + + CMAKE_ARGS ${ABSEIL_CMAKE_ARGS} 103 + + ) 104 + + ExternalProject_Get_Property(abseil-cpp install_dir) 105 + + set(abseil_install_dir ${install_dir}) 106 + + include_directories (${abseil_install_dir}/include) 107 + + 108 + + add_dependencies(_tree abseil-cpp) 109 + + 110 + + if (WIN32 OR MSVC) 111 + + set(ABSEIL_LIB_PREF "absl") 112 + + set(LIB_SUFF "lib") 113 + + else() 114 + + set(ABSEIL_LIB_PREF "libabsl") 115 + + set(LIB_SUFF "a") 116 + + endif() 117 + + 118 + + # Link abseil static libs. 119 + + # We don't use find_library here to force cmake to build abseil before linking. 120 + + set(ABSEIL_LIBS int128 raw_hash_set raw_logging_internal strings throw_delegate) 121 + + foreach(ABSEIL_LIB IN LISTS ABSEIL_LIBS) 122 + + target_link_libraries(_tree PRIVATE 123 + + "${abseil_install_dir}/lib/${ABSEIL_LIB_PREF}_${ABSEIL_LIB}.${LIB_SUFF}") 124 + + endforeach() 125 + else() 126 + - set(ABSEIL_LIB_PREF "libabsl") 127 + - set(LIB_SUFF "a") 128 + + target_link_libraries(_tree PRIVATE absl::int128 absl::raw_hash_set absl::raw_logging_internal absl::strings absl::throw_delegate) 129 + endif() 130 + 131 + -# Link abseil static libs. 132 + -# We don't use find_library here to force cmake to build abseil before linking. 133 + -set(ABSEIL_LIBS int128 raw_hash_set raw_logging_internal strings throw_delegate) 134 + -foreach(ABSEIL_LIB IN LISTS ABSEIL_LIBS) 135 + - target_link_libraries(_tree PRIVATE 136 + - "${abseil_install_dir}/lib/${ABSEIL_LIB_PREF}_${ABSEIL_LIB}.${LIB_SUFF}") 137 + -endforeach() 138 + - 139 + # Make the module private to tree package. 140 + set_target_properties(_tree PROPERTIES OUTPUT_NAME tree/_tree) 141 +
+39 -30
pkgs/development/python-modules/dm-tree/default.nix
··· 1 - { autoPatchelfHook 1 + { abseil-cpp 2 + , absl-py 3 + , attrs 2 4 , buildPythonPackage 3 - , fetchPypi 4 - , isPy39 5 + , cmake 6 + , fetchFromGitHub 5 7 , lib 6 - , six 7 - , stdenv 8 + , numpy 9 + , pybind11 10 + , wrapt 8 11 }: 9 12 10 13 buildPythonPackage rec { 11 14 pname = "dm-tree"; 12 - version = "0.1.6"; 13 - format = "wheel"; 15 + # As of 2021-12-29, the latest stable version still builds with Bazel. 16 + version = "unstable-2021-12-20"; 17 + 18 + src = fetchFromGitHub { 19 + owner = "deepmind"; 20 + repo = "tree"; 21 + rev = "b452e5c2743e7489b4ba7f16ecd51c516d7cd8e3"; 22 + sha256 = "1r187xwpvnnj98lyasngcv3lbxz0ziihpl5dbnjbfbjr0kh6z0j9"; 23 + }; 24 + 25 + patches = [ 26 + ./cmake.patch 27 + ]; 14 28 15 - # At the time of writing (8/19/21), there are releases for 3.6-3.9. Supporting 16 - # all of them is a pain, so we focus on 3.9, the current nixpkgs python3 17 - # version. 18 - disabled = !isPy39; 29 + dontUseCmakeConfigure = true; 19 30 20 - src = fetchPypi { 21 - inherit version format; 22 - sha256 = "1f71dy5xa5ywa5chbdhpdf8k0w1v9cvpn3qyk8nnjm79j90la9c4"; 23 - pname = "dm_tree"; 24 - dist = "cp39"; 25 - python = "cp39"; 26 - abi = "cp39"; 27 - platform = "manylinux_2_24_x86_64"; 28 - }; 31 + nativeBuildInputs = [ 32 + cmake 33 + pybind11 34 + ]; 29 35 30 - # Prebuilt wheels are dynamically linked against things that nix can't find. 31 - # Run `autoPatchelfHook` to automagically fix them. 32 - nativeBuildInputs = [ autoPatchelfHook ]; 33 - # Dynamic link dependencies 34 - buildInputs = [ stdenv.cc.cc ]; 36 + buildInputs = [ 37 + abseil-cpp 38 + pybind11 39 + ]; 35 40 36 - propagatedBuildInputs = [ six ]; 41 + checkInputs = [ 42 + absl-py 43 + attrs 44 + numpy 45 + wrapt 46 + ]; 37 47 38 48 pythonImportsCheck = [ "tree" ]; 39 49 40 50 meta = with lib; { 41 51 description = "Tree is a library for working with nested data structures."; 42 - homepage = "https://github.com/deepmind/tree"; 43 - license = licenses.asl20; 44 - maintainers = with maintainers; [ samuela ]; 45 - platforms = [ "x86_64-linux" ]; 52 + homepage = "https://github.com/deepmind/tree"; 53 + license = licenses.asl20; 54 + maintainers = with maintainers; [ samuela ndl ]; 46 55 }; 47 56 }