jedisct1 / libhydrogen

A lightweight, secure, easy-to-use crypto library suitable for constrained environments.
https://libhydrogen.org
Other
594 stars 88 forks source link

Meson build system #149

Closed edmonds closed 4 months ago

edmonds commented 4 months ago

Hi, Frank!

This branch adds a meson.build file for building libhydrogen. Not sure if you want another build system in your tree, but since I saw you have a few Makefiles and CMake already, I thought I would check :-)

If you aren't familiar with meson and its wrap dependency system , this makes it easy for a meson project to take a dependency on another one, especially and even if the dependency is not available from the OS.

E.g., I want to depend on libhydrogen from a project that I'm working on that uses meson, but libhydrogen is not available from my OS's packages repository, so I added these commits to my project:

https://github.com/edmonds/vacon/commit/045c9202d13b9db2736f2770530d117390791441 https://github.com/edmonds/vacon/commit/82bce87f0f65e11f92adb30fd6e0ce035d5e2cb9

Meson then takes care of automatically downloading libhydrogen and building it into my project if the dependency can't be satisfied from the system:

$ meson setup build
[…]
Run-time dependency libhydrogen found: NO (tried pkgconfig and cmake)
Looking for a fallback subproject for the dependency libhydrogen
Initialized empty Git repository in /home/edmonds/proj/vacon/subprojects/libhydrogen/.git/
remote: Enumerating objects: 69, done.
remote: Counting objects: 100% (69/69), done.
remote: Compressing objects: 100% (63/63), done.
remote: Total 69 (delta 10), reused 25 (delta 3), pack-reused 0
Unpacking objects: 100% (69/69), 51.52 KiB | 2.58 MiB/s, done.
From https://github.com/edmonds/libhydrogen
 * branch            f8782bf07b5211ff0cb37b5b7a6f7b5c6b52626b -> FETCH_HEAD
HEAD is now at f8782bf Add meson build system

Executing subproject libhydrogen

libhydrogen| Project name: libhydrogen
libhydrogen| Project version: undefined
libhydrogen| C compiler for the host machine: sccache cc (gcc 13.2.0 "cc (Debian 13.2.0-16.1) 13.2.0")
libhydrogen| C linker for the host machine: cc ld.bfd 2.42
libhydrogen| Compiler for C supports arguments -Wbad-function-cast: YES
libhydrogen| Compiler for C supports arguments -Wcast-align: YES
libhydrogen| Compiler for C supports arguments -Wcast-qual: YES
libhydrogen| Compiler for C supports arguments -Wdiv-by-zero: YES
libhydrogen| Compiler for C supports arguments -Wfloat-equal: YES
libhydrogen| Compiler for C supports arguments -Wmissing-declarations: YES
libhydrogen| Compiler for C supports arguments -Wmissing-prototypes: YES
libhydrogen| Compiler for C supports arguments -Wnested-externs: YES
libhydrogen| Compiler for C supports arguments -Wno-type-limits: YES
libhydrogen| Compiler for C supports arguments -Wno-unknown-pragmas: YES
libhydrogen| Compiler for C supports arguments -Wpointer-arith: YES
libhydrogen| Compiler for C supports arguments -Wredundant-decls: YES
libhydrogen| Compiler for C supports arguments -Wstrict-prototypes: YES
libhydrogen| Compiler for C supports arguments -Wswitch-enum: YES
libhydrogen| Compiler for C supports arguments -fno-exceptions: YES
libhydrogen| Compiler for C supports arguments -mtune=native: YES
libhydrogen| Build targets in project: 3
libhydrogen| Subproject libhydrogen finished.

Dependency libhydrogen from subproject subprojects/libhydrogen found: YES undefined
[…]

I also added pkg-config .pc file generation, but if you want a meson.build without that functionality that commit can be omitted.

Thanks!

jedisct1 commented 4 months ago

Hi!

Could you add some tests for this to the CI scripts?

I don't use Meson nor CMake, so having this tested at least in CI can help to make sure that it doesn't unintentionally break.

edmonds commented 4 months ago

Hi!

Could you add some tests for this to the CI scripts?

I don't use Meson nor CMake, so having this tested at least in CI can help to make sure that it doesn't unintentionally break.

Sure. I just pushed some additional commits that run the three build systems (CMake, Make, Meson) in CI and also fixed a few deprecation warnings.

jedisct1 commented 4 months ago

Awesome, thank you!