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

Meson build system #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Meson build system #38

wants to merge 2 commits into from

Conversation

eli-schwartz
Copy link

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:

  • meson is really fast, compared to ./configure
  • supports VS solutions on Windows (clang is recommended over MSVC due to above point, I suppose)
  • supports xcode on macOS
  • meson will automatically support including libb2 into your project via https://mesonbuild.com/Wrap-dependency-system-manual.html, with fine-grained control over detecting a system copy, or falling back to / forcing downloading and compiling/linking it as a private static library (see --wrap-mode=[default|nofallback|forcefallback] or --force-fallback-for=libb2)
  • declarative build system is easier to reason about than turing-complete configure scripts
$ 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.

https://mesonbuild.com/

requirements:
- meson 0.38
- python 3.3 (required by meson)
- ninja (C++11) or samurai (C99)

Note:

HAVE_SSE41 is checked for but never ever defined, not even by ax_ext.m4,
so I have not bothered setting it in the conf file.
Requires meson 0.47 (and thus python 3.5)
@eli-schwartz
Copy link
Author

Alternative to #2

Comment on lines +8 to +17
if false # the code uses defines, not separate files
simd_mod = import('unstable-simd')
libb2_simd = simd_mod.check('blake2b',
sse2: 'blake2b-sse2.c',
ssse3: 'blake2b-ssse3.c',
sse41: 'blake2b-sse41.c',
avx: 'blake2b-avx.c',
# xop is not available in meson
)
endif
Copy link
Author

Choose a reason for hiding this comment

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

See https://mesonbuild.com/Simd-module.html

This would have actually been fairly convenient, since meson's compiler definitions include MSVC and include SIMD mappings.

A future optimization would be to improve the meson SIMD module to also allow retrieving a list of compiler-supported isets alongside their CFLAGS, then reuse that for a completely custom implementation of library building. In order to reuse it for the native codepath, it would additionally require all-new code to teach a compiler how to test for CPU (not compiler) support. I have WIP code for this, but it would end up requiring bleeding edge versions of meson...

@kloczek
Copy link

kloczek commented Sep 27, 2022

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

@vtorri vtorri mentioned this pull request Sep 12, 2023
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.

2 participants