summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-12-31 17:29:23 +0100
committerDavid Robillard <d@drobilla.net>2020-12-31 20:15:19 +0100
commit3215d4f4f963f740bfa2886680d2c90feb132ef4 (patch)
tree531faca81d18088581bde9ee0b416cab69ae89e2
parentce3e4266e4f0712b27563d079b7e7b6fd8013014 (diff)
downloadzix-3215d4f4f963f740bfa2886680d2c90feb132ef4.tar.gz
zix-3215d4f4f963f740bfa2886680d2c90feb132ef4.tar.bz2
zix-3215d4f4f963f740bfa2886680d2c90feb132ef4.zip
Switch to Meson
-rw-r--r--.gitlab-ci.yml206
-rw-r--r--include/zix/common.h19
-rw-r--r--meson.build295
-rw-r--r--meson_options.txt11
m---------waflib0
-rw-r--r--wscript314
6 files changed, 383 insertions, 462 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 09e5596..7d936dc 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,214 +1,150 @@
stages:
- build
- - test
-
-variables:
- GIT_SUBMODULE_STRATEGY: normal
+ - deploy
.build_template: &build_definition
stage: build
- artifacts:
- paths:
- - build/
- - .lock-waf*
-
-.test_template: &test_definition
- stage: test
- artifacts:
- paths:
- - build/coverage
arm32_dbg:
<<: *build_definition
image: lv2plugin/debian-arm32
- script: python ./waf configure build -dST --werror
- variables:
- CC: "arm-linux-gnueabihf-gcc"
- CXX: "arm-linux-gnueabihf-g++"
-
-test:arm32_dbg:
- <<: *test_definition
- image: lv2plugin/debian-arm32
- script: python ./waf test --wrapper=qemu-arm
- needs: ["arm32_dbg"]
-
+ script:
+ - meson . build --cross-file=/usr/share/meson/cross/arm-linux-gnueabihf.ini -Dbuildtype=debug -Dstrict=true -Dwerror=true
+ - ninja -C build test
arm32_rel:
<<: *build_definition
image: lv2plugin/debian-arm32
- script: python ./waf configure build -ST --werror
- variables:
- CC: "arm-linux-gnueabihf-gcc"
- CXX: "arm-linux-gnueabihf-g++"
-
-test:arm32_rel:
- <<: *test_definition
- image: lv2plugin/debian-arm32
- script: python ./waf test --wrapper=qemu-arm
- needs: ["arm32_rel"]
+ script:
+ - meson . build --cross-file=/usr/share/meson/cross/arm-linux-gnueabihf.ini -Dbuildtype=release -Dstrict=true -Dwerror=true
+ - ninja -C build test
arm64_dbg:
<<: *build_definition
image: lv2plugin/debian-arm64
- script: python ./waf configure build -dST --werror
- variables:
- CC: "aarch64-linux-gnu-gcc"
- CXX: "aarch64-linux-gnu-g++"
-
-test:arm64_dbg:
- <<: *test_definition
- image: lv2plugin/debian-arm64
- script: python ./waf test --wrapper=qemu-aarch64
- needs: ["arm64_dbg"]
-
+ script:
+ - meson . build --cross-file=/usr/share/meson/cross/aarch64-linux-gnu.ini -Dbuildtype=debug -Dstrict=true -Dwerror=true
+ - ninja -C build test
arm64_rel:
<<: *build_definition
image: lv2plugin/debian-arm64
- script: python ./waf configure build -ST --werror
- variables:
- CC: "aarch64-linux-gnu-gcc"
- CXX: "aarch64-linux-gnu-g++"
-
-test:arm64_rel:
- <<: *test_definition
- image: lv2plugin/debian-arm64
- script: python ./waf test --wrapper=qemu-aarch64
- needs: ["arm64_rel"]
+ script:
+ - meson . build --cross-file=/usr/share/meson/cross/aarch64-linux-gnu.ini -Dbuildtype=release -Dstrict=true -Dwerror=true
+ - ninja -C build test
x64_dbg:
<<: *build_definition
image: lv2plugin/debian-x64
- script: python ./waf configure build -dST --werror --docs
-
-test:x64_dbg:
- <<: *test_definition
- image: lv2plugin/debian-x64
- script: python ./waf test
- needs: ["x64_dbg"]
-
+ script:
+ - meson . build -Dbuildtype=debug -Dstrict=true -Dwerror=true -Db_coverage=true
+ - ninja -C build test
+ - ninja -C build coverage-html
+ artifacts:
+ paths:
+ - build/meson-logs/coveragereport
x64_rel:
<<: *build_definition
image: lv2plugin/debian-x64
- script: python ./waf configure build -ST --werror
-
-test:x64_rel:
- <<: *test_definition
- image: lv2plugin/debian-x64
- script: python ./waf test
- needs: ["x64_rel"]
+ script:
+ - meson . build -Dbuildtype=release -Dstrict=true -Dwerror=true
+ - ninja -C build test
x64_static:
<<: *build_definition
image: lv2plugin/debian-x64
- script: python ./waf configure build -ST --werror
+ script:
+ - meson . build -Ddefault_library=static -Dstrict=true -Dwerror=true
+ - ninja -C build test
-test:x64_static:
- <<: *test_definition
- image: lv2plugin/debian-x64
- script: python ./waf test
- needs: ["x64_static"]
x64_sanitize:
<<: *build_definition
image: lv2plugin/debian-x64-clang
- script: python ./waf configure build -ST --werror --no-coverage --no-test-malloc
+ script:
+ - meson . build -Db_lundef=false -Dbuildtype=plain -Dtest_malloc=false -Dstrict=true -Dwerror=true
+ - ninja -C build test
variables:
CC: "clang"
- CFLAGS: "-fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=unsigned-integer-overflow -fsanitize=implicit-conversion -fsanitize=local-bounds -fsanitize=nullability"
- CXX: "clang++"
- CXXFLAGS: "-fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=unsigned-integer-overflow -fsanitize=implicit-conversion -fsanitize=local-bounds -fsanitize=nullability"
- LINKFLAGS: "-fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=unsigned-integer-overflow -fsanitize=implicit-conversion -fsanitize=local-bounds -fsanitize=nullability"
-
-test:x64_sanitize:
- <<: *test_definition
- image: lv2plugin/debian-x64-clang
- script: python ./waf test
- needs: ["x64_sanitize"]
+ CFLAGS: "-fno-sanitize-recover=all -fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=implicit-conversion -fsanitize=local-bounds -fsanitize=nullability"
+ LDFLAGS: "-fno-sanitize-recover=all -fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=implicit-conversion -fsanitize=local-bounds -fsanitize=nullability"
mingw32_dbg:
<<: *build_definition
image: lv2plugin/debian-mingw32
- script: python ./waf configure build -dST --werror --no-coverage
- variables:
- CC: "i686-w64-mingw32-gcc"
- CXX: "i686-w64-mingw32-g++"
+ script:
+ - meson . build --cross-file=/usr/share/meson/cross/i686-w64-mingw32.ini -Dbuildtype=debug -Dstrict=true -Dwerror=true
+ - ninja -C build test
mingw32_rel:
<<: *build_definition
image: lv2plugin/debian-mingw32
- script: python ./waf configure build -ST --werror --no-coverage
- variables:
- CC: "i686-w64-mingw32-gcc"
- CXX: "i686-w64-mingw32-g++"
+ script:
+ - meson . build --cross-file=/usr/share/meson/cross/i686-w64-mingw32.ini -Dbuildtype=release -Dstrict=true -Dwerror=true
+ - ninja -C build test
mingw64_dbg:
<<: *build_definition
image: lv2plugin/debian-mingw64
- script: python ./waf configure build -dST --werror --no-coverage
- variables:
- CC: "x86_64-w64-mingw32-gcc"
- CXX: "x86_64-w64-mingw32-g++"
+ script:
+ - meson . build --cross-file=/usr/share/meson/cross/x86_64-w64-mingw32.ini -Dbuildtype=debug -Dstrict=true -Dwerror=true
+ - ninja -C build test
mingw64_rel:
<<: *build_definition
image: lv2plugin/debian-mingw64
- script: python ./waf configure build -ST --werror --no-coverage
- variables:
- CC: "x86_64-w64-mingw32-gcc"
- CXX: "x86_64-w64-mingw32-g++"
+ script:
+ - meson . build --cross-file=/usr/share/meson/cross/x86_64-w64-mingw32.ini -Dbuildtype=release -Dstrict=true -Dwerror=true
+ - ninja -C build test
mac_dbg:
<<: *build_definition
- script: python ./waf configure build -dST --werror --no-coverage
- tags: [macos]
-
-test:mac_dbg:
- <<: *test_definition
- script: python ./waf test
- needs: ["mac_dbg"]
tags: [macos]
-
+ script:
+ - meson . build -Dbuildtype=debug -Dstrict=true -Dwerror=true
+ - ninja -C build test
mac_rel:
<<: *build_definition
- script: python ./waf configure build -ST --werror --no-coverage
- tags: [macos]
-
-test:mac_rel:
- <<: *test_definition
- script: python ./waf test
- needs: ["mac_rel"]
tags: [macos]
+ script:
+ - meson . build -Dbuildtype=release -Dstrict=true -Dwerror=true
+ - ninja -C build test
win_dbg:
<<: *build_definition
- script: python ./waf configure build -dST --werror --no-coverage
- tags: [windows,msvc,python]
-
-test:win_dbg:
- <<: *test_definition
- script: python ./waf test
- needs: ["win_dbg"]
- tags: [windows,msvc,python]
-
+ tags: [windows,meson]
+ script:
+ - meson . build -Dbuildtype=debug -Dstrict=true -Dwerror=true -Dtest_malloc=false
+ - ninja -C build test
win_rel:
<<: *build_definition
- script: python ./waf configure build -ST --werror --no-coverage
- tags: [windows,msvc,python]
+ tags: [windows,meson]
+ script:
+ - meson . build -Dbuildtype=release -Dstrict=true -Dwerror=true -Dtest_malloc=false
+ - ninja -C build test
+
-test:win_rel:
- <<: *test_definition
- script: python ./waf test
- needs: ["win_rel"]
- tags: [windows,msvc,python]
+pages:
+ stage: deploy
+ script:
+ - mkdir -p .public
+ - mv build/meson-logs/coveragereport/ .public/coverage
+ - mv .public public
+ dependencies:
+ - x64_dbg
+ artifacts:
+ paths:
+ - public
+ only:
+ - master
diff --git a/include/zix/common.h b/include/zix/common.h
index 0191cca..b494481 100644
--- a/include/zix/common.h
+++ b/include/zix/common.h
@@ -25,19 +25,12 @@
*/
/** @cond */
-#ifdef ZIX_SHARED
-# ifdef _WIN32
-# define ZIX_LIB_IMPORT __declspec(dllimport)
-# define ZIX_LIB_EXPORT __declspec(dllexport)
-# else
-# define ZIX_LIB_IMPORT __attribute__((visibility("default")))
-# define ZIX_LIB_EXPORT __attribute__((visibility("default")))
-# endif
-# ifdef ZIX_INTERNAL
-# define ZIX_API ZIX_LIB_EXPORT
-# else
-# define ZIX_API ZIX_LIB_IMPORT
-# endif
+#if defined(_WIN32) && !defined(ZIX_STATIC) && defined(ZIX_INTERNAL)
+# define ZIX_API __declspec(dllexport)
+#elif defined(_WIN32) && !defined(ZIX_STATIC)
+# define ZIX_API __declspec(dllimport)
+#elif defined(__GNUC__)
+# define ZIX_API __attribute__((visibility("default")))
#else
# define ZIX_API
#endif
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..4babf8c
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,295 @@
+project('zix', ['c'],
+ version: '0.0.3',
+ license: 'ISC',
+ meson_version: '>= 0.49.0',
+ default_options: [
+ 'b_ndebug=if-release',
+ 'buildtype=release',
+ 'c_std=c99',
+ 'default_library=shared',
+ 'warning_level=3',
+ ])
+
+major_version = meson.project_version().split('.')[0]
+version_suffix = '-@0@'.format(major_version)
+versioned_name = 'zix' + version_suffix
+
+#
+# General Setup
+#
+
+# Load build tools
+pkg = import('pkgconfig')
+cc = meson.get_compiler('c')
+
+# Set ultra strict warnings for developers, if requested
+if get_option('strict')
+ if cc.get_id() == 'clang'
+ c_warnings = [
+ '-Weverything',
+ '-Wno-bad-function-cast',
+ '-Wno-conversion',
+ '-Wno-padded',
+ '-Wno-reserved-id-macro',
+ ]
+ elif cc.get_id() == 'gcc'
+ c_warnings = [
+ # '-Waggregate-return',
+ '-Walloc-size-larger-than=4096',
+ '-Walloc-zero',
+ '-Walloca',
+ '-Wanalyzer-too-complex',
+ '-Warith-conversion',
+ '-Warray-bounds=2',
+ '-Wattribute-alias=2',
+ '-Wcast-align=strict',
+ '-Wcast-qual',
+ # '-Wconversion',
+ '-Wdate-time',
+ '-Wdisabled-optimization',
+ '-Wdouble-promotion',
+ '-Wduplicated-branches',
+ '-Wduplicated-cond',
+ '-Wfloat-equal',
+ '-Wformat-overflow=2',
+ '-Wformat-signedness',
+ '-Wformat-truncation=2',
+ '-Wformat=2',
+ '-Wframe-larger-than=512',
+ '-Wimplicit-fallthrough=2',
+ '-Winit-self',
+ # '-Winline',
+ '-Winvalid-pch',
+ # '-Wlarger-than=',
+ '-Wlogical-op',
+ '-Wmissing-declarations',
+ '-Wmissing-include-dirs',
+ '-Wmultichar',
+ '-Wnormalized=nfc',
+ '-Wnull-dereference',
+ '-Wpacked',
+ # '-Wpadded',
+ '-Wredundant-decls',
+ '-Wscalar-storage-order',
+ '-Wshadow',
+ '-Wshift-overflow=2',
+ '-Wsizeof-array-argument',
+ '-Wstack-protector',
+ '-Wstack-usage=512',
+ '-Wstrict-aliasing=3',
+ # '-Wstrict-overflow=5',
+ '-Wstringop-overflow=3',
+ '-Wsuggest-attribute=cold',
+ '-Wsuggest-attribute=const',
+ '-Wsuggest-attribute=format',
+ '-Wsuggest-attribute=malloc',
+ '-Wsuggest-attribute=noreturn',
+ '-Wsuggest-attribute=pure',
+ # '-Wswitch-default',
+ '-Wswitch-enum',
+ '-Wsync-nand',
+ # '-Wsystem-headers',
+ # '-Wtraditional',
+ # '-Wtraditional-conversion',
+ '-Wtrampolines',
+ '-Wundef',
+ '-Wunused-const-variable=2',
+ '-Wunused-macros',
+ '-Wvarargs',
+ '-Wvector-operation-performance',
+ '-Wvla',
+ '-Wwrite-strings',
+ ]
+ elif cc.get_id() == 'msvc'
+ c_warnings = [
+ '/Wall', # everything, except...
+ '/wd4191', # unsafe function conversion
+ '/wd4200', # zero-sized array in struct/union
+ '/wd4365', # signed/unsigned mismatch
+ '/wd4514', # unreferenced inline function has been removed
+ '/wd4706', # assignment within conditional expression
+ '/wd4710', # function not inlined
+ '/wd4711', # function selected for automatic inline expansion
+ '/wd4777', # format string and argument mismatch
+ '/wd4820', # padding added after construct
+ '/wd5045', # will insert Spectre mitigation for memory load
+ ]
+ else
+ c_warnings = []
+ endif
+
+ if cc.get_id() == 'gcc' and host_machine.system() == 'windows'
+ c_warnings += [
+ '-Wno-cast-function-type',
+ '-Wno-format',
+ ]
+ endif
+
+ add_project_arguments(cc.get_supported_arguments(c_warnings), language: ['c'])
+endif
+
+if cc.get_id() == 'msvc'
+ # Build as C++
+ add_project_arguments(['/TP'], language: ['c'])
+
+ # Suppress warnings in system headers
+ add_project_arguments(['/experimental:external',
+ '/external:W0',
+ '/external:anglebrackets'],
+ language: ['c'])
+endif
+
+# Determine library type and the flags needed to build it
+if get_option('default_library') == 'both'
+ if host_machine.system() == 'windows'
+ error('default_library=both is not supported on Windows')
+ endif
+
+ library_type = 'both_libraries'
+ library_args = ['-DZIX_INTERNAL']
+elif get_option('default_library') == 'shared'
+ library_type = 'shared_library'
+ library_args = ['-DZIX_INTERNAL']
+else
+ library_type = 'static_library'
+ library_args = ['-DZIX_INTERNAL', '-DZIX_STATIC']
+endif
+
+#
+# System Checks and Dependencies
+#
+
+# Check for mlock() (used by ZixRing)
+mlock_fragment = '''#include <sys/mman.h>
+ int main(void) { return mlock(0, 0); }'''
+if cc.compiles(mlock_fragment, name: 'mlock')
+ add_project_arguments(['-DHAVE_MLOCK'], language: 'c')
+endif
+
+#
+# Library
+#
+
+sources = [
+ 'src/bitset.c',
+ 'src/btree.c',
+ 'src/chunk.c',
+ 'src/digest.c',
+ 'src/hash.c',
+ 'src/ring.c',
+ 'src/sorted_array.c',
+ 'src/strindex.c',
+ 'src/tree.c',
+]
+
+# Build shared and/or static library/libraries
+libzix = build_target(
+ versioned_name,
+ sources,
+ version: meson.project_version(),
+ include_directories: include_directories(['include']),
+ c_args: library_args,
+ gnu_symbol_visibility: 'hidden',
+ install: true,
+ target_type: library_type)
+
+libzix_dep = declare_dependency(link_with: libzix)
+
+#
+# Installation
+#
+
+# Generage pkg-config file
+pkg.generate(
+ libzix,
+ name: 'Zix',
+ filebase: versioned_name,
+ subdirs: [versioned_name],
+ version: meson.project_version(),
+ description: 'A lightweight portability and data structure C library')
+
+headers = [
+ 'include/zix/bitset.h',
+ 'include/zix/btree.h',
+ 'include/zix/chunk.h',
+ 'include/zix/common.h',
+ 'include/zix/digest.h',
+ 'include/zix/hash.h',
+ 'include/zix/ring.h',
+ 'include/zix/sem.h',
+ 'include/zix/sorted_array.h',
+ 'include/zix/strindex.h',
+ 'include/zix/thread.h',
+ 'include/zix/tree.h',
+]
+
+# Install headers to a versioned include directory
+install_headers(headers, subdir: versioned_name / 'zix')
+
+#
+# Tests
+#
+
+tests = [
+ 'bitset_test',
+ 'btree_test',
+ 'digest_test',
+ 'hash_test',
+ 'ring_test',
+ 'sem_test',
+ 'sorted_array_test',
+ 'strindex_test',
+ 'tree_test',
+]
+
+# Build and run tests
+if get_option('tests')
+ thread_dep = dependency('threads')
+ dl_dep = cc.find_library('dl', required: false)
+
+ foreach test : tests
+ c_args = []
+ sources = ['test/@0@.c'.format(test)]
+
+ if get_option('test_malloc') and host_machine.system() != 'windows'
+ sources += ['test/test_malloc.c']
+ c_args += ['-DZIX_WITH_TEST_MALLOC']
+ endif
+
+ test(test,
+ executable(test,
+ sources,
+ include_directories: include_directories(['include']),
+ c_args: c_args,
+ dependencies: [dl_dep, libzix_dep, thread_dep]),
+ timeout: 120)
+ endforeach
+endif
+
+#
+# Benchmarks
+#
+
+benchmarks = [
+ 'dict_bench',
+ 'tree_bench',
+]
+
+# Build benchmarks
+if not get_option('benchmarks').disabled()
+ glib_dep = dependency('glib-2.0',
+ version: '>= 2.0.0',
+ required: get_option('benchmarks'))
+
+ if glib_dep.found()
+ foreach benchmark : benchmarks
+ benchmark(benchmark,
+ executable(benchmark,
+ 'benchmark/@0@.c'.format(benchmark),
+ include_directories: include_directories(['include']),
+ dependencies: [libzix_dep, glib_dep]))
+ endforeach
+ else
+ warning('Not building benchmarks because glib was not found')
+ endif
+endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..8c53858
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,11 @@
+option('strict', type: 'boolean', value: false,
+ description: 'Enable ultra-strict warnings')
+
+option('test_malloc', type: 'boolean', value: true,
+ description: 'Test allocation failure')
+
+option('tests', type: 'boolean', value: true,
+ description: 'Build tests')
+
+option('benchmarks', type: 'feature', value: 'auto',
+ description: 'Build benchmarks')
diff --git a/waflib b/waflib
deleted file mode 160000
-Subproject d19992202543ebb810609c074f754b5ec48c0fd
diff --git a/wscript b/wscript
deleted file mode 100644
index 993bbbe..0000000
--- a/wscript
+++ /dev/null
@@ -1,314 +0,0 @@
-#!/usr/bin/env python
-
-import os
-import subprocess
-import sys
-
-from waflib import Build, Logs, Options
-from waflib.extras import autowaf
-
-# Library and package version (UNIX style major, minor, micro)
-# major increment <=> incompatible changes
-# minor increment <=> compatible changes (additions)
-# micro increment <=> no interface changes
-ZIX_VERSION = '0.0.2'
-ZIX_MAJOR_VERSION = '0'
-
-# Mandatory waf variables
-APPNAME = 'zix' # Package name for waf dist
-VERSION = ZIX_VERSION # Package version for waf dist
-top = '.' # Source directory
-out = 'build' # Build directory
-
-
-def options(ctx):
- ctx.load('compiler_c')
- opt = ctx.get_option_group('Configuration options')
- ctx.add_flags(opt, {'bench': 'build benchmarks',
- 'static': 'build static library'})
- opt.add_option('--page-size', type='int', default=4096, dest='page_size',
- help='Page size for B-tree')
- opt.add_option('--no-test-malloc', action='store_true',
- dest='no_test_malloc',
- help='Do not use test malloc implementation')
-
-
-def configure(conf):
- conf.load('compiler_c', cache=True)
- conf.load('autowaf', cache=True)
-
- if not autowaf.set_c_lang(conf, 'c11', mandatory=False):
- autowaf.set_c_lang(conf, 'c99')
-
- conf.env.update({
- 'BUILD_BENCH': Options.options.bench,
- 'BUILD_STATIC': Options.options.static})
-
- if Options.options.strict:
- # Check for programs used by lint target
- conf.find_program("flake8", var="FLAKE8", mandatory=False)
- conf.find_program("clang-tidy", var="CLANG_TIDY", mandatory=False)
- conf.find_program("iwyu_tool", var="IWYU_TOOL", mandatory=False)
-
- if Options.options.ultra_strict:
- autowaf.add_compiler_flags(conf.env, '*', {
- 'clang': [
- '-Wno-bad-function-cast',
- '-Wno-cast-align',
- '-Wno-padded',
- '-Wno-reserved-id-macro',
- '-Wno-sign-conversion',
- ],
- 'gcc': [
- '-Wno-bad-function-cast',
- '-Wno-cast-align',
- '-Wno-conversion',
- '-Wno-inline',
- '-Wno-padded',
- ],
- 'msvc': [
- '/wd4191', # unsafe function conversion
- '/wd4200', # zero-sized array in struct/union
- '/wd4365', # signed/unsigned mismatch
- '/wd4514', # unreferenced inline function has been removed
- '/wd4706', # assignment within conditional expression
- '/wd4710', # function not inlined
- '/wd4711', # function selected for automatic inline expansion
- '/wd4777', # format string and argument mismatch
- '/wd4820', # padding added after construct
- '/wd5045', # will insert Spectre mitigation for memory load
- ],
- })
-
- if 'mingw' in conf.env.CC[0]:
- conf.env.append_unique('CFLAGS', [
- '-Wno-cast-function-type',
- '-Wno-format',
- ])
-
- # Check for mlock
- conf.check_function('c', 'mlock',
- header_name='sys/mman.h',
- return_type='int',
- arg_types='const void*,size_t',
- define_name='HAVE_MLOCK',
- mandatory=False)
-
- if Options.options.bench:
- conf.check_pkg('glib-2.0 >= 2.0.0',
- uselib_store='GLIB',
- system=True,
- mandatory=False)
- if not conf.is_defined('HAVE_GLIB'):
- conf.fatal('Glib is required to build benchmarks')
-
- if not (conf.env.DEST_OS == 'win32' or Options.options.no_test_malloc):
- conf.env['ZIX_WITH_TEST_MALLOC'] = True
- else:
- conf.env['ZIX_WITH_TEST_MALLOC'] = False
-
- conf.define('ZIX_VERSION', ZIX_VERSION)
- conf.define('ZIX_BTREE_PAGE_SIZE', Options.options.page_size)
- conf.write_config_header('zix-config.h', remove=False)
-
- autowaf.display_summary(
- conf,
- {'Build unit tests': bool(conf.env.BUILD_TESTS),
- 'Build benchmarks': bool(conf.env.BUILD_BENCH),
- 'Page size': Options.options.page_size})
-
-
-sources = [
- 'src/chunk.c',
- 'src/digest.c',
- 'src/hash.c',
- 'src/ring.c',
- 'src/sorted_array.c',
- 'src/strindex.c',
- 'src/tree.c',
- 'src/btree.c',
- 'src/bitset.c',
-]
-
-tests = [
- 'digest_test',
- 'hash_test',
- 'ring_test',
- 'sem_test',
- 'sorted_array_test',
- 'strindex_test',
- 'tree_test',
- 'btree_test',
- 'bitset_test',
-]
-
-
-def build(bld):
- # C Headers
- includedir = '${INCLUDEDIR}/zix-%s/zix' % ZIX_MAJOR_VERSION
- bld.install_files(includedir, bld.path.ant_glob('include/zix/*.h'))
-
- # Pkgconfig file
- autowaf.build_pc(bld, 'ZIX', ZIX_VERSION, ZIX_MAJOR_VERSION, [],
- {'ZIX_MAJOR_VERSION': ZIX_MAJOR_VERSION})
-
- framework = ''
- if sys.platform == 'darwin':
- framework = ['CoreServices']
-
- libflags = ['-fvisibility=hidden']
- if bld.env.MSVC_COMPILER:
- libflags = []
-
- # Library
- bld(features = 'c cshlib',
- export_includes = ['.', 'include'],
- source = sources,
- includes = ['.', 'include'],
- name = 'libzix',
- target = 'zix',
- vnum = ZIX_VERSION,
- install_path = '${LIBDIR}',
- framework = framework,
- cflags = libflags + ['-DZIX_SHARED', '-DZIX_INTERNAL'])
-
- if bld.env.BUILD_STATIC or bld.env.BUILD_BENCH:
- bld(features = 'c cstlib',
- export_includes = ['.', 'include'],
- source = sources,
- includes = ['.', 'include'],
- name = 'libzix_static',
- target = 'zix',
- vnum = ZIX_VERSION,
- install_path = None,
- framework = framework,
- cflags = libflags + ['-DZIX_SHARED', '-DZIX_INTERNAL'])
-
- if bld.env.BUILD_TESTS:
- test_cflags = []
- test_linkflags = []
- test_libs = ['pthread', 'dl']
- if bld.env.MSVC_COMPILER:
- test_libs = []
- elif bld.env.DEST_OS == 'win32':
- test_libs = 'pthread'
- if bld.is_defined('HAVE_GCOV'):
- test_cflags += ['--coverage']
- test_linkflags += ['--coverage']
-
- # Profiled static library (for unit test code coverage)
- bld(features = 'c cstlib',
- source = sources,
- includes = ['.', 'include'],
- lib = test_libs,
- name = 'libzix_profiled',
- target = 'zix_profiled',
- install_path = '',
- framework = framework,
- cflags = test_cflags + ['-DZIX_INTERNAL'],
- linkflags = test_linkflags)
-
- if bld.env.ZIX_WITH_TEST_MALLOC:
- test_malloc = ['test/test_malloc.c']
- test_cflags += ['-DZIX_WITH_TEST_MALLOC']
- else:
- test_malloc = []
-
- # Unit test programs
- for i in tests:
- bld(features = 'c cprogram',
- source = ['test/%s.c' % i] + test_malloc,
- includes = ['.', 'include'],
- use = 'libzix_profiled',
- lib = test_libs,
- target = 'test/%s' % i,
- install_path = None,
- framework = framework,
- cflags = test_cflags,
- linkflags = test_linkflags)
-
- if bld.env.BUILD_BENCH:
- # Benchmark programs
- for i in ['tree_bench', 'dict_bench']:
- bld(features = 'c cprogram',
- source = 'benchmark/%s.c' % i,
- includes = ['.', 'include'],
- use = 'libzix_static',
- uselib = 'GLIB',
- lib = ['rt'],
- target = 'benchmark/%s' % i,
- framework = framework,
- install_path = '')
-
- # Documentation
- autowaf.build_dox(bld, 'ZIX', ZIX_VERSION, top, out)
-
- bld.add_post_fun(autowaf.run_ldconfig)
-
-
-class LintContext(Build.BuildContext):
- fun = cmd = 'lint'
-
-
-def lint(ctx):
- "checks code for style issues"
-
- import glob
- import subprocess
-
- st = 0
-
- if "FLAKE8" in ctx.env:
- Logs.info("Running flake8")
- st = subprocess.call([ctx.env.FLAKE8[0],
- "wscript",
- "--ignore",
- "E101,E129,W191,E221,W504,E251,E241,E741"])
- else:
- Logs.warn("Not running flake8")
-
- if "IWYU_TOOL" in ctx.env:
- Logs.info("Running include-what-you-use")
- cmd = [ctx.env.IWYU_TOOL[0], "-o", "clang", "-p", "build"]
- output = subprocess.check_output(cmd).decode('utf-8')
- if 'error: ' in output:
- sys.stdout.write(output)
- st += 1
- else:
- Logs.warn("Not running include-what-you-use")
-
- if "CLANG_TIDY" in ctx.env and "clang" in ctx.env.CC[0]:
- Logs.info("Running clang-tidy")
- sources = glob.glob('zix/*.c') + glob.glob('test/*.c*')
- sources = list(map(os.path.abspath, sources))
- procs = []
- for source in sources:
- cmd = [ctx.env.CLANG_TIDY[0], "--quiet", "-p=.", source]
- procs += [subprocess.Popen(cmd, cwd="build")]
-
- for proc in procs:
- stdout, stderr = proc.communicate()
- st += proc.returncode
- else:
- Logs.warn("Not running clang-tidy")
-
- if st != 0:
- sys.exit(st)
-
-
-def build_dir(ctx, subdir):
- if autowaf.is_child():
- return os.path.join('build', APPNAME, subdir)
- else:
- return os.path.join('build', subdir)
-
-
-def upload_docs(ctx):
- os.system('rsync -avz --delete -e ssh build/doc/html/*'
- ' drobilla@drobilla.net:~/drobilla.net/docs/zix')
-
-
-def test(tst):
- with tst.group('unit') as check:
- for test in tests:
- check([os.path.join('test', test)])