diff --git a/.gitignore b/.gitignore index ba990be..374c80c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ test/version_tmp tmp Makefile +extconf.h mkmf.log .DS_Store \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..aeaac3b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "ext/gnista/sparkey"] + path = ext/gnista/sparkey + url = https://github.com/spotify/sparkey.git +[submodule "ext/gnista/snappy"] + path = ext/gnista/snappy + url = https://github.com/google/snappy diff --git a/README.md b/README.md index 5d350f5..ba35801 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,7 @@ Gnista is a wrapper for the database/hashstore [Sparkey](http://github.com/spoti ## Setup -You will need Sparkey, obviously. It's really easy to install. Head over to [http://github.com/spotify/sparkey](http://github.com/spotify/sparkey) and install it, I'll wait.. - -Now, add this line to your application's Gemfile: +Add this line to your application's Gemfile: gem 'gnista' @@ -88,7 +86,8 @@ Both ```Logreader```and ```Hash``` mixin [Enumerable](http://ruby-doc.org/core-2 __Step-by-step:__ -1. Fork it +1. Fork it + 1. Fetch submodules (`git submodule update`) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Write some code 4. Build and test diff --git a/ext/gnista/extconf.rb b/ext/gnista/extconf.rb index 2dae132..d198238 100644 --- a/ext/gnista/extconf.rb +++ b/ext/gnista/extconf.rb @@ -3,7 +3,66 @@ extension_name = 'gnista' dir_config(extension_name) -have_library('sparkey') or raise "Sparkey is missing" -have_header('sparkey/sparkey.h') or raise "sparkey.h could not be found" +$CFLAGS << ' -std=c99' +$INCFLAGS << ' -I$(srcdir)/sparkey/src' +$INCFLAGS << ' -I$(srcdir)/snappy' +$VPATH ||= [] +$VPATH << '$(srcdir)/sparkey/src' +$VPATH << '$(srcdir)/snappy' +gnista_srcs = %w[ + gnista.c +] +sparkey_srcs = %w[ + buf.c + hashalgorithms.c + hashiter.c + hashwriter.c + logreader.c + returncodes.c + util.c + endiantools.c + hashheader.c + hashreader.c + logheader.c + logwriter.c + MurmurHash3.c +] + +snappy_srcs = %w[ + snappy.cc + snappy-c.cc + snappy-sinksource.cc +] + +$srcs = gnista_srcs + sparkey_srcs + snappy_srcs + +# Create macro definitions used by Snappy sources. +%w[ + byteswap.h + stddef.h + stdint.h + sys/endian.h + sys/mman.h + sys/resource.h + sys/time.h + sys/uio.h + unistd.h + windows.h +].each { |header| have_header header } + +if have_func 'mmap', 'sys/mman.h' + $defs << '-DHAVE_FUNC_MMAP' +end +if have_func 'sysconf', 'unistd.h' + $defs << '-DHAVE_FUNC_SYSCONF' +end +if try_compile('int main(void) { return __builtin_expect(0, 1); }') + $defs << '-DHAVE_BUILTIN_EXPECT' +end +if try_compile('int main(void) { return __builtin_ctzll(0); }') + $defs << '-DHAVE_BUILTIN_CTZ' +end + +create_header create_makefile(extension_name) diff --git a/ext/gnista/gnista.c b/ext/gnista/gnista.c index acd7d0c..611efec 100644 --- a/ext/gnista/gnista.c +++ b/ext/gnista/gnista.c @@ -1,5 +1,5 @@ #include -#include +#include typedef uint8_t bool; #define true 1 diff --git a/ext/gnista/snappy b/ext/gnista/snappy new file mode 160000 index 0000000..4f7bd2d --- /dev/null +++ b/ext/gnista/snappy @@ -0,0 +1 @@ +Subproject commit 4f7bd2dbfd12bfda77488baf46c2f7648c9f1999 diff --git a/ext/gnista/snappy-stubs-public.h b/ext/gnista/snappy-stubs-public.h new file mode 100644 index 0000000..97f1aa1 --- /dev/null +++ b/ext/gnista/snappy-stubs-public.h @@ -0,0 +1,94 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// Author: sesse@google.com (Steinar H. Gunderson) +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Various type stubs for the open-source version of Snappy. +// +// This file cannot include config.h, as it is included from snappy.h, +// which is a public header. Instead, snappy-stubs-public.h is generated by +// from snappy-stubs-public.h.in at configure time. + +#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ +#define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ + +#ifdef HAVE_STDINT_H +#include +#endif // HAVE_STDDEF_H + +#ifdef HAVE_STDDEF_H +#include +#endif // HAVE_STDDEF_H + +#ifdef HAVE_SYS_UIO_H +#include +#endif // HAVE_SYS_UIO_H + +#define SNAPPY_MAJOR 1 +#define SNAPPY_MINOR 1 +#define SNAPPY_PATCHLEVEL 7 +#define SNAPPY_VERSION \ + ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) + +#include + +namespace snappy { + +#ifdef HAVE_STDINT_H +typedef int8_t int8; +typedef uint8_t uint8; +typedef int16_t int16; +typedef uint16_t uint16; +typedef int32_t int32; +typedef uint32_t uint32; +typedef int64_t int64; +typedef uint64_t uint64; +#else +typedef signed char int8; +typedef unsigned char uint8; +typedef short int16; +typedef unsigned short uint16; +typedef int int32; +typedef unsigned int uint32; +typedef long long int64; +typedef unsigned long long uint64; +#endif // HAVE_STDINT_H + +typedef std::string string; + +#ifndef HAVE_SYS_UIO_H +// Windows does not have an iovec type, yet the concept is universally useful. +// It is simple to define it ourselves, so we put it inside our own namespace. +struct iovec { + void* iov_base; + size_t iov_len; +}; +#endif // !HAVE_SYS_UIO_H + +} // namespace snappy + +#endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ diff --git a/ext/gnista/sparkey b/ext/gnista/sparkey new file mode 160000 index 0000000..e3f71b7 --- /dev/null +++ b/ext/gnista/sparkey @@ -0,0 +1 @@ +Subproject commit e3f71b746d9c488e6a2191905ffbb506d2f8a5c1 diff --git a/gnista.gemspec b/gnista.gemspec index cedf04a..094e470 100644 --- a/gnista.gemspec +++ b/gnista.gemspec @@ -16,7 +16,9 @@ Gem::Specification.new do |spec| spec.files = %w[README.md LICENSE.txt HISTORY.md Rakefile ext/gnista/extconf.rb ext/gnista/gnista.c test/test_gnista.rb test/test_commands.rb - lib/gnista.rb lib/gnista/version.rb] + lib/gnista.rb lib/gnista/version.rb] + + # Add all files from all included submodules. + `git submodule --quiet foreach 'git ls-files | sed "s|^|$path/|"'`.split("\n") spec.test_files = ['test/test_gnista.rb', 'test/test_commands.rb'] spec.require_paths = ["ext", "lib"]