From fc4d0ce3bf959b5350eb42c81f42c5429d49e0c6 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Thu, 14 Jun 2012 07:24:40 -0500 Subject: [PATCH] remove the dependency on libv8 --- Gemfile | 1 + ext/v8/build.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++ ext/v8/extconf.rb | 24 ++++++++-------------- therubyracer.gemspec | 2 -- 4 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 ext/v8/build.rb diff --git a/Gemfile b/Gemfile index 2c27393..3fa2f9e 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,4 @@ source 'http://rubygems.org' gemspec gem 'redjs', :git => 'https://github.com/cowboyd/redjs.git', :tag => 'v0.6.1' +gem 'libv8', "~> 3.10.8" diff --git a/ext/v8/build.rb b/ext/v8/build.rb new file mode 100644 index 0000000..4ace75c --- /dev/null +++ b/ext/v8/build.rb @@ -0,0 +1,48 @@ + +LIBV8_COMPATIBILITY = '~> 3.10.8' + +def have_rubygem_libv8? + gem 'libv8', LIBV8_COMPATIBILITY + return true +rescue Gem::LoadError + return false +end + +def build_with_system_libv8 + dir_config('v8') + find_header('v8.h') or begin + puts <<-EOS + The Ruby Racer requires libv8 #{LIBV8_COMPATIBILITY} + to be present on your system in order to compile + and link, but it could not be found. + + In order to resolve this, you will either need to manually + install an appropriate libv8 and make sure that this + build process can find it. If you install it into the + standard system path, then it should just be picked up + automatically. Otherwise, you'll have to pass some extra + flags to the build process as a hint. + + If you don't want to bother with all that, there is a + rubygem that will do all this for you. You can add + following line to your Gemfile: + gem 'libv8', '#{LIBV8_COMPATIBILITY}' + + We hope that helps, and we apologize, but now we have + to push the eject button on this install. + + thanks, + The Mgmt. + + EOS + raise "unable to locate libv8. Please see output for details" + end + $LDFLAGS << " -lv8_base -lv8_snapshot " +end + +def build_with_rubygem_libv8 + require 'libv8' + include Libv8 + $INCFLAGS.insert 0, "#{libv8_include_flags} " + $LDFLAGS.insert 0, libv8_objects.join(' ') + " " +end diff --git a/ext/v8/extconf.rb b/ext/v8/extconf.rb index acc71e5..a1efd92 100644 --- a/ext/v8/extconf.rb +++ b/ext/v8/extconf.rb @@ -1,31 +1,23 @@ require 'mkmf' -begin - require 'libv8' -rescue LoadError - require 'rubygems' - require 'libv8' -end -include Libv8 +require File.expand_path '../build', __FILE__ +have_library('pthread') have_library('objc') if RUBY_PLATFORM =~ /darwin/ - -#we have to manually prepend the libv8 include path to INCFLAGS -#since find_header() does not actually work as advertized. -#see https://github.com/cowboyd/therubyracer/issues/91 -$INCFLAGS.insert 0, "#{libv8_include_flags} " $CPPFLAGS += " -Wall" unless $CPPFLAGS.split.include? "-Wall" $CPPFLAGS += " -g" unless $CPPFLAGS.split.include? "-g" $CPPFLAGS += " -rdynamic" unless $CPPFLAGS.split.include? "-rdynamic" $CPPFLAGS += " -fPIC" unless $CPPFLAGS.split.include? "-rdynamic" or RUBY_PLATFORM =~ /darwin/ -$LDFLAGS.insert 0, libv8_objects.join(' ') + " " -$LIBS << ' -lpthread ' - - CONFIG['LDSHARED'] = '$(CXX) -shared' unless RUBY_PLATFORM =~ /darwin/ if CONFIG['warnflags'] CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '') CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '') end +if have_rubygem_libv8? + build_with_rubygem_libv8 +else + build_with_system_libv8 +end + create_makefile('v8/init') diff --git a/therubyracer.gemspec b/therubyracer.gemspec index cf28138..0b47179 100644 --- a/therubyracer.gemspec +++ b/therubyracer.gemspec @@ -16,8 +16,6 @@ Gem::Specification.new do |gem| gem.require_paths = ["lib", "ext"] gem.version = V8::VERSION - gem.add_dependency "libv8", "~> 3.10.8" - gem.add_development_dependency "rake" gem.add_development_dependency "rake-compiler" gem.add_development_dependency "gem-compiler"