Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions pkgs/development/python-modules/dm-tree/cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
diff --git a/tree/CMakeLists.txt b/tree/CMakeLists.txt
index 8f9946c..b9d6e9b 100644
--- a/tree/CMakeLists.txt
+++ b/tree/CMakeLists.txt
@@ -50,70 +50,80 @@ if(APPLE)
set (CMAKE_FIND_FRAMEWORK LAST)
endif()

-# Fetch pybind to be able to use pybind11_add_module symbol.
-set(PYBIND_VER v2.6.2)
-include(FetchContent)
-FetchContent_Declare(
- pybind11
- GIT_REPOSITORY https://github.com/pybind/pybind11
- GIT_TAG ${PYBIND_VER}
-)
-if(NOT pybind11_POPULATED)
- FetchContent_Populate(pybind11)
- add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
- include_directories(${pybind11_INCLUDE_DIR})
-endif()
-
-# Needed to disable Abseil tests.
-set (BUILD_TESTING OFF)
-
-# Include abseil-cpp.
-set(ABSEIL_VER 20210324.2)
-include(ExternalProject)
-set(ABSEIL_CMAKE_ARGS
- "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}/abseil-cpp"
- "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
- "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
- "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
- "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
- "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}"
- "-DLIBRARY_OUTPUT_PATH=${CMAKE_SOURCE_DIR}/abseil-cpp/lib")
-if(DEFINED CMAKE_OSX_ARCHITECTURES)
- set(ABSEIL_CMAKE_ARGS
- ${ABSEIL_CMAKE_ARGS}
- "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
+find_package(pybind11 CONFIG)
+
+if (NOT pybind11_FOUND)
+ # Fetch pybind to be able to use pybind11_add_module symbol.
+ set(PYBIND_VER v2.6.2)
+ include(FetchContent)
+ FetchContent_Declare(
+ pybind11
+ GIT_REPOSITORY https://github.com/pybind/pybind11
+ GIT_TAG ${PYBIND_VER}
+ )
+ if(NOT pybind11_POPULATED)
+ FetchContent_Populate(pybind11)
+ add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
+ include_directories(${pybind11_INCLUDE_DIR})
+ endif()
endif()
-ExternalProject_Add(abseil-cpp
- GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
- GIT_TAG ${ABSEIL_VER}
- PREFIX ${CMAKE_SOURCE_DIR}/abseil-cpp
- CMAKE_ARGS ${ABSEIL_CMAKE_ARGS}
-)
-ExternalProject_Get_Property(abseil-cpp install_dir)
-set(abseil_install_dir ${install_dir})
-include_directories (${abseil_install_dir}/include)
-

# Define pybind11 tree module.
pybind11_add_module(_tree tree.h tree.cc)
-add_dependencies(_tree abseil-cpp)

-if (WIN32 OR MSVC)
- set(ABSEIL_LIB_PREF "absl")
- set(LIB_SUFF "lib")
+find_package(absl)
+
+if (NOT absl_FOUND)
+ # Needed to disable Abseil tests.
+ set (BUILD_TESTING OFF)
+
+ # Include abseil-cpp.
+ set(ABSEIL_VER 20210324.2)
+ include(ExternalProject)
+ set(ABSEIL_CMAKE_ARGS
+ "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}/abseil-cpp"
+ "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
+ "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
+ "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
+ "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
+ "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}"
+ "-DLIBRARY_OUTPUT_PATH=${CMAKE_SOURCE_DIR}/abseil-cpp/lib")
+ if(DEFINED CMAKE_OSX_ARCHITECTURES)
+ set(ABSEIL_CMAKE_ARGS
+ ${ABSEIL_CMAKE_ARGS}
+ "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
+ endif()
+ ExternalProject_Add(abseil-cpp
+ GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
+ GIT_TAG ${ABSEIL_VER}
+ PREFIX ${CMAKE_SOURCE_DIR}/abseil-cpp
+ CMAKE_ARGS ${ABSEIL_CMAKE_ARGS}
+ )
+ ExternalProject_Get_Property(abseil-cpp install_dir)
+ set(abseil_install_dir ${install_dir})
+ include_directories (${abseil_install_dir}/include)
+
+ add_dependencies(_tree abseil-cpp)
+
+ if (WIN32 OR MSVC)
+ set(ABSEIL_LIB_PREF "absl")
+ set(LIB_SUFF "lib")
+ else()
+ set(ABSEIL_LIB_PREF "libabsl")
+ set(LIB_SUFF "a")
+ endif()
+
+ # Link abseil static libs.
+ # We don't use find_library here to force cmake to build abseil before linking.
+ set(ABSEIL_LIBS int128 raw_hash_set raw_logging_internal strings throw_delegate)
+ foreach(ABSEIL_LIB IN LISTS ABSEIL_LIBS)
+ target_link_libraries(_tree PRIVATE
+ "${abseil_install_dir}/lib/${ABSEIL_LIB_PREF}_${ABSEIL_LIB}.${LIB_SUFF}")
+ endforeach()
else()
- set(ABSEIL_LIB_PREF "libabsl")
- set(LIB_SUFF "a")
+ target_link_libraries(_tree PRIVATE absl::int128 absl::raw_hash_set absl::raw_logging_internal absl::strings absl::throw_delegate)
endif()

-# Link abseil static libs.
-# We don't use find_library here to force cmake to build abseil before linking.
-set(ABSEIL_LIBS int128 raw_hash_set raw_logging_internal strings throw_delegate)
-foreach(ABSEIL_LIB IN LISTS ABSEIL_LIBS)
- target_link_libraries(_tree PRIVATE
- "${abseil_install_dir}/lib/${ABSEIL_LIB_PREF}_${ABSEIL_LIB}.${LIB_SUFF}")
-endforeach()
-
# Make the module private to tree package.
set_target_properties(_tree PROPERTIES OUTPUT_NAME tree/_tree)

71 changes: 40 additions & 31 deletions pkgs/development/python-modules/dm-tree/default.nix
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
{ autoPatchelfHook
{ abseil-cpp
, absl-py
, attrs
, buildPythonPackage
, fetchPypi
, isPy39
, cmake
, fetchFromGitHub
, lib
, six
, stdenv
, numpy
, pybind11
, wrapt
}:

buildPythonPackage rec {
pname = "dm-tree";
version = "0.1.6";
format = "wheel";

# At the time of writing (8/19/21), there are releases for 3.6-3.9. Supporting
# all of them is a pain, so we focus on 3.9, the current nixpkgs python3
# version.
disabled = !isPy39;

src = fetchPypi {
inherit version format;
sha256 = "1f71dy5xa5ywa5chbdhpdf8k0w1v9cvpn3qyk8nnjm79j90la9c4";
pname = "dm_tree";
dist = "cp39";
python = "cp39";
abi = "cp39";
platform = "manylinux_2_24_x86_64";
# As of 2021-12-29, the latest stable version still builds with Bazel.
version = "unstable-2021-12-20";

src = fetchFromGitHub {
owner = "deepmind";
repo = "tree";
rev = "b452e5c2743e7489b4ba7f16ecd51c516d7cd8e3";
sha256 = "1r187xwpvnnj98lyasngcv3lbxz0ziihpl5dbnjbfbjr0kh6z0j9";
};

# Prebuilt wheels are dynamically linked against things that nix can't find.
# Run `autoPatchelfHook` to automagically fix them.
nativeBuildInputs = [ autoPatchelfHook ];
# Dynamic link dependencies
buildInputs = [ stdenv.cc.cc ];
patches = [
./cmake.patch
];

dontUseCmakeConfigure = true;

nativeBuildInputs = [
cmake
pybind11
];

buildInputs = [
abseil-cpp
pybind11
];

propagatedBuildInputs = [ six ];
checkInputs = [
absl-py
attrs
numpy
wrapt
];

pythonImportsCheck = [ "tree" ];

meta = with lib; {
description = "Tree is a library for working with nested data structures.";
homepage = "https://github.com/deepmind/tree";
license = licenses.asl20;
maintainers = with maintainers; [ samuela ];
platforms = [ "x86_64-linux" ];
homepage = "https://github.com/deepmind/tree";
license = licenses.asl20;
maintainers = with maintainers; [ samuela ndl ];
};
}