snappy 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +34 -0
  3. data/.github/workflows/publish.yml +34 -0
  4. data/Gemfile +3 -4
  5. data/Rakefile +32 -30
  6. data/ext/api.c +6 -1
  7. data/lib/snappy.rb +5 -5
  8. data/lib/snappy/hadoop/reader.rb +6 -2
  9. data/lib/snappy/reader.rb +11 -7
  10. data/lib/snappy/shim.rb +1 -1
  11. data/lib/snappy/version.rb +1 -1
  12. data/snappy.gemspec +13 -9
  13. data/test/hadoop/snappy_hadoop_reader_test.rb +115 -0
  14. data/test/hadoop/snappy_hadoop_writer_test.rb +48 -0
  15. data/test/snappy_hadoop_test.rb +26 -0
  16. data/test/snappy_reader_test.rb +148 -0
  17. data/test/snappy_test.rb +95 -0
  18. data/test/snappy_writer_test.rb +55 -0
  19. data/test/test_helper.rb +7 -0
  20. data/vendor/snappy/CMakeLists.txt +177 -54
  21. data/vendor/snappy/NEWS +8 -0
  22. data/vendor/snappy/README.md +19 -20
  23. data/vendor/snappy/cmake/SnappyConfig.cmake.in +33 -0
  24. data/vendor/snappy/cmake/config.h.in +6 -6
  25. data/vendor/snappy/docs/README.md +72 -0
  26. data/vendor/snappy/snappy-internal.h +12 -5
  27. data/vendor/snappy/snappy-stubs-internal.cc +1 -1
  28. data/vendor/snappy/snappy-stubs-internal.h +60 -15
  29. data/vendor/snappy/snappy-stubs-public.h.in +16 -36
  30. data/vendor/snappy/snappy-test.cc +16 -15
  31. data/vendor/snappy/snappy-test.h +12 -60
  32. data/vendor/snappy/snappy.cc +333 -187
  33. data/vendor/snappy/snappy.h +14 -10
  34. data/vendor/snappy/snappy_compress_fuzzer.cc +59 -0
  35. data/vendor/snappy/snappy_uncompress_fuzzer.cc +57 -0
  36. data/vendor/snappy/snappy_unittest.cc +220 -124
  37. metadata +26 -20
  38. data/.travis.yml +0 -31
  39. data/smoke.sh +0 -8
  40. data/test/hadoop/test-snappy-hadoop-reader.rb +0 -103
  41. data/test/hadoop/test-snappy-hadoop-writer.rb +0 -48
  42. data/test/test-snappy-hadoop.rb +0 -22
  43. data/test/test-snappy-reader.rb +0 -129
  44. data/test/test-snappy-writer.rb +0 -55
  45. data/test/test-snappy.rb +0 -58
  46. data/vendor/snappy/cmake/SnappyConfig.cmake +0 -1
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "stringio"
5
+
6
+ class SnappyHadoopWriterTest < Test::Unit::TestCase
7
+ def setup
8
+ @buffer = StringIO.new
9
+ end
10
+
11
+ def subject
12
+ @subject ||= Snappy::Hadoop::Writer.new @buffer
13
+ end
14
+
15
+ sub_test_case "#initialize" do
16
+ test "should yield itself to the block" do
17
+ yielded = nil
18
+ returned = Snappy::Hadoop::Writer.new @buffer do |w|
19
+ yielded = w
20
+ end
21
+ assert_equal returned, yielded
22
+ end
23
+
24
+ test "should write the header" do
25
+ Snappy::Hadoop::Writer.new @buffer do |w|
26
+ w << "foo"
27
+ end
28
+ assert_equal "\u0000\u0000\u0000\u0003\u0000\u0000\u0000\u0005\u0003\bfoo", @buffer.string
29
+ end
30
+ end
31
+
32
+ sub_test_case "#io" do
33
+ test "should be a constructor argument" do
34
+ io = StringIO.new
35
+ assert_equal io, Snappy::Hadoop::Writer.new(io).io
36
+ end
37
+ end
38
+
39
+ sub_test_case "#block_size" do
40
+ test "should default to DEFAULT_BLOCK_SIZE" do
41
+ assert_equal Snappy::Hadoop::Writer::DEFAULT_BLOCK_SIZE, subject.block_size
42
+ end
43
+
44
+ test "should be settable via the constructor" do
45
+ assert_equal 42, Snappy::Hadoop::Writer.new(StringIO.new, 42).block_size
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "stringio"
5
+
6
+ class SnappyHadoopTest < Test::Unit::TestCase
7
+ T = [*"a".."z", *"A".."Z", *"0".."9"].freeze
8
+
9
+ def random_data(length = 1024)
10
+ Array.new(length) { T.sample }.join
11
+ end
12
+
13
+ test "well done" do
14
+ s = random_data
15
+ assert_equal s, Snappy::Hadoop.inflate(Snappy::Hadoop.deflate(s))
16
+ end
17
+
18
+ test "well done(pair)" do
19
+ s = random_data
20
+ [
21
+ %i[deflate inflate]
22
+ ].each do |(i, o)|
23
+ assert_equal s, Snappy::Hadoop.__send__(o, Snappy::Hadoop.__send__(i, s))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "stringio"
5
+
6
+ class SnappyReaderTest < Test::Unit::TestCase
7
+ def setup
8
+ @buffer = StringIO.new
9
+ Snappy::Writer.new @buffer do |w|
10
+ w << "foo"
11
+ w << "bar"
12
+ w << "baz"
13
+ w << "quux"
14
+ end
15
+ @buffer.rewind
16
+ end
17
+
18
+ def subject
19
+ @subject ||= Snappy::Reader.new @buffer
20
+ end
21
+
22
+ sub_test_case "#initialize" do
23
+ test "should yield itself to the block" do
24
+ yielded = nil
25
+ returned = Snappy::Reader.new @buffer do |r|
26
+ yielded = r
27
+ end
28
+ assert_equal returned, yielded
29
+ end
30
+
31
+ test "should read the header" do
32
+ assert_equal Snappy::Writer::MAGIC, subject.magic
33
+ assert_equal Snappy::Writer::DEFAULT_VERSION, subject.default_version
34
+ assert_equal Snappy::Writer::MINIMUM_COMPATIBLE_VERSION, subject.minimum_compatible_version
35
+ end
36
+ end
37
+
38
+ sub_test_case :initialize_without_headers do
39
+ def setup
40
+ @buffer = StringIO.new
41
+ @buffer << Snappy.deflate("HelloWorld" * 10)
42
+ @buffer.rewind
43
+ end
44
+
45
+ test "should inflate with a magic header" do
46
+ assert_equal "HelloWorld" * 10, subject.read
47
+ end
48
+
49
+ test "should not receive `length' in eaching" do
50
+ dont_allow(@buffer).length
51
+ subject.read
52
+ end
53
+ end
54
+
55
+ sub_test_case "#io" do
56
+ test "should be a constructor argument" do
57
+ assert_equal @buffer, subject.io
58
+ end
59
+
60
+ test "should not receive `length' in initializing" do
61
+ dont_allow(@buffer).length
62
+ Snappy::Reader.new @buffer
63
+ end
64
+ end
65
+
66
+ sub_test_case "#each" do
67
+ def setup
68
+ @buffer = StringIO.new
69
+ Snappy::Writer.new @buffer do |w|
70
+ w << "foo"
71
+ w << "bar"
72
+ w.dump!
73
+ w << "baz"
74
+ w << "quux"
75
+ end
76
+ @buffer.rewind
77
+ end
78
+
79
+ test "should yield each chunk" do
80
+ chunks = []
81
+ subject.each do |chunk|
82
+ chunks << chunk
83
+ end
84
+ assert_equal %w[foobar bazquux], chunks
85
+ end
86
+
87
+ test "should return enumerator w/o block" do
88
+ eacher = subject.each
89
+ assert_instance_of Enumerator, eacher
90
+ chunks = []
91
+ chunks << eacher.next
92
+ chunks << eacher.next
93
+ assert_raise(StopIteration) { eacher.next }
94
+ assert_equal %w[foobar bazquux], chunks
95
+ end
96
+ end
97
+
98
+ sub_test_case "#read" do
99
+ test "should return the bytes" do
100
+ assert_equal "foobarbazquux", subject.read
101
+ end
102
+ end
103
+
104
+ sub_test_case "#each_line" do
105
+ def setup
106
+ @buffer = StringIO.new
107
+ Snappy::Writer.new @buffer do |w|
108
+ w << "foo\n"
109
+ w << "bar"
110
+ w.dump!
111
+ w << "baz\n"
112
+ w << "quux\n"
113
+ end
114
+ @buffer.rewind
115
+ end
116
+
117
+ test "should yield each line" do
118
+ lines = []
119
+ subject.each_line do |line|
120
+ lines << line
121
+ end
122
+ assert_equal %w[foo barbaz quux], lines
123
+ end
124
+
125
+ test "should return enumerator w/o block" do
126
+ eacher = subject.each_line
127
+ assert_instance_of Enumerator, eacher
128
+ lines = []
129
+ loop { lines << eacher.next }
130
+ assert_equal %w[foo barbaz quux], lines
131
+ end
132
+
133
+ test "each_line split by sep_string" do
134
+ buffer = StringIO.new
135
+ Snappy::Writer.new buffer do |w|
136
+ w << %w[a b c].join(",")
137
+ w.dump!
138
+ w << %w[d e f].join(",")
139
+ end
140
+ buffer.rewind
141
+ reader = Snappy::Reader.new buffer
142
+ eacher = reader.each_line(",")
143
+ lines = []
144
+ loop { lines << eacher.next }
145
+ assert_equal %w[a b cd e f], lines
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class SnappyTest < Test::Unit::TestCase
6
+ T = [*"a".."z", *"A".."Z", *"0".."9"].freeze
7
+
8
+ def random_data(length = 1024)
9
+ Array.new(length) { T.sample }.join
10
+ end
11
+
12
+ test "VERSION" do
13
+ assert do
14
+ ::Snappy.const_defined?(:VERSION)
15
+ end
16
+ end
17
+
18
+ test "well done" do
19
+ s = random_data
20
+ assert_equal s, Snappy.inflate(Snappy.deflate(s))
21
+ end
22
+
23
+ test "well done (pair)" do
24
+ s = random_data
25
+ [
26
+ %i[deflate inflate],
27
+ %i[compress uncompress],
28
+ %i[dump load]
29
+ ].each do |(i, o)|
30
+ assert_equal s, Snappy.__send__(o, Snappy.__send__(i, s))
31
+ end
32
+ end
33
+
34
+ sub_test_case ".deflate" do
35
+ test "can pass buffer" do
36
+ if defined? JRUBY_VERSION
37
+ notify "cannot pass buffer in jruby"
38
+ omit
39
+ end
40
+ s = random_data
41
+ d = " " * 1024
42
+ r = Snappy.deflate(s, d)
43
+ assert_equal r.object_id, d.object_id
44
+ end
45
+ end
46
+
47
+ sub_test_case ".inflate" do
48
+ test "can pass buffer" do
49
+ if defined? JRUBY_VERSION
50
+ notify "cannot pass buffer in jruby"
51
+ omit
52
+ end
53
+ s = Snappy.deflate(random_data)
54
+ d = " " * 1024
55
+ r = Snappy.inflate(s, d)
56
+ assert_equal r.object_id, d.object_id
57
+ end
58
+ end
59
+
60
+ sub_test_case ".valid?" do
61
+ test "return true when passed deflated data" do
62
+ if defined? JRUBY_VERSION
63
+ notify "snappy-jars does not have valid?"
64
+ omit
65
+ end
66
+ d = Snappy.deflate(random_data)
67
+ assert_true Snappy.valid?(d)
68
+ end
69
+
70
+ test "return false when passed invalid data" do
71
+ if defined? JRUBY_VERSION
72
+ notify "snappy-jars does not have valid?"
73
+ omit
74
+ end
75
+ d = Snappy.deflate(random_data).reverse
76
+ assert_false Snappy.valid?(d)
77
+ end
78
+ end
79
+
80
+ sub_test_case "Ractor safe" do
81
+ test "able to invoke non-main ractor" do
82
+ unless defined? ::Ractor
83
+ notify "Ractor not defined"
84
+ omit
85
+ end
86
+ s = random_data
87
+ a = Array.new(2) do
88
+ Ractor.new(s) do |s|
89
+ Snappy.inflate(Snappy.deflate(s)) == s
90
+ end
91
+ end
92
+ assert_equal [true, true], a.map(&:take)
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "stringio"
5
+
6
+ class SnappyWriterTest < Test::Unit::TestCase
7
+ def setup
8
+ @buffer = StringIO.new
9
+ end
10
+
11
+ def subject
12
+ @subject ||= Snappy::Writer.new @buffer
13
+ end
14
+
15
+ sub_test_case "#initialize" do
16
+ test "should yield itself to the block" do
17
+ yielded = nil
18
+ returned = Snappy::Writer.new @buffer do |w|
19
+ yielded = w
20
+ end
21
+ assert_equal returned, yielded
22
+ end
23
+
24
+ test "should write the header" do
25
+ assert_equal [Snappy::Writer::MAGIC,
26
+ Snappy::Writer::DEFAULT_VERSION,
27
+ Snappy::Writer::MINIMUM_COMPATIBLE_VERSION].pack("a8NN"), subject.io.string
28
+ end
29
+
30
+ test "should dump on the end of yield" do
31
+ Snappy::Writer.new @buffer do |w|
32
+ w << "foo"
33
+ end
34
+ foo = Snappy.deflate "foo"
35
+ assert_equal [foo.size, foo].pack("Na#{foo.size}"), @buffer.string[16, @buffer.size - 16]
36
+ end
37
+ end
38
+
39
+ sub_test_case "#io" do
40
+ test "should be a constructor argument" do
41
+ io = StringIO.new
42
+ assert_equal io, Snappy::Writer.new(io).io
43
+ end
44
+ end
45
+
46
+ sub_test_case "#block_size" do
47
+ test "should default to DEFAULT_BLOCK_SIZE" do
48
+ assert_equal Snappy::Writer::DEFAULT_BLOCK_SIZE, subject.block_size
49
+ end
50
+
51
+ test "should be settable via the constructor" do
52
+ assert_equal 42, Snappy::Writer.new(StringIO.new, 42).block_size
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "snappy"
5
+
6
+ require "test-unit"
7
+ require "test/unit/rr"
@@ -1,5 +1,41 @@
1
+ # Copyright 2019 Google Inc. All Rights Reserved.
2
+ #
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions are
5
+ # met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above
10
+ # copyright notice, this list of conditions and the following disclaimer
11
+ # in the documentation and/or other materials provided with the
12
+ # distribution.
13
+ # * Neither the name of Google Inc. nor the names of its
14
+ # contributors may be used to endorse or promote products derived from
15
+ # this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+
1
29
  cmake_minimum_required(VERSION 3.1)
2
- project(Snappy VERSION 1.1.7 LANGUAGES C CXX)
30
+ project(Snappy VERSION 1.1.8 LANGUAGES C CXX)
31
+
32
+ # C++ standard can be overridden when this is used as a sub-project.
33
+ if(NOT CMAKE_CXX_STANDARD)
34
+ # This project requires C++11.
35
+ set(CMAKE_CXX_STANDARD 11)
36
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
37
+ set(CMAKE_CXX_EXTENSIONS OFF)
38
+ endif(NOT CMAKE_CXX_STANDARD)
3
39
 
4
40
  # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to make
5
41
  # it prominent in the GUI.
@@ -7,13 +43,19 @@ option(BUILD_SHARED_LIBS "Build shared libraries(DLLs)." OFF)
7
43
 
8
44
  option(SNAPPY_BUILD_TESTS "Build Snappy's own tests." ON)
9
45
 
46
+ option(SNAPPY_FUZZING_BUILD "Build Snappy for fuzzing." OFF)
47
+
48
+ option(SNAPPY_REQUIRE_AVX "Target processors with AVX support." OFF)
49
+
50
+ option(SNAPPY_REQUIRE_AVX2 "Target processors with AVX2 support." OFF)
51
+
52
+ option(SNAPPY_INSTALL "Install Snappy's header and library" ON)
53
+
10
54
  include(TestBigEndian)
11
55
  test_big_endian(SNAPPY_IS_BIG_ENDIAN)
12
56
 
13
57
  include(CheckIncludeFile)
14
58
  check_include_file("byteswap.h" HAVE_BYTESWAP_H)
15
- check_include_file("stddef.h" HAVE_STDDEF_H)
16
- check_include_file("stdint.h" HAVE_STDINT_H)
17
59
  check_include_file("sys/endian.h" HAVE_SYS_ENDIAN_H)
18
60
  check_include_file("sys/mman.h" HAVE_SYS_MMAN_H)
19
61
  check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H)
@@ -26,12 +68,58 @@ include(CheckLibraryExists)
26
68
  check_library_exists(z zlibVersion "" HAVE_LIBZ)
27
69
  check_library_exists(lzo2 lzo1x_1_15_compress "" HAVE_LIBLZO2)
28
70
 
71
+ include(CheckCXXCompilerFlag)
72
+ CHECK_CXX_COMPILER_FLAG("/arch:AVX" HAVE_VISUAL_STUDIO_ARCH_AVX)
73
+ CHECK_CXX_COMPILER_FLAG("/arch:AVX2" HAVE_VISUAL_STUDIO_ARCH_AVX2)
74
+ CHECK_CXX_COMPILER_FLAG("-mavx" HAVE_CLANG_MAVX)
75
+ CHECK_CXX_COMPILER_FLAG("-mbmi2" HAVE_CLANG_MBMI2)
76
+ if(SNAPPY_REQUIRE_AVX2)
77
+ if(HAVE_VISUAL_STUDIO_ARCH_AVX2)
78
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
79
+ endif(HAVE_VISUAL_STUDIO_ARCH_AVX2)
80
+ if(HAVE_CLANG_MAVX)
81
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
82
+ endif(HAVE_CLANG_MAVX)
83
+ if(HAVE_CLANG_MBMI2)
84
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi2")
85
+ endif(HAVE_CLANG_MBMI2)
86
+ elseif (SNAPPY_REQUIRE_AVX)
87
+ if(HAVE_VISUAL_STUDIO_ARCH_AVX)
88
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX")
89
+ endif(HAVE_VISUAL_STUDIO_ARCH_AVX)
90
+ if(HAVE_CLANG_MAVX)
91
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
92
+ endif(HAVE_CLANG_MAVX)
93
+ endif(SNAPPY_REQUIRE_AVX2)
94
+
29
95
  include(CheckCXXSourceCompiles)
30
- check_cxx_source_compiles(
31
- "int main(void) { return __builtin_expect(0, 1); }" HAVE_BUILTIN_EXPECT)
96
+ check_cxx_source_compiles("
97
+ int main() {
98
+ return __builtin_expect(0, 1);
99
+ }" HAVE_BUILTIN_EXPECT)
100
+
101
+ check_cxx_source_compiles("
102
+ int main() {
103
+ return __builtin_ctzll(0);
104
+ }" HAVE_BUILTIN_CTZ)
32
105
 
33
- check_cxx_source_compiles(
34
- "int main(void) { return __builtin_ctzll(0); }" HAVE_BUILTIN_CTZ)
106
+ check_cxx_source_compiles("
107
+ #include <tmmintrin.h>
108
+
109
+ int main() {
110
+ const __m128i *src = 0;
111
+ __m128i dest;
112
+ const __m128i shuffle_mask = _mm_load_si128(src);
113
+ const __m128i pattern = _mm_shuffle_epi8(_mm_loadl_epi64(src), shuffle_mask);
114
+ _mm_storeu_si128(&dest, pattern);
115
+ return 0;
116
+ }" SNAPPY_HAVE_SSSE3)
117
+
118
+ check_cxx_source_compiles("
119
+ #include <immintrin.h>
120
+ int main() {
121
+ return _bzhi_u32(0, 1);
122
+ }" SNAPPY_HAVE_BMI2)
35
123
 
36
124
  include(CheckSymbolExists)
37
125
  check_symbol_exists("mmap" "sys/mman.h" HAVE_FUNC_MMAP)
@@ -48,39 +136,45 @@ if(GFLAGS_FOUND)
48
136
  endif(GFLAGS_FOUND)
49
137
 
50
138
  configure_file(
51
- "${PROJECT_SOURCE_DIR}/cmake/config.h.in"
139
+ "cmake/config.h.in"
52
140
  "${PROJECT_BINARY_DIR}/config.h"
53
141
  )
54
142
 
55
143
  # We don't want to define HAVE_ macros in public headers. Instead, we use
56
144
  # CMake's variable substitution with 0/1 variables, which will be seen by the
57
145
  # preprocessor as constants.
58
- set(HAVE_STDINT_H_01 ${HAVE_STDINT_H})
59
- set(HAVE_STDDEF_H_01 ${HAVE_STDDEF_H})
60
146
  set(HAVE_SYS_UIO_H_01 ${HAVE_SYS_UIO_H})
61
- if(NOT HAVE_STDINT_H_01)
62
- set(HAVE_STDINT_H_01 0)
63
- endif(NOT HAVE_STDINT_H_01)
64
- if(NOT HAVE_STDDEF_H_01)
65
- set(HAVE_STDDEF_H_01 0)
66
- endif(NOT HAVE_STDDEF_H_01)
67
147
  if(NOT HAVE_SYS_UIO_H_01)
68
148
  set(HAVE_SYS_UIO_H_01 0)
69
149
  endif(NOT HAVE_SYS_UIO_H_01)
70
150
 
151
+ if (SNAPPY_FUZZING_BUILD)
152
+ if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
153
+ message(WARNING "Fuzzing builds are only supported with Clang")
154
+ endif (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
155
+
156
+ if(NOT CMAKE_CXX_FLAGS MATCHES "-fsanitize=address")
157
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
158
+ endif(NOT CMAKE_CXX_FLAGS MATCHES "-fsanitize=address")
159
+
160
+ if(NOT CMAKE_CXX_FLAGS MATCHES "-fsanitize=fuzzer-no-link")
161
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer-no-link")
162
+ endif(NOT CMAKE_CXX_FLAGS MATCHES "-fsanitize=fuzzer-no-link")
163
+ endif (SNAPPY_FUZZING_BUILD)
164
+
71
165
  configure_file(
72
- "${PROJECT_SOURCE_DIR}/snappy-stubs-public.h.in"
166
+ "snappy-stubs-public.h.in"
73
167
  "${PROJECT_BINARY_DIR}/snappy-stubs-public.h")
74
168
 
75
169
  add_library(snappy "")
76
170
  target_sources(snappy
77
171
  PRIVATE
78
- "${PROJECT_SOURCE_DIR}/snappy-internal.h"
79
- "${PROJECT_SOURCE_DIR}/snappy-stubs-internal.h"
80
- "${PROJECT_SOURCE_DIR}/snappy-c.cc"
81
- "${PROJECT_SOURCE_DIR}/snappy-sinksource.cc"
82
- "${PROJECT_SOURCE_DIR}/snappy-stubs-internal.cc"
83
- "${PROJECT_SOURCE_DIR}/snappy.cc"
172
+ "snappy-internal.h"
173
+ "snappy-stubs-internal.h"
174
+ "snappy-c.cc"
175
+ "snappy-sinksource.cc"
176
+ "snappy-stubs-internal.cc"
177
+ "snappy.cc"
84
178
  "${PROJECT_BINARY_DIR}/config.h"
85
179
 
86
180
  # Only CMake 3.3+ supports PUBLIC sources in targets exported by "install".
@@ -114,8 +208,8 @@ if(SNAPPY_BUILD_TESTS)
114
208
  add_executable(snappy_unittest "")
115
209
  target_sources(snappy_unittest
116
210
  PRIVATE
117
- "${PROJECT_SOURCE_DIR}/snappy_unittest.cc"
118
- "${PROJECT_SOURCE_DIR}/snappy-test.cc"
211
+ "snappy_unittest.cc"
212
+ "snappy-test.cc"
119
213
  )
120
214
  target_compile_definitions(snappy_unittest PRIVATE -DHAVE_CONFIG_H)
121
215
  target_link_libraries(snappy_unittest snappy ${GFLAGS_LIBRARIES})
@@ -140,35 +234,64 @@ if(SNAPPY_BUILD_TESTS)
140
234
  COMMAND "${PROJECT_BINARY_DIR}/snappy_unittest")
141
235
  endif(SNAPPY_BUILD_TESTS)
142
236
 
237
+ if(SNAPPY_FUZZING_BUILD)
238
+ add_executable(snappy_compress_fuzzer "")
239
+ target_sources(snappy_compress_fuzzer
240
+ PRIVATE "snappy_compress_fuzzer.cc"
241
+ )
242
+ target_link_libraries(snappy_compress_fuzzer snappy)
243
+ set_target_properties(snappy_compress_fuzzer
244
+ PROPERTIES LINK_FLAGS "-fsanitize=fuzzer"
245
+ )
246
+
247
+ add_executable(snappy_uncompress_fuzzer "")
248
+ target_sources(snappy_uncompress_fuzzer
249
+ PRIVATE "snappy_uncompress_fuzzer.cc"
250
+ )
251
+ target_link_libraries(snappy_uncompress_fuzzer snappy)
252
+ set_target_properties(snappy_uncompress_fuzzer
253
+ PROPERTIES LINK_FLAGS "-fsanitize=fuzzer"
254
+ )
255
+ endif(SNAPPY_FUZZING_BUILD)
256
+
257
+ # Must be included before CMAKE_INSTALL_INCLUDEDIR is used.
143
258
  include(GNUInstallDirs)
144
- install(TARGETS snappy
145
- EXPORT SnappyTargets
146
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
147
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
148
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
149
- )
150
- install(
151
- FILES
152
- "${PROJECT_SOURCE_DIR}/snappy-c.h"
153
- "${PROJECT_SOURCE_DIR}/snappy-sinksource.h"
154
- "${PROJECT_SOURCE_DIR}/snappy.h"
155
- "${PROJECT_BINARY_DIR}/snappy-stubs-public.h"
156
- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
157
- )
158
259
 
159
- include(CMakePackageConfigHelpers)
160
- write_basic_package_version_file(
161
- "${PROJECT_BINARY_DIR}/SnappyConfigVersion.cmake"
260
+ if(SNAPPY_INSTALL)
261
+ install(TARGETS snappy
262
+ EXPORT SnappyTargets
263
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
264
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
265
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
266
+ )
267
+ install(
268
+ FILES
269
+ "snappy-c.h"
270
+ "snappy-sinksource.h"
271
+ "snappy.h"
272
+ "${PROJECT_BINARY_DIR}/snappy-stubs-public.h"
273
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
274
+ )
275
+
276
+ include(CMakePackageConfigHelpers)
277
+ configure_package_config_file(
278
+ "cmake/${PROJECT_NAME}Config.cmake.in"
279
+ "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake"
280
+ INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
281
+ )
282
+ write_basic_package_version_file(
283
+ "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake"
162
284
  COMPATIBILITY SameMajorVersion
163
- )
164
- install(
165
- EXPORT SnappyTargets
166
- NAMESPACE Snappy::
167
- DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Snappy"
168
- )
169
- install(
170
- FILES
171
- "${PROJECT_SOURCE_DIR}/cmake/SnappyConfig.cmake"
172
- "${PROJECT_BINARY_DIR}/SnappyConfigVersion.cmake"
173
- DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Snappy"
174
- )
285
+ )
286
+ install(
287
+ EXPORT SnappyTargets
288
+ NAMESPACE Snappy::
289
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
290
+ )
291
+ install(
292
+ FILES
293
+ "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake"
294
+ "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake"
295
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
296
+ )
297
+ endif(SNAPPY_INSTALL)