Nheko-Reborn / mtxclient

Client API library for Matrix, built on top of libcurl
MIT License
40 stars 25 forks source link

Tests fail to build with nlohmann_json 3.11.2 #93

Closed inglor closed 1 year ago

inglor commented 1 year ago

Hello

I'm a package maintainer in Archlinux and looking to get nheko into the repos. Building the mtxclient using cmake and enabled tests fails with the below which I think is due to nlogmann_json dependency (maybe I'm wrong):

FAILED: messages 
: && /usr/bin/c++ -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security         -fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS -g -ffile-prefix-map=/build/mtxclient/src=/usr/src/debug/mtxclient -flto=auto        -Wall       -Wextra         -Wconversion        -pipe       -pedantic       -fsized-deallocation        -fdiagnostics-color=always      -Wno-attributes         -Wunreachable-code -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -flto=auto CMakeFiles/messages.dir/tests/messages.cpp.o -o messages  -Wl,-rpath,/build/mtxclient/src/build  libmatrix_client.so.0.9.1  /usr/lib/libspdlog.so.1.11.0  /usr/lib/libfmt.so.9.1.0  /usr/lib/libcoeurl.so  /usr/lib/libssl.so  /usr/lib/libcrypto.so  /usr/lib/libolm.so.3.2.12  /usr/lib/libgtest_main.so.1.13.0  /usr/lib/libgtest.so.1.13.0 && :
/usr/bin/ld: /tmp/ccqB79NN.ltrans1.ltrans.o: in function `RoomEvents_Encrypted_Test::TestBody()':
/usr/include/nlohmann/detail/conversions/from_json.hpp:478: undefined reference to `void mtx::events::from_json<mtx::events::msg::Encrypted>(nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > const&, mtx::events::RoomEvent<mtx::events::msg::Encrypted>&)'
/usr/bin/ld: /tmp/ccqB79NN.ltrans1.ltrans.o: in function `RoomEvents_Encrypted_Test::TestBody()':
/usr/include/nlohmann/detail/conversions/to_json.hpp:428: undefined reference to `void mtx::events::to_json<mtx::events::msg::Encrypted>(nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >&, mtx::events::RoomEvent<mtx::events::msg::Encrypted> const&)'
/usr/bin/ld: /usr/include/nlohmann/detail/conversions/to_json.hpp:428: undefined reference to `void mtx::events::to_json<mtx::events::msg::Encrypted>(nlohmann::json_abi_v3_11_2::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_2::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >&, mtx::events::RoomEvent<mtx::events::msg::Encrypted> const&)'
collect2: error: ld returned 1 exit status

Build command used:

  cmake \
    -Bbuild \
    -GNinja \
    -S "$pkgname" \
    -DCMAKE_BUILD_TYPE='None' \
    -DCMAKE_INSTALL_PREFIX='/usr' \
    -DCMAKE_INSTALL_LIBDIR='lib' \
    -DBUILD_LIB_EXAMPLES=OFF \
    -DBUILD_SHARED_LIBS=ON \
    -Wno-dev
  cmake --build build --verbose

cmake build detection log:

-- The C compiler identification is GNU 12.2.1
-- The CXX compiler identification is GNU 12.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Found OpenSSL: /usr/lib/libcrypto.so (found suitable version "3.0.8", minimum required is "1.1.0")  
-- Found nlohmann_json: /usr/share/cmake/nlohmann_json/nlohmann_jsonConfig.cmake (found suitable version "3.11.2", minimum required is "3.2.0") 
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.0") 
-- Checking for module 're2'
--   Found re2, version 10.0.0
-- Checking for module 'libevent_core'
--   Found libevent_core, version 2.1.12
-- Checking for module 'libevent_pthreads'
--   Found libevent_pthreads, version 2.1.12
-- Checking for module 'libcurl'
--   Found libcurl, version 7.87.0
-- Checking for module 'coeurl>=0.3.0'
--   Found coeurl, version 0.3.0
-- The following REQUIRED packages have been found:

 * OpenSSL (required version >= 1.1.0), Open source SSL and TLS implementation and cryptographic library, <https://www.openssl.org/>
 * Olm (required version >= 3.2.7), An implementation of the Double Ratchet cryptographic ratchet, <https://git.matrix.org/git/olm/about/>
 * nlohmann_json (required version >= 3.2.0), JSON for Modern C++, a C++11 header-only JSON class, <https://nlohmann.github.io/json/>
 * Threads
 * spdlog (required version >= 1.0.0), Very fast, header only, C++ logging library, <https://github.com/gabime/spdlog>
 * PkgConfig

-- Found GTest: /usr/lib/cmake/GTest/GTestConfig.cmake (found version "1.13.0") 
-- Configuring done

[...]

You can see the full log mtxclient-0.9.1-1-x86_64-build.log

Thanks for the assistance

deepbluev7 commented 1 year ago

Ah, this is probably #80 , let me check, if I can fix that.

deepbluev7 commented 1 year ago

The issue was only in the test code. You can either disable building those tests using -DBUILD_LIB_TESTS=OFF or use the commit https://github.com/Nheko-Reborn/mtxclient/commit/6daf21627c36704e28245e52ad525508ec5be51f . (Or disable LTO for those tests, which prevents the functions from being removed.)

inglor commented 1 year ago

Thank you - I ended up not using it after all for now since the tests depend on synapse server running in docker (according to docs). I'll try to revisit tests once I got the rest packaged.

tastytea commented 1 year ago

Thank you - I ended up not using it after all for now since the tests depend on synapse server running in docker (according to docs). I'll try to revisit tests once I got the rest packaged.

Not all tests. We have a patch in Gentoo ::guru to disable the ones requiring a server: 0.6.0_remove_network_tests.patch.

deepbluev7 commented 1 year ago

(Some day you will just be able to use the "nonetwork" testsuite in meson... some day :D)

inglor commented 1 year ago

@deepbluev7 is there somewhere written down what's left to fully transition to meson? And interested in PRs? :)

deepbluev7 commented 1 year ago

The problem is that for ease of development we wanted to provide wraps for everything. This included curl on Windows. However, as you can see, usually we naively use a cmake subproject as a wrap instead. That doesn't work on Windows if you include Qt, since both have an xhash header and the way meson uses cmake for subprojects uses the cmake API, which does not distinguish between public and private headers. So basically we needed to write a meson.build for curl, so that we can have a wrap on Windows and I gave up halfway. The meson branch for Nheko should still be on our gitlab (nheko.im) and possibly also on github. :D

inglor commented 1 year ago

Oof! 😅 I'll check but it already looks complicated 🤣

deepbluev7 commented 1 year ago

I do already Arch work, better not burn out all the good will :p

Otherwise join us in our matrix room and I can walk you through it in detail.

inglor commented 1 year ago

Might be confusing due to my GitHub username but I'm @artafinde@fosstodon.org :) so I appreciate the comments, assistance and prompt resolution 😃

I'll get into the matrix room :)