BLAKE2 / libb2

C library providing BLAKE2b, BLAKE2s, BLAKE2bp, BLAKE2sp
Creative Commons Zero v1.0 Universal
132 stars 47 forks source link

Meson build system #38

Open eli-schwartz opened 3 years ago

eli-schwartz commented 3 years ago

Fairly straightforward port from autotools to meson. Should work on Linux, *BSD, Solaris, macOS and Windows. Probably works on AIX via gcc.

Detecting CPU or compiler availability of instruction sets relies on GCC or clang specific __builtin_cpu_supports and checking if the compiler accepts -m<iset>, but should fall back reasonably well to unoptimized binaries on, say, MSVC -- which currently isn't supported anyway, the autotools build system is both Windows unfriendly and also hardcodes assumptions like... accepting GCC-style flags for -m<iset>. Oh well, at least it should build. Implementing that can be left to someone who cares about Windows.

Benefits:

$ time meson setup builddir --prefix /usr -Dfat=true
The Meson build system
Version: 0.59.99
Source dir: /tmp/libb2
Build dir: /tmp/libb2/builddir
Build type: native build
Project name: libb2
Project version: 0.98.1
C compiler for the host machine: ccache cc (gcc 11.1.0 "cc (GCC) 11.1.0")
C linker for the host machine: cc ld.bfd 2.36.1
Host machine cpu family: x86_64
Host machine cpu: x86_64
Run-time dependency OpenMP found: YES 4.5
Compiler for C supports arguments -mavx: YES 
Compiler for C supports arguments -mavx2: YES 
Compiler for C supports arguments -msse2: YES 
Compiler for C supports arguments -mssse3: YES 
Compiler for C supports arguments -msse4.1: YES 
Compiler for C supports arguments -mxop: YES 
Configuring config.h using configuration
Build targets in project: 11

Found ninja-1.10.2 at /usr/bin/ninja

real    0m1.649s
user    0m1.428s
sys 0m0.226s
$ time ninja -C builddir
ninja: Entering directory `builddir'
[1/31] Compiling C object src/libblake2_ssse3.a.p/blake2s.c.o
../src/blake2s.c:60:22: warning: ‘blake2s_sigma’ defined but not used [-Wunused-const-variable=]
   60 | static const uint8_t blake2s_sigma[10][16] =
      |                      ^~~~~~~~~~~~~
[3/31] Compiling C object src/libblake2_sse2.a.p/blake2s.c.o
../src/blake2s.c:60:22: warning: ‘blake2s_sigma’ defined but not used [-Wunused-const-variable=]
   60 | static const uint8_t blake2s_sigma[10][16] =
      |                      ^~~~~~~~~~~~~
[6/31] Compiling C object src/libblake2_ssse3.a.p/blake2b.c.o
../src/blake2b.c:63:22: warning: ‘blake2b_sigma’ defined but not used [-Wunused-const-variable=]
   63 | static const uint8_t blake2b_sigma[12][16] =
      |                      ^~~~~~~~~~~~~
[8/31] Compiling C object src/libblake2_sse2.a.p/blake2b.c.o
../src/blake2b.c:63:22: warning: ‘blake2b_sigma’ defined but not used [-Wunused-const-variable=]
   63 | static const uint8_t blake2b_sigma[12][16] =
      |                      ^~~~~~~~~~~~~
[10/31] Compiling C object src/libblake2_sse4.1.a.p/blake2s.c.o
../src/blake2s.c:60:22: warning: ‘blake2s_sigma’ defined but not used [-Wunused-const-variable=]
   60 | static const uint8_t blake2s_sigma[10][16] =
      |                      ^~~~~~~~~~~~~
[11/31] Compiling C object src/libblake2_sse4.1.a.p/blake2b.c.o
../src/blake2b.c:63:22: warning: ‘blake2b_sigma’ defined but not used [-Wunused-const-variable=]
   63 | static const uint8_t blake2b_sigma[12][16] =
      |                      ^~~~~~~~~~~~~
[15/31] Compiling C object src/libb2.so.1.0.4.p/blake2-dispatch.c.o
../src/blake2-dispatch.c:41:19: warning: ‘feature_names’ defined but not used [-Wunused-const-variable=]
   41 | static const char feature_names[][8] =
      |                   ^~~~~~~~~~~~~
[16/31] Compiling C object src/libblake2_avx.a.p/blake2s.c.o
../src/blake2s.c:60:22: warning: ‘blake2s_sigma’ defined but not used [-Wunused-const-variable=]
   60 | static const uint8_t blake2s_sigma[10][16] =
      |                      ^~~~~~~~~~~~~
[18/31] Compiling C object src/libblake2_avx.a.p/blake2b.c.o
../src/blake2b.c:63:22: warning: ‘blake2b_sigma’ defined but not used [-Wunused-const-variable=]
   63 | static const uint8_t blake2b_sigma[12][16] =
      |                      ^~~~~~~~~~~~~
[20/31] Compiling C object src/libblake2_xop.a.p/blake2s.c.o
../src/blake2s.c:60:22: warning: ‘blake2s_sigma’ defined but not used [-Wunused-const-variable=]
   60 | static const uint8_t blake2s_sigma[10][16] =
      |                      ^~~~~~~~~~~~~
[22/31] Compiling C object src/libblake2_xop.a.p/blake2b.c.o
../src/blake2b.c:63:22: warning: ‘blake2b_sigma’ defined but not used [-Wunused-const-variable=]
   63 | static const uint8_t blake2b_sigma[12][16] =
      |                      ^~~~~~~~~~~~~
[31/31] Linking target src/blake2sp-test

real    0m5.326s
user    0m15.603s
sys 0m1.219s
$ ninja -C builddir test
ninja: Entering directory `builddir'
[0/1] Running all tests.
1/4 blake2s-test         OK              0.02s
2/4 blake2b-test         OK              0.01s
3/4 blake2sp-test        OK              0.02s
4/4 blake2bp-test        OK              0.03s

Ok:                 4   
Expected Fail:      0   
Fail:               0   
Unexpected Pass:    0   
Skipped:            0   
Timeout:            0   

Full log written to /tmp/libb2/builddir/meson-logs/testlog.txt

This is a third of the time ./configure or make takes on the same machine. :)

Note that libb2 currently fails to ./configure properly at all, unless you run it as bash configure --prefix /usr --enable-fat it trips over a syntax error and disables both fat and native binaries.

eli-schwartz commented 3 years ago

Alternative to #2

kloczek commented 1 year ago

Is i tpossible to merge that PR and tag the new version? 🤔