colmap: cleanup, fix on aarch64-linux and darwin (#524173)

This commit is contained in:
kirillrdy
2026-06-15 08:48:55 +00:00
committed by GitHub
3 changed files with 107 additions and 27 deletions
+69 -21
View File
@@ -1,8 +1,8 @@
{
lib,
fetchFromGitHub,
fetchpatch,
fetchurl,
fetchpatch,
nix-update-script,
cmake,
boost,
@@ -62,14 +62,12 @@ let
onnxruntime
]
++ lib.optionals cudaSupport [
cudatoolkit
(lib.getOutput "static" cudaPackages.cuda_cudart)
cudaPackages.cuda_cudart # CUDA::cudart, used by COLMAP and faiss
cudaPackages.libcublas # CUDA::cublas, propagated by faiss' exported targets
cudaPackages.libcurand # CUDA::curand, used by COLMAP
]
++ lib.optional stdenv'.cc.isClang llvmPackages.openmp;
# TODO: migrate to redist packages
inherit (cudaPackages) cudatoolkit;
# COLMAP needs these model files to run the ONNX tests
# Based on: https://github.com/colmap/colmap/blob/79efc74b2b614935a3c69b1f983f2bad23a836a1/src/colmap/feature/resources.h#L36
modelsForTesting = [
@@ -100,16 +98,41 @@ let
}
];
in
stdenv'.mkDerivation rec {
stdenv'.mkDerivation (finalAttrs: {
version = "4.0.4";
pname = "colmap";
src = fetchFromGitHub {
owner = "colmap";
repo = "colmap";
tag = version;
tag = finalAttrs.version;
hash = "sha256-n9YwEqMSIh6vM2MVf7qxxVvDpsTLEsT37xoHiX66bL0=";
};
__structuredAttrs = true;
strictDeps = true;
patches =
lib.optionals stdenv'.hostPlatform.isAarch64 [
# Set SANITIZE_PR for PoissonRecon to fix data races on aarch64
# https://github.com/colmap/colmap/pull/4429
(fetchpatch {
url = "https://github.com/colmap/colmap/commit/e13294e43baae6cf7f4e3ec05a19060e0b230a72.patch";
hash = "sha256-hoIjWdrOlXeT78X+g3YCDWaWnmQMzHVQNkdpx5vXpGk=";
})
(fetchpatch {
url = "https://github.com/colmap/colmap/commit/6c5c59f96f9e819bcc57267ef48b193d77707fe0.patch";
hash = "sha256-2dAhy3sgxF2SXPAYE/EV1hd61dm05vJ5JJXEjQxEKWM=";
})
]
++ lib.optionals (stdenv'.hostPlatform.isLinux && stdenv'.hostPlatform.isAarch64) [
# Fix determinism check in rotation_averaging_test
# https://github.com/colmap/colmap/pull/4426
(fetchpatch {
url = "https://github.com/colmap/colmap/commit/d38b65b9312c66e841739989f4a38924d8cb5ec5.patch";
hash = "sha256-dbs+TNfa4o5L79+krPpF4VmP8PhFHtzYZehYZbsnx5s=";
})
];
cmakeFlags = [
(lib.cmakeBool "DOWNLOAD_ENABLED" true) # We want COLMAP to be able to fetch models like LightGlue.
(lib.cmakeBool "UNINSTALL_ENABLED" false)
@@ -117,8 +140,8 @@ stdenv'.mkDerivation rec {
(lib.cmakeBool "FETCH_FAISS" false)
(lib.cmakeBool "FETCH_ONNX" false)
(lib.cmakeBool "TESTS_ENABLED" enableTests)
(lib.cmakeFeature "CHOLMOD_INCLUDE_DIR_HINTS" "${suitesparse.dev}/include")
(lib.cmakeFeature "CHOLMOD_LIBRARY_DIR_HINTS" "${suitesparse}/lib")
(lib.cmakeFeature "CHOLMOD_INCLUDE_DIR_HINTS" "${lib.getDev suitesparse}/include")
(lib.cmakeFeature "CHOLMOD_LIBRARY_DIR_HINTS" "${lib.getLib suitesparse}/lib")
]
++ lib.optionals cudaSupport [
(lib.cmakeBool "CUDA_ENABLED" cudaSupport)
@@ -135,6 +158,7 @@ stdenv'.mkDerivation rec {
glog
libGLU
glew
gtest
qt5.qtbase
flann
lz4
@@ -153,21 +177,43 @@ stdenv'.mkDerivation rec {
]
++ lib.optionals cudaSupport [
autoAddDriverRunpath
cudaPackages.cuda_nvcc
];
doCheck = enableTests;
preCheck = lib.optionalString enableTests ''
export GTEST_FILTER='-*Gpu*:*GPU*:*OpenGL*' # Disable any test involving OpenGL or GPU, these won't work in the sandbox.
export HOME=$PWD
preCheck = lib.optionalString enableTests (
let
disabledTestPatterns = [
# Disable any test involving OpenGL or GPU, these won't work in the sandbox.
"*Gpu*"
"*GPU*"
"*OpenGL*"
]
++ lib.optionals stdenv'.hostPlatform.isDarwin [
# reconstruction_pruning_test.cc:65: Failure
# Expected: (redundant_point3D_ids.size()) > (prev_num_redundant_points3D), actual: 0 vs 0
"FindRedundantPoints3D.VaryingCoverageGain"
];
in
''
export GTEST_FILTER='-${lib.concatStringsSep ":" disabledTestPatterns}'
''
+ ''
export HOME=$PWD
''
# Pre-fetch the ONNX models into COLMAP's cache dir so we can run their tests.
mkdir -p .cache/colmap
${lib.concatMapStringsSep "\n" (model: ''
ln -s ${fetchurl model} .cache/colmap/${model.sha256}-${model.name}
'') modelsForTesting}
'';
+ ''
mkdir -p .cache/colmap
${lib.concatMapStringsSep "\n" (model: ''
ln -s ${fetchurl model} .cache/colmap/${model.sha256}-${model.name}
'') modelsForTesting}
''
);
passthru.depsAlsoForPycolmap = depsAlsoForPycolmap;
passthru.updateScript = nix-update-script { };
passthru = {
depsAlsoForPycolmap = depsAlsoForPycolmap;
updateScript = nix-update-script { };
};
meta = {
description = "Structure-From-Motion and Multi-View Stereo pipeline";
@@ -177,6 +223,8 @@ stdenv'.mkDerivation rec {
'';
mainProgram = "colmap";
homepage = "https://colmap.github.io/index.html";
downloadPage = "https://github.com/colmap/colmap";
changelog = "https://github.com/colmap/colmap/blob/${finalAttrs.src.tag}/CHANGELOG.rst";
license = lib.licenses.bsd3;
platforms = if cudaSupport then lib.platforms.linux else lib.platforms.unix;
maintainers = with lib.maintainers; [
@@ -185,4 +233,4 @@ stdenv'.mkDerivation rec {
chpatrick
];
};
}
})
+16 -4
View File
@@ -97,10 +97,22 @@ stdenv.mkDerivation (finalAttrs: {
python -m pip wheel --verbose --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist .)
'';
postInstall = lib.optionalString pythonSupport ''
mkdir "$dist"
cp faiss/python/dist/*.whl "$dist/"
'';
postInstall =
lib.optionalString pythonSupport ''
mkdir "$dist"
cp faiss/python/dist/*.whl "$dist/"
''
# The GPU targets in faiss-targets.cmake reference CUDA imported targets
# (CUDA::cudart, CUDA::cublas), but faiss-config.cmake never finds them.
# Declare the dependency so downstream find_package(faiss) resolves them.
+ lib.optionalString cudaSupport ''
substituteInPlace "$out/share/faiss/faiss-config.cmake" \
--replace-fail \
'include("''${CMAKE_CURRENT_LIST_DIR}/faiss-targets.cmake")' \
'include(CMakeFindDependencyMacro)
find_dependency(CUDAToolkit)
include("''${CMAKE_CURRENT_LIST_DIR}/faiss-targets.cmake")'
'';
passthru = {
inherit cudaSupport cudaPackages pythonSupport;
+22 -2
View File
@@ -21,15 +21,27 @@
zlib,
llvmPackages_20,
versionCheckHook,
config,
cudaSupport ? config.cudaSupport,
cudaPackages,
}:
let
turingstdenv = if stdenv.hostPlatform.isDarwin then llvmPackages_20.stdenv else stdenv;
turingstdenv =
if stdenv.hostPlatform.isDarwin then
llvmPackages_20.stdenv
else if cudaSupport then
cudaPackages.backendStdenv
else
stdenv;
in
turingstdenv.mkDerivation (finalAttrs: {
pname = "turingdb";
version = "1.33";
__structuredAttrs = true;
src = fetchFromGitHub {
owner = "turing-db";
repo = "turingdb";
@@ -74,6 +86,10 @@ turingstdenv.mkDerivation (finalAttrs: {
gitMinimal
pkg-config
python3
]
++ lib.optionals cudaSupport [
# Needed by transitive dependency faiss
cudaPackages.cuda_nvcc
];
buildInputs = [
@@ -90,7 +106,11 @@ turingstdenv.mkDerivation (finalAttrs: {
zlib
]
++ lib.optionals turingstdenv.isDarwin [ llvmPackages_20.openmp ]
++ lib.optionals stdenv.hostPlatform.isLinux [ stdenv.cc.cc.lib ];
++ lib.optionals stdenv.hostPlatform.isLinux [ stdenv.cc.cc.lib ]
++ lib.optionals cudaSupport [
cudaPackages.cuda_cudart
cudaPackages.libcublas
];
cmakeFlags = [
(lib.cmakeBool "NIX_BUILD" true)