mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
add basic template for compiling extension and hooking into jsapi_spec test harness.
This commit is contained in:
parent
aa6e4ae928
commit
23f1654ca0
9 changed files with 90 additions and 13 deletions
15
Rakefile
15
Rakefile
|
|
@ -1,23 +1,24 @@
|
|||
#!/usr/bin/env rake
|
||||
require "bundler/gem_tasks"
|
||||
|
||||
require "rake/extensiontask"
|
||||
|
||||
# desc "remove all generated artifacts except built v8 objects"
|
||||
task :clean do
|
||||
sh "rm -rf lib/v8/vm.bundle lib/v8/vm.so"
|
||||
sh "rm -rf pkg"
|
||||
end
|
||||
|
||||
require "rake/extensiontask"
|
||||
Rake::ExtensionTask.new("vm", eval(File.read("therubyracer.gemspec"))) do |ext|
|
||||
ext.ext_dir = "ext/v8"
|
||||
ext.lib_dir = "lib/v8"
|
||||
ext.source_pattern = "*.{cc,h}"
|
||||
end
|
||||
|
||||
|
||||
require "rspec/core/rake_task"
|
||||
require 'rspec/core/rake_task'
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
|
||||
task :sanity => [:clean, :compile] do
|
||||
sh %q{ruby -Ilib -e "require 'v8'"}
|
||||
end
|
||||
|
||||
task :default => :spec
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
5
ext/v8/context.cc
Normal file
5
ext/v8/context.cc
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#include "rr.h"
|
||||
|
||||
namespace rr {
|
||||
void Context::Initialize() {}
|
||||
} //namespace rr
|
||||
26
ext/v8/extconf.rb
Normal file
26
ext/v8/extconf.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
require 'mkmf'
|
||||
begin
|
||||
require 'libv8'
|
||||
rescue LoadError
|
||||
require 'rubygems'
|
||||
require 'libv8'
|
||||
end
|
||||
|
||||
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, "-I#{Libv8.include_path} "
|
||||
|
||||
$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/
|
||||
|
||||
$DEFLIBPATH.unshift(Libv8.library_path)
|
||||
$LIBS << ' -lv8 -lpthread'
|
||||
|
||||
CONFIG['LDSHARED'] = '$(CXX) -shared' unless RUBY_PLATFORM =~ /darwin/
|
||||
|
||||
create_makefile('vm')
|
||||
34
ext/v8/rr.h
Normal file
34
ext/v8/rr.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef THE_RUBY_RACER
|
||||
#define THE_RUBY_RACER
|
||||
|
||||
#include <stdio.h>
|
||||
#include <v8.h>
|
||||
#include <ruby.h>
|
||||
|
||||
#define RR_DEFINE_METHOD(klass, name, impl, argc) rb_define_method(klass, name, (VALUE(*)(...))impl, argc)
|
||||
|
||||
namespace rr {
|
||||
|
||||
class Object {
|
||||
public:
|
||||
Object(VALUE value);
|
||||
inline operator VALUE() {return value;};
|
||||
private:
|
||||
VALUE value;
|
||||
};
|
||||
|
||||
class Class {
|
||||
public:
|
||||
Class(const char* name);
|
||||
Class defineSingletonMethod(const char* name, VALUE(*impl)(...), int argc);
|
||||
Class defineMethod(const char* name, VALUE(*impl)(...), int argc);
|
||||
};
|
||||
|
||||
class Context {
|
||||
public:
|
||||
static void Initialize();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
13
ext/v8/vm.cc
Normal file
13
ext/v8/vm.cc
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include "rr.h"
|
||||
|
||||
extern "C" {
|
||||
void Init_vm();
|
||||
}
|
||||
|
||||
using namespace rr;
|
||||
|
||||
extern "C" {
|
||||
void Init_vm() {
|
||||
Context::Initialize();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
require 'mkmf'
|
||||
|
||||
create_makefile('vm')
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
module V8
|
||||
class Context
|
||||
def initialize
|
||||
@native = CC::Context::New()
|
||||
|
||||
end
|
||||
def eval(*args)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,10 +12,11 @@ Gem::Specification.new do |gem|
|
|||
gem.files = `git ls-files`.split("\n")
|
||||
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||
gem.name = "therubyracer"
|
||||
gem.require_paths = ["lib"]
|
||||
gem.extensions = ["ext/v8/extconf.rb"]
|
||||
gem.require_paths = ["lib", "ext"]
|
||||
gem.version = V8::VERSION
|
||||
|
||||
gem.add_dependency "libv8", "~> 3.7.0"
|
||||
gem.add_dependency "libv8", "~> 3.8.9"
|
||||
|
||||
gem.add_development_dependency "rake"
|
||||
gem.add_development_dependency "rake-compiler"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue