From 7d4ba9cacde584047a0e57f8ccd23f1b1139e36e Mon Sep 17 00:00:00 2001 From: "Issam E. Maghni" Date: Sat, 19 Dec 2020 14:08:40 -0500 Subject: [PATCH 1/6] meson: use SPDX licenses --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 92877c9e..640c30d7 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('libspng', 'c', version : '0.6.2', - license : [ 'bsd', 'libpng2' ], + license : [ 'BSD-2-Clause', 'libpng-2.0' ], default_options : 'c_std=c99' ) From 9dfef606cb3aafd67f9c99689debe01346f5493b Mon Sep 17 00:00:00 2001 From: "Issam E. Maghni" Date: Sat, 19 Dec 2020 14:09:17 -0500 Subject: [PATCH 2/6] meson: use sane default options --- meson.build | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 640c30d7..3539e94b 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,14 @@ project('libspng', 'c', version : '0.6.2', license : [ 'BSD-2-Clause', 'libpng-2.0' ], - default_options : 'c_std=c99' + default_options : [ + 'b_lto=true', + 'b_ndebug=if-release', + 'buildtype=debugoptimized', + 'c_std=c99', + 'warning_level=3', + # 'werror=true', + ], ) spng_args = [] From a761251a5d93bb6c547be7216f9e7ae5d3ca1c9f Mon Sep 17 00:00:00 2001 From: "Issam E. Maghni" Date: Sat, 19 Dec 2020 14:09:49 -0500 Subject: [PATCH 3/6] tests: fix header guard format --- tests/framac_stubs.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/framac_stubs.h b/tests/framac_stubs.h index 7a33a224..4b03f9d2 100644 --- a/tests/framac_stubs.h +++ b/tests/framac_stubs.h @@ -1,5 +1,5 @@ -#ifndef SPNG_FRAMAC_STUBS_H -#define SPNG_FRAMAC_STUBS_H +#ifndef FRAMAC_STUBS_H +#define FRAMAC_STUBS_H #include @@ -86,4 +86,4 @@ unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int le return crc+len; } -#endif /* SPNG_FRAMAC_STUBS_H */ +#endif /* FRAMAC_STUBS_H */ From 2b8b1d211a8de8acd44ed2b94c87c03553319611 Mon Sep 17 00:00:00 2001 From: "Issam E. Maghni" Date: Sat, 19 Dec 2020 14:10:30 -0500 Subject: [PATCH 4/6] tests: fix warnings to fix target_clones test (-Werror) --- tests/target_clones.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/target_clones.c b/tests/target_clones.c index 6bdd5d9a..0eecf0af 100644 --- a/tests/target_clones.c +++ b/tests/target_clones.c @@ -1,12 +1,18 @@ /* This will only be available for GCC with glibc for the foreseeable future */ +#include /* EXIT_*, exit */ + __attribute__((target_clones("default,avx2"))) int f(int x) { return x + 3; } -int main(int argc, char **argv) +int main(void) { - int y = f(39); - return 0; -} \ No newline at end of file + const int y = f(39); + if (y != 42) { + exit(EXIT_FAILURE); + } + + return EXIT_SUCCESS; +} From f93e28d9bcf595574b23256658c2c7a68048f1c5 Mon Sep 17 00:00:00 2001 From: "Issam E. Maghni" Date: Sat, 19 Dec 2020 14:11:57 -0500 Subject: [PATCH 5/6] meson: various minor improvements --- examples/meson.build | 2 +- meson.build | 55 +++++++++++++++++++++------------------- meson_options.txt | 3 +-- tests/meson.build | 23 ++++++++--------- tests/spng_read_fuzzer.c | 2 +- 5 files changed, 43 insertions(+), 42 deletions(-) diff --git a/examples/meson.build b/examples/meson.build index 3317fe97..678f9974 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -1 +1 @@ -example_exe = executable('example', 'example.c', dependencies : spng_dep) \ No newline at end of file +example_exe = executable('example', 'example.c', dependencies : spng_dep) diff --git a/meson.build b/meson.build index 3539e94b..7ccf290a 100644 --- a/meson.build +++ b/meson.build @@ -19,7 +19,7 @@ if get_option('default_library') == 'static' static_subproject = meson.is_subproject() endif -if get_option('enable_opt') == false +if not get_option('enable_opt') add_project_arguments('-DSPNG_DISABLE_OPT', language : 'c') endif @@ -30,30 +30,29 @@ if cc.compiles(files('tests/target_clones.c'), args : '-Werror', name : 'have ta add_project_arguments('-DSPNG_ENABLE_TARGET_CLONES', language : 'c') endif -if get_option('use_miniz') == true +spng_deps = [ cc.find_library('m', required : false) ] + +if get_option('use_miniz') add_project_arguments('-DSPNG_USE_MINIZ', language : 'c') - zlib_dep = dependency('miniz', fallback : [ 'miniz', 'miniz_dep']) + spng_deps += dependency('miniz', + default_options : [ 'default_library=static' ], + fallback : [ 'miniz', 'miniz_dep' ], + ) else zlib_dep = dependency('zlib', + default_options : [ 'default_library=static' ], + fallback : [ 'zlib', 'zlib_dep' ], required : false, - fallback : ['zlib', 'zlib_dep'], - static : get_option('static_zlib')) - - if not zlib_dep.found() - zlib_dep = cc.find_library('z') - endif + static : get_option('static_zlib'), + ) + spng_deps += zlib_dep.found() ? zlib_dep : cc.find_library('z') endif -m_dep = cc.find_library('m', required : false) - -spng_deps = [ zlib_dep, m_dep ] - spng_inc = include_directories('spng') spng_src = files('spng/spng.c') -spng_lib = library('spng', - spng_src, +spng_lib = library('spng', spng_src, c_args : spng_args, dependencies : spng_deps, install : not static_subproject, @@ -61,20 +60,28 @@ spng_lib = library('spng', ) spng_dep = declare_dependency( - link_with : spng_lib, compile_args : spng_args, include_directories : spng_inc, - version : meson.project_version() + link_with : spng_lib, ) if meson.version().version_compare('>= 0.54.0') meson.override_dependency('spng', spng_dep) endif +if meson.is_subproject() + subdir_done() +endif + +install_headers('spng/spng.h') + subdir('examples') -subdir('tests') -if get_option('benchmarks') == true +if get_option('dev_build') + subdir('tests') +endif + +if get_option('benchmarks') subproject('spngt') endif @@ -82,12 +89,8 @@ if static_subproject subdir_done() endif -install_headers('spng/spng.h') - -pkg = import('pkgconfig') - -pkg.generate(spng_lib, +pc= import('pkgconfig') +pc.generate(spng_lib, + description : 'PNG decoding and encoding library', extra_cflags : spng_args, - libraries_private : [ '-lm', '-lz' ], - description : 'PNG decoding and encoding library' ) diff --git a/meson_options.txt b/meson_options.txt index c2489bbc..c5d8b43c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -4,7 +4,6 @@ option('use_miniz', type : 'boolean', value : false, description : 'Compile with option('static_zlib', type : 'boolean', value : false, description : 'Link zlib statically') option('benchmarks', type : 'boolean', value : false, description : 'Enable benchmarks, requires Git LFS') - # Not for end-users option('multithreading', type : 'feature', value : 'disabled', description : 'Experimental multithreading features') -option('oss_fuzz', type : 'boolean', value : false, description : 'Enable regression tests with OSS-Fuzz corpora') \ No newline at end of file +option('oss_fuzz', type : 'boolean', value : false, description : 'Enable regression tests with OSS-Fuzz corpora') diff --git a/tests/meson.build b/tests/meson.build index db792d29..3e1d66bf 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,7 +1,3 @@ -if get_option('dev_build') == false - subdir_done() -endif - add_languages('cpp', native : false) cpp = meson.get_compiler('cpp') @@ -11,14 +7,17 @@ if cc.has_function('fmemopen', prefix : '#include ', args : '-D_GNU_SOU fuzzer_args = [ '-D_GNU_SOURCE', '-DSPNGT_HAVE_FMEMOPEN' ] endif -read_fuzzer = executable('fuzz_repro', - 'fuzz_main.c', - 'spng_read_fuzzer.c', +read_fuzzer = executable('fuzz_repro', 'fuzz_main.c', 'spng_read_fuzzer.c', c_args : fuzzer_args, - link_with : spng_lib + include_directories : spng_inc, + link_with : spng_lib, ) -png_dep = dependency('libpng', version : '>=1.6.0', fallback : ['libpng', 'png_dep']) +png_dep = dependency('libpng', + version : '>=1.6.0', + fallback : [ 'libpng', 'png_dep' ], + default_options : [ 'default_library=static' ], +) test_deps = [ spng_dep, png_dep ] @@ -29,10 +28,10 @@ test('info', test_exe, args : 'info') cpp_exe = executable('cpp_exe', 'test.cpp', dependencies : spng_dep) test('cpp_test', cpp_exe) -subdir('images') subdir('crashers') +subdir('images') -if get_option('oss_fuzz') == false +if not get_option('oss_fuzz') subdir_done() endif @@ -40,4 +39,4 @@ corpora = subproject('fuzzing_corpora').get_variable('corpora') foreach case : corpora test('testcase', read_fuzzer, args : case) -endforeach \ No newline at end of file +endforeach diff --git a/tests/spng_read_fuzzer.c b/tests/spng_read_fuzzer.c index ed0f2124..0c6e07da 100644 --- a/tests/spng_read_fuzzer.c +++ b/tests/spng_read_fuzzer.c @@ -1,5 +1,5 @@ #define SPNG_UNTESTED -#include "../spng/spng.h" +#include "spng.h" #include From 5507afa6760ab455ccb0bbecb647fab88452e7a2 Mon Sep 17 00:00:00 2001 From: "Issam E. Maghni" Date: Sat, 19 Dec 2020 14:12:51 -0500 Subject: [PATCH 6/6] ossfuzz: add spng include dir to compiler flags --- tests/ossfuzz.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ossfuzz.sh b/tests/ossfuzz.sh index ce8eaf36..e3c5ce7d 100755 --- a/tests/ossfuzz.sh +++ b/tests/ossfuzz.sh @@ -18,12 +18,14 @@ ar x libz.a ar rcs libspng_static.a *.o $CXX $CXXFLAGS -std=c++11 \ + -I$SRC/libspng/spng \ $SRC/libspng/tests/spng_read_fuzzer.c \ -DSPNGT_HAVE_FMEMOPEN=1 \ -o $OUT/spng_read_fuzzer \ $LIB_FUZZING_ENGINE $SRC/libspng/build/libspng_static.a $SRC/zlib/build/libz.a $CXX $CXXFLAGS -std=c++11 -I$SRC/zlib/build -I$SRC/zlib \ + -I$SRC/libspng/spng \ $SRC/libspng/tests/spng_read_fuzzer.c \ -DSPNGT_HAVE_FMEMOPEN=1 \ -o $OUT/spng_read_fuzzer_structure_aware \