jeremy-rifkin / libassert

The most over-engineered C++ assertion library
MIT License
505 stars 33 forks source link

Support for VCPKG #36

Closed A-F-V closed 8 months ago

A-F-V commented 1 year ago

Are there any plans to create a port for vcpkg?

jeremy-rifkin commented 1 year ago

Hey @A-F-V thanks for opening this issue. I'd definitely be interested in setting up support for vcpkg and conan. Nothing is in the works yet but I will try to find some time to look into this more.

A-F-V commented 1 year ago

Hi @jeremy-rifkin, I am happy to contribute. Just started on a fork. We can take this offline but to summarise the features I wanted to create for consideration: 1) Make the installation find_packageable 2) Create a vcpkg port (which is basically just the wrapper of a fetch content) 3) Also have a configuration option to add a prefix to the macros in case of conflict with other libraries assert macros

GavinRay97 commented 1 year ago

For what it's worth, I'd probably use the vcpkg port as well

GavinRay97 commented 1 year ago

So I have a working vcpkg portfile written, but the issue is that we can't submit them to the official ports repo until we make the CMakeLists.txt product debug library as well as a release library:

The /lib/cmake folder should be merged with /debug/lib/cmake and moved to /share/libassert/cmake.
Please use the helper function `vcpkg_cmake_config_fixup()` from the port vcpkg-cmake-config.`
The following cmake files were found outside /share/libassert. Please place cmake files in /share/libassert.

    /home/user/vcpkg/packages/libassert_x64-linux/lib/cmake/assert/assert-config-version.cmake
    /home/user/vcpkg/packages/libassert_x64-linux/lib/cmake/assert/assert_targets.cmake
    /home/user/vcpkg/packages/libassert_x64-linux/lib/cmake/assert/assert_targets-release.cmake
    /home/user/vcpkg/packages/libassert_x64-linux/lib/cmake/assert/assert-config.cmake

Mismatching number of debug and release binaries. Found 0 for debug but 1 for release.
Debug binaries

Release binaries

    /home/user/vcpkg/packages/libassert_x64-linux/lib/libassert.a

Debug binaries were not found

Found 3 post-build check problem(s). To submit these ports to curated catalogs, please first correct the portfile:
    /home/user/projects/libassert-vcpkg-test/./ports/libassert/portfile.cmake

The portfile is just:

vcpkg_from_github(
  OUT_SOURCE_PATH SOURCE_PATH
  REPO jeremy-rifkin/libassert
  REF a94970435d077666d8c712ececb5993c546732c2
  SHA512 9d952a291fa2fe4a4bf80f5ccf132f9c36729d342522d80eb7339591a4a0658aa0e223b650fa39aeea9f787fc4c0972e058950f9396e7ccbdbb1eb03c5629baf
  HEAD_REF master
)

################################################
# NOTE: This doesn't contain the feature flags for libassert
# but just a basic implementation as an example
################################################

vcpkg_configure_cmake(
  SOURCE_PATH "${SOURCE_PATH}"
  PREFER_NINJA
)
vcpkg_install_cmake()
# vcpkg_fixup_cmake_targets()  <-- uncomment this once debug library in CMakeLists.txt

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/tests")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug")

file(
  INSTALL "${SOURCE_PATH}/LICENSE"
  DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}"
  RENAME copyright)

Now, it is still possible to install libassert from your own vcpkg portfile or custom registry. If you want to test that out, you can try it by downloading this example project.

Run $ vcpkg build libassert --overlay-ports=./ports from the directory containing this project, and you should see it build successfully (albeit with some warnings about how it can't be officially submitted yet):

libassert-vcpkg-example.zip

[user@MSI libassert-vcpkg-test]$ vcpkg build libassert --overlay-ports=./ports
Detecting compiler hash for triplet x64-linux...
-- Installing port from location: /home/user/projects/libassert-vcpkg-test/./ports/libassert
-- Using cached jeremy-rifkin-libassert-a94970435d077666d8c712ececb5993c546732c2.tar.gz.
-- Using source at /home/user/vcpkg/buildtrees/libassert/src/3c546732c2-75bc8cf19e
-- Found external ninja('1.11.1').
-- Configuring x64-linux-dbg
-- Configuring x64-linux-rel
-- Building x64-linux-dbg
-- Building x64-linux-rel
-- Installing: /home/user/vcpkg/packages/libassert_x64-linux/share/libassert/copyright
-- Performing post-build validation
The /lib/cmake folder should be merged with /debug/lib/cmake and moved to /share/libassert/cmake.
Please use the helper function `vcpkg_cmake_config_fixup()` from the port vcpkg-cmake-config.`
The following cmake files were found outside /share/libassert. Please place cmake files in /share/libassert.

    /home/user/vcpkg/packages/libassert_x64-linux/lib/cmake/assert/assert-config-version.cmake
    /home/user/vcpkg/packages/libassert_x64-linux/lib/cmake/assert/assert_targets.cmake
    /home/user/vcpkg/packages/libassert_x64-linux/lib/cmake/assert/assert_targets-release.cmake
    /home/user/vcpkg/packages/libassert_x64-linux/lib/cmake/assert/assert-config.cmake

Mismatching number of debug and release binaries. Found 0 for debug but 1 for release.
Debug binaries

Release binaries

    /home/user/vcpkg/packages/libassert_x64-linux/lib/libassert.a

Debug binaries were not found

Found 3 post-build check problem(s). To submit these ports to curated catalogs, please first correct the portfile:
    /home/user/projects/libassert-vcpkg-test/./ports/libassert/portfile.cmake
-- Performing post-build validation done
Stored binary cache: "/home/user/.cache/vcpkg/archives/7a/7adc93afcff479f915aa65ff391624e986fa92680b2450e2ec3fcf1769af965f.zip"
A-F-V commented 1 year ago

How did you make the package FindPackageable?

GavinRay97 commented 1 year ago

It'll only be FindPackage available currently in Release mode because the CMakeLists.txt in the repo doesn't build dedicated Debug and Release artifacts

We'll need a small tweak to fix that 👍

jeremy-rifkin commented 1 year ago

Thank you @GavinRay97! It's probably time for me to bite the bullet and actually learn cmake. I'm hoping to have time this week to do so.

A-F-V commented 1 year ago

It'll only be FindPackage available currently in Release mode because the CMakeLists.txt in the repo doesn't build dedicated Debug and Release artifacts

We'll need a small tweak to fix that 👍

So FindPackage(assert CONFIG REQUIRED) is all you would need?

GavinRay97 commented 1 year ago

@jeremy-rifkin I can also PR it, but aye, as terrible as it is, it's one of those thing you just suck up in the sake of "it gets less and less awful the more you know how to use it", especially the more modern features 😅

I fucking hate CMake. Worst C++ build tool, but everyone uses it. I like XMake and Meson/Bazel a lot better. Or even Gradle lol.

@A-F-V Exactly, but with the example above, it would only work if your CMake project was being built in Release mode for the reasons mentioned.

It should be only a couple of lines to get a dedicated Debug asset but I don't think either Jeremy or I have had the time

GavinRay97 commented 1 year ago

The last step we'd want to add for the vcpkg port is just a section containing the FEATURE FLAGS that users can enable

option(ASSERT_DECOMPOSE_BINARY_LOGICAL "Enables expression decomposition of && and ||" OFF)
option(ASSERT_LOWERCASE "Enables assert alias for ASSERT" OFF)
option(ASSERT_USE_MAGIC_ENUM "Use the MagicEnum library to print better diagnostics for enum classes" ON)

So to make these user-configurable when people install from vcpkg, we translate them like this:

vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}" OPTIONS

Expands to "-DASSERT_DECOMPOSE_BINARY_LOGICAL=ON;-DASSERT_LOWERCASE=ON;..."

    ${FEATURE_OPTIONS}

)

shrinktofit commented 9 months ago

This thread has not been updated so far, what's the status?

jeremy-rifkin commented 9 months ago

Hi @shrinktofit, I have a PR open to to add cpptrace to vcpkg https://github.com/microsoft/vcpkg/pull/34217 but that depends on https://github.com/microsoft/vcpkg/pull/34382 to add libdwarf to vcpkg, and the pr has stalled a bit. Once cpptrace is added to vcpkg then libassert can be added.

jeremy-rifkin commented 9 months ago

I think maybe I just got the libdwarf pr working

jeremy-rifkin commented 8 months ago

Pr opened at vcpkg https://github.com/microsoft/vcpkg/pull/35094

jeremy-rifkin commented 8 months ago

And now the pr has been merged!