Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boost170: Fix cmake files #73940

Closed
wants to merge 1 commit into from
Closed

Conversation

knedlsepp
Copy link
Member

@knedlsepp knedlsepp commented Nov 22, 2019

Motivation for this change

Fixes: #63104
The *-config.cmake files before this commit incorrectly assumed that
their location will be in $out/lib, thus leading to incorrect relative
paths.
I used the following derivation to test that the change really makes a difference. Before this commit this doesn't build. (Interestingly enough it already worked with boost171.)

{ stdenv, cmake, boost170, writeTextDir}:

stdenv.mkDerivation rec {
  pname = "boost-cmake-example";
  version = "0.0.1";
  src = writeTextDir "CMakeLists.txt" ''
    cmake_minimum_required(VERSION 3.15)
    project(example)
    find_package(Boost REQUIRED COMPONENTS filesystem system program_options thread date_time)
  '';
  nativeBuildInputs = [
    cmake
  ];
  installPhase = ''
    mkdir $out
    echo test >> $out/test
  '';
  buildInputs = [
    boost170
  ];
}
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

The *-config.cmake files before this commit incorrectly assumed that
their location will be in $out/lib, thus leading to incorrect relative
paths.

Fixes: NixOS#63104
@veprbl
Copy link
Member

veprbl commented Nov 22, 2019

Wow, this a really simple fix!

cc @ktf and @arximboldi for feedback

@knedlsepp
Copy link
Member Author

@ktf @arximboldi ping

@veprbl veprbl self-assigned this Dec 4, 2019
@veprbl
Copy link
Member

veprbl commented Dec 4, 2019

I tried the test from the title and this doesn't seem to fix it:

-- Found Boost 1.70.0 at /nix/store/igmy3x78mabgr6r27zyiklmb78j7rpxg-boost-1.70.0-dev/lib/cmake/Boost-1.70.0
--   Requested configuration: QUIET REQUIRED COMPONENTS filesystem;system;program_options;thread;date_time
-- Found boost_headers 1.70.0 at /nix/store/igmy3x78mabgr6r27zyiklmb78j7rpxg-boost-1.70.0-dev/lib/cmake/boost_headers-1.70.0
-- Found boost_filesystem 1.70.0 at /nix/store/igmy3x78mabgr6r27zyiklmb78j7rpxg-boost-1.70.0-dev/lib/cmake/boost_filesystem-1.70.0
-- No suitable boost_filesystem variant has been identified!
--   libboost_filesystem.so.1.70.0 (shared, BUILD_SHARED_LIBS not ON, set Boost_USE_STATIC_LIBS=OFF to override)
CMake Error at /nix/store/igmy3x78mabgr6r27zyiklmb78j7rpxg-boost-1.70.0-dev/lib/cmake/Boost-1.70.0/BoostConfig.cmake:95 (find_package):
  Found package configuration file:

    /nix/store/igmy3x78mabgr6r27zyiklmb78j7rpxg-boost-1.70.0-dev/lib/cmake/boost_filesystem-1.70.0/boost_filesystem-config.cmake

  but it set boost_filesystem_FOUND to FALSE so package "boost_filesystem" is
  considered to be NOT FOUND.  Reason given by package:

  No suitable build variant has been found.

Call Stack (most recent call first):
  /nix/store/igmy3x78mabgr6r27zyiklmb78j7rpxg-boost-1.70.0-dev/lib/cmake/Boost-1.70.0/BoostConfig.cmake:124 (boost_find_dependency)
  /nix/store/0rwxndjblrj8ashnfv0g9sxcnv2mdiw3-cmake-3.15.4/share/cmake-3.15/Modules/FindBoost.cmake:443 (find_package)
  CMakeLists.txt:3 (find_package)


-- Configuring incomplete, errors occurred!
See also "/build/CMakeLists.txt/build/CMakeFiles/CMakeOutput.log".
builder for '/nix/store/2b30n09c4j0l07vaa80a437q4p03lx52-boost-cmake-example-0.0.1.drv' failed with exit code 1

It does, however, work for boost169 and boost171.

@veprbl veprbl removed their assignment Dec 4, 2019
@knedlsepp
Copy link
Member Author

I tried the test from the title and this doesn't seem to fix it:

-- Found Boost 1.70.0 at /nix/store/igmy3x78mabgr6r27zyiklmb78j7rpxg-boost-1.70.0-dev/lib/cmake/Boost-1.70.0
--   Requested configuration: QUIET REQUIRED COMPONENTS filesystem;system;program_options;thread;date_time
-- Found boost_headers 1.70.0 at /nix/store/igmy3x78mabgr6r27zyiklmb78j7rpxg-boost-1.70.0-dev/lib/cmake/boost_headers-1.70.0
-- Found boost_filesystem 1.70.0 at /nix/store/igmy3x78mabgr6r27zyiklmb78j7rpxg-boost-1.70.0-dev/lib/cmake/boost_filesystem-1.70.0
-- No suitable boost_filesystem variant has been identified!
--   libboost_filesystem.so.1.70.0 (shared, BUILD_SHARED_LIBS not ON, set Boost_USE_STATIC_LIBS=OFF to override)
CMake Error at /nix/store/igmy3x78mabgr6r27zyiklmb78j7rpxg-boost-1.70.0-dev/lib/cmake/Boost-1.70.0/BoostConfig.cmake:95 (find_package):
  Found package configuration file:

    /nix/store/igmy3x78mabgr6r27zyiklmb78j7rpxg-boost-1.70.0-dev/lib/cmake/boost_filesystem-1.70.0/boost_filesystem-config.cmake

  but it set boost_filesystem_FOUND to FALSE so package "boost_filesystem" is
  considered to be NOT FOUND.  Reason given by package:

  No suitable build variant has been found.

Call Stack (most recent call first):
  /nix/store/igmy3x78mabgr6r27zyiklmb78j7rpxg-boost-1.70.0-dev/lib/cmake/Boost-1.70.0/BoostConfig.cmake:124 (boost_find_dependency)
  /nix/store/0rwxndjblrj8ashnfv0g9sxcnv2mdiw3-cmake-3.15.4/share/cmake-3.15/Modules/FindBoost.cmake:443 (find_package)
  CMakeLists.txt:3 (find_package)


-- Configuring incomplete, errors occurred!
See also "/build/CMakeLists.txt/build/CMakeFiles/CMakeOutput.log".
builder for '/nix/store/2b30n09c4j0l07vaa80a437q4p03lx52-boost-cmake-example-0.0.1.drv' failed with exit code 1

It does, however, work for boost169 and boost171.

Hm. That's very weird. Worked for me. I'm gonna check that again. Thanks for trying it out!

@stolyaroleh
Copy link

stolyaroleh commented Jan 8, 2020

The above only fixes header only libraries for Boost 1.70 and above, since headers and CMake config are in the same output.
Here's how Boost CMake config tries to find headers:

get_filename_component(_BOOST_INCLUDEDIR "${_BOOST_CMAKEDIR}/../../../77ia59yvf36lg8c3vz628flsmzplr817-boost-1.70.0-dev/include/" ABSOLUTE)

...and here's how it tries to find libraries:

get_filename_component(_BOOST_LIBDIR "${_BOOST_CMAKEDIR}/../" ABSOLUTE)

It assumes that libraries are also in dev output.
We need to replace above with set(_BOOST_LIBDIR "$out/lib") to make multiple outputs work (or submit a pull request upstream).

Edit: I just realized I can only reproduce it with a static build using clang:

boost170 = boost170.override {
  enableStatic = true;
  enableShared = false;
};

@stolyaroleh
Copy link

stolyaroleh commented Jan 8, 2020

The following patch works for me:

diff --git a/pkgs/development/libraries/boost/generic.nix b/pkgs/development/libraries/boost/generic.nix
index 82bcd49592d..edc9c27c543 100644
--- a/pkgs/development/libraries/boost/generic.nix
+++ b/pkgs/development/libraries/boost/generic.nix
@@ -72,7 +72,8 @@ let
     "link=${link}"
     "-sEXPAT_INCLUDE=${expat.dev}/include"
     "-sEXPAT_LIBPATH=${expat.out}/lib"
-
+  ] ++ optionals (versionAtLeast version "1.70") [
+    "--cmakedir=$dev/lib/cmake"
     # TODO: make this unconditional
   ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
     "address-model=${toString stdenv.hostPlatform.parsed.cpu.bits}"
@@ -183,6 +184,16 @@ stdenv.mkDerivation {
       -exec sed '1s/^\xef\xbb\xbf//;1i#line 1 "{}"' -i '{}' \;
   '' + optionalString (stdenv.hostPlatform.libc == "msvcrt") ''
     $RANLIB "$out/lib/"*.a
+  '' + optionalString (versionAtLeast version "1.70") ''
+    for file in "$dev/lib/cmake/"*/*-config.cmake; do
+      sed -i -e \
+        " \
+        s|get_filename_component(_BOOST_CMAKEDIR .*)|set(_BOOST_CMAKEDIR \"$dev/lib/cmake\")|g; \
+        s|get_filename_component(_BOOST_INCLUDEDIR .*)|set(_BOOST_INCLUDEDIR \"$dev/include\")|g; \
+        s|get_filename_component(_BOOST_LIBDIR .*)|set(_BOOST_LIBDIR \"$out/lib\")|g; \
+        " \
+        "$file"
+    done
   '';
 
   outputs = [ "out" "dev" ];

@veprbl
Copy link
Member

veprbl commented Feb 29, 2020

A similar issue: #81004

@stolyaroleh
Copy link

stolyaroleh commented Mar 1, 2020

Not using separate outputs with Boost is a bad idea, since the headers alone are 156M:

$ du -hs $(nix-build --attr boost.dev)
156M	/nix/store/c9cga0sq8hykyviaz37bgb63lyjnlfvx-boost-1.69.0-dev

@arximboldi
Copy link
Contributor

Sorry for my long silence. What is the current status, which commit should I try now?

@arximboldi
Copy link
Contributor

(Last time I tried upgrading to a recent nixpkgs a couple of weeks ago I recall the problem still ocurred.)

@veprbl
Copy link
Member

veprbl commented Apr 14, 2020

Relevant PR #85254

@doronbehar
Copy link
Contributor

Hey, what's the status of this?

I also experience the issue described in #63104 with this error message in a build:

make[2]: *** No rule to make target '/nix/store/rxqaqc7j9a7fpwj0gspn5wiwxq1pybqz-boost-1.72.0-dev/lib/libboost_iostreams.so.1.72.0', needed by 'libmatrix_client.so.0.3.0'.  Stop.

Just to note anyone who may want to perform the version bump I'm attempting:

I'm trying to build mtxclient 0.3.0 which depends on boost17x and mtxclient is a dependency of nheko 0.7.1 (matrix client).

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/could-weve-implemented-multi-output-packages-better/6597/5

@doronbehar doronbehar mentioned this pull request Apr 24, 2020
10 tasks
@doronbehar
Copy link
Contributor

BTW I confirm now that this PR fixes the issue for me with mtxclient.

@doronbehar
Copy link
Contributor

Just wanted to say that both this and #85254 work, as mentioned in #85922 . What I've found out today though, was that with the workaround supplied at: #85922 (comment)

Makes (e.g) mtxclient reference boost.dev. With either this or the other patch, it doesn't.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-in-distress/3604/20

@doronbehar
Copy link
Contributor

Closed in favor of #85254

@doronbehar doronbehar closed this May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Boost 1.70 cmake config broken
6 participants