Skip to content

Commit d2b9ff7

Browse files
committed
Add zstd sources in gems
1 parent dddd59c commit d2b9ff7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+44123
-9
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ sudo: false
22
language: ruby
33
rvm:
44
- 2.4.0
5+
- 2.3.1
56
before_install: gem install bundler -v 1.14.3
7+
8+
before_script:
9+
- bundle exec rake compile

LICENSE-zstd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zstd/LICENSE

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
# Zstd
1+
[![Build Status](https://travis-ci.org/SpringMT/zstd-ruby.svg?branch=master)](https://travis-ci.org/SpringMT/zstd-ruby)
22

3-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zstd_ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
3+
# zstd-ruby
4+
5+
Ruby binding for zstd(Zstandard - Fast real-time compression algorithm)
6+
7+
See https://github.com/facebook/zstd
8+
9+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zstd-ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
10+
11+
## Zstd version
12+
v1.1.2 (https://github.com/facebook/zstd/releases/tag/v1.1.2)
413

514
## Installation
615

716
Add this line to your application's Gemfile:
817

918
```ruby
10-
gem 'zstd_ruby'
19+
gem 'zstd-ruby'
1120
```
1221

1322
And then execute:
@@ -16,11 +25,10 @@ And then execute:
1625

1726
Or install it yourself as:
1827

19-
$ gem install zstd_ruby
28+
$ gem install zstd-ruby
2029

2130
## Usage
2231

23-
TODO: Write usage instructions here
2432

2533
## Development
2634

Rakefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ Rake::ExtensionTask.new("zstdruby") do |ext|
1313
end
1414

1515
task :default => [:clobber, :compile, :spec]
16+
17+
#task :sync
18+

bin/console

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env ruby
22

33
require "bundler/setup"
4-
require "zstd_ruby"
4+
require "zstd-ruby"
55

66
# You can add fixtures and/or initialization code here to make experimenting
77
# with your gem easier. You can also use a different console, if you like.

ext/zstdruby/extconf.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
require "mkmf"
22

3+
$CFLAGS = '-I. -O3 -std=c99 -pedantic'
4+
5+
Dir.chdir File.expand_path('..', __FILE__) do
6+
$srcs = Dir['**/*.c']
7+
8+
Dir.glob('libzstd/*') do |path|
9+
if Dir.exist?(path)
10+
$VPATH << "$(srcdir)/#{path}"
11+
$INCFLAGS << " -I$(srcdir)/#{path}"
12+
end
13+
end
14+
15+
end
16+
17+
# add include path to the internal folder
18+
# $(srcdir) is a root folder, where "extconf.rb" is stored
19+
$INCFLAGS << " -I$(srcdir) -I$(srcdir)/libzstd"
20+
# add folder, where compiler can search source files
21+
$VPATH << "$(srcdir)"
22+
323
create_makefile("zstdruby")

ext/zstdruby/libzstd/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# make install artefact
2+
libzstd.pc

ext/zstdruby/libzstd/Makefile

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# ################################################################
2+
# Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree. An additional grant
7+
# of patent rights can be found in the PATENTS file in the same directory.
8+
# ################################################################
9+
10+
# Version numbers
11+
LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
12+
LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
13+
LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
14+
LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
15+
LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
16+
LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
17+
LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
18+
LIBVER := $(shell echo $(LIBVER_SCRIPT))
19+
VERSION?= $(LIBVER)
20+
21+
DESTDIR?=
22+
PREFIX ?= /usr/local
23+
LIBDIR ?= $(PREFIX)/lib
24+
INCLUDEDIR=$(PREFIX)/include
25+
26+
CPPFLAGS+= -I. -I./common -DXXH_NAMESPACE=ZSTD_
27+
CFLAGS ?= -O3
28+
CFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 \
29+
-Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes -Wundef \
30+
-Wpointer-arith
31+
CFLAGS += $(MOREFLAGS)
32+
FLAGS = $(CPPFLAGS) $(CFLAGS)
33+
34+
35+
ZSTD_FILES := $(wildcard common/*.c compress/*.c decompress/*.c dictBuilder/*.c deprecated/*.c)
36+
37+
ifeq ($(ZSTD_LEGACY_SUPPORT), 0)
38+
CPPFLAGS += -DZSTD_LEGACY_SUPPORT=0
39+
else
40+
CPPFLAGS += -I./legacy -DZSTD_LEGACY_SUPPORT=1
41+
ZSTD_FILES+= $(wildcard legacy/*.c)
42+
endif
43+
44+
# OS X linker doesn't support -soname, and use different extension
45+
# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
46+
ifeq ($(shell uname), Darwin)
47+
SHARED_EXT = dylib
48+
SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
49+
SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
50+
SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
51+
else
52+
SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
53+
SHARED_EXT = so
54+
SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
55+
SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
56+
endif
57+
58+
LIBZSTD = libzstd.$(SHARED_EXT_VER)
59+
60+
61+
.PHONY: default all clean install uninstall
62+
63+
default: lib
64+
65+
all: lib
66+
67+
libzstd.a: ARFLAGS = rcs
68+
libzstd.a: $(ZSTD_FILES)
69+
@echo compiling static library
70+
@$(CC) $(FLAGS) -c $^
71+
@$(AR) $(ARFLAGS) $@ *.o
72+
73+
$(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden
74+
$(LIBZSTD): $(ZSTD_FILES)
75+
@echo compiling dynamic library $(LIBVER)
76+
ifneq (,$(filter Windows%,$(OS)))
77+
@$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -shared $^ -o dll\libzstd.dll
78+
dlltool -D dll\libzstd.dll -d dll\libzstd.def -l dll\libzstd.lib
79+
else
80+
@$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
81+
@echo creating versioned links
82+
@ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
83+
@ln -sf $@ libzstd.$(SHARED_EXT)
84+
endif
85+
86+
libzstd : $(LIBZSTD)
87+
88+
lib: libzstd.a libzstd
89+
90+
clean:
91+
@$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc dll/libzstd.dll dll/libzstd.lib
92+
@$(RM) decompress/*.o
93+
@echo Cleaning library completed
94+
95+
#------------------------------------------------------------------------
96+
#make install is validated only for Linux, OSX, kFreeBSD, Hurd and some BSD targets
97+
ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU FreeBSD DragonFly NetBSD))
98+
99+
libzstd.pc:
100+
libzstd.pc: libzstd.pc.in
101+
@echo creating pkgconfig
102+
@sed -e 's|@PREFIX@|$(PREFIX)|' \
103+
-e 's|@LIBDIR@|$(LIBDIR)|' \
104+
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
105+
-e 's|@VERSION@|$(VERSION)|' \
106+
$< >$@
107+
108+
install: libzstd.a libzstd libzstd.pc
109+
@install -d -m 755 $(DESTDIR)$(LIBDIR)/pkgconfig/ $(DESTDIR)$(INCLUDEDIR)/
110+
@install -m 755 libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)
111+
@cp -a libzstd.$(SHARED_EXT_MAJOR) $(DESTDIR)$(LIBDIR)
112+
@cp -a libzstd.$(SHARED_EXT) $(DESTDIR)$(LIBDIR)
113+
@cp -a libzstd.pc $(DESTDIR)$(LIBDIR)/pkgconfig/
114+
@install -m 644 libzstd.a $(DESTDIR)$(LIBDIR)
115+
@install -m 644 zstd.h $(DESTDIR)$(INCLUDEDIR)
116+
@install -m 644 common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
117+
@install -m 644 deprecated/zbuff.h $(DESTDIR)$(INCLUDEDIR) # prototypes generate deprecation warnings
118+
@install -m 644 dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR)
119+
@echo zstd static and shared library installed
120+
121+
uninstall:
122+
@$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
123+
@$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
124+
@$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
125+
@$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_VER)
126+
@$(RM) $(DESTDIR)$(LIBDIR)/pkgconfig/libzstd.pc
127+
@$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h
128+
@$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h
129+
@$(RM) $(DESTDIR)$(INCLUDEDIR)/zbuff.h # Deprecated streaming functions
130+
@$(RM) $(DESTDIR)$(INCLUDEDIR)/zdict.h
131+
@echo zstd libraries successfully uninstalled
132+
133+
endif

ext/zstdruby/libzstd/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
Zstandard library files
2+
================================
3+
4+
The __lib__ directory contains several directories.
5+
Depending on target use case, it's enough to include only files from relevant directories.
6+
7+
8+
#### API
9+
10+
Zstandard's stable API is exposed within [zstd.h](zstd.h),
11+
at the root of `lib` directory.
12+
13+
14+
#### Advanced API
15+
16+
Some additional API may be useful if you're looking into advanced features :
17+
- common/error_public.h : transforms `size_t` function results into an `enum`,
18+
for precise error handling.
19+
- ZSTD_STATIC_LINKING_ONLY : if you define this macro _before_ including `zstd.h`,
20+
it will give access to advanced and experimental API.
21+
These APIs shall ___never be used with dynamic library___ !
22+
They are not "stable", their definition may change in the future.
23+
Only static linking is allowed.
24+
25+
26+
#### Modular build
27+
28+
Directory `common/` is required in all circumstances.
29+
You can select to support compression only, by just adding files from the `compress/` directory,
30+
In a similar way, you can build a decompressor-only library with the `decompress/` directory.
31+
32+
Other optional functionalities provided are :
33+
34+
- `dictBuilder/` : source files to create dictionaries.
35+
The API can be consulted in `dictBuilder/zdict.h`.
36+
This module also depends on `common/` and `compress/` .
37+
38+
- `legacy/` : source code to decompress previous versions of zstd, starting from `v0.1`.
39+
This module also depends on `common/` and `decompress/` .
40+
Library compilation must include directive `ZSTD_LEGACY_SUPPORT = 1` .
41+
The main API can be consulted in `legacy/zstd_legacy.h`.
42+
Advanced API from each version can be found in their relevant header file.
43+
For example, advanced API for version `v0.4` is in `legacy/zstd_v04.h` .
44+
45+
46+
#### Using MinGW+MSYS to create DLL
47+
48+
DLL can be created using MinGW+MSYS with the `make libzstd` command.
49+
This command creates `dll\libzstd.dll` and the import library `dll\libzstd.lib`.
50+
The import library is only required with Visual C++.
51+
The header file `zstd.h` and the dynamic library `dll\libzstd.dll` are required to
52+
compile a project using gcc/MinGW.
53+
The dynamic library has to be added to linking options.
54+
It means that if a project that uses ZSTD consists of a single `test-dll.c`
55+
file it should be linked with `dll\libzstd.dll`. For example:
56+
```
57+
gcc $(CFLAGS) -Iinclude/ test-dll.c -o test-dll dll\libzstd.dll
58+
```
59+
The compiled executable will require ZSTD DLL which is available at `dll\libzstd.dll`.
60+
61+
62+
#### Obsolete streaming API
63+
64+
Streaming is now provided within `zstd.h`.
65+
Older streaming API is still available within `deprecated/zbuff.h`.
66+
It will be removed in a future version.
67+
Consider migrating code towards newer streaming API in `zstd.h`.
68+
69+
70+
#### Miscellaneous
71+
72+
The other files are not source code. There are :
73+
74+
- LICENSE : contains the BSD license text
75+
- Makefile : script to compile or install zstd library (static and dynamic)
76+
- libzstd.pc.in : for pkg-config (`make install`)
77+
- README.md : this file

0 commit comments

Comments
 (0)