Skip to content

Meson wrap support #9

Closed
Closed

Description

@z3ntu

Documentation: http://mesonbuild.com/Wrap-dependency-system-manual.html

Basically, it's a part of the meson build system that can download (and build) missing dependencies which is pretty convenient especially on platforms without native package managers (so Windows).

This works by including a meson.build file into the source tree (theoretically it would also be possible to keep that separate), e.g. https://github.com/z3ntu/hidapi/blob/razer_test/meson.build (note: this file works but just has support for hidraw linux, darwin/macOS and windows) that "declares" the dependency so it can be used from another meson project. The consuming project would just need something like https://github.com/z3ntu/razer_test/blob/master/subprojects/hidapi.wrap - and best case this would be submitted to the Meson WrapDB which puts this hidapi.wrap file into a central git repo that can be used with meson wrap install hidapi which adds that file into the local source tree.

I'll open a PR once I have it working on most/all supported platforms.

Activity

  1. added
    build system/CIAnything related to building the project or running on CI
    on Jul 13, 2021
  2. hanetzer commented on Sep 21, 2021

    @hanetzer

    on another note, meson also has a dist target which produces sensibly named tarballs
    (hidapi-ver.tar.* instead of hidapi-hidapi-ver.tar.*).
    I'm relatively skilled at writing meson buildscripts, so if you're interested in that I can whip
    one up and pr it.

  3. Youw commented on Sep 22, 2021

    @Youw
    Member

    I imagine having possible "meson wrap install hidapi" would be very convenient for Meson users.
    The question here is - what does it take on HIDAPI side to make it possible?

    Recently we've developed a CMake build system, which happened to be slightly less trivial than I have originally imagined it would (extra complexity for usage convenience). And we're deprecating support of the Autotools in favor of CMake on this matter.

    So do we need to make a whole new (Mason) build script for HIDAPI?
    Because that would mean we need to support two (three as Autotools is not obsolete yet) build systems at the same time, which would be unfortunate.

    Can we have Mason re-use CMake scripts for its build?

    As an alternative: can we have CMake generate Mason "import files" (is that even a thing?), similarly as we generate pkg-config import files? I.e. build HIDAPI with CMake and then publish the artifacts somewhere where meson wrap ... could get it from.

  4. hanetzer commented on Sep 23, 2021

    @hanetzer

    meson can consume FindFoo.cmake files, I know that much, not sure about wrapdb integration. However, its a pretty simple 'scripting language' (not right term but close enough for gov't work), so once its in-tree, maintenance of it would be simple enough, unless the project decides to add some truly insane steps to the build.

  5. Youw commented on Sep 23, 2021

    @Youw
    Member

    once its in-tree, maintenance of it would be simple enough

    I'd say this statement is true for any modern build system. It is more about the fact that a developer have to remember to go into yet another build script/configuration file and get it updated, e.g. when one more source file is added, etc.
    For example: aaf5f3d
    There is two trivial changes to libusb/CMakeLists.txt and libusb/Makefile.am. With meson it will become 3 places. Tomorrow someone else will say that "oh, you already have 3, lets make it 4, because I like/need X<BUILD SYSTEM> better".


    My point is: if it is possible to wrap around CMake (instead of copying it) - lets rather have a wrap.

  6. hanetzer commented on Sep 23, 2021

    @hanetzer

    My point is: if it is possible to wrap around CMake (instead of copying it) - lets rather have a wrap.

    No, as far as I can see the way a wrapdb works is you have pkgname.wrap file, which defines what deps
    it provides, where to get the raw source, and if pkgname isn't already meson, provide a 'patch' which
    converts it over.

    You can see it here https://github.com/mesonbuild/wrapdb, under the subprojects directory. If you go a directory deeper under pkgfiles you'll find the files used to create the 'patch'.

  7. xclaesse commented on Sep 23, 2021

    @xclaesse

    The question here is - what does it take on HIDAPI side to make it possible?

    You'll have to port its build system to meson, either in upstream repository or as a patch overlay in Meson's wrapdb.

  8. xclaesse commented on Sep 23, 2021

    @xclaesse

    A project that uses hidapi could uses Meson's cmake module to build hidapi: https://mesonbuild.com/CMake-module.html#cmake-subprojects. But that has many limitations and bugs.

  9. eli-schwartz commented on Sep 24, 2021

    @eli-schwartz

    As an alternative: can we have CMake generate Mason "import files" (is that even a thing?), similarly as we generate pkg-config import files? I.e. build HIDAPI with CMake and then publish the artifacts somewhere where meson wrap ... could get it from.

    meson natively uses pkg-config. Projects depending on hidapi do e.g. hidapi_dep = dependency('hidapi') and this will look up hidapi.pc via pkg-config.

    meson wrap is an additional dependency lookup method. By passing a meson option, the build system can be told to prefer local (vendored) private versions of dependencies, which relies on having hidapi build using meson -- then hidapi would get imported into the other project and built from scratch. This has some advantages, if users might not have hidapi installed or their distro doesn't provide a new enough version. Or if they use Windows where dependency management is complicated.

  10. Youw commented on Sep 24, 2021

    @Youw
    Member

    A project that uses hidapi could uses Meson's cmake module to build hidapi

    I would give it a shot.

    But that has many limitations and bugs.

    Let see if we hit any of those.

  11. Youw commented on Sep 24, 2021

    @Youw
    Member

    So yes, we do hit some limitation here (e.g. cannot re-use CMake alias targets), but there is a straight-forward workaround and so far I came up with this:
    https://github.com/libusb/hidapi/tree/meson_support

    I guess it can be greatly improved (add version info for starters), but I'd be more than happy to accept such change into master.
    I also not sure how my current implementation would fit with already existing pkg-config method on linux (e.g. compatibility over target names and so on).

    But other than that - I don't see any "limitations and bugs" that would make such approach unfeasible.

    Thoughts?

  12. Youw commented on May 4, 2022

    @Youw
    Member
  13. Youw commented on May 4, 2022

    @Youw
    Member

    Lets make it even better: #410

  14. eli-schwartz commented on May 5, 2022

    @eli-schwartz

    I tried to build it, but whatever magic incantations the auto-translation attempted to do seem to have failed because the libraries don't have any source files as far as Meson is aware.

  15. eli-schwartz commented on May 5, 2022

    @eli-schwartz

    Update: it works successfully if I move the hidapi source tree into subprojects/hidapi_build_cmake/ rather than using that shim file which I don't quite understand the workings of.

  16. Youw commented on May 5, 2022

    @Youw
    Member

    move the hidapi source tree into subprojects/hidapi_build_cmake/

    That shouldn't be required. Can you share failure logs when running on the original branch?

  17. Youw commented on May 5, 2022

    @Youw
    Member

    Ah, I see:

    hidapi_build_cmake| WARNING: CMake: path C:/projects/hidapi/hidapi is inside the root project but not inside the subproject.
    hidapi_build_cmake| WARNING:  --> Ignoring. This can lead to build errors.
    hidapi_build_cmake| WARNING: CMake: path C:/projects/hidapi/windows/hid.c is inside the root project but not inside the subproject.
    hidapi_build_cmake| WARNING:  --> Ignoring. This can lead to build errors.
    hidapi_build_cmake| WARNING: CMake: path C:/projects/hidapi/hidapi/hidapi.h is inside the root project but not inside the subproject.
    hidapi_build_cmake| WARNING:  --> Ignoring. This can lead to build errors.
    hidapi_build_cmake| WARNING: CMake: path C:/projects/hidapi/windows/hidapi_winapi.h is inside the root project but not inside the subproject.
    hidapi_build_cmake| WARNING:  --> Ignoring. This can lead to build errors.
    hidapi_build_cmake| WARNING: CMake: path C:/projects/hidapi/windows/hidapi_cfgmgr32.h is inside the root project but not inside the subproject.
    hidapi_build_cmake| WARNING:  --> Ignoring. This can lead to build errors.
    hidapi_build_cmake| WARNING: CMake: path C:/projects/hidapi/windows/hidapi_hidclass.h is inside the root project but not inside the subproject.
    hidapi_build_cmake| WARNING:  --> Ignoring. This can lead to build errors.
    hidapi_build_cmake| WARNING: CMake: path C:/projects/hidapi/windows/hidapi_hidpi.h is inside the root project but not inside the subproject.
    hidapi_build_cmake| WARNING:  --> Ignoring. This can lead to build errors.
    hidapi_build_cmake| WARNING: CMake: path C:/projects/hidapi/windows/hidapi_hidsdi.h is inside the root project but not inside the subproject.
    hidapi_build_cmake| WARNING:  --> Ignoring. This can lead to build errors.
    hidapi_build_cmake| WARNING: CMake: path C:/projects/hidapi/hidapi is inside the root project but not inside the subproject.
    hidapi_build_cmake| WARNING:  --> Ignoring. This can lead to build errors.
    hidapi_build_cmake| CMake project Project has 2 build targets.
    

    I haven't tried to build hidapi directly. Instead I used a different project, where hidapi is a subproject on its own - that way it works.

  18. Youw commented on May 5, 2022

    @Youw
    Member

    Updated the implementation.
    Added CI scripts.

  19. Youw commented on Mar 12, 2023

    @Youw
    Member

    As much as will be done in scope of this repo - already done in scope of #410

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    build system/CIAnything related to building the project or running on CIenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions