diff --git a/Rakefile b/Rakefile index db6a1a0..1da4544 100644 --- a/Rakefile +++ b/Rakefile @@ -12,7 +12,8 @@ task :checkout do sh "git submodule update --init" Dir.chdir(V8_Source) do sh "git fetch" - sh "git checkout #{V8_Version}" + # sh "git checkout #{V8_Version}" + sh "git checkout master" sh "make dependencies" end end @@ -25,9 +26,10 @@ end desc "manually invoke the GYP compile. Useful for seeing debug output" task :manual_compile do + require File.expand_path '../ext/libv8/arch.rb', __FILE__ + include Libv8::Arch Dir.chdir(V8_Source) do - puts "compiling libv8" - sh "make native GYP_GENERATORS=make" + sh "make #{libv8_arch}.release GYP_GENERATORS=make" end end @@ -38,7 +40,7 @@ task :binary => :compile do gemspec.platform = Gem::Platform.new(RUBY_PLATFORM) # We don't need most things for the binary - gemspec.files = ['lib/libv8.rb', 'lib/libv8/version.rb'] + gemspec.files = ['lib/libv8.rb', 'lib/arch.rb', 'lib/libv8/version.rb'] # V8 gemspec.files += Dir['vendor/v8/include/*'] gemspec.files += Dir['vendor/v8/out/native/*'] diff --git a/ext/libv8/arch.rb b/ext/libv8/arch.rb new file mode 100644 index 0000000..67d4a36 --- /dev/null +++ b/ext/libv8/arch.rb @@ -0,0 +1,35 @@ +require 'rbconfig' + +module Libv8 + module Arch + module_function + + def x86_64_from_build_cpu + RbConfig::MAKEFILE_CONFIG['build_cpu'] == 'x86_64' + end + + def x86_64_from_byte_length + ['foo'].pack('p').size == 8 + end + + def x86_64_from_arch_flag + RbConfig::MAKEFILE_CONFIG['ARCH_FLAG'] =~ /x86_64/ + end + + def rubinius? + Object.const_defined?(:RUBY_ENGINE) && RUBY_ENGINE == "rbx" + end + + def x64? + if rubinius? + x86_64_from_build_cpu || x86_64_from_arch_flag + else + x86_64_from_byte_length + end + end + + def libv8_arch + x64? ? "x64" : "ia32" + end + end +end \ No newline at end of file diff --git a/ext/libv8/extconf.rb b/ext/libv8/extconf.rb index 1232e00..f6816a0 100644 --- a/ext/libv8/extconf.rb +++ b/ext/libv8/extconf.rb @@ -1,7 +1,9 @@ require 'mkmf' create_makefile('libv8') +require File.expand_path '../arch.rb', __FILE__ + +include Libv8::Arch Dir.chdir(File.expand_path '../../../vendor/v8', __FILE__) do - puts "compiling libv8" - puts `make native GYP_GENERATORS=make` + puts `make #{libv8_arch}.release GYP_GENERATORS=make` end diff --git a/lib/libv8.rb b/lib/libv8.rb index 0a7657b..60ac2e6 100644 --- a/lib/libv8.rb +++ b/lib/libv8.rb @@ -1,31 +1,46 @@ -require 'libv8/version' - +require 'mkmf' +require 'libv8/arch' module Libv8 module_function - def libv8(name) - path = File.expand_path "../../vendor/v8/out/native/libv8_#{name}.a", __FILE__ - if File.exists? path - path - else - File.expand_path "../../vendor/v8/out/native/obj.target/tools/gyp/libv8_#{name}.a", __FILE__ - end + def libv8_object(name) + "#{libv8_source_path}/out/#{Libv8::Arch.libv8_arch}.release/libv8_#{name}.#{$LIBEXT}" end def libv8_base - libv8 :base + libv8_object :base end def libv8_snapshot - libv8 :snapshot + libv8_object :snapshot end def libv8_nosnapshot - libv8 :nosnapshot + libv8_object :nosnapshot + end + + def libv8_objects(*names) + names = [:base, :snapshot] if names.empty? + names.map do |name| + fail "no libv8 object #{name}" unless File.exists?(object = libv8_object(name)) + object + end end def libv8_ldflags - "-l#{libv8_base} -l#{libv8_snapshot}" + "-L#{libv8_base} -L#{libv8_snapshot}" + end + + def libv8_include_flags + "-I#{libv8_include_path}" + end + + def libv8_include_path + "#{libv8_source_path}/include" + end + + def libv8_source_path + File.expand_path "../../vendor/v8", __FILE__ end end diff --git a/lib/libv8/version.rb b/lib/libv8/version.rb index 8e8f60b..5eeec14 100644 --- a/lib/libv8/version.rb +++ b/lib/libv8/version.rb @@ -1,3 +1,3 @@ module Libv8 - VERSION = "3.9.24.0" + VERSION = "3.10.7.0" end diff --git a/libv8.gemspec b/libv8.gemspec index cfb1f16..9399f71 100644 --- a/libv8.gemspec +++ b/libv8.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| end s.extensions = ["ext/libv8/extconf.rb"] - s.require_paths = ["lib"] + s.require_paths = ["lib", "ext"] s.add_development_dependency "rake", "~> 0.9.2" s.add_development_dependency "rake-compiler" diff --git a/spec/libv8_spec.rb b/spec/libv8_spec.rb index 41a50b7..3aecf54 100644 --- a/spec/libv8_spec.rb +++ b/spec/libv8_spec.rb @@ -5,8 +5,19 @@ describe Libv8 do include Libv8 it "can find the static library components" do - Pathname(libv8_base).should be_exist - Pathname(libv8_snapshot).should be_exist - Pathname(libv8_nosnapshot).should be_exist + Pathname(libv8_base).should exist + Pathname(libv8_snapshot).should exist + Pathname(libv8_nosnapshot).should exist end + + it "has a valid include path" do + Pathname(libv8_include_path).should be_exist + end + + it "can retrieve objects by name" do + libv8_objects(:base, :snapshot, :nosnapshot).each do |obj| + Pathname(obj).should exist + end + end + end diff --git a/v8-gyp-osx-x64-support.patch b/v8-gyp-osx-x64-support.patch new file mode 100644 index 0000000..c13801f --- /dev/null +++ b/v8-gyp-osx-x64-support.patch @@ -0,0 +1,110 @@ +diff --git a/Makefile b/Makefile +index 5dc6ca5..e4e36d8 100644 +--- a/Makefile ++++ b/Makefile +@@ -260,4 +260,4 @@ $(ENVFILE).new: + # Dependencies. + dependencies: + svn checkout --force http://gyp.googlecode.com/svn/trunk build/gyp \ +- --revision 1026 ++ --revision 1251 +diff --git a/build/common.gypi b/build/common.gypi +index 5c0c323..4f2452c 100644 +--- a/build/common.gypi ++++ b/build/common.gypi +@@ -317,6 +317,16 @@ + 'cflags': [ '-Wall', '<(werror)', '-W', '-Wno-unused-parameter', + '-Wnon-virtual-dtor', '-Woverloaded-virtual' ], + }], ++ ['OS=="mac" and target_arch=="ia32"', { ++ 'xcode_settings': { ++ 'ARCHS': ['i386'] ++ } ++ }], ++ ['OS=="mac" and target_arch=="x64"', { ++ 'xcode_settings': { ++ 'ARCHS': ['x86_64'] ++ } ++ }], + ], + }, # Debug + 'Release': { +@@ -358,6 +368,18 @@ + # is specified explicitly. + 'GCC_STRICT_ALIASING': 'YES', + }, ++ 'conditions': [ ++ ['target_arch=="ia32"', { ++ 'xcode_settings': { ++ 'ARCHS': ['i386'] ++ } ++ }], ++ ['target_arch=="x64"', { ++ 'xcode_settings': { ++ 'ARCHS': ['x86_64'] ++ } ++ }], ++ ], + }], # OS=="mac" + ['OS=="win"', { + 'msvs_configuration_attributes': { +diff --git a/build/gyp_v8 b/build/gyp_v8 +index 4293e76..54f3f7f 100755 +--- a/build/gyp_v8 ++++ b/build/gyp_v8 +@@ -156,7 +156,12 @@ if __name__ == '__main__': + + # Generate for the architectures supported on the given platform. + gyp_args = list(args) +- gyp_args.append('-Dtarget_arch=ia32') ++ target_arch = None ++ for p in gyp_args: ++ if p.find('-Dtarget_arch=') == 0: ++ target_arch = p ++ if target_arch is None: ++ gyp_args.append('-Dtarget_arch=ia32') + if utils.GuessOS() == 'linux': + gyp_args.append('-S-ia32') + run_gyp(gyp_args) +diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp +index 764789a..2913cdf 100644 +--- a/tools/gyp/v8.gyp ++++ b/tools/gyp/v8.gyp +@@ -59,6 +59,9 @@ + '../../src/v8dll-main.cc', + ], + 'conditions': [ ++ ['OS=="mac"', { ++ 'xcode_settings': {'OTHER_LDFLAGS': ['-dynamiclib', '-all_load']}, ++ }], + ['OS=="win"', { + 'defines': [ + 'BUILDING_V8_SHARED', +@@ -536,7 +539,7 @@ + '../../src/arm/stub-cache-arm.cc', + ], + }], +- ['v8_target_arch=="ia32" or v8_target_arch=="mac" or OS=="mac"', { ++ ['v8_target_arch=="ia32"', { + 'sources': [ + '../../src/ia32/assembler-ia32-inl.h', + '../../src/ia32/assembler-ia32.cc', +@@ -601,7 +604,7 @@ + '../../src/mips/stub-cache-mips.cc', + ], + }], +- ['v8_target_arch=="x64" or v8_target_arch=="mac" or OS=="mac"', { ++ ['v8_target_arch=="x64"', { + 'sources': [ + '../../src/x64/assembler-x64-inl.h', + '../../src/x64/assembler-x64.cc', +@@ -982,6 +985,9 @@ + }, { + 'toolsets': ['target'], + }], ++ ['OS=="mac" and component=="shared_library"', { ++ 'xcode_settings': {'OTHER_LDFLAGS': ['-dynamiclib', '-all_load']}, ++ }], + ], + 'link_settings': { + 'libraries': [ \ No newline at end of file diff --git a/vendor/v8 b/vendor/v8 index a1e3ff8..09a5564 160000 --- a/vendor/v8 +++ b/vendor/v8 @@ -1 +1 @@ -Subproject commit a1e3ff82b79ab8d92cebc9133fca3b15b00d5921 +Subproject commit 09a5564086c71bc40bcfea0e102b3a3f31fc8180