NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.31k stars 13.54k forks source link

Invalid include path with rapidcheck+cmake #296348

Open lockshaw opened 5 months ago

lockshaw commented 5 months ago

Describe the bug

Along the lines of https://discourse.nixos.org/t/could-weve-implemented-multi-output-packages-better/6597/6, the cmake configuration for the rapidcheck package (share/rapidcheck/cmake/rapidcheckConfig.cmake) expects the include directory to exist, but it is instead in the dev output which is located at a different path, yielding the resulting error message:

CMake Error in lib/utils/rapidcheck_extra/CMakeLists.txt:
  Imported target "rapidcheck" includes non-existent path

    "/nix/store/rcb38jkml5gdpq8jag4y8k2nxia4p8ql-rapidcheck-unstable-2023-12-14/include"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.

I attempted the fix recommended by @jtojnar in https://github.com/jtojnar/cmake-snips in https://github.com/lockshaw/rapidcheck/commit/7f82845ac2b10fa854c739ce2af4497cd8604387 (definitely possible my attempted fix is incorrect, it was blind guesswork based on the previous fmt PR), but when I try to build the new package locally to test the fix I encounter the following error:

error: cycle detected in build of '/nix/store/zp52hb15lr07hi4aii7wsychwhrsl71z-rapidcheck-unstable-2023-12-14-patched.drv' in the references of output 'dev' from output 'out'

Steps To Reproduce

See https://github.com/lockshaw/rapidcheck-issue for a minimal example (also contains a workaround that provides the expected behavior)

Notify maintainers

@Ericson2314

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.78, NixOS, 24.05 (Uakari), 24.05.20240218.b98a4e1`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Add a :+1: reaction to issues you find important.

jtojnar commented 5 months ago

To debug this, you can move the outputs to the build directory using the following patch and then preserve them with nix build .#rapidcheckPatched --keep-failed -L:

--- a/rapidcheckPatched.nix
+++ b/rapidcheckPatched.nix
@@ -31,6 +31,11 @@ stdenv.mkDerivation (finalAttrs: {
     tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
   };

+  postFixup = ''
+    cp -r "$out" outOutput
+    cp -r "$dev" devOutput
+  '';
+
   meta = with lib; {
     description = "A C++ framework for property based testing inspired by QuickCheck";
     inherit (finalAttrs.src.meta) homepage;

The build log will end with something like the following:

note: keeping build directory '/tmp/nix-build-rapidcheck-unstable-2023-12-14-patched.drv-2'

Then, to find the cycle, you can search for the dev output reference in the out tree:

$ rg /nix/store/8jca2z8r3yiv1xgz8m5nbc2lf2wyb8nc-rapidcheck-unstable-2023-12-14-patched-dev  /tmp/nix-build-rapidcheck-unstable-2023-12-14-patched.drv-2/source/build/outOutput/
/tmp/nix-build-rapidcheck-unstable-2023-12-14-patched.drv-2/source/build/outOutput/share/rapidcheck/cmake/rapidcheckConfig.cmake
62:  INTERFACE_INCLUDE_DIRECTORIES "/nix/store/8jca2z8r3yiv1xgz8m5nbc2lf2wyb8nc-rapidcheck-unstable-2023-12-14-patched-dev/include"

Apparently, a cmake file referring to the dev output is responsible for the cycle, because it remained in out.

The solution is to either remove the reference (which would break builds since the reference is used to find headers), or move the cmake file to dev output.

We actually have a setup hook for that but it does not support cmake files in datadir, only in libdir:

https://github.com/NixOS/nixpkgs/blob/d89547b0e13ca2f72813ab27ef0d7a78faadfc9f/pkgs/build-support/setup-hooks/multiple-outputs.sh#L172