diff --git a/.travis.yml b/.travis.yml index 226acaa37..8cb40b1e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,13 @@ language: c dist: trusty sudo: required + addons: apt: update: true matrix: + fast_finish: true include: # Ubuntu 14.04 - env: Cmd='make test' @@ -49,6 +51,11 @@ matrix: - if: tag =~ ^v[0-9]\.[0-9] env: Cmd='make -C tests checkTag && tests/checkTag $TRAVIS_BRANCH' + - dist: xenial + env: BUILD_SYSTEM='meson' + allow_failures: + - env: BUILD_SYSTEM='meson' + git: depth: 1 @@ -59,9 +66,28 @@ branches: - travisTest script: - - JOB_NUMBER=$(echo $TRAVIS_JOB_NUMBER | sed -e 's:[0-9][0-9]*\.\(.*\):\1:') - - echo JOB_NUMBER=$JOB_NUMBER TRAVIS_BRANCH=$TRAVIS_BRANCH TRAVIS_EVENT_TYPE=$TRAVIS_EVENT_TYPE TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST + - JOB_NUMBER=$(printf '%s' "${TRAVIS_JOB_NUMBER}" | sed -E 's@[0-9]+\.([0-9]+)@\1@') + - printf 'JOB_NUMBER=%s TRAVIS_BRANCH=%s TRAVIS_EVENT_TYPE=%s TRAVIS_PULL_REQUEST=%s\n' + "${JOB_NUMBER}" "${TRAVIS_BRANCH}" "${TRAVIS_EVENT_TYPE}" "${TRAVIS_PULL_REQUEST}" + - if [ "${BUILD_SYSTEM}" = meson ]; then + set -x; + sudo apt-get install -qq liblz4-dev valgrind tree + && curl -o ~/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' + && python3 ~/get-pip.py --user + && pip3 install --user meson ninja + && export CC=clang CXX=clang++ + && meson --buildtype=debug + -Db_lundef=false + -Dauto_features=enabled + -Dbuild_{programs,tests,contrib}=true + -Ddefault_library=both + build/meson builddir + && cd "$_" + && DESTDIR=./staging ninja install + && tree ./staging; + travis_terminate "$?"; + fi - export FUZZERTEST=-T2mn; export ZSTREAM_TESTTIME=-T2mn; export DECODECORPUS_TESTTIME=-T1mn; - sh -c "$Cmd" || travis_terminate 1; + sh -c "${Cmd}" || travis_terminate 1; diff --git a/README.md b/README.md index dc99dc0fd..c0b550572 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ By default, `CMAKE_BUILD_TYPE` is set to `Release`. #### Meson -A Meson project is provided within `contrib/meson`. +A Meson project is provided within `build/meson`. #### Visual Studio (Windows) diff --git a/contrib/meson/GetZstdLibraryVersion.py b/build/meson/GetZstdLibraryVersion.py similarity index 51% rename from contrib/meson/GetZstdLibraryVersion.py rename to build/meson/GetZstdLibraryVersion.py index 364edc5aa..53c61008a 100644 --- a/contrib/meson/GetZstdLibraryVersion.py +++ b/build/meson/GetZstdLibraryVersion.py @@ -11,35 +11,31 @@ import re import sys -def usage(): - print('usage: python3 GetZstdLibraryVersion.py ') - sys.exit(1) - - def find_version(filepath): - version_file_data = None - with open(filepath) as fd: - version_file_data = fd.read() + version_file_data = None + with open(filepath) as fd: + version_file_data = fd.read() - patterns = r"""#\s*define\s+ZSTD_VERSION_MAJOR\s+([0-9]+) + patterns = r"""#\s*define\s+ZSTD_VERSION_MAJOR\s+([0-9]+) #\s*define\s+ZSTD_VERSION_MINOR\s+([0-9]+) #\s*define\s+ZSTD_VERSION_RELEASE\s+([0-9]+) """ - regex = re.compile(patterns, re.MULTILINE) - version_match = regex.search(version_file_data) - if version_match: - return version_match.groups() - raise RuntimeError("Unable to find version string.") + regex = re.compile(patterns, re.MULTILINE) + version_match = regex.search(version_file_data) + if version_match: + return version_match.groups() + raise Exception("Unable to find version string.") def main(): - if len(sys.argv) < 2: - usage() - - filepath = sys.argv[1] - version_tup = find_version(filepath) - print('.'.join(version_tup)) + import argparse + parser = argparse.ArgumentParser(description='Print zstd version from lib/zstd.h') + parser.add_argument('file', help='path to lib/zstd.h') + args = parser.parse_args() + filepath = args.file + version_tup = find_version(filepath) + print('.'.join(version_tup)) if __name__ == '__main__': - main() + main() diff --git a/build/meson/InstallSymlink.py b/build/meson/InstallSymlink.py new file mode 100644 index 000000000..9c68cb33e --- /dev/null +++ b/build/meson/InstallSymlink.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +# ############################################################################# +# Copyright (c) 2018-present lzutao +# All rights reserved. +# +# This source code is licensed under both the BSD-style license (found in the +# LICENSE file in the root directory of this source tree) and the GPLv2 (found +# in the COPYING file in the root directory of this source tree). +# ############################################################################# +import errno +import os + + +def mkdir_p(path, dir_mode=0o777): + try: + os.makedirs(path, mode=dir_mode) + except OSError as exc: # Python >2.5 + if exc.errno == errno.EEXIST and os.path.isdir(path): + pass + else: + raise + + +def install_symlink(src, dst, install_dir, dst_is_dir=False, dir_mode=0o777): + if not os.path.exists(install_dir): + mkdir_p(install_dir, dir_mode) + if not os.path.isdir(install_dir): + raise NotADirectoryError(install_dir) + + new_dst = os.path.join(install_dir, dst) + if os.path.islink(new_dst) and os.readlink(new_dst) == src: + print('File exists: {!r} -> {!r}'.format(new_dst, src)) + return + print('Installing symlink {!r} -> {!r}'.format(new_dst, src)) + os.symlink(src, new_dst, dst_is_dir) + + +def main(): + import argparse + parser = argparse.ArgumentParser(description='Install a symlink', + usage='InstallSymlink.py [-h] [-d] [-m MODE] src dst install_dir\n\n' + 'example:\n' + '\tInstallSymlink.py dash sh /bin\n' + '\tDESTDIR=./staging InstallSymlink.py dash sh /bin') + parser.add_argument('src', help='target to link') + parser.add_argument('dst', help='link name') + parser.add_argument('install_dir', help='installation directory') + parser.add_argument('-d', '--isdir', + action='store_true', + help='dst is a directory') + parser.add_argument('-m', '--mode', + help='directory mode on creating if not exist', + default='0o777') + args = parser.parse_args() + + src = args.src + dst = args.dst + install_dir = args.install_dir + dst_is_dir = args.isdir + dir_mode = int(args.mode, 8) + + DESTDIR = os.environ.get('DESTDIR') + if DESTDIR: + install_dir = DESTDIR + install_dir if os.path.isabs(install_dir) \ + else os.path.join(DESTDIR, install_dir) + + install_symlink(src, dst, install_dir, dst_is_dir, dir_mode) + + +if __name__ == '__main__': + main() diff --git a/build/meson/README.md b/build/meson/README.md new file mode 100644 index 000000000..dae503fef --- /dev/null +++ b/build/meson/README.md @@ -0,0 +1,38 @@ +Meson build system for zstandard +================================ + +Meson is a build system designed to optimize programmer productivity. +It aims to do this by providing simple, out-of-the-box support for +modern software development tools and practices, such as unit tests, +coverage reports, Valgrind, CCache and the like. + +This Meson build system is provided with no guarantee and maintained +by Dima Krasner . + +It outputs one `libzstd`, either shared or static, depending on +`default_library` option. + +## How to build + +`cd` to this meson directory (`build/meson`) + +```sh +meson --buildtype=release -D with-contrib=true -D with-tests=true -D with-contrib=true builddir +cd builddir +ninja # to build +ninja install # to install +``` + +You might want to install it in staging directory: + +```sh +DESTDIR=./staging ninja install +``` + +To configure build options, use: + +```sh +meson configure +``` + +See [man meson(1)](https://manpages.debian.org/testing/meson/meson.1.en.html). diff --git a/build/meson/contrib/gen_html/meson.build b/build/meson/contrib/gen_html/meson.build new file mode 100644 index 000000000..cabff209d --- /dev/null +++ b/build/meson/contrib/gen_html/meson.build @@ -0,0 +1,29 @@ +# ############################################################################# +# Copyright (c) 2018-present lzutao +# All rights reserved. +# +# This source code is licensed under both the BSD-style license (found in the +# LICENSE file in the root directory of this source tree) and the GPLv2 (found +# in the COPYING file in the root directory of this source tree). +# ############################################################################# + +zstd_rootdir = '../../../..' + +gen_html_includes = include_directories(join_paths(zstd_rootdir, 'programs'), + join_paths(zstd_rootdir, 'lib'), + join_paths(zstd_rootdir, 'lib/common'), + join_paths(zstd_rootdir, 'contrib/gen_html')) + +gen_html = executable('gen_html', + join_paths(zstd_rootdir, 'contrib/gen_html/gen_html.cpp'), + include_directories: gen_html_includes, + install: false) + +# Update zstd manual +zstd_manual_html = custom_target('zstd_manual.html', + output : 'zstd_manual.html', + command : [gen_html, + zstd_version, + join_paths(meson.current_source_dir(), zstd_rootdir, 'lib/zstd.h'), + '@OUTPUT@'], + install : false) diff --git a/contrib/meson/contrib/meson.build b/build/meson/contrib/meson.build similarity index 100% rename from contrib/meson/contrib/meson.build rename to build/meson/contrib/meson.build diff --git a/build/meson/contrib/pzstd/meson.build b/build/meson/contrib/pzstd/meson.build new file mode 100644 index 000000000..8f3822fd7 --- /dev/null +++ b/build/meson/contrib/pzstd/meson.build @@ -0,0 +1,24 @@ +# ############################################################################# +# Copyright (c) 2018-present lzutao +# All rights reserved. +# +# This source code is licensed under both the BSD-style license (found in the +# LICENSE file in the root directory of this source tree) and the GPLv2 (found +# in the COPYING file in the root directory of this source tree). +# ############################################################################# + +zstd_rootdir = '../../../..' + +pzstd_includes = include_directories(join_paths(zstd_rootdir, 'programs'), + join_paths(zstd_rootdir, 'contrib/pzstd')) +pzstd_sources = [join_paths(zstd_rootdir, 'programs/util.c'), + join_paths(zstd_rootdir, 'contrib/pzstd/main.cpp'), + join_paths(zstd_rootdir, 'contrib/pzstd/Options.cpp'), + join_paths(zstd_rootdir, 'contrib/pzstd/Pzstd.cpp'), + join_paths(zstd_rootdir, 'contrib/pzstd/SkippableFrame.cpp')] +pzstd = executable('pzstd', + pzstd_sources, + cpp_args: [ '-DNDEBUG', '-Wno-shadow', '-pedantic' ], + include_directories: pzstd_includes, + dependencies: [ libzstd_dep, thread_dep ], + install: true) diff --git a/build/meson/lib/meson.build b/build/meson/lib/meson.build new file mode 100644 index 000000000..bce6b7c56 --- /dev/null +++ b/build/meson/lib/meson.build @@ -0,0 +1,130 @@ +# ############################################################################# +# Copyright (c) 2018-present Dima Krasner +# lzutao +# All rights reserved. +# +# This source code is licensed under both the BSD-style license (found in the +# LICENSE file in the root directory of this source tree) and the GPLv2 (found +# in the COPYING file in the root directory of this source tree). +# ############################################################################# + +zstd_rootdir = '../../..' + +libzstd_includes = [include_directories(join_paths(zstd_rootdir,'lib'), + join_paths(zstd_rootdir, 'lib/common'), + join_paths(zstd_rootdir, 'lib/compress'), + join_paths(zstd_rootdir, 'lib/decompress'), + join_paths(zstd_rootdir, 'lib/dictBuilder'), + join_paths(zstd_rootdir, 'lib/deprecated'))] + +libzstd_sources = [join_paths(zstd_rootdir, 'lib/common/entropy_common.c'), + join_paths(zstd_rootdir, 'lib/common/fse_decompress.c'), + join_paths(zstd_rootdir, 'lib/common/threading.c'), + join_paths(zstd_rootdir, 'lib/common/pool.c'), + join_paths(zstd_rootdir, 'lib/common/zstd_common.c'), + join_paths(zstd_rootdir, 'lib/common/error_private.c'), + join_paths(zstd_rootdir, 'lib/common/xxhash.c'), + join_paths(zstd_rootdir, 'lib/compress/hist.c'), + join_paths(zstd_rootdir, 'lib/compress/fse_compress.c'), + join_paths(zstd_rootdir, 'lib/compress/huf_compress.c'), + join_paths(zstd_rootdir, 'lib/compress/zstd_compress.c'), + join_paths(zstd_rootdir, 'lib/compress/zstdmt_compress.c'), + join_paths(zstd_rootdir, 'lib/compress/zstd_fast.c'), + join_paths(zstd_rootdir, 'lib/compress/zstd_double_fast.c'), + join_paths(zstd_rootdir, 'lib/compress/zstd_lazy.c'), + join_paths(zstd_rootdir, 'lib/compress/zstd_opt.c'), + join_paths(zstd_rootdir, 'lib/compress/zstd_ldm.c'), + join_paths(zstd_rootdir, 'lib/decompress/huf_decompress.c'), + join_paths(zstd_rootdir, 'lib/decompress/zstd_decompress.c'), + join_paths(zstd_rootdir, 'lib/decompress/zstd_decompress_block.c'), + join_paths(zstd_rootdir, 'lib/decompress/zstd_ddict.c'), + join_paths(zstd_rootdir, 'lib/dictBuilder/cover.c'), + join_paths(zstd_rootdir, 'lib/dictBuilder/fastcover.c'), + join_paths(zstd_rootdir, 'lib/dictBuilder/divsufsort.c'), + join_paths(zstd_rootdir, 'lib/dictBuilder/zdict.c'), + join_paths(zstd_rootdir, 'lib/deprecated/zbuff_common.c'), + join_paths(zstd_rootdir, 'lib/deprecated/zbuff_compress.c'), + join_paths(zstd_rootdir, 'lib/deprecated/zbuff_decompress.c')] + +# Explicit define legacy support +add_project_arguments('-DZSTD_LEGACY_SUPPORT=@0@'.format(legacy_level), + language: 'c') + +if legacy_level == 0 + message('Legacy support: DISABLED') +else + # See ZSTD_LEGACY_SUPPORT of lib/README.md + message('Enable legacy support back to version 0.@0@'.format(legacy_level)) + + libzstd_includes += [ include_directories(join_paths(zstd_rootdir, 'lib/legacy')) ] + foreach i : [1, 2, 3, 4, 5, 6, 7] + if legacy_level <= i + libzstd_sources += join_paths(zstd_rootdir, 'lib/legacy/zstd_v0@0@.c'.format(i)) + endif + endforeach +endif + +libzstd_deps = [] +if use_multi_thread + message('Enable multi-threading support') + add_project_arguments('-DZSTD_MULTITHREAD', language: 'c') + libzstd_deps = [ thread_dep ] +endif + +libzstd_c_args = [] +if cc_id == compiler_msvc + if default_library_type != 'static' + libzstd_sources += [windows_mod.compile_resources( + join_paths(zstd_rootdir, 'build/VS2010/libzstd-dll/libzstd-dll.rc'))] + libzstd_c_args += ['-DZSTD_DLL_EXPORT=1', + '-DZSTD_HEAPMODE=0', + '-D_CONSOLE', + '-D_CRT_SECURE_NO_WARNINGS'] + else + libzstd_c_args += ['-DZSTD_HEAPMODE=0', + '-D_CRT_SECURE_NO_WARNINGS'] + endif +endif + +mingw_ansi_stdio_flags = [] +if host_machine_os == os_windows and cc_id == compiler_gcc + mingw_ansi_stdio_flags = [ '-D__USE_MINGW_ANSI_STDIO' ] +endif +libzstd_c_args += mingw_ansi_stdio_flags + +libzstd_debug_cflags = [] +if use_debug + libzstd_c_args += '-DDEBUGLEVEL=@0@'.format(debug_level) + if cc_id == compiler_gcc or cc_id == compiler_clang + libzstd_debug_cflags = ['-Wstrict-aliasing=1', '-Wswitch-enum', + '-Wdeclaration-after-statement', '-Wstrict-prototypes', + '-Wundef', '-Wpointer-arith', '-Wformat-security', '-Wvla', + '-Wformat=2', '-Winit-self', '-Wfloat-equal', '-Wwrite-strings', + '-Wredundant-decls', '-Wmissing-prototypes', '-Wc++-compat'] + endif +endif +libzstd_c_args += cc.get_supported_arguments(libzstd_debug_cflags) + +libzstd = library('zstd', + libzstd_sources, + include_directories: libzstd_includes, + c_args: libzstd_c_args, + dependencies: libzstd_deps, + install: true, + version: zstd_libversion, + soversion: '1') + +libzstd_dep = declare_dependency(link_with: libzstd, + include_directories: libzstd_includes) + +pkgconfig.generate(name: 'libzstd', + filebase: 'libzstd', + libraries: [libzstd], + description: 'fast lossless compression algorithm library', + version: zstd_libversion, + url: 'http://www.zstd.net/') + +install_headers(join_paths(zstd_rootdir, 'lib/zstd.h'), + join_paths(zstd_rootdir, 'lib/deprecated/zbuff.h'), + join_paths(zstd_rootdir, 'lib/dictBuilder/zdict.h'), + join_paths(zstd_rootdir, 'lib/common/zstd_errors.h')) diff --git a/build/meson/meson.build b/build/meson/meson.build new file mode 100644 index 000000000..2e1f9d06b --- /dev/null +++ b/build/meson/meson.build @@ -0,0 +1,171 @@ +# ############################################################################# +# Copyright (c) 2018-present Dima Krasner +# lzutao +# All rights reserved. +# +# This source code is licensed under both the BSD-style license (found in the +# LICENSE file in the root directory of this source tree) and the GPLv2 (found +# in the COPYING file in the root directory of this source tree). +# ############################################################################# + +project('zstd', + ['c', 'cpp'], + license: ['BSD', 'GPLv2'], + default_options : ['c_std=c99', + 'cpp_std=c++11', + 'buildtype=release'], + version: '1.3.8', + meson_version: '>=0.47.0') + +cc = meson.get_compiler('c') +cxx = meson.get_compiler('cpp') +pkgconfig = import('pkgconfig') +python3 = import('python').find_installation() +windows_mod = import('windows') + +host_machine_os = host_machine.system() +os_windows = 'windows' +os_linux = 'linux' +os_darwin = 'darwin' +os_freebsd = 'freebsd' +os_sun = 'sunos' + +cc_id = cc.get_id() +compiler_gcc = 'gcc' +compiler_clang = 'clang' +compiler_msvc = 'msvc' + +zstd_version = meson.project_version() +zstd_libversion = '' + +# ============================================================================= +# Project directories +# ============================================================================= + +zstd_rootdir = '../..' + +# ============================================================================= +# Installation directories +# ============================================================================= + +if host_machine_os == os_windows + zstd_prefix = '.' + zstd_bindir = 'bin' + zstd_datadir = 'share' + zstd_mandir = join_paths(zstd_datadir, 'man') +else + zstd_prefix = get_option('prefix') + zstd_bindir = join_paths(zstd_prefix, get_option('bindir')) + zstd_datadir = join_paths(zstd_prefix, get_option('datadir')) + zstd_mandir = join_paths(zstd_prefix, get_option('mandir')) +endif + +zstd_docdir = join_paths(zstd_datadir, 'doc', meson.project_name()) + +# ============================================================================= +# Project options +# ============================================================================= + +# Built-in options +use_debug = get_option('debug') +buildtype = get_option('buildtype') + +# Custom options +debug_level = get_option('debug_level') +legacy_level = get_option('legacy_level') +use_backtrace = get_option('backtrace') +use_static_runtime = get_option('static_runtime') + +build_programs = get_option('build_programs') +build_contrib = get_option('build_contrib') +build_tests = get_option('build_tests') + +feature_multi_thread = get_option('multi_thread') +feature_zlib = get_option('zlib') +feature_lzma = get_option('lzma') +feature_lz4 = get_option('lz4') + +# ============================================================================= +# Helper scripts for Meson +# ============================================================================= + +GetZstdLibraryVersion_py = files('GetZstdLibraryVersion.py') + +# ============================================================================= +# Getting project version from zstd.h +# ============================================================================= + +zstd_h_file = join_paths(meson.current_source_dir(), zstd_rootdir, 'lib/zstd.h') +r = run_command(python3, GetZstdLibraryVersion_py, zstd_h_file) +if r.returncode() == 0 + output = r.stdout().strip() + if output.version_compare('>@0@'.format(zstd_version)) + zstd_version = output + message('Project version is now: @0@'.format(zstd_version)) + endif +endif + +if host_machine_os != os_windows + zstd_libversion = zstd_version +endif + +# ============================================================================= +# Dependencies +# ============================================================================= + +libm_dep = cc.find_library('m', required: build_tests) +thread_dep = dependency('threads', required: feature_multi_thread) +use_multi_thread = thread_dep.found() +# Arguments in dependency should be equivalent to those passed to pkg-config +zlib_dep = dependency('zlib', required: feature_zlib) +use_zlib = zlib_dep.found() +lzma_dep = dependency('liblzma', required: feature_lzma) +use_lzma = lzma_dep.found() +lz4_dep = dependency('liblz4', required: feature_lz4) +use_lz4 = lz4_dep.found() + +# ============================================================================= +# Compiler flags +# ============================================================================= + +add_project_arguments('-DXXH_NAMESPACE=ZSTD_', language: ['c']) + +if [compiler_gcc, compiler_clang].contains(cc_id) + common_warning_flags = [ '-Wextra', '-Wundef', '-Wshadow', '-Wcast-align', '-Wcast-qual' ] + if cc_id == compiler_clang + # Should use Meson's own --werror build option + #common_warning_flags += '-Werror' + common_warning_flags += ['-Wconversion', '-Wno-sign-conversion', '-Wdocumentation'] + endif + cc_compile_flags = cc.get_supported_arguments(common_warning_flags + ['-Wstrict-prototypes']) + cxx_compile_flags = cxx.get_supported_arguments(common_warning_flags) + add_project_arguments(cc_compile_flags, language : 'c') + add_project_arguments(cxx_compile_flags, language : 'cpp') +elif cc_id == compiler_msvc + msvc_compile_flags = [ '/D_UNICODE', '/DUNICODE' ] + if use_multi_thread + msvc_compile_flags += '/MP' + endif + if enable_static_runtime + msvc_compile_flags += '/MT' + endif + add_project_arguments(msvc_compile_flags, language: ['c', 'cpp']) +endif + +# ============================================================================= +# Subdirs +# ============================================================================= + +subdir('lib') + +if build_programs + subdir('programs') +endif + +if build_tests + subdir('tests') +endif + +if build_contrib + subdir('contrib') +endif diff --git a/build/meson/meson_options.txt b/build/meson/meson_options.txt new file mode 100644 index 000000000..349d915c7 --- /dev/null +++ b/build/meson/meson_options.txt @@ -0,0 +1,36 @@ +# ############################################################################# +# Copyright (c) 2018-present Dima Krasner +# lzutao +# All rights reserved. +# +# This source code is licensed under both the BSD-style license (found in the +# LICENSE file in the root directory of this source tree) and the GPLv2 (found +# in the COPYING file in the root directory of this source tree). +# ############################################################################# + +# Read guidelines from https://wiki.gnome.org/Initiatives/GnomeGoals/MesonPorting + +option('legacy_level', type: 'integer', min: 0, max: 7, value: '5', + description: 'Support any legacy format: 7 to 1 for v0.7+ to v0.1+') +option('debug_level', type: 'integer', min: 0, max: 9, value: 1, + description: 'Enable run-time debug. See lib/common/debug.h') +option('backtrace', type: 'boolean', value: false, + description: 'Display a stack backtrace when execution generates a runtime exception') +option('static_runtime', type: 'boolean', value: false, + description: 'Link to static run-time libraries on MSVC') + +option('build_programs', type: 'boolean', value: true, + description: 'Enable programs build') +option('build_tests', type: 'boolean', value: false, + description: 'Enable tests build') +option('build_contrib', type: 'boolean', value: false, + description: 'Enable contrib build') + +option('multi_thread', type: 'feature', value: 'enabled', + description: 'Enable multi-threading when pthread is detected') +option('zlib', type: 'feature', value: 'auto', + description: 'Enable zlib support') +option('lzma', type: 'feature', value: 'auto', + description: 'Enable lzma support') +option('lz4', type: 'feature', value: 'auto', + description: 'Enable lz4 support') diff --git a/build/meson/programs/meson.build b/build/meson/programs/meson.build new file mode 100644 index 000000000..333ad8e8b --- /dev/null +++ b/build/meson/programs/meson.build @@ -0,0 +1,101 @@ +# ############################################################################# +# Copyright (c) 2018-present Dima Krasner +# lzutao +# All rights reserved. +# +# This source code is licensed under both the BSD-style license (found in the +# LICENSE file in the root directory of this source tree) and the GPLv2 (found +# in the COPYING file in the root directory of this source tree). +# ############################################################################# + +zstd_rootdir = '../../..' + +zstd_programs_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'), + join_paths(zstd_rootdir, 'programs/util.c'), + join_paths(zstd_rootdir, 'programs/fileio.c'), + join_paths(zstd_rootdir, 'programs/benchfn.c'), + join_paths(zstd_rootdir, 'programs/benchzstd.c'), + join_paths(zstd_rootdir, 'programs/datagen.c'), + join_paths(zstd_rootdir, 'programs/dibio.c')] + +zstd_c_args = libzstd_debug_cflags +if use_multi_thread + zstd_c_args += [ '-DZSTD_MULTITHREAD' ] +endif + +zstd_deps = [ libzstd_dep ] +if use_zlib + zstd_deps += [ zlib_dep ] + zstd_c_args += [ '-DZSTD_GZCOMPRESS', '-DZSTD_GZDECOMPRESS' ] +endif + +if use_lzma + zstd_deps += [ lzma_dep ] + zstd_c_args += [ '-DZSTD_LZMACOMPRESS', '-DZSTD_LZMADECOMPRESS' ] +endif + +if use_lz4 + zstd_deps += [ lz4_dep ] + zstd_c_args += [ '-DZSTD_LZ4COMPRESS', '-DZSTD_LZ4DECOMPRESS' ] +endif + +export_dynamic_on_windows = false +# explicit backtrace enable/disable for Linux & Darwin +if not use_backtrace + zstd_c_args += '-DBACKTRACE_ENABLE=0' +elif use_debug and host_machine_os == os_windows # MinGW target + zstd_c_args += '-DBACKTRACE_ENABLE=1' + export_dynamic_on_windows = true +endif + +if cc_id == compiler_msvc + if default_library_type != 'static' + zstd_programs_sources += [windows_mod.compile_resources( + join_paths(zstd_rootdir, 'build/VS2010/zstd/zstd.rc'))] + endif +endif + +zstd = executable('zstd', + zstd_programs_sources, + c_args: zstd_c_args, + dependencies: zstd_deps, + export_dynamic: export_dynamic_on_windows, # Since Meson 0.45.0 + install: true) + +zstd_frugal_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'), + join_paths(zstd_rootdir, 'programs/util.c'), + join_paths(zstd_rootdir, 'programs/fileio.c')] + +# Minimal target, with only zstd compression and decompression. +# No bench. No legacy. +executable('zstd-frugal', + zstd_frugal_sources, + dependencies: libzstd_dep, + c_args: [ '-DZSTD_NOBENCH', '-DZSTD_NODICT' ], + install: true) + +install_data(join_paths(zstd_rootdir, 'programs/zstdgrep'), + join_paths(zstd_rootdir, 'programs/zstdless'), + install_dir: zstd_bindir) + +# ============================================================================= +# Programs and manpages installing +# ============================================================================= + +install_man(join_paths(zstd_rootdir, 'programs/zstd.1'), + join_paths(zstd_rootdir, 'programs/zstdgrep.1'), + join_paths(zstd_rootdir, 'programs/zstdless.1')) + +InstallSymlink_py = '../InstallSymlink.py' +zstd_man1_dir = join_paths(zstd_mandir, 'man1') +man1_EXT = host_machine_os != os_windows ? '.1.gz' : '.1' + +foreach f : ['zstdcat', 'unzstd'] + meson.add_install_script(InstallSymlink_py, 'zstd', f, zstd_bindir) + meson.add_install_script(InstallSymlink_py, 'zstd' + man1_EXT, f + man1_EXT, zstd_man1_dir) +endforeach + +if use_multi_thread + meson.add_install_script(InstallSymlink_py, 'zstd', 'zstdmt', zstd_bindir) + meson.add_install_script(InstallSymlink_py, 'zstd' + man1_EXT, 'zstdmt' + man1_EXT, zstd_man1_dir) +endif diff --git a/build/meson/tests/meson.build b/build/meson/tests/meson.build new file mode 100644 index 000000000..aa9cd86f4 --- /dev/null +++ b/build/meson/tests/meson.build @@ -0,0 +1,218 @@ +# ############################################################################# +# Copyright (c) 2018-present Dima Krasner +# lzutao +# All rights reserved. +# +# This source code is licensed under both the BSD-style license (found in the +# LICENSE file in the root directory of this source tree) and the GPLv2 (found +# in the COPYING file in the root directory of this source tree). +# ############################################################################# + +zstd_rootdir = '../../..' + +tests_supported_oses = [os_linux, 'gnu/kfreebsd', os_darwin, 'gnu', 'openbsd', + os_freebsd, 'netbsd', 'dragonfly', os_sun] + +# ============================================================================= +# Test flags +# ============================================================================= + +FUZZER_FLAGS = ['--no-big-tests'] +FUZZERTEST = '-T200s' +ZSTREAM_TESTTIME = '-T90s' +DECODECORPUS_TESTTIME = '-T30' +ZSTDRTTEST = ['--test-large-data'] + +# ============================================================================= +# Executables +# ============================================================================= + +test_includes = [ include_directories(join_paths(zstd_rootdir, 'programs')) ] + +datagen_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'), + join_paths(zstd_rootdir, 'tests/datagencli.c')] +datagen = executable('datagen', + datagen_sources, + c_args: [ '-DNDEBUG' ], + include_directories: test_includes, + dependencies: libzstd_dep, + install: false) + +fullbench_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'), + join_paths(zstd_rootdir, 'programs/util.c'), + join_paths(zstd_rootdir, 'programs/benchfn.c'), + join_paths(zstd_rootdir, 'programs/benchzstd.c'), + join_paths(zstd_rootdir, 'tests/fullbench.c')] +fullbench = executable('fullbench', + fullbench_sources, + include_directories: test_includes, + dependencies: libzstd_dep, + install: false) + +fuzzer_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'), + join_paths(zstd_rootdir, 'programs/util.c'), + join_paths(zstd_rootdir, 'tests/fuzzer.c')] +fuzzer = executable('fuzzer', + fuzzer_sources, + include_directories: test_includes, + dependencies: libzstd_dep, + install: false) + +zbufftest_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'), + join_paths(zstd_rootdir, 'programs/util.c'), + join_paths(zstd_rootdir, 'tests/zbufftest.c')] +zbufftest = executable('zbufftest', + zbufftest_sources, + c_args: ['-Wno-deprecated-declarations'], + include_directories: test_includes, + dependencies: libzstd_dep, + install: false) + +zstreamtest_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'), + join_paths(zstd_rootdir, 'programs/util.c'), + join_paths(zstd_rootdir, 'tests/seqgen.c'), + join_paths(zstd_rootdir, 'tests/zstreamtest.c')] +zstreamtest = executable('zstreamtest', + zstreamtest_sources, + include_directories: test_includes, + dependencies: libzstd_dep, + install: false) + +paramgrill_sources = [join_paths(zstd_rootdir, 'programs/benchfn.c'), + join_paths(zstd_rootdir, 'programs/benchzstd.c'), + join_paths(zstd_rootdir, 'programs/datagen.c'), + join_paths(zstd_rootdir, 'programs/util.c'), + join_paths(zstd_rootdir, 'tests/paramgrill.c')] +paramgrill = executable('paramgrill', + paramgrill_sources, + include_directories: test_includes, + dependencies: [ libzstd_dep, libm_dep ], + install: false) + +roundTripCrash_sources = [join_paths(zstd_rootdir, 'tests/roundTripCrash.c')] +roundTripCrash = executable('roundTripCrash', + roundTripCrash_sources, + dependencies: [ libzstd_dep ], + install: false) + +longmatch_sources = [join_paths(zstd_rootdir, 'tests/longmatch.c')] +longmatch = executable('longmatch', + longmatch_sources, + dependencies: [ libzstd_dep ], + install: false) + +invalidDictionaries_sources = [join_paths(zstd_rootdir, 'tests/invalidDictionaries.c')] +invalidDictionaries = executable('invalidDictionaries', + invalidDictionaries_sources, + dependencies: [ libzstd_dep ], + install: false) + +legacy_sources = [join_paths(zstd_rootdir, 'tests/legacy.c')] +legacy = executable('legacy', + legacy_sources, + # Use -Dlegacy_level build option to control it + #c_args: '-DZSTD_LEGACY_SUPPORT=4', + dependencies: [ libzstd_dep ], + install: false) + +decodecorpus_sources = [join_paths(zstd_rootdir, 'programs/util.c'), + join_paths(zstd_rootdir, 'tests/decodecorpus.c')] +decodecorpus = executable('decodecorpus', + decodecorpus_sources, + include_directories: test_includes, + dependencies: [ libzstd_dep, libm_dep ], + install: false) + +symbols_sources = [join_paths(zstd_rootdir, 'tests/symbols.c')] +symbols = executable('symbols', + symbols_sources, + include_directories: test_includes, + c_args: host_machine_os == os_windows ? '-DZSTD_DLL_IMPORT=1' : [], + dependencies: [ libzstd_dep ], + install: false) + +poolTests_sources = [join_paths(zstd_rootdir, 'programs/util.c'), + join_paths(zstd_rootdir, 'tests/poolTests.c'), + join_paths(zstd_rootdir, 'lib/common/pool.c'), + join_paths(zstd_rootdir, 'lib/common/threading.c'), + join_paths(zstd_rootdir, 'lib/common/zstd_common.c'), + join_paths(zstd_rootdir, 'lib/common/error_private.c')] +poolTests = executable('poolTests', + poolTests_sources, + include_directories: test_includes, + dependencies: [ libzstd_dep, thread_dep ], + install: false) + +checkTag_sources = [join_paths(zstd_rootdir, 'tests/checkTag.c')] +checkTag = executable('checkTag', + checkTag_sources, + dependencies: [ libzstd_dep ], + install: false) + +# ============================================================================= +# Tests (Use "meson test --list" to list all tests) +# ============================================================================= + +if tests_supported_oses.contains(host_machine_os) + valgrind_prog = find_program('valgrind', ['/usr/bin/valgrind'], required: true) + valgrindTest_py = files('valgrindTest.py') + test('valgrindTest', + valgrindTest_py, + args: [valgrind_prog.path(), zstd, datagen, fuzzer, fullbench], + depends: [zstd, datagen, fuzzer, fullbench], + timeout: 600) # Timeout should work on HDD drive +endif + +if host_machine_os != os_windows + playTests_sh = find_program(join_paths(zstd_rootdir, 'tests/playTests.sh'), required: true) + test('test-zstd', + playTests_sh, + args: ZSTDRTTEST, + env: ['ZSTD=' + zstd.full_path()], + depends: [datagen], + timeout: 600) # Timeout should work on HDD drive +endif + +test('test-fullbench-1', + fullbench, + args: ['-i1'], + depends: [datagen], + timeout: 60) +test('test-fullbench-2', + fullbench, + args: ['-i1', '-P0'], + depends: [datagen], + timeout: 60) + +if use_zlib + test('test-fuzzer', + fuzzer, + args: ['-v', FUZZERTEST] + FUZZER_FLAGS, + timeout: 240) +endif + +test('test-zbuff', + zbufftest, + args: [ZSTREAM_TESTTIME], + timeout: 120) +test('test-zstream-1', + zstreamtest, + args: ['-v', ZSTREAM_TESTTIME] + FUZZER_FLAGS, + timeout: 120) +test('test-zstream-2', + zstreamtest, + args: ['-mt', '-t1', ZSTREAM_TESTTIME] + FUZZER_FLAGS, + timeout: 120) +test('test-zstream-3', + zstreamtest, + args: ['--newapi', '-t1', ZSTREAM_TESTTIME] + FUZZER_FLAGS, + timeout: 120) +test('test-longmatch', longmatch, timeout: 36) +test('test-invalidDictionaries', invalidDictionaries) # should be fast +test('test-symbols', symbols) # should be fast +test('test-legacy', legacy) # should be fast +test('test-decodecorpus', + decodecorpus, + args: ['-t', DECODECORPUS_TESTTIME], + timeout: 60) +test('test-poolTests', poolTests) # should be fast diff --git a/build/meson/tests/valgrindTest.py b/build/meson/tests/valgrindTest.py new file mode 100644 index 000000000..218f7458b --- /dev/null +++ b/build/meson/tests/valgrindTest.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +# ############################################################################# +# Copyright (c) 2018-present lzutao +# All rights reserved. +# +# This source code is licensed under both the BSD-style license (found in the +# LICENSE file in the root directory of this source tree) and the GPLv2 (found +# in the COPYING file in the root directory of this source tree). +# ############################################################################# +import os +import subprocess +import tempfile + + +def valgrindTest(valgrind, datagen, fuzzer, zstd, fullbench): + VALGRIND_ARGS = [valgrind, '--leak-check=full', '--show-leak-kinds=all', '--error-exitcode=1'] + + print('\n ---- valgrind tests : memory analyzer ----') + + subprocess.check_call([*VALGRIND_ARGS, datagen, '-g50M'], stdout=subprocess.DEVNULL) + + if subprocess.call([*VALGRIND_ARGS, zstd], + stdout=subprocess.DEVNULL) == 0: + raise subprocess.CalledProcessError('zstd without argument should have failed') + + with subprocess.Popen([datagen, '-g80'], stdout=subprocess.PIPE) as p1, \ + subprocess.Popen([*VALGRIND_ARGS, zstd, '-', '-c'], + stdin=p1.stdout, + stdout=subprocess.DEVNULL) as p2: + p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. + p2.communicate() + if p2.returncode != 0: + raise subprocess.CalledProcessError() + + with subprocess.Popen([datagen, '-g16KB'], stdout=subprocess.PIPE) as p1, \ + subprocess.Popen([*VALGRIND_ARGS, zstd, '-vf', '-', '-c'], + stdin=p1.stdout, + stdout=subprocess.DEVNULL) as p2: + p1.stdout.close() + p2.communicate() + if p2.returncode != 0: + raise subprocess.CalledProcessError() + + with tempfile.NamedTemporaryFile() as tmp_fd: + with subprocess.Popen([datagen, '-g2930KB'], stdout=subprocess.PIPE) as p1, \ + subprocess.Popen([*VALGRIND_ARGS, zstd, '-5', '-vf', '-', '-o', tmp_fd.name], + stdin=p1.stdout) as p2: + p1.stdout.close() + p2.communicate() + if p2.returncode != 0: + raise subprocess.CalledProcessError() + + subprocess.check_call([*VALGRIND_ARGS, zstd, '-vdf', tmp_fd.name, '-c'], + stdout=subprocess.DEVNULL) + + with subprocess.Popen([datagen, '-g64MB'], stdout=subprocess.PIPE) as p1, \ + subprocess.Popen([*VALGRIND_ARGS, zstd, '-vf', '-', '-c'], + stdin=p1.stdout, + stdout=subprocess.DEVNULL) as p2: + p1.stdout.close() + p2.communicate() + if p2.returncode != 0: + raise subprocess.CalledProcessError() + + subprocess.check_call([*VALGRIND_ARGS, fuzzer, '-T1mn', '-t1']) + subprocess.check_call([*VALGRIND_ARGS, fullbench, '-i1']) + + +def main(): + import argparse + parser = argparse.ArgumentParser(description='Valgrind tests : memory analyzer') + parser.add_argument('valgrind', help='valgrind path') + parser.add_argument('zstd', help='zstd path') + parser.add_argument('datagen', help='datagen path') + parser.add_argument('fuzzer', help='fuzzer path') + parser.add_argument('fullbench', help='fullbench path') + + args = parser.parse_args() + + valgrind = args.valgrind + zstd = args.zstd + datagen = args.datagen + fuzzer = args.fuzzer + fullbench = args.fullbench + + valgrindTest(valgrind, datagen, fuzzer, zstd, fullbench) + + +if __name__ == '__main__': + main() diff --git a/contrib/meson/CopyFile.py b/contrib/meson/CopyFile.py deleted file mode 100644 index 6c0288ee4..000000000 --- a/contrib/meson/CopyFile.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python3 -# ############################################################################# -# Copyright (c) 2018-present lzutao -# All rights reserved. -# -# This source code is licensed under both the BSD-style license (found in the -# LICENSE file in the root directory of this source tree) and the GPLv2 (found -# in the COPYING file in the root directory of this source tree). -# ############################################################################# -import os -import sys -import shutil - - -def usage(): - print('usage: python3 CreateSymlink.py ') - print('Copy the file named src to a file named dst') - sys.exit(1) - - -def main(): - if len(sys.argv) < 3: - usage() - src = sys.argv[1] - dst = sys.argv[2] - - if os.path.exists(dst): - print ('File already exists: %r' % (dst)) - return - - shutil.copy2(src, dst) - - -if __name__ == '__main__': - main() diff --git a/contrib/meson/CreateSymlink.py b/contrib/meson/CreateSymlink.py deleted file mode 100644 index d0f9918ab..000000000 --- a/contrib/meson/CreateSymlink.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python3 -# ############################################################################# -# Copyright (c) 2018-present lzutao -# All rights reserved. -# -# This source code is licensed under both the BSD-style license (found in the -# LICENSE file in the root directory of this source tree) and the GPLv2 (found -# in the COPYING file in the root directory of this source tree). -# ############################################################################# -import os -import sys - - -def usage(): - print('usage: python3 CreateSymlink.py [dst is dir: True or False]') - sys.exit(1) - - -def main(): - if len(sys.argv) < 3: - usage() - src = sys.argv[1] - dst = sys.argv[2] - is_dir = False - if len(sys.argv) == 4: - is_dir = bool(sys.argv[3]) - - if os.path.islink(dst) and os.readlink(dst) == src: - print ('File exists: %r -> %r' % (dst, src)) - return - - os.symlink(src, dst, is_dir) - - -if __name__ == '__main__': - main() diff --git a/contrib/meson/README.md b/contrib/meson/README.md deleted file mode 100644 index a2730faaa..000000000 --- a/contrib/meson/README.md +++ /dev/null @@ -1,31 +0,0 @@ -This Meson project is provided with no guarantee and maintained -by Dima Krasner . - -It outputs one `libzstd`, either shared or static, depending on -`default_library` option. - -How to build -============ - -`cd` to this meson directory (`zstd/contrib/meson`) and type: - -```sh -meson --buildtype=release --strip --prefix=/usr builddir -cd builddir -ninja # to build -ninja install # to install -``` - -You might want to install it in staging directory: - -```sh -DESTDIR=./staging ninja install -``` - -To configure the build, use: - -```sh -meson configure -``` - -See [man meson(1)](https://manpages.debian.org/testing/meson/meson.1.en.html). diff --git a/contrib/meson/contrib/gen_html/meson.build b/contrib/meson/contrib/gen_html/meson.build deleted file mode 100644 index 086b8f058..000000000 --- a/contrib/meson/contrib/gen_html/meson.build +++ /dev/null @@ -1,36 +0,0 @@ -# ############################################################################# -# Copyright (c) 2018-present lzutao -# All rights reserved. -# -# This source code is licensed under both the BSD-style license (found in the -# LICENSE file in the root directory of this source tree) and the GPLv2 (found -# in the COPYING file in the root directory of this source tree). -# ############################################################################# - -zstd_source_dir = join_paths('..', '..', '..', '..') -library_dir = join_paths(zstd_source_dir, 'lib') -library_common_dir = join_paths(library_dir, 'common') -programs_dir = join_paths(zstd_source_dir, 'programs') -contrib_gen_html_dir = join_paths(zstd_source_dir, 'contrib', 'gen_html') - -gen_html_includes = include_directories(programs_dir, - library_dir, - library_common_dir, - contrib_gen_html_dir ) - -gen_html = executable('gen_html', - join_paths(contrib_gen_html_dir, 'gen_html.cpp'), - include_directories: gen_html_includes, - install: false ) - -# Update zstd manual -zstd_manual_html = custom_target('zstd_manual.html', - output : 'zstd_manual.html', - command : [ - gen_html, - zstd_version, - join_paths(meson.current_source_dir(), library_dir, 'zstd.h'), - '@OUTPUT@' - ], - install : true, - install_dir : zstd_docdir ) diff --git a/contrib/meson/contrib/pzstd/meson.build b/contrib/meson/contrib/pzstd/meson.build deleted file mode 100644 index 923990145..000000000 --- a/contrib/meson/contrib/pzstd/meson.build +++ /dev/null @@ -1,32 +0,0 @@ -# ############################################################################# -# Copyright (c) 2018-present lzutao -# All rights reserved. -# -# This source code is licensed under both the BSD-style license (found in the -# LICENSE file in the root directory of this source tree) and the GPLv2 (found -# in the COPYING file in the root directory of this source tree). -# ############################################################################# - -zstd_source_dir = join_paths('..', '..', '..', '..') -library_dir = join_paths(zstd_source_dir, 'lib') -library_common_dir = join_paths(library_dir, 'common') -programs_dir = join_paths(zstd_source_dir, 'programs') -contrib_pzstd_dir = join_paths(zstd_source_dir, 'contrib', 'pzstd') - -pzstd_includes = include_directories(programs_dir, - library_dir, - library_common_dir, - contrib_pzstd_dir) -pzstd_sources = [join_paths(programs_dir, 'util.c'), - join_paths(contrib_pzstd_dir, 'main.cpp'), - join_paths(contrib_pzstd_dir, 'Options.cpp'), - join_paths(contrib_pzstd_dir, 'Pzstd.cpp'), - join_paths(contrib_pzstd_dir, 'SkippableFrame.cpp')] - -pzstd = executable('pzstd', - pzstd_sources, - cpp_args: [ '-DNDEBUG', '-Wno-shadow' ], - include_directories: pzstd_includes, - link_with: libzstd, - dependencies: [ thread_dep ], - install: true) diff --git a/contrib/meson/lib/meson.build b/contrib/meson/lib/meson.build deleted file mode 100644 index b5d6778dd..000000000 --- a/contrib/meson/lib/meson.build +++ /dev/null @@ -1,122 +0,0 @@ -# ############################################################################# -# Copyright (c) 2018-present Dima Krasner -# lzutao -# All rights reserved. -# -# This source code is licensed under both the BSD-style license (found in the -# LICENSE file in the root directory of this source tree) and the GPLv2 (found -# in the COPYING file in the root directory of this source tree). -# ############################################################################# - -zstd_source_dir = join_paths('..', '..', '..') -library_dir = join_paths(zstd_source_dir, 'lib') -library_common_dir = join_paths(library_dir, 'common') -library_compress_dir = join_paths(library_dir, 'compress') -library_decompress_dir = join_paths(library_dir, 'decompress') -library_dictbuilder_dir = join_paths(library_dir, 'dictBuilder') -library_deprecated_dir = join_paths(library_dir, 'deprecated') -library_legacy_dir = join_paths(library_dir, 'legacy') - -libzstd_includes = [include_directories(library_dir, - library_common_dir, - library_compress_dir, - library_decompress_dir, - library_dictbuilder_dir, - library_deprecated_dir)] - -libzstd_sources = [join_paths(library_common_dir, 'entropy_common.c'), - join_paths(library_common_dir, 'fse_decompress.c'), - join_paths(library_common_dir, 'threading.c'), - join_paths(library_common_dir, 'pool.c'), - join_paths(library_common_dir, 'zstd_common.c'), - join_paths(library_common_dir, 'error_private.c'), - join_paths(library_common_dir, 'xxhash.c'), - join_paths(library_compress_dir, 'hist.c'), - join_paths(library_compress_dir, 'fse_compress.c'), - join_paths(library_compress_dir, 'huf_compress.c'), - join_paths(library_compress_dir, 'zstd_compress.c'), - join_paths(library_compress_dir, 'zstdmt_compress.c'), - join_paths(library_compress_dir, 'zstd_fast.c'), - join_paths(library_compress_dir, 'zstd_double_fast.c'), - join_paths(library_compress_dir, 'zstd_lazy.c'), - join_paths(library_compress_dir, 'zstd_opt.c'), - join_paths(library_compress_dir, 'zstd_ldm.c'), - join_paths(library_decompress_dir, 'huf_decompress.c'), - join_paths(library_decompress_dir, 'zstd_decompress.c'), - join_paths(library_decompress_dir, 'zstd_decompress_block.c'), - join_paths(library_decompress_dir, 'zstd_ddict.c'), - join_paths(library_dictbuilder_dir, 'cover.c'), - join_paths(library_dictbuilder_dir, 'fastcover.c'), - join_paths(library_dictbuilder_dir, 'divsufsort.c'), - join_paths(library_dictbuilder_dir, 'zdict.c'), - join_paths(library_deprecated_dir, 'zbuff_common.c'), - join_paths(library_deprecated_dir, 'zbuff_compress.c'), - join_paths(library_deprecated_dir, 'zbuff_decompress.c')] - -if legacy_support == '0' - legacy_support = 'false' -endif -if legacy_support != 'false' - if legacy_support == 'true' - legacy_support = '1' - endif - legacy_int = legacy_support.to_int() - if legacy_int < 0 or legacy_int >= 8 - legacy_int = 0 - endif - add_project_arguments('-DZSTD_LEGACY_SUPPORT=@0@'.format(legacy_int), - language: 'c') - libzstd_includes += [ include_directories(library_legacy_dir) ] - # See ZSTD_LEGACY_SUPPORT of programs/README.md - message('Enable legacy support back to version 0.@0@'.format(legacy_int)) - if legacy_int <= 1 - libzstd_sources += join_paths(library_legacy_dir, 'zstd_v01.c') - endif - if legacy_int <= 2 - libzstd_sources += join_paths(library_legacy_dir, 'zstd_v02.c') - endif - if legacy_int <= 3 - libzstd_sources += join_paths(library_legacy_dir, 'zstd_v03.c') - endif - if legacy_int <= 4 - libzstd_sources += join_paths(library_legacy_dir, 'zstd_v04.c') - endif - if legacy_int <= 5 - libzstd_sources += join_paths(library_legacy_dir, 'zstd_v05.c') - endif - if legacy_int <= 6 - libzstd_sources += join_paths(library_legacy_dir, 'zstd_v06.c') - endif - if legacy_int <= 7 - libzstd_sources += join_paths(library_legacy_dir, 'zstd_v07.c') - endif -endif - -if enable_multithread - message('Enable multi-threading support') - add_project_arguments('-DZSTD_MULTITHREAD', language: 'c') - libzstd_deps = [ thread_dep ] -else - libzstd_deps = [] -endif - -libzstd = library('zstd', - libzstd_sources, - include_directories: libzstd_includes, - dependencies: libzstd_deps, - install: true, - soversion: '1') - -pkgconfig.generate(name: 'libzstd', - description: 'fast lossless compression algorithm library', - version: zstd_version, - filebase: 'libzstd', - libraries: [libzstd], - #subdirs: ['.'] - ) - -install_headers(join_paths(library_dir, 'zstd.h'), - join_paths(library_deprecated_dir, 'zbuff.h'), - join_paths(library_dictbuilder_dir, 'zdict.h'), - join_paths(library_dictbuilder_dir, 'cover.h'), - join_paths(library_common_dir, 'zstd_errors.h')) diff --git a/contrib/meson/meson.build b/contrib/meson/meson.build deleted file mode 100644 index b9ac88281..000000000 --- a/contrib/meson/meson.build +++ /dev/null @@ -1,109 +0,0 @@ -# ############################################################################# -# Copyright (c) 2018-present Dima Krasner -# lzutao -# All rights reserved. -# -# This source code is licensed under both the BSD-style license (found in the -# LICENSE file in the root directory of this source tree) and the GPLv2 (found -# in the COPYING file in the root directory of this source tree). -# ############################################################################# - -project('zstd', - ['c', 'cpp'], - license: 'BSD', - default_options : ['c_std=c99', - 'cpp_std=c++11', - 'buildtype=release'], - version: '1.3.7', - # for install_man - meson_version: '>=0.47.0') - -cc = meson.get_compiler('c') -cxx = meson.get_compiler('cpp') -pkgconfig = import('pkgconfig') -python3 = import('python').find_installation() - -zstd_version = meson.project_version() - -# ============================================================================= -# Project directories -# ============================================================================= - -zstd_prefix = get_option('prefix') -zstd_bindir = join_paths(zstd_prefix, get_option('bindir')) -zstd_datadir = join_paths(zstd_prefix, get_option('datadir')) -zstd_docdir = join_paths(zstd_datadir, 'doc', meson.project_name()) -zstd_mandir = join_paths(zstd_prefix, get_option('mandir')) - -zstd_source_dir = join_paths('..', '..') -library_dir = join_paths(zstd_source_dir, 'lib') -contrib_meson_dir = join_paths(zstd_source_dir, 'contrib', 'meson') - -# ============================================================================= -# Project options -# ============================================================================= - -legacy_support = get_option('legacy_support') -enable_programs = get_option('build_programs') -enable_tests = get_option('build_tests') -enable_contrib = get_option('build_contrib') -enable_multithread = get_option('multithread_support') -enable_zlib = get_option('zlib_support') -enable_lzma = get_option('lzma_support') - -# ============================================================================= -# Getting project version from zstd.h -# ============================================================================= - -GetZstdLibraryVersion_py = files('GetZstdLibraryVersion.py') -zstd_h_file = join_paths(library_dir, 'zstd.h') -r = run_command(python3, GetZstdLibraryVersion_py, zstd_h_file) -if r.returncode() == 0 - output = r.stdout().strip() - if output.version_compare('>@0@'.format(zstd_version)) - zstd_version = output - message('Project version is now: @0@'.format(zstd_version)) - endif -endif - -# ============================================================================= -# Dependencies -# ============================================================================= - -libm_dep = cc.find_library('m', required: true) -thread_dep = dependency('threads', required: false) -zlib_dep = dependency('zlib', required: false) -lzma_dep = dependency('lzma', required: false) - -# ============================================================================= -# Compiler flags -# ============================================================================= - -if cxx.get_id() == 'gcc' or cxx.get_id() == 'clang' - common_flags = [ '-DXXH_NAMESPACE=ZSTD_' ] - zstd_compilation_flags = [ '-Wextra', '-Wundef', '-Wshadow', '-Wcast-align', '-Wcast-qual' ] - cc_common_flags = cc.get_supported_arguments(zstd_compilation_flags) - cc_common_flags += cc.get_supported_arguments(['-Wstrict-prototypes']) - cc_common_flags += common_flags - cxx_common_flags = cxx.get_supported_arguments(zstd_compilation_flags) - cxx_common_flags += common_flags - add_project_arguments(cc_common_flags, language : 'c') - add_project_arguments(cxx_common_flags, language : 'cpp') -endif - -# ============================================================================= -# Subdirs -# ============================================================================= - -subdir('lib') -if enable_programs - subdir('programs') -endif - -if enable_tests - subdir('tests') -endif - -if enable_contrib - subdir('contrib') -endif diff --git a/contrib/meson/meson_options.txt b/contrib/meson/meson_options.txt deleted file mode 100644 index 1d28c71a8..000000000 --- a/contrib/meson/meson_options.txt +++ /dev/null @@ -1,26 +0,0 @@ -# ############################################################################# -# Copyright (c) 2018-present Dima Krasner -# lzutao -# All rights reserved. -# -# This source code is licensed under both the BSD-style license (found in the -# LICENSE file in the root directory of this source tree) and the GPLv2 (found -# in the COPYING file in the root directory of this source tree). -# ############################################################################# - -option('multithread_support', type: 'boolean', value: true, - description: 'Enable multithreading when pthread is detected') -option('legacy_support', type: 'string', value: '4', - description: 'Support any legacy format: true or false, or 7 to 1 for v0.7+ to v0.1+') -option('build_programs', type: 'boolean', value: true, - description: 'Enable programs build') -option('build_contrib', type: 'boolean', value: false, - description: 'Enable contrib build') -option('build_tests', type: 'boolean', value: false, - description: 'Enable tests build') -option('use_static_runtime', type: 'boolean', value: false, - description: 'Link to static run-time libraries on MSVC') -option('zlib_support', type: 'boolean', value: false, - description: 'Enable zlib support') -option('lzma_support', type: 'boolean', value: false, - description: 'Enable lzma support') diff --git a/contrib/meson/programs/meson.build b/contrib/meson/programs/meson.build deleted file mode 100644 index 63ea328ae..000000000 --- a/contrib/meson/programs/meson.build +++ /dev/null @@ -1,113 +0,0 @@ -# ############################################################################# -# Copyright (c) 2018-present Dima Krasner -# lzutao -# All rights reserved. -# -# This source code is licensed under both the BSD-style license (found in the -# LICENSE file in the root directory of this source tree) and the GPLv2 (found -# in the COPYING file in the root directory of this source tree). -# ############################################################################# - -zstd_source_dir = join_paths('..', '..', '..') -programs_dir = join_paths(zstd_source_dir, 'programs') - -zstdcli_c_file = join_paths(programs_dir, 'zstdcli.c') -util_c_file = join_paths(programs_dir, 'util.c') -fileio_c_file = join_paths(programs_dir, 'fileio.c') -zstd_programs_sources = [zstdcli_c_file, - util_c_file, - fileio_c_file, - join_paths(programs_dir, 'benchfn.c'), - join_paths(programs_dir, 'benchzstd.c'), - join_paths(programs_dir, 'datagen.c'), - join_paths(programs_dir, 'dibio.c')] - -zstd_c_args = [] -if enable_multithread - zstd_c_args += [ '-DZSTD_MULTITHREAD' ] -endif - -zstd_deps = [] -if enable_zlib and zlib_dep.found() - zstd_deps += [ zlib_dep ] - zstd_c_args += [ '-DZSTD_GZCOMPRESS', '-DZSTD_GZDECOMPRESS' ] -endif - -if enable_lzma and lzma_dep.found() - zstd_deps += [ lzma_dep ] - zstd_c_args += [ '-DZSTD_LZMACOMPRESS', '-DZSTD_LZMADECOMPRESS' ] -endif - -zstd = executable('zstd', - zstd_programs_sources, - c_args: zstd_c_args, - include_directories: libzstd_includes, - link_with: libzstd, - dependencies: zstd_deps, - install: true) - -zstd_frugal_sources = [join_paths(programs_dir, 'zstdcli.c'), - util_c_file, - fileio_c_file] - -executable('zstd-frugal', - zstd_frugal_sources, - include_directories: libzstd_includes, - link_with: libzstd, - c_args: [ '-DZSTD_NOBENCH', '-DZSTD_NODICT' ], - install: true) - -# ============================================================================= -# Program symlinks -# ============================================================================= - -CreateSymlink_py = join_paths(meson.current_source_dir(), '..', 'CreateSymlink.py') - -foreach f : [ 'zstdcat', 'unzstd' ] - custom_target(f, - output : f, - input: zstd, - command : [python3, CreateSymlink_py, '@PLAINNAME@', '@OUTPUT@'], - build_always_stale: false, - install : true, - install_dir: zstd_bindir) -endforeach - -if enable_multithread - custom_target('zstdmt', - output : 'zstdmt', - input: zstd, - command : [python3, CreateSymlink_py, '@PLAINNAME@', '@OUTPUT@'], - build_always_stale: false, - install : true, - install_dir: zstd_bindir) -endif - -# ============================================================================= -# Manpages -# ============================================================================= - -zstd_man1_dir = join_paths(zstd_mandir, 'man1') -zstd_1_file = join_paths(programs_dir, 'zstd.1') -CopyFile_py = join_paths(meson.current_source_dir(), '..', 'CopyFile.py') - -custom_target('zstd.1', - output : 'zstd.1', - input: zstd_1_file, - command : [python3, CopyFile_py, '@INPUT@', '@OUTPUT@'], - build_always_stale: false, - install : true, - install_dir: zstd_man1_dir) - -foreach f : [ 'zstdcat.1', 'unzstd.1' ] - custom_target(f, - output : f, - input: zstd_1_file, - command : [python3, CreateSymlink_py, '@PLAINNAME@', '@OUTPUT@'], - install : true, - build_always_stale: false, - install_dir: zstd_man1_dir) -endforeach - -install_man(join_paths(programs_dir, 'zstdgrep.1'), - join_paths(programs_dir, 'zstdless.1')) diff --git a/contrib/meson/tests/meson.build b/contrib/meson/tests/meson.build deleted file mode 100644 index cc9e1ee10..000000000 --- a/contrib/meson/tests/meson.build +++ /dev/null @@ -1,65 +0,0 @@ -# ############################################################################# -# Copyright (c) 2018-present Dima Krasner -# lzutao -# All rights reserved. -# -# This source code is licensed under both the BSD-style license (found in the -# LICENSE file in the root directory of this source tree) and the GPLv2 (found -# in the COPYING file in the root directory of this source tree). -# ############################################################################# - -zstd_source_dir = join_paths('..', '..', '..') -programs_dir = join_paths(zstd_source_dir, 'programs') -tests_dir = join_paths(zstd_source_dir, 'tests') - -datagen_c_file = join_paths(programs_dir, 'datagen.c') -util_c_file = join_paths(programs_dir, 'util.c') -benchfn_c_file = join_paths(programs_dir, 'benchfn.c') - -datagen_sources = [datagen_c_file, - join_paths(tests_dir, 'datagencli.c')] -test_includes = libzstd_includes + [include_directories(programs_dir)] - -datagen = executable('datagen', - datagen_sources, - include_directories: test_includes, - link_with: libzstd, - install: false) -test('datagen', datagen) - -fullbench_sources = [datagen_c_file, - util_c_file, - benchfn_c_file, - join_paths(programs_dir, 'benchzstd.c'), - join_paths(programs_dir, 'fullbench.c')] -fullbench = executable('fullbench', - fullbench_sources, - include_directories: test_includes, - link_with: libzstd, - install: false) -test('fullbench', fullbench) - -fuzzer_sources = [datagen_c_file, - util_c_file, - join_paths(tests_dir, 'fuzzer.c')] -fuzzer = executable('fuzzer', - fuzzer_sources, - include_directories: test_includes, - link_with: libzstd, - install: false) -test('fuzzer', fuzzer) - -paramgrill_sources = [benchfn_c_file - join_paths(programs_dir, 'benchzstd.c'), - datagen_c_file - util_c_file - join_paths(tests_dir, 'paramgrill.c')] -if host_machine.system() != 'windows' - paramgrill = executable('paramgrill', - paramgrill_sources, - include_directories: test_includes, - link_with: libzstd, - dependencies: libm_dep, - install: false ) - test('paramgrill', paramgrill) -endif