diff --git a/.github/workflows/generic-dev.yml b/.github/workflows/generic-dev.yml index c66a2bee3b1..dd418fc0d15 100644 --- a/.github/workflows/generic-dev.yml +++ b/.github/workflows/generic-dev.yml @@ -22,184 +22,55 @@ jobs: # The master branch exclusive jobs will be in a separate # workflow file (the osx tests and meson build that is) - benchmarking: - runs-on: ubuntu-latest + meson-msvc: + name: 'Meson on Windows MSVC' + runs-on: windows-latest steps: - uses: actions/checkout@v2 - - name: make benchmarking - run: make benchmarking - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: make test - run: make test + # Some replacements: + # * https://renenyffenegger.ch/notes/Windows/development/Visual-Studio/environment-variables/index + # * https://github.com/microsoft/vswhere/wiki/Start-Developer-Command-Prompt + - uses: ilammy/msvc-dev-cmd@v1 - gcc-6-7-libzstd: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: gcc-6 + gcc-7 + libzstdmt compilation + - name: install meson run: | - make gcc6install gcc7install - CC=gcc-6 CFLAGS=-Werror make -j all - make clean - CC=gcc-7 CFLAGS=-Werror make -j all - make clean - LDFLAGS=-Wl,--no-undefined make -C lib libzstd-mt - make -C tests zbufftest-dll - - gcc-8-asan-ubsan-testzstd: - runs-on: ubuntu-16.04 # fails on 18.04 - steps: - - uses: actions/checkout@v2 - - name: gcc-8 + ASan + UBSan + Test Zstd + pip install -U meson + + - run: | + git clone https://github.com/lzutao/lz4/ third-party\lz4 + cd third-party\lz4 + git switch std + meson setup ` + --buildtype=release ` + -Ddefault_library=shared ` + -Dprefix=C:\lz4 ` + contrib\meson builddir + cd builddir + meson compile + meson install + + - name: install zlib run: | - make gcc8install - CC=gcc-8 CFLAGS="-Werror" make -j all - make clean - CC=gcc-8 make -j uasan-test-zstd =0.47.0') + meson_version: '>=0.49.0') cc = meson.get_compiler('c') cxx = meson.get_compiler('cpp') @@ -25,16 +25,21 @@ pkgconfig = import('pkgconfig') 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' +is_os_windows = host_machine_os == 'windows' +is_os_linux = host_machine_os == 'linux' +is_os_darwin = host_machine_os == 'darwin' +is_os_freebsd = host_machine_os == 'freebsd' +is_os_sun = host_machine_os == 'sunos' cc_id = cc.get_id() -compiler_gcc = 'gcc' -compiler_clang = 'clang' -compiler_msvc = 'msvc' +cc_arg_syntax = cc.get_argument_syntax() +is_like_clang = cc_id == 'clang' +is_like_gcc = cc_arg_syntax == 'gcc' +is_like_msvc = cc_arg_syntax == 'msvc' + +if not is_like_msvc and not is_like_gcc + error('Unsupported compiler: @0@'.format(cc_id)) +endif zstd_version = meson.project_version() @@ -103,11 +108,15 @@ use_lz4 = lz4_dep.found() # Compiler flags # ============================================================================= -add_project_arguments('-DXXH_NAMESPACE=ZSTD_', language: ['c']) +if is_like_gcc + add_project_arguments('-DXXH_NAMESPACE=ZSTD_', language: ['c']) +elif is_like_msvc + add_project_arguments('/DXXH_NAMESPACE=ZSTD_', language: ['c']) +endif -if [compiler_gcc, compiler_clang].contains(cc_id) +if is_like_gcc common_warning_flags = [ '-Wextra', '-Wundef', '-Wshadow', '-Wcast-align', '-Wcast-qual' ] - if cc_id == compiler_clang + if is_like_clang # Should use Meson's own --werror build option #common_warning_flags += '-Werror' common_warning_flags += ['-Wconversion', '-Wno-sign-conversion', '-Wdocumentation'] @@ -116,8 +125,8 @@ if [compiler_gcc, compiler_clang].contains(cc_id) 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' ] +elif is_like_msvc + msvc_compile_flags = [ '/D_UNICODE', '/DUNICODE', '/DNOMINMAX' ] if use_multi_thread msvc_compile_flags += '/MP' endif diff --git a/build/meson/programs/meson.build b/build/meson/programs/meson.build index 363818f9d64..c07e96d3bb1 100644 --- a/build/meson/programs/meson.build +++ b/build/meson/programs/meson.build @@ -21,38 +21,66 @@ zstd_programs_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'), zstd_c_args = libzstd_debug_cflags if use_multi_thread - zstd_c_args += [ '-DZSTD_MULTITHREAD' ] + if is_like_msvc + zstd_c_args += [ '/DZSTD_MULTITHREAD' ] + else + zstd_c_args += [ '-DZSTD_MULTITHREAD' ] + endif endif zstd_deps = [ libzstd_dep ] if use_zlib zstd_deps += [ zlib_dep ] - zstd_c_args += [ '-DZSTD_GZCOMPRESS', '-DZSTD_GZDECOMPRESS' ] + if is_like_msvc + zstd_c_args += [ '/DZSTD_GZCOMPRESS', '/DZSTD_GZDECOMPRESS' ] + else + zstd_c_args += [ '-DZSTD_GZCOMPRESS', '-DZSTD_GZDECOMPRESS' ] + endif endif if use_lzma zstd_deps += [ lzma_dep ] - zstd_c_args += [ '-DZSTD_LZMACOMPRESS', '-DZSTD_LZMADECOMPRESS' ] + if is_like_msvc + zstd_c_args += [ '/DZSTD_LZMACOMPRESS', '/DZSTD_LZMADECOMPRESS' ] + else + zstd_c_args += [ '-DZSTD_LZMACOMPRESS', '-DZSTD_LZMADECOMPRESS' ] + endif endif if use_lz4 zstd_deps += [ lz4_dep ] - zstd_c_args += [ '-DZSTD_LZ4COMPRESS', '-DZSTD_LZ4DECOMPRESS' ] + if is_like_msvc + zstd_c_args += [ '/DZSTD_LZ4COMPRESS', '/DZSTD_LZ4DECOMPRESS' ] + else + zstd_c_args += [ '-DZSTD_LZ4COMPRESS', '-DZSTD_LZ4DECOMPRESS' ] + endif 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' + if is_like_msvc + zstd_c_args += [ '/DBACKTRACE_ENABLE=0' ] + else + zstd_c_args += '-DBACKTRACE_ENABLE=0' + endif +elif use_debug and is_os_windows # MinGW target + if is_like_msvc + zstd_c_args += [ '/DDBACKTRACE_ENABLE=1' ] + else + zstd_c_args += '-DBACKTRACE_ENABLE=1' + endif export_dynamic_on_windows = true endif -if cc_id == compiler_msvc +if is_like_msvc if default_library_type != 'static' - zstd_programs_sources += [windows_mod.compile_resources( - join_paths(zstd_rootdir, 'build/VS2010/zstd/zstd.rc'))] + zstd_programs_sources += [ + windows_mod.compile_resources( + join_paths(zstd_rootdir, 'build/VS2010/zstd/zstd.rc'), + include_directories: include_directories(join_paths(zstd_rootdir, 'lib')), + ) + ] endif endif @@ -70,10 +98,15 @@ zstd_frugal_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'), # Minimal target, with only zstd compression and decompression. # No bench. No legacy. +if is_like_msvc + zstd_frugal_c_args = [ '/DZSTD_NOBENCH', '/DZSTD_NODICT' ] +else + zstd_frugal_c_args = [ '-DZSTD_NOBENCH', '-DZSTD_NODICT' ] +endif executable('zstd-frugal', zstd_frugal_sources, dependencies: libzstd_dep, - c_args: [ '-DZSTD_NOBENCH', '-DZSTD_NODICT' ], + c_args: zstd_frugal_c_args, install: true) install_data(join_paths(zstd_rootdir, 'programs/zstdgrep'), @@ -90,7 +123,7 @@ install_man(join_paths(zstd_rootdir, 'programs/zstd.1'), InstallSymlink_py = '../InstallSymlink.py' zstd_man1_dir = join_paths(zstd_mandir, 'man1') -bin_EXT = host_machine_os == os_windows ? '.exe' : '' +bin_EXT = is_os_windows ? '.exe' : '' man1_EXT = meson.version().version_compare('>=0.49.0') ? '.1' : '.1.gz' foreach f : ['zstdcat', 'unzstd'] diff --git a/build/meson/tests/meson.build b/build/meson/tests/meson.build index 0587f9a70d5..cae86b90c34 100644 --- a/build/meson/tests/meson.build +++ b/build/meson/tests/meson.build @@ -10,8 +10,8 @@ zstd_rootdir = '../../..' -tests_supported_oses = [os_linux, 'gnu/kfreebsd', os_darwin, 'gnu', 'openbsd', - os_freebsd, 'netbsd', 'dragonfly', os_sun] +tests_supported_oses = ['linux', 'gnu/kfreebsd', 'darwin', 'gnu', 'openbsd', + 'freebsd', 'netbsd', 'dragonfly', 'sunos'] # ============================================================================= # Test flags @@ -31,9 +31,14 @@ 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')] +if is_like_msvc + datagen_c_args = [ '/DNDEBUG' ] +else + datagen_c_args = [ '-DNDEBUG' ] +endif datagen = executable('datagen', datagen_sources, - c_args: [ '-DNDEBUG' ], + c_args: datagen_c_args, include_directories: test_includes, dependencies: libzstd_dep, install: false) @@ -153,7 +158,7 @@ if tests_supported_oses.contains(host_machine_os) timeout: 600) # Timeout should work on HDD drive endif -if host_machine_os != os_windows +if not is_os_windows playTests_sh = find_program(join_paths(zstd_rootdir, 'tests/playTests.sh'), required: true) test('test-zstd', playTests_sh, diff --git a/lib/common/xxhash.c b/lib/common/xxhash.c index e708df3c338..6160662b430 100644 --- a/lib/common/xxhash.c +++ b/lib/common/xxhash.c @@ -459,7 +459,7 @@ FORCE_INLINE_TEMPLATE U64 XXH64_endian_align(const void* input, size_t len, U64 } -XXH_PUBLIC_API unsigned long long XXH64 (const void* input, size_t len, unsigned long long seed) +XXHASH_DLL_PUBLIC XXH_PUBLIC_API unsigned long long XXH64 (const void* input, size_t len, unsigned long long seed) { #if 0 /* Simple version, good for code maintenance, but unfortunately slow for small inputs */ diff --git a/lib/common/xxhash.h b/lib/common/xxhash.h index eceb55d5e07..cefed82719d 100644 --- a/lib/common/xxhash.h +++ b/lib/common/xxhash.h @@ -88,6 +88,20 @@ typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode; # define XXH_PUBLIC_API /* do nothing */ #endif /* XXH_PRIVATE_API */ +#if defined _WIN32 || defined __CYGWIN__ + #ifdef __GNUC__ + #define XXHASH_DLL_PUBLIC __attribute__ ((dllexport)) + #else + #define XXHASH_DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. + #endif +#else + #if __GNUC__ >= 4 + #define XXHASH_DLL_PUBLIC __attribute__ ((visibility ("default"))) + #else + #define XXHASH_DLL_PUBLIC + #endif +#endif + /*!XXH_NAMESPACE, aka Namespace Emulation : If you want to include _and expose_ xxHash functions from within your own library, @@ -141,7 +155,7 @@ typedef unsigned int XXH32_hash_t; typedef unsigned long long XXH64_hash_t; XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t length, unsigned int seed); -XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed); +XXHASH_DLL_PUBLIC XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed); /*! XXH32() : diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index b1bb9fa1021..1b51f2acf94 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -1057,7 +1057,7 @@ ZSTD_clampCParams(ZSTD_compressionParameters cParams) /** ZSTD_cycleLog() : * condition for correct operation : hashLog > 1 */ -U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat) +ZSTD_COMPRESS_DLL_PUBLIC U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat) { U32 const btScale = ((U32)strat >= (U32)ZSTD_btlazy2); return hashLog - btScale; diff --git a/lib/compress/zstd_compress_internal.h b/lib/compress/zstd_compress_internal.h index a0a9d53bac5..b82ebdd8be0 100644 --- a/lib/compress/zstd_compress_internal.h +++ b/lib/compress/zstd_compress_internal.h @@ -24,6 +24,20 @@ # include "zstdmt_compress.h" #endif +#if defined _WIN32 || defined __CYGWIN__ + #ifdef __GNUC__ + #define ZSTD_COMPRESS_DLL_PUBLIC __attribute__ ((dllexport)) + #else + #define ZSTD_COMPRESS_DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. + #endif +#else + #if __GNUC__ >= 4 + #define ZSTD_COMPRESS_DLL_PUBLIC __attribute__ ((visibility ("default"))) + #else + #define ZSTD_COMPRESS_DLL_PUBLIC + #endif +#endif + #if defined (__cplusplus) extern "C" { #endif @@ -1173,6 +1187,6 @@ size_t ZSTD_referenceExternalSequences(ZSTD_CCtx* cctx, rawSeq* seq, size_t nbSe /** ZSTD_cycleLog() : * condition for correct operation : hashLog > 1 */ -U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat); +ZSTD_COMPRESS_DLL_PUBLIC U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat); #endif /* ZSTD_COMPRESS_H */ diff --git a/lib/dictBuilder/zdict.c b/lib/dictBuilder/zdict.c index 6bb66347753..69399ebe5f3 100644 --- a/lib/dictBuilder/zdict.c +++ b/lib/dictBuilder/zdict.c @@ -968,16 +968,11 @@ static size_t ZDICT_addEntropyTablesFromBuffer_advanced( return MIN(dictBufferCapacity, hSize+dictContentSize); } -/* Hidden declaration for dbio.c */ -size_t ZDICT_trainFromBuffer_unsafe_legacy( - void* dictBuffer, size_t maxDictSize, - const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples, - ZDICT_legacy_params_t params); /*! ZDICT_trainFromBuffer_unsafe_legacy() : * Warning : `samplesBuffer` must be followed by noisy guard band. * @return : size of dictionary, or an error code which can be tested with ZDICT_isError() */ -size_t ZDICT_trainFromBuffer_unsafe_legacy( +ZDICTLIB_API size_t ZDICT_trainFromBuffer_unsafe_legacy( void* dictBuffer, size_t maxDictSize, const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples, ZDICT_legacy_params_t params) diff --git a/programs/platform.h b/programs/platform.h index 68be70bb333..ef320d14613 100644 --- a/programs/platform.h +++ b/programs/platform.h @@ -138,6 +138,7 @@ extern "C" { # define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream)) #elif defined(WIN32) || defined(_WIN32) # include /* _isatty */ + #define NOMINMAX /* Avoid clashing name with max in windows.h and std */ # include /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */ # include /* FILE */ static __inline int IS_CONSOLE(FILE* stdStream) {