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

catch2: Upgrade to v3.1.0 #643

Merged
merged 1 commit into from Sep 23, 2022

Conversation

mikecrowe
Copy link
Contributor

Catch v3 now builds as a library rather than a single include file, which means that the meson.build files need to be rather more complex.

Catch v3's own CMake build system doesn't build dynamic libraries, and it doesn't seem like doing so would be worthwhile for such a project, so the Meson build only builds static libraries.

@neheb neheb marked this pull request as ready for review September 19, 2022 17:55
@neheb
Copy link
Collaborator

neheb commented Sep 19, 2022

Whoops. Meant to just run the CI

Copy link
Member

@eli-schwartz eli-schwartz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI is failing because this no longer provides catch2_dep = declare_dependency(...) -- it would be apropos to provide one using link_with: catch2, include_directories: 'src'.

Now that catch2-with-main.pc is an upstream thing, I think it would be nice to additionally add that to the [provide] section of the wrap file.

subprojects/packagefiles/catch2/src/catch2/meson.build Outdated Show resolved Hide resolved
subprojects/packagefiles/catch2/src/catch2/meson.build Outdated Show resolved Hide resolved
'Catch2Main',
[ 'internal/catch_main.cpp' ],
include_directories : '..',
dependencies : [],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add link_with: catch2, in order to guarantee that dependencies are traced.

libraries : catch2_with_main,
version : meson.project_version(),
description : 'A modern, C++-native, test framework for C++14 and above (links in default main)',
requires : 'catch2 = ' + meson.project_version()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here, the link_with will cause pkg.generate to detect that catch2_with_main depends on the "catch2" pkg-config dependency, although this automatic handling doesn't add a version match, hmm...

subprojects/packagefiles/catch2/meson.build Outdated Show resolved Hide resolved
subprojects/packagefiles/catch2/meson.build Outdated Show resolved Hide resolved
subprojects/packagefiles/catch2/src/catch2/meson.build Outdated Show resolved Hide resolved
@eli-schwartz
Copy link
Member

eli-schwartz commented Sep 20, 2022

Catch v3's own CMake build system doesn't build dynamic libraries, and it doesn't seem like doing so would be worthwhile for such a project, so the Meson build only builds static libraries.

Excellent analysis, I agree.

EDIT: Note you can build them with BUILD_SHARED_LIBS=ON, but then their cmake configuration throws a warning at you.

And in the FAQ:

Yes, Catch2 supports the standard CMake BUILD_SHARED_LIBS option. However, the dynamic library support is provided as-is. Catch2 does not provide API export annotations, and so you can only use it as a dynamic library on platforms that default to public visibility, or with tooling support to force export Catch2's API.

@mikecrowe
Copy link
Contributor Author

Thank you for the comprehensive and positive review. I believe that I've addressed all your points. I did need to use include_directories: '..' when declaring the dependencies rather than include_directories: 'src' though. Once these, and any future fixes, have been reviewed I can squash them down to a single commit.

I was also able to actually test the results rather better this time too by copying the wrap file and symlinking my Catch repository into another project that used Catch2. Is there a better way to do this that I've missed mention in the documentation for?

@eli-schwartz
Copy link
Member

I did need to use include_directories: '..' when declaring the dependencies rather than include_directories: 'src' though.

Yeah, that's fine, it just depends on which directory you create it from. :)

I was also able to actually test the results rather better this time too by copying the wrap file and symlinking my Catch repository into another project that used Catch2. Is there a better way to do this that I've missed mention in the documentation for?

The wrapdb repository itself can be used, via meson setup -Dwraps=catch2 builddir/, and that's how we test it in CI. That won't test using it in a project that makes use of catch2 though. For that, the usual real solution is, in fact, to copy over the .wrap file and e.g. the subprojects/packagefiles/catch2/ directory or the extracted sources.

The other solution is to run python3 tools/create_release.py which when run without authentication tokens for https://wrapdb.mesonbuild.com will simply generate catch2_3.1.0-1_patch.zip and catch2.wrap into subprojects/packagecache/

This is not precisely documented, though.

@eli-schwartz
Copy link
Member

There are two CI failures:

  • one of them is irrelevant and just means you need to rebase after another PR was merged
  • the other is saying that the catch2-with-main dependency isn't mentioned in releases.json

Comment on lines +55 to +56
# This isn't as good as the CMake tests, but it proves that we've
# actually put something in the library files.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like most of what the CMake tests are doing is regexes on the output of the test binary, implementing that would mean having to write a custom test runner python script... Probably not worth it. :D

@mikecrowe
Copy link
Contributor Author

I added "catch2-with-main" to dependency_names in release.json as you suggested, rebased, and it looks like the tests now pass. Thanks for that.

Whilst reviewing the patch I did realise that I've been rather inconsistent in where I've put the closing parentheses. I can make them consistent, but to do that I've to decide whether they should be on a line on their own for multi-line function invocations (e.g. as currently used for pkg.generate) or at the end of the last line (e.g. as currently used for static_library). Which do you prefer? Looking at the existing files there seems to be a preference for the former, though there are many instances of the latter too.

Thanks.

@eli-schwartz
Copy link
Member

FWIW my personal preference tends to the former.

Catch v3 now builds as static libraries rather than being a single
include file, which means that the meson.build files need to be rather
more complex. In addition to the main libCatch2.a library there's also a
libCatch2Main.a library that contains the main() function that was
previously enabled by defining CATCH_CONFIG_MAIN.

Catch v3's own CMake build system doesn't build dynamic libraries by
default, as described in the FAQ[1], so the Meson build only builds
static libraries.

[1] https://github.com/catchorg/Catch2/blob/devel/docs/faq.md#can-i-compile-catch2-into-a-dynamic-library
@mikecrowe
Copy link
Contributor Author

eli-shwartz wrote:

FWIW my personal preference tends to [parentheses on their own line].

After initially managing to do exactly the wrong thing, I believe that I've now done this correctly. I also switched to consistently using two spaces for indents. (Previously, for some reason Emacs wanted to use two characters for the function invocations but four characters for the foreach.) Please let me know if you'd like me to change anything else.

@eli-schwartz eli-schwartz merged commit 771b8d1 into mesonbuild:master Sep 23, 2022
@eli-schwartz
Copy link
Member

Thanks! Looks great.

@mikecrowe
Copy link
Contributor Author

Thank you for the reviews and for merging the change.

mikecrowe added a commit to mikecrowe/Catch2 that referenced this pull request Sep 26, 2022
Incorporate improvements suggested by Meson maintainer in
mesonbuild/wrapdb#643 .
mikecrowe added a commit to mikecrowe/Catch2 that referenced this pull request Oct 1, 2022
Incorporate improvements suggested by Meson maintainer in
mesonbuild/wrapdb#643 .
@neheb
Copy link
Collaborator

neheb commented Oct 3, 2022

This PR breaks cppzmq:

../subprojects/cppzmq-4.8.1/tests/recv_multipart.cpp:1:10: fatal error: catch2/catch.hpp: No such file or directory
    1 | #include <catch2/catch.hpp>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
[8/14] Compiling C++ object subprojects/cppzmq-4.8.1/unit_tests.p/tests_socket.cpp.o
FAILED: subprojects/cppzmq-4.8.1/unit_tests.p/tests_socket.cpp.o 
ccache c++ -Isubprojects/cppzmq-4.8.1/unit_tests.p -Isubprojects/cppzmq-4.8.1 -I../subprojects/cppzmq-4.8.1 -I../subprojects/cppzmq-4.8.1/tests -Isubprojects/Catch2-3.1.0/src -I../subprojects/Catch2-3.1.0/src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++17 -O0 -g -pthread -MD -MQ subprojects/cppzmq-4.8.1/unit_tests.p/tests_socket.cpp.o -MF subprojects/cppzmq-4.8.1/unit_tests.p/tests_socket.cpp.o.d -o subprojects/cppzmq-4.8.1/unit_tests.p/tests_socket.cpp.o -c ../subprojects/cppzmq-4.8.1/tests/socket.cpp
../subprojects/cppzmq-4.8.1/tests/socket.cpp:1:10: fatal error: catch2/catch.hpp: No such file or directory
    1 | #include <catch2/catch.hpp>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
[9/14] Compiling C++ object subprojects/cppzmq-4.8.1/unit_tests.p/tests_message.cpp.o
FAILED: subprojects/cppzmq-4.8.1/unit_tests.p/tests_message.cpp.o 
ccache c++ -Isubprojects/cppzmq-4.8.1/unit_tests.p -Isubprojects/cppzmq-4.8.1 -I../subprojects/cppzmq-4.8.1 -I../subprojects/cppzmq-4.8.1/tests -Isubprojects/Catch2-3.1.0/src -I../subprojects/Catch2-3.1.0/src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++17 -O0 -g -pthread -MD -MQ subprojects/cppzmq-4.8.1/unit_tests.p/tests_message.cpp.o -MF subprojects/cppzmq-4.8.1/unit_tests.p/tests_message.cpp.o.d -o subprojects/cppzmq-4.8.1/unit_tests.p/tests_message.cpp.o -c ../subprojects/cppzmq-4.8.1/tests/message.cpp
../subprojects/cppzmq-4.8.1/tests/message.cpp:2:10: fatal error: catch2/catch.hpp: No such file or directory
    2 | #include <catch2/catch.hpp>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
[10/14] Compiling C++ object subprojects/cppzmq-4.8.1/unit_tests.p/tests_context.cpp.o
FAILED: subprojects/cppzmq-4.8.1/unit_tests.p/tests_context.cpp.o 
ccache c++ -Isubprojects/cppzmq-4.8.1/unit_tests.p -Isubprojects/cppzmq-4.8.1 -I../subprojects/cppzmq-4.8.1 -I../subprojects/cppzmq-4.8.1/tests -Isubprojects/Catch2-3.1.0/src -I../subprojects/Catch2-3.1.0/src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++17 -O0 -g -pthread -MD -MQ subprojects/cppzmq-4.8.1/unit_tests.p/tests_context.cpp.o -MF subprojects/cppzmq-4.8.1/unit_tests.p/tests_context.cpp.o.d -o subprojects/cppzmq-4.8.1/unit_tests.p/tests_context.cpp.o -c ../subprojects/cppzmq-4.8.1/tests/context.cpp
../subprojects/cppzmq-4.8.1/tests/context.cpp:1:10: fatal error: catch2/catch.hpp: No such file or directory
    1 | #include <catch2/catch.hpp>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
[11/14] Compiling C++ object subprojects/cppzmq-4.8.1/unit_tests.p/tests_monitor.cpp.o
FAILED: subprojects/cppzmq-4.8.1/unit_tests.p/tests_monitor.cpp.o 
ccache c++ -Isubprojects/cppzmq-4.8.1/unit_tests.p -Isubprojects/cppzmq-4.8.1 -I../subprojects/cppzmq-4.8.1 -I../subprojects/cppzmq-4.8.1/tests -Isubprojects/Catch2-3.1.0/src -I../subprojects/Catch2-3.1.0/src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++17 -O0 -g -pthread -MD -MQ subprojects/cppzmq-4.8.1/unit_tests.p/tests_monitor.cpp.o -MF subprojects/cppzmq-4.8.1/unit_tests.p/tests_monitor.cpp.o.d -o subprojects/cppzmq-4.8.1/unit_tests.p/tests_monitor.cpp.o -c ../subprojects/cppzmq-4.8.1/tests/monitor.cpp
In file included from ../subprojects/cppzmq-4.8.1/tests/monitor.cpp:1:
../subprojects/cppzmq-4.8.1/tests/testutil.hpp:3:10: fatal error: catch2/catch.hpp: No such file or directory
    3 | #include <catch2/catch.hpp>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
[12/14] Compiling C++ object subprojects/cppzmq-4.8.1/unit_tests.p/tests_buffer.cpp.o
FAILED: subprojects/cppzmq-4.8.1/unit_tests.p/tests_buffer.cpp.o 
ccache c++ -Isubprojects/cppzmq-4.8.1/unit_tests.p -Isubprojects/cppzmq-4.8.1 -I../subprojects/cppzmq-4.8.1 -I../subprojects/cppzmq-4.8.1/tests -Isubprojects/Catch2-3.1.0/src -I../subprojects/Catch2-3.1.0/src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++17 -O0 -g -pthread -MD -MQ subprojects/cppzmq-4.8.1/unit_tests.p/tests_buffer.cpp.o -MF subprojects/cppzmq-4.8.1/unit_tests.p/tests_buffer.cpp.o.d -o subprojects/cppzmq-4.8.1/unit_tests.p/tests_buffer.cpp.o -c ../subprojects/cppzmq-4.8.1/tests/buffer.cpp
../subprojects/cppzmq-4.8.1/tests/buffer.cpp:1:10: fatal error: catch2/catch.hpp: No such file or directory
    1 | #include <catch2/catch.hpp>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
[13/14] Compiling C++ object subprojects/cppzmq-4.8.1/unit_tests.p/tests_active_poller.cpp.o
FAILED: subprojects/cppzmq-4.8.1/unit_tests.p/tests_active_poller.cpp.o 
ccache c++ -Isubprojects/cppzmq-4.8.1/unit_tests.p -Isubprojects/cppzmq-4.8.1 -I../subprojects/cppzmq-4.8.1 -I../subprojects/cppzmq-4.8.1/tests -Isubprojects/Catch2-3.1.0/src -I../subprojects/Catch2-3.1.0/src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++17 -O0 -g -pthread -MD -MQ subprojects/cppzmq-4.8.1/unit_tests.p/tests_active_poller.cpp.o -MF subprojects/cppzmq-4.8.1/unit_tests.p/tests_active_poller.cpp.o.d -o subprojects/cppzmq-4.8.1/unit_tests.p/tests_active_poller.cpp.o -c ../subprojects/cppzmq-4.8.1/tests/active_poller.cpp
In file included from ../subprojects/cppzmq-4.8.1/tests/active_poller.cpp:3:
../subprojects/cppzmq-4.8.1/tests/testutil.hpp:3:10: fatal error: catch2/catch.hpp: No such file or directory
    3 | #include <catch2/catch.hpp>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.

@eli-schwartz
Copy link
Member

So "catch2" updating from version 2 to version 3 is incompatible, which is an interesting naming scheme but okay.

@mikecrowe
Copy link
Contributor Author

It's a bit confusing, but "Catch2" is now the name of the project, not its version number. See also: catchorg/Catch2#769

The project tries to follow semantic versioning, so Catch2 v3.1.0 isn't API compatible with Catch2 v2.x.

Does this mean that we need separate catch2-2 and catch2-3 in the wrapdb? Or should we just wait for cppzmq to catch up?

@neheb
Copy link
Collaborator

neheb commented Oct 3, 2022

Probably the latter. I don't know if this was fixed upstream.

@eli-schwartz
Copy link
Member

If software is intended to be parallel-installable across major versions, it usually comes with separate dependency names. See for example gtk2 vs. gtk3 vs. gtk4.

Having multiple different providers for the same dependency in the wrapdb might not work 100% fantastically...

@mikecrowe mikecrowe deleted the mac/catch2-v3.1.0 branch October 30, 2022 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants