diff --git a/pkgs/development/libraries/opencv/4.x.nix b/pkgs/development/libraries/opencv/4.x.nix index dd62e53989817..71a01a5467716 100644 --- a/pkgs/development/libraries/opencv/4.x.nix +++ b/pkgs/development/libraries/opencv/4.x.nix @@ -3,6 +3,7 @@ stdenv, fetchurl, fetchFromGitHub, + fetchpatch2, cmake, pkg-config, unzip, @@ -300,6 +301,13 @@ effectiveStdenv.mkDerivation { patches = [ ./cmake-don-t-use-OpenCVFindOpenEXR.patch + # NOTE: remove patch in opencv v4.12.0 (next release) + # https://github.com/opencv/opencv/pull/27428 + # it is required to allow cross compilation by letting PROTOC_EXE be set by protobuf hook + (fetchpatch2 { + url = "https://github.com/opencv/opencv/commit/bbe2f50b5d50a282b2260100be9e559067e55fbf.patch?full_index=1"; + hash = "sha256-T+zmrOeyEmNyu1hJPDGUub59EMXwe6ZqP6PV/tDJFCk="; + }) ] ++ optionals enableCuda [ ./cuda_opt_flow.patch diff --git a/pkgs/development/libraries/protobuf/cmake-configure-protoc-exe-21.patch b/pkgs/development/libraries/protobuf/cmake-configure-protoc-exe-21.patch new file mode 100644 index 0000000000000..c6476d216dd14 --- /dev/null +++ b/pkgs/development/libraries/protobuf/cmake-configure-protoc-exe-21.patch @@ -0,0 +1,47 @@ +commit 649864521c0e09f3a3bd7939d91ba1ef488946dc +Author: phanirithvij +Date: Tue Jun 10 10:58:49 2025 +0530 + + [CMake] Allow for protoc executable to be configured + + copied from commit 3163111b6fb1da08b9d6ad75518d91b89cd03bbf + + Signed-off-by: phanirithvij + +diff --git a/cmake/protobuf-config.cmake.in b/cmake/protobuf-config.cmake.in +index 61669118c..55f32516f 100644 +--- a/cmake/protobuf-config.cmake.in ++++ b/cmake/protobuf-config.cmake.in +@@ -11,7 +11,7 @@ function(protobuf_generate) + include(CMakeParseArguments) + + set(_options APPEND_PATH) +- set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR PLUGIN PLUGIN_OPTIONS) ++ set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR PLUGIN PLUGIN_OPTIONS PROTOC_EXE) + if(COMMAND target_sources) + list(APPEND _singleargs TARGET) + endif() +@@ -92,6 +92,11 @@ function(protobuf_generate) + endforeach() + endif() + ++ if(NOT protobuf_generate_PROTOC_EXE) ++ # Default to using the CMake executable ++ set(protobuf_generate_PROTOC_EXE protobuf::protoc) ++ endif() ++ + foreach(DIR ${protobuf_generate_IMPORT_DIRS}) + get_filename_component(ABS_PATH ${DIR} ABSOLUTE) + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) +@@ -146,9 +151,9 @@ function(protobuf_generate) + + add_custom_command( + OUTPUT ${_generated_srcs} +- COMMAND protobuf::protoc ++ COMMAND ${protobuf_generate_PROTOC_EXE} + ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_plugin_options}:${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file} +- DEPENDS ${_abs_file} protobuf::protoc ++ DEPENDS ${_abs_file} ${protobuf_generate_PROTOC_EXE} + COMMENT ${_comment} + VERBATIM ) + endforeach() diff --git a/pkgs/development/libraries/protobuf/generic.nix b/pkgs/development/libraries/protobuf/generic.nix index e0094c8521656..5a5deea7abf94 100644 --- a/pkgs/development/libraries/protobuf/generic.nix +++ b/pkgs/development/libraries/protobuf/generic.nix @@ -13,7 +13,6 @@ zlib, version, hash, - replaceVars, versionCheckHook, # downstream dependencies @@ -42,14 +41,27 @@ stdenv.mkDerivation (finalAttrs: { --replace-fail 'tmpnam(b)' '"'$TMPDIR'/foo"' ''; - patches = lib.optionals (lib.versionOlder version "22") [ - # fix protobuf-targets.cmake installation paths, and allow for CMAKE_INSTALL_LIBDIR to be absolute - # https://github.com/protocolbuffers/protobuf/pull/10090 - (fetchpatch { - url = "https://github.com/protocolbuffers/protobuf/commit/a7324f88e92bc16b57f3683403b6c993bf68070b.patch"; - hash = "sha256-SmwaUjOjjZulg/wgNmR/F5b8rhYA2wkKAjHIOxjcQdQ="; - }) - ]; + patches = + lib.optionals (lib.versionOlder version "22") [ + # fix protobuf-targets.cmake installation paths, and allow for CMAKE_INSTALL_LIBDIR to be absolute + # https://github.com/protocolbuffers/protobuf/pull/10090 + (fetchpatch { + url = "https://github.com/protocolbuffers/protobuf/commit/a7324f88e92bc16b57f3683403b6c993bf68070b.patch"; + hash = "sha256-SmwaUjOjjZulg/wgNmR/F5b8rhYA2wkKAjHIOxjcQdQ="; + }) + ] + ++ lib.optionals (lib.head (lib.splitVersion version) == "21") [ + # patch 3163111b6fb1da08b9d6ad75518d91b89cd03bbf with additional modifications + ./cmake-configure-protoc-exe-21.patch + ] + ++ lib.optionals (lib.versionAtLeast version "22" && lib.versionOlder version "29") [ + # for cross compilation allow for invocations of `protobuf_generate` pass their preferred programs + # https://github.com/protocolbuffers/protobuf/pull/17888 (in tree from 29 onwards) + (fetchpatch { + url = "https://github.com/protocolbuffers/protobuf/commit/3163111b6fb1da08b9d6ad75518d91b89cd03bbf.patch"; + hash = "sha256-px085y1MRt9qgYHCqR7ZOaNaHO1RV+VK3WWaI9I9wPg="; + }) + ]; # hook to provide the path to protoc executable, used at build time build_protobuf =