Skip to content

Commit

Permalink
Compile recent libwebp as part of gem installation
Browse files Browse the repository at this point in the history
  • Loading branch information
knarewski committed Oct 26, 2022
1 parent 671a9c9 commit 645c8ed
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,27 @@ require 'rake/clean'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'ffi-compiler/compile_task'
require 'mini_portile2'

WEBP = MiniPortile.new('libwebp', '1.2.4')
WEBP.files = ['https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.2.4.tar.gz']
WEBP.configure_options << '--disable-gl' << '--disable-sdl'

desc "compiler tasks"
namespace "ffi-compiler" do
task :libs do
old_cflags = ENV['CFLAGS']
ENV['CFLAGS'] = (ENV['CFLAGS'].to_s + ' -fPIC').strip
WEBP.cook
ENV['CFLAGS'] = old_cflags
WEBP.activate
end
FFI::Compiler::CompileTask.new('ext/webp_ffi/webp_ffi') do |c|
c.have_header?('stdio.h', '/usr/local/include')
c.have_func?('puts')
c.have_library?('z')
c.ldflags << '-L' + File.join(WEBP.path, 'lib')
c.cflags << '-I' + File.join(WEBP.path, 'include')
c.have_header?('decode.h', '/usr/local/include')
c.have_header?('encode.h', '/usr/local/include')
c.have_func?('WebPDecoderConfig')
Expand All @@ -24,7 +38,7 @@ namespace "ffi-compiler" do
c.cflags << ENV['C_FLAGS'] if ENV['C_FLAGS']
end
end
task :compile => ["ffi-compiler:default"]
task :compile => ["ffi-compiler:libs", "ffi-compiler:default"]

desc "run specs"
task :spec do
Expand Down
16 changes: 16 additions & 0 deletions ext/webp_ffi/Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
require 'ffi-compiler/compile_task'
require 'mini_portile2'

WEBP = MiniPortile.new('libwebp', '1.2.4')
WEBP.files = ['https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.2.4.tar.gz']
WEBP.configure_options << '--disable-gl' << '--disable-sdl'
task :libwebp do
old_cflags = ENV['CFLAGS']
ENV['CFLAGS'] = (ENV['CFLAGS'].to_s + ' -fPIC').strip
WEBP.cook
ENV['CFLAGS'] = old_cflags
WEBP.activate
end
task default: :libwebp

FFI::Compiler::CompileTask.new('webp_ffi') do |c|
c.ldflags << '-L' + File.join(WEBP.path, 'lib')
c.cflags << '-I' + File.join(WEBP.path, 'include')

c.have_header?('stdio.h', '/usr/local/include')
c.have_func?('puts')
c.have_library?('z')
Expand Down
1 change: 1 addition & 0 deletions webp-ffi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency "ffi", ">= 1.9.0"
spec.add_runtime_dependency "ffi-compiler", ">= 0.1.2"
spec.add_dependency("mini_portile2", "~> 2.8.0")

spec.add_development_dependency "bundler", ">= 1.2"
spec.add_development_dependency "rake"
Expand Down

0 comments on commit 645c8ed

Please sign in to comment.