Skip to content

Instantly share code, notes, and snippets.

@geoffyoungs
Created October 25, 2022 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geoffyoungs/ae1c4b3250695946f46f09a9cbc4c70c to your computer and use it in GitHub Desktop.
Save geoffyoungs/ae1c4b3250695946f46f09a9cbc4c70c to your computer and use it in GitHub Desktop.
Patch webp-ffi to install libwebp using mini_portile2
diff --git a/Rakefile b/Rakefile
index 67b32ec..e5d2660 100644
--- a/Rakefile
+++ b/Rakefile
@@ -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')
@@ -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
@@ -36,3 +50,4 @@ task :default => [:clean, :compile, :spec]
CLEAN.include('ext/**/*{.o,.log,.so,.bundle}')
CLEAN.include('lib/**/*{.o,.log,.so,.bundle}')
CLEAN.include('ext/**/Makefile')
+
diff --git a/ext/webp_ffi/Rakefile b/ext/webp_ffi/Rakefile
index 22e2e98..23af362 100644
--- a/ext/webp_ffi/Rakefile
+++ b/ext/webp_ffi/Rakefile
@@ -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')
@@ -17,3 +33,4 @@ FFI::Compiler::CompileTask.new('webp_ffi') do |c|
c.ldflags << ENV['LD_FLAGS'] if ENV['LD_FLAGS']
c.cflags << ENV['C_FLAGS'] if ENV['C_FLAGS']
end
+
diff --git a/webp-ffi.gemspec b/webp-ffi.gemspec
index ba81650..18532a5 100644
--- a/webp-ffi.gemspec
+++ b/webp-ffi.gemspec
@@ -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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment