From 11291afcb3f633920281af8d9bc71091d1dd70ca Mon Sep 17 00:00:00 2001 From: qbisi Date: Fri, 30 May 2025 07:18:02 +0800 Subject: [PATCH 1/3] testers.hasCmakeConfigModules: init --- doc/build-helpers/testers.chapter.md | 20 +++++ doc/redirects.json | 6 ++ pkgs/build-support/testers/default.nix | 2 + .../testers/hasCmakeConfigModules/tester.nix | 86 +++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 pkgs/build-support/testers/hasCmakeConfigModules/tester.nix diff --git a/doc/build-helpers/testers.chapter.md b/doc/build-helpers/testers.chapter.md index 9e46635c600c..7f7e6bd7d3e7 100644 --- a/doc/build-helpers/testers.chapter.md +++ b/doc/build-helpers/testers.chapter.md @@ -40,6 +40,26 @@ If the `moduleNames` argument is omitted, `hasPkgConfigModules` will use `meta.p ::: +## `hasCmakeConfigModules` {#tester-hasCmakeConfigModules} + +Checks whether a package exposes a given list of `*config.cmake` modules. +Note the moduleNames used in cmake find_package are case sensitive. + +:::{.example #ex-hascmakeconfigmodules} + +# Check that `*config.cmake` modules are exposed using explicit module names + +```nix +{ + passthru.tests.cmake-config = testers.hasCmakeConfigModules { + package = finalAttrs.finalPackage; + moduleNames = [ "Foo" ]; + }; +} +``` + +::: + ## `lycheeLinkCheck` {#tester-lycheeLinkCheck} Check a packaged static site's links with the [`lychee` package](https://search.nixos.org/packages?show=lychee&type=packages&query=lychee). diff --git a/doc/redirects.json b/doc/redirects.json index 4c243c6cc852..b93961666a4b 100644 --- a/doc/redirects.json +++ b/doc/redirects.json @@ -1694,6 +1694,12 @@ "ex-haspkgconfigmodules-explicitmodules": [ "index.html#ex-haspkgconfigmodules-explicitmodules" ], + "tester-hasCmakeConfigModules": [ + "index.html#tester-hasCmakeConfigModules" + ], + "ex-hascmakeconfigmodules": [ + "index.html#ex-hascmakeconfigmodules" + ], "tester-lycheeLinkCheck": [ "index.html#tester-lycheeLinkCheck" ], diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix index b48320f7e270..3a2fcbfa4d1d 100644 --- a/pkgs/build-support/testers/default.nix +++ b/pkgs/build-support/testers/default.nix @@ -225,6 +225,8 @@ ); hasPkgConfigModules = callPackage ./hasPkgConfigModules/tester.nix { }; + hasCmakeConfigModules = callPackage ./hasCmakeConfigModules/tester.nix { }; + testMetaPkgConfig = callPackage ./testMetaPkgConfig/tester.nix { }; shellcheck = callPackage ./shellcheck/tester.nix { }; diff --git a/pkgs/build-support/testers/hasCmakeConfigModules/tester.nix b/pkgs/build-support/testers/hasCmakeConfigModules/tester.nix new file mode 100644 index 000000000000..85938ef3bf4f --- /dev/null +++ b/pkgs/build-support/testers/hasCmakeConfigModules/tester.nix @@ -0,0 +1,86 @@ +# Static arguments +{ + lib, + runCommandCC, + cmake, +}: + +# Tester arguments +{ + package, + moduleNames, + # Extra nativeBuildInputs needed to pass the cmake find_package test, e.g. pkg-config. + nativeBuildInputs ? [ ], + # buildInputs is used to help pass the cmake find_package test. + # The purpose of buildInputs here is to allow us to iteratively add + # any missing dependencies required by the *Config.cmake module + # during testing. This allows us to test and fix the CMake setup + # without rebuilding the finalPackage each time. Once all required + # packages are properly added to the finalPackage's propagateBuildInputs, + # this buildInputs should be set to an empty list []. + buildInputs ? [ ], + # Extra cmakeFlags needed to pass the cmake find_package test. + # Can be used to set verbose/debug flags. + cmakeFlags ? [ ], + testName ? "check-cmake-config-${package.pname or package.name}", + version ? package.version or null, + versionCheck ? false, +}: + +runCommandCC testName + { + inherit moduleNames versionCheck cmakeFlags; + version = if versionCheck then version else null; + nativeBuildInputs = [ + cmake + ] ++ nativeBuildInputs; + buildInputs = [ package ] ++ buildInputs; + meta = + { + description = "Test whether ${package.name} exposes cmake-config modules ${lib.concatStringsSep ", " moduleNames}"; + } + # Make sure licensing info etc is preserved, as this is a concern for e.g. cache.nixos.org, + # as hydra can't check this meta info in dependencies. + # The test itself is just Nixpkgs, with MIT license. + // builtins.intersectAttrs { + available = throw "unused"; + broken = throw "unused"; + insecure = throw "unused"; + license = throw "unused"; + maintainers = throw "unused"; + teams = throw "unused"; + platforms = throw "unused"; + unfree = throw "unused"; + unsupported = throw "unused"; + } package.meta; + } + '' + touch "$out" + notFound=0 + for moduleName in $moduleNames; do + echo "checking cmake-config module $moduleName" + + cat < CMakeLists.txt + cmake_minimum_required(VERSION 3.14) + project(CheckCmakeModule) + + find_package($moduleName $version EXACT NO_MODULE REQUIRED) + EOF + + echoCmd 'cmake flags' $cmakeFlags + set +e + cmake . $cmakeFlags + r=$? + set -e + if [[ $r = 0 ]]; then + echo "✅ cmake-config module $moduleName exists" + else + echo "❌ cmake-config module $moduleName was not found" + ((notFound+=1)) + fi + done + + if [[ $notFound -ne 0 ]]; then + exit 1 + fi + '' From e4ab873cc1e63bbd704d580ac7cc2269839a5381 Mon Sep 17 00:00:00 2001 From: qbisi Date: Fri, 30 May 2025 17:58:58 +0800 Subject: [PATCH 2/3] testers.hasCmakeConfigModules: add self tests --- .../testers/hasCmakeConfigModules/tests.nix | 73 +++++++++++++++++++ pkgs/build-support/testers/test/default.nix | 2 + 2 files changed, 75 insertions(+) create mode 100644 pkgs/build-support/testers/hasCmakeConfigModules/tests.nix diff --git a/pkgs/build-support/testers/hasCmakeConfigModules/tests.nix b/pkgs/build-support/testers/hasCmakeConfigModules/tests.nix new file mode 100644 index 000000000000..d691916db82f --- /dev/null +++ b/pkgs/build-support/testers/hasCmakeConfigModules/tests.nix @@ -0,0 +1,73 @@ +# cd nixpkgs +# nix-build -A tests.testers.hasCmakeConfigModules +{ + lib, + testers, + boost, + mpi, + eigen, + runCommand, +}: + +lib.recurseIntoAttrs { + + boost-versions-match = testers.hasCmakeConfigModules { + package = boost; + moduleNames = [ + "Boost" + "boost_math" + ]; + versionCheck = true; + }; + + boost-versions-mismatch = testers.testBuildFailure ( + testers.hasCmakeConfigModules { + package = boost; + moduleNames = [ + "Boost" + "boost_math" + ]; + version = "1.2.3"; # Deliberately-incorrect version number + versionCheck = true; + } + ); + + boost-no-versionCheck = testers.hasCmakeConfigModules { + package = boost; + moduleNames = [ + "Boost" + "boost_math" + ]; + version = "1.2.3"; # Deliberately-incorrect version number + versionCheck = false; + }; + + boost-has-boost_mpi = testers.hasCmakeConfigModules { + package = boost.override { useMpi = true; }; + moduleNames = [ + "boost_mpi" + ]; + buildInputs = [ mpi ]; + }; + + boost_mpi-does-not-have-mpi = testers.testBuildFailure ( + testers.hasCmakeConfigModules { + package = boost.override { useMpi = true; }; + moduleNames = [ + "boost_mpi" + ]; + } + ); + + eigen-has-Eigen = testers.hasCmakeConfigModules { + package = eigen; + moduleNames = [ "Eigen3" ]; + }; + + eigen-does-not-have-eigen = testers.testBuildFailure ( + testers.hasCmakeConfigModules { + package = eigen; + moduleNames = [ "eigen3" ]; + } + ); +} diff --git a/pkgs/build-support/testers/test/default.nix b/pkgs/build-support/testers/test/default.nix index fbcf6c0cad7d..ec54b7044c28 100644 --- a/pkgs/build-support/testers/test/default.nix +++ b/pkgs/build-support/testers/test/default.nix @@ -37,6 +37,8 @@ lib.recurseIntoAttrs { hasPkgConfigModules = pkgs.callPackage ../hasPkgConfigModules/tests.nix { }; + hasCmakeConfigModules = pkgs.callPackage ../hasCmakeConfigModules/tests.nix { }; + shellcheck = pkgs.callPackage ../shellcheck/tests.nix { }; shfmt = pkgs.callPackages ../shfmt/tests.nix { }; From bb3d46c9943623f078d3fcd46a336b3c5d9346c0 Mon Sep 17 00:00:00 2001 From: qbisi Date: Sat, 24 May 2025 21:13:58 +0800 Subject: [PATCH 3/3] c-blosc2: add cmake-config and propagate buildInputs --- pkgs/by-name/ad/adios2/package.nix | 6 ------ pkgs/development/libraries/c-blosc/1.nix | 14 +++++++++----- pkgs/development/libraries/c-blosc/2.nix | 14 +++++++++----- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pkgs/by-name/ad/adios2/package.nix b/pkgs/by-name/ad/adios2/package.nix index 6dc9083f41dd..498e2246d258 100644 --- a/pkgs/by-name/ad/adios2/package.nix +++ b/pkgs/by-name/ad/adios2/package.nix @@ -11,7 +11,6 @@ python3Packages, mpi, bzip2, - lz4, c-blosc2, hdf5-mpi, libfabric, @@ -22,8 +21,6 @@ zeromq, zfp, zlib, - zlib-ng, - zstd, ucx, yaml-cpp, nlohmann_json, @@ -69,7 +66,6 @@ stdenv.mkDerivation (finalAttrs: { [ mpi bzip2 - lz4 c-blosc2 (hdf5-mpi.override { inherit mpi; }) libfabric @@ -80,8 +76,6 @@ stdenv.mkDerivation (finalAttrs: { zeromq zfp zlib - zlib-ng # required by c-blocs2 - zstd # required by c-blocs2 yaml-cpp nlohmann_json diff --git a/pkgs/development/libraries/c-blosc/1.nix b/pkgs/development/libraries/c-blosc/1.nix index 745521a686b7..6349063e3dd9 100644 --- a/pkgs/development/libraries/c-blosc/1.nix +++ b/pkgs/development/libraries/c-blosc/1.nix @@ -33,7 +33,7 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ cmake ]; - buildInputs = [ + propagatedBuildInputs = [ lz4 zlib zstd @@ -54,15 +54,19 @@ stdenv.mkDerivation (finalAttrs: { doCheck = !static; - passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; + passthru.tests = { + pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; + cmake-config = testers.hasCmakeConfigModules { + moduleNames = [ "Blosc2" ]; + package = finalAttrs.finalPackage; + }; + }; meta = with lib; { description = "Blocking, shuffling and loss-less compression library"; homepage = "https://www.blosc.org"; changelog = "https://github.com/Blosc/c-blosc/releases/tag/v${finalAttrs.version}"; - pkgConfigModules = [ - "blosc" - ]; + pkgConfigModules = [ "blosc2" ]; license = licenses.bsd3; platforms = platforms.all; maintainers = with maintainers; [ ris ]; diff --git a/pkgs/development/libraries/c-blosc/2.nix b/pkgs/development/libraries/c-blosc/2.nix index 507c862c27f1..9c47d90f9849 100644 --- a/pkgs/development/libraries/c-blosc/2.nix +++ b/pkgs/development/libraries/c-blosc/2.nix @@ -33,7 +33,7 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ cmake ]; - buildInputs = [ + propagatedBuildInputs = [ lz4 zlib-ng zstd @@ -56,15 +56,19 @@ stdenv.mkDerivation (finalAttrs: { # possibly https://github.com/Blosc/c-blosc2/issues/432 enableParallelChecking = false; - passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; + passthru.tests = { + pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; + cmake-config = testers.hasCmakeConfigModules { + moduleNames = [ "Blosc2" ]; + package = finalAttrs.finalPackage; + }; + }; meta = with lib; { description = "Fast, compressed, persistent binary data store library for C"; homepage = "https://www.blosc.org"; changelog = "https://github.com/Blosc/c-blosc2/releases/tag/v${finalAttrs.version}"; - pkgConfigModules = [ - "blosc2" - ]; + pkgConfigModules = [ "blosc2" ]; license = licenses.bsd3; platforms = platforms.all; maintainers = with maintainers; [ ris ];