From ee3355df30752456481541d6e120f60fd1f81e8f Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 9 Aug 2021 20:03:57 -0400 Subject: [PATCH 1/3] meson: link tests with a convenience library of sources used by multiple binaries This saves repeatedly compiling them, resulting in 16 fewer compile steps, in exchange for one `ar` step. --- build/meson/tests/meson.build | 50 +++++++++++++++-------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/build/meson/tests/meson.build b/build/meson/tests/meson.build index 4d6cd1d7539..0c4c3535a5b 100644 --- a/build/meson/tests/meson.build +++ b/build/meson/tests/meson.build @@ -29,58 +29,54 @@ ZSTDRTTEST = ['--test-large-data'] 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')] +testcommon_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'), + join_paths(zstd_rootdir, 'programs/util.c'), + join_paths(zstd_rootdir, 'programs/timefn.c'), + join_paths(zstd_rootdir, 'programs/benchfn.c'), + join_paths(zstd_rootdir, 'programs/benchzstd.c')] +testcommon = static_library('testcommon', + testcommon_sources) + +datagen_sources = [join_paths(zstd_rootdir, 'tests/datagencli.c')] datagen = executable('datagen', datagen_sources, c_args: [ '-DNDEBUG' ], include_directories: test_includes, dependencies: libzstd_dep, + link_with: testcommon, install: false) -fullbench_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'), - join_paths(zstd_rootdir, 'programs/util.c'), - join_paths(zstd_rootdir, 'programs/timefn.c'), - join_paths(zstd_rootdir, 'programs/benchfn.c'), - join_paths(zstd_rootdir, 'programs/benchzstd.c'), - join_paths(zstd_rootdir, 'tests/fullbench.c')] +fullbench_sources = [join_paths(zstd_rootdir, 'tests/fullbench.c')] fullbench = executable('fullbench', fullbench_sources, include_directories: test_includes, dependencies: libzstd_dep, + link_with: testcommon, install: false) -fuzzer_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'), - join_paths(zstd_rootdir, 'programs/util.c'), - join_paths(zstd_rootdir, 'programs/timefn.c'), - join_paths(zstd_rootdir, 'tests/fuzzer.c')] +fuzzer_sources = [join_paths(zstd_rootdir, 'tests/fuzzer.c')] fuzzer = executable('fuzzer', fuzzer_sources, include_directories: test_includes, dependencies: [ libzstd_dep, thread_dep ], + link_with: testcommon, install: false) -zstreamtest_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'), - join_paths(zstd_rootdir, 'programs/util.c'), - join_paths(zstd_rootdir, 'programs/timefn.c'), - join_paths(zstd_rootdir, 'tests/seqgen.c'), +zstreamtest_sources = [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, + link_with: testcommon, install: false) -paramgrill_sources = [join_paths(zstd_rootdir, 'programs/benchfn.c'), - join_paths(zstd_rootdir, 'programs/timefn.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_sources = [join_paths(zstd_rootdir, 'tests/paramgrill.c')] paramgrill = executable('paramgrill', paramgrill_sources, include_directories: test_includes, dependencies: [ libzstd_dep, libm_dep ], + link_with: testcommon, install: false) roundTripCrash_sources = [join_paths(zstd_rootdir, 'tests/roundTripCrash.c')] @@ -111,18 +107,15 @@ if 0 < legacy_level and legacy_level <= 4 install: false) endif -decodecorpus_sources = [join_paths(zstd_rootdir, 'programs/util.c'), - join_paths(zstd_rootdir, 'programs/timefn.c'), - join_paths(zstd_rootdir, 'tests/decodecorpus.c')] +decodecorpus_sources = [join_paths(zstd_rootdir, 'tests/decodecorpus.c')] decodecorpus = executable('decodecorpus', decodecorpus_sources, include_directories: test_includes, dependencies: [ libzstd_dep, libm_dep ], + link_with: testcommon, install: false) -poolTests_sources = [join_paths(zstd_rootdir, 'programs/util.c'), - join_paths(zstd_rootdir, 'programs/timefn.c'), - join_paths(zstd_rootdir, 'tests/poolTests.c'), +poolTests_sources = [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'), @@ -131,6 +124,7 @@ poolTests = executable('poolTests', poolTests_sources, include_directories: test_includes, dependencies: [ libzstd_dep, thread_dep ], + link_with: testcommon, install: false) checkTag_sources = [join_paths(zstd_rootdir, 'tests/checkTag.c')] From d95a3f50973592184f956cf937cc1aedca4e464c Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 8 Aug 2021 21:11:20 -0400 Subject: [PATCH 2/3] meson: fix warnings in build files meson prefers that project-level options for Wall/Wextra/pedantic be used, rather than hardcoding raw flags in add_project_arguments. If you do the latter anyway, it raises a meson warning. Set the default options for the project to use all this. Also move the -Werror comment to the project default options with appropriate format, but leave it commented out since it does not work. --- build/meson/contrib/pzstd/meson.build | 2 +- build/meson/meson.build | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/build/meson/contrib/pzstd/meson.build b/build/meson/contrib/pzstd/meson.build index dcf2136db43..2c47999fa27 100644 --- a/build/meson/contrib/pzstd/meson.build +++ b/build/meson/contrib/pzstd/meson.build @@ -18,7 +18,7 @@ pzstd_sources = [join_paths(zstd_rootdir, 'programs/util.c'), join_paths(zstd_rootdir, 'contrib/pzstd/SkippableFrame.cpp')] pzstd = executable('pzstd', pzstd_sources, - cpp_args: [ '-DNDEBUG', '-Wno-shadow', '-pedantic', '-Wno-deprecated-declarations' ], + cpp_args: [ '-DNDEBUG', '-Wno-shadow', '-Wno-deprecated-declarations' ], include_directories: pzstd_includes, dependencies: [ libzstd_dep, thread_dep ], install: true) diff --git a/build/meson/meson.build b/build/meson/meson.build index 2a425b2fa39..b74932c41e2 100644 --- a/build/meson/meson.build +++ b/build/meson/meson.build @@ -14,7 +14,11 @@ project('zstd', default_options : [ 'c_std=gnu99', 'cpp_std=c++11', - 'buildtype=release' + 'buildtype=release', + 'warning_level=3', + # -Wdocumentation does not actually pass, nor do the test binaries, + # so this isn't safe + #'werror=true' ], version: 'DUMMY', meson_version: '>=0.47.0') @@ -106,10 +110,8 @@ use_lz4 = lz4_dep.found() 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' ] + common_warning_flags = [ '-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']) From 9748608aeb6a68ca622268eb8ba07e9003079e8f Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 8 Aug 2021 21:43:59 -0400 Subject: [PATCH 3/3] meson: set the symbol visibility of the shared library to hidden This matches the Makefile build. Due to one private xxhash symbol in use by the program, it recompiles a private copy of xxhash. Due to the test binaries making extensive (?) use of private symbols, it doesn't even attempt to link to shared libzstd, and instead, all of the original object files are added to libtestcommon itself for private linkage. This, too, matches the Makefile build. Ref. #2261 --- build/meson/lib/meson.build | 1 + build/meson/meson.build | 2 +- build/meson/programs/meson.build | 4 +++- build/meson/tests/meson.build | 32 ++++++++++++++++---------------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/build/meson/lib/meson.build b/build/meson/lib/meson.build index 5cc9fee8625..5da53872959 100644 --- a/build/meson/lib/meson.build +++ b/build/meson/lib/meson.build @@ -108,6 +108,7 @@ libzstd = library('zstd', libzstd_sources, include_directories: libzstd_includes, c_args: libzstd_c_args, + gnu_symbol_visibility: 'hidden', dependencies: libzstd_deps, install: true, version: zstd_libversion) diff --git a/build/meson/meson.build b/build/meson/meson.build index b74932c41e2..0c29a7621b9 100644 --- a/build/meson/meson.build +++ b/build/meson/meson.build @@ -21,7 +21,7 @@ project('zstd', #'werror=true' ], version: 'DUMMY', - meson_version: '>=0.47.0') + meson_version: '>=0.48.0') cc = meson.get_compiler('c') cxx = meson.get_compiler('cpp') diff --git a/build/meson/programs/meson.build b/build/meson/programs/meson.build index d255627cd30..4181030c2ee 100644 --- a/build/meson/programs/meson.build +++ b/build/meson/programs/meson.build @@ -18,7 +18,9 @@ zstd_programs_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'), join_paths(zstd_rootdir, 'programs/benchzstd.c'), join_paths(zstd_rootdir, 'programs/datagen.c'), join_paths(zstd_rootdir, 'programs/dibio.c'), - join_paths(zstd_rootdir, 'programs/zstdcli_trace.c')] + join_paths(zstd_rootdir, 'programs/zstdcli_trace.c'), + # needed due to use of private symbol + -fvisibility=hidden + join_paths(zstd_rootdir, 'lib/common/xxhash.c')] zstd_c_args = libzstd_debug_cflags if use_multi_thread diff --git a/build/meson/tests/meson.build b/build/meson/tests/meson.build index 0c4c3535a5b..14f45982ab1 100644 --- a/build/meson/tests/meson.build +++ b/build/meson/tests/meson.build @@ -34,32 +34,36 @@ testcommon_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'), join_paths(zstd_rootdir, 'programs/timefn.c'), join_paths(zstd_rootdir, 'programs/benchfn.c'), join_paths(zstd_rootdir, 'programs/benchzstd.c')] + testcommon = static_library('testcommon', - testcommon_sources) + testcommon_sources, + # needed due to use of private symbol + -fvisibility=hidden + objects: libzstd.extract_all_objects(recursive: false)) + +testcommon_dep = declare_dependency(link_with: testcommon, + dependencies: libzstd_deps, + include_directories: libzstd_includes) datagen_sources = [join_paths(zstd_rootdir, 'tests/datagencli.c')] datagen = executable('datagen', datagen_sources, c_args: [ '-DNDEBUG' ], include_directories: test_includes, - dependencies: libzstd_dep, - link_with: testcommon, + dependencies: testcommon_dep, install: false) fullbench_sources = [join_paths(zstd_rootdir, 'tests/fullbench.c')] fullbench = executable('fullbench', fullbench_sources, include_directories: test_includes, - dependencies: libzstd_dep, - link_with: testcommon, + dependencies: testcommon_dep, install: false) fuzzer_sources = [join_paths(zstd_rootdir, 'tests/fuzzer.c')] fuzzer = executable('fuzzer', fuzzer_sources, include_directories: test_includes, - dependencies: [ libzstd_dep, thread_dep ], - link_with: testcommon, + dependencies: [ testcommon_dep, thread_dep ], install: false) zstreamtest_sources = [join_paths(zstd_rootdir, 'tests/seqgen.c'), @@ -67,22 +71,20 @@ zstreamtest_sources = [join_paths(zstd_rootdir, 'tests/seqgen.c'), zstreamtest = executable('zstreamtest', zstreamtest_sources, include_directories: test_includes, - dependencies: libzstd_dep, - link_with: testcommon, + dependencies: testcommon_dep, install: false) paramgrill_sources = [join_paths(zstd_rootdir, 'tests/paramgrill.c')] paramgrill = executable('paramgrill', paramgrill_sources, include_directories: test_includes, - dependencies: [ libzstd_dep, libm_dep ], - link_with: testcommon, + dependencies: [ testcommon_dep, libm_dep ], install: false) roundTripCrash_sources = [join_paths(zstd_rootdir, 'tests/roundTripCrash.c')] roundTripCrash = executable('roundTripCrash', roundTripCrash_sources, - dependencies: [ libzstd_dep ], + dependencies: [ testcommon_dep ], install: false) longmatch_sources = [join_paths(zstd_rootdir, 'tests/longmatch.c')] @@ -111,8 +113,7 @@ decodecorpus_sources = [join_paths(zstd_rootdir, 'tests/decodecorpus.c')] decodecorpus = executable('decodecorpus', decodecorpus_sources, include_directories: test_includes, - dependencies: [ libzstd_dep, libm_dep ], - link_with: testcommon, + dependencies: [ testcommon_dep, libm_dep ], install: false) poolTests_sources = [join_paths(zstd_rootdir, 'tests/poolTests.c'), @@ -123,8 +124,7 @@ poolTests_sources = [join_paths(zstd_rootdir, 'tests/poolTests.c'), poolTests = executable('poolTests', poolTests_sources, include_directories: test_includes, - dependencies: [ libzstd_dep, thread_dep ], - link_with: testcommon, + dependencies: [ testcommon_dep, thread_dep ], install: false) checkTag_sources = [join_paths(zstd_rootdir, 'tests/checkTag.c')]