Bundled C core with Ruby library

pull/4538/head
murgatroid99 9 years ago
parent 08ae945aac
commit d7e1a10628
  1. 6
      .rspec
  2. 0
      Gemfile
  3. 21
      Rakefile
  4. 21
      grpc.gemspec
  5. 6
      src/ruby/.rspec
  6. 68
      src/ruby/ext/grpc/extconf.rb
  7. 2
      tools/run_tests/build_ruby.sh
  8. 2
      tools/run_tests/run_ruby.sh

@ -0,0 +1,6 @@
-Isrc/ruby
-Isrc/ruby/pb
--backtrace
--require spec/spec_helper
--format documentation
--color

@ -5,23 +5,28 @@ require 'rubocop/rake_task'
require 'bundler/gem_tasks' require 'bundler/gem_tasks'
# Add rubocop style checking tasks # Add rubocop style checking tasks
RuboCop::RakeTask.new RuboCop::RakeTask.new(:rubocop) do |task|
task.options = ['-c', 'src/ruby/.rubocop.yml']
task.patterns = ['src/ruby/{lib,spec}/**/*.rb']
end
# Add the extension compiler task # Add the extension compiler task
Rake::ExtensionTask.new 'grpc' do |ext| Rake::ExtensionTask.new 'grpc' do |ext|
ext.lib_dir = File.join('lib', 'grpc') ext.source_pattern = '**/*.{c,h}'
ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc')
ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc')
end end
# Define the test suites # Define the test suites
SPEC_SUITES = [ SPEC_SUITES = [
{ id: :wrapper, title: 'wrapper layer', files: %w(spec/*.rb) }, { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) },
{ id: :idiomatic, title: 'idiomatic layer', dir: %w(spec/generic), { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic),
tags: ['~bidi', '~server'] }, tags: ['~bidi', '~server'] },
{ id: :bidi, title: 'bidi tests', dir: %w(spec/generic), { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic),
tag: 'bidi' }, tag: 'bidi' },
{ id: :server, title: 'rpc server thread tests', dir: %w(spec/generic), { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic),
tag: 'server' }, tag: 'server' },
{ id: :pb, title: 'protobuf service tests', dir: %w(spec/pb) } { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) }
] ]
namespace :suite do namespace :suite do
SPEC_SUITES.each do |suite| SPEC_SUITES.each do |suite|
@ -34,7 +39,7 @@ namespace :suite do
if suite[:dir] if suite[:dir]
suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] } suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] }
end end
helper = 'spec/spec_helper.rb' helper = 'src/ruby/spec/spec_helper.rb'
spec_files << helper unless spec_files.include?(helper) spec_files << helper unless spec_files.include?(helper)
t.pattern = spec_files t.pattern = spec_files

@ -1,6 +1,6 @@
# -*- ruby -*- # -*- ruby -*-
# encoding: utf-8 # encoding: utf-8
$LOAD_PATH.push File.expand_path('../lib', __FILE__) $LOAD_PATH.push File.expand_path('../src/ruby/lib', __FILE__)
require 'grpc/version' require 'grpc/version'
Gem::Specification.new do |s| Gem::Specification.new do |s|
@ -16,17 +16,20 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.0.0' s.required_ruby_version = '>= 2.0.0'
s.requirements << 'libgrpc ~> 0.11.0 needs to be installed' s.requirements << 'libgrpc ~> 0.11.0 needs to be installed'
s.files = %w( Rakefile ) s.files = %w( Rakefile Makefile )
s.files += Dir.glob('bin/**/*') s.files += Dir.glob('src/ruby/bin/**/*')
s.files += Dir.glob('ext/**/*') s.files += Dir.glob('src/ruby/ext/**/*')
s.files += Dir.glob('lib/**/*') s.files += Dir.glob('src/ruby/lib/**/*')
s.files += Dir.glob('pb/**/*') s.files += Dir.glob('src/ruby/pb/**/*')
s.test_files = Dir.glob('spec/**/*') s.files += Dir.glob('include/grpc/**/*')
s.files += Dir.glob('src/core/**/*')
s.test_files = Dir.glob('src/ruby/spec/**/*')
s.bindir = 'src/ruby/bin'
%w(math noproto).each do |b| %w(math noproto).each do |b|
s.executables += ["#{b}_client.rb", "#{b}_server.rb"] s.executables += ["#{b}_client.rb", "#{b}_server.rb"]
end end
s.executables += %w(grpc_ruby_interop_client grpc_ruby_interop_server) s.executables += %w(grpc_ruby_interop_client grpc_ruby_interop_server)
s.require_paths = %w( bin lib pb ) s.require_paths = %w( src/ruby/bin src/ruby/lib src/ruby/pb )
s.platform = Gem::Platform::RUBY s.platform = Gem::Platform::RUBY
s.add_dependency 'google-protobuf', '~> 3.0.0alpha.1.1' s.add_dependency 'google-protobuf', '~> 3.0.0alpha.1.1'
@ -41,5 +44,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rubocop', '~> 0.30.0' s.add_development_dependency 'rubocop', '~> 0.30.0'
s.add_development_dependency 'signet', '~>0.6.0' s.add_development_dependency 'signet', '~>0.6.0'
s.extensions = %w(ext/grpc/extconf.rb) s.extensions = %w(src/ruby/ext/grpc/extconf.rb)
end end

@ -1,6 +0,0 @@
-I.
-Ipb
--backtrace
--require spec_helper
--format documentation
--color

@ -54,53 +54,30 @@ LIB_DIRS = [
LIBDIR LIBDIR
] ]
def check_grpc_root fail 'libdl not found' unless have_library('dl', 'dlopen')
grpc_root = ENV['GRPC_ROOT'] fail 'zlib not found' unless have_library('z', 'inflate')
if grpc_root.nil?
r = File.expand_path(File.join(File.dirname(__FILE__), '../../../..')) grpc_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
grpc_root = r if File.exist?(File.join(r, 'include/grpc/grpc.h'))
end
grpc_root
end
grpc_pkg_config = system('pkg-config --exists grpc') grpc_config = ENV['GRPC_CONFIG'] || 'opt'
if grpc_pkg_config if ENV.key?('GRPC_LIB_DIR')
$CFLAGS << ' ' + `pkg-config --static --cflags grpc`.strip + ' ' grpc_lib_dir = File.join(grpc_root, ENV['GRPC_LIB_DIR'])
$LDFLAGS << ' ' + `pkg-config --static --libs grpc`.strip + ' '
else else
dir_config('grpc', HEADER_DIRS, LIB_DIRS) grpc_lib_dir = File.join(File.join(grpc_root, 'libs'), grpc_config)
fail 'libdl not found' unless have_library('dl', 'dlopen') end
fail 'zlib not found' unless have_library('z', 'inflate')
begin unless File.exist?(File.join(grpc_lib_dir, 'libgrpc.a'))
fail 'Fail' unless have_library('gpr', 'gpr_now') print "Building internal gRPC\n"
fail 'Fail' unless have_library('grpc', 'grpc_channel_destroy') system("make -C #{grpc_root} static_c CONFIG=#{grpc_config}")
rescue end
# Check to see if GRPC_ROOT is defined or available
grpc_root = check_grpc_root $CFLAGS << ' -I' + File.join(grpc_root, 'include')
$LDFLAGS << ' ' + File.join(grpc_lib_dir, 'libgrpc.a')
# Stop if there is still no grpc_root $LDFLAGS << ' ' + File.join(grpc_lib_dir, 'libgpr.a')
exit 1 if grpc_root.nil? if grpc_config == 'gcov'
$CFLAGS << ' -O0 -fprofile-arcs -ftest-coverage'
grpc_config = ENV['GRPC_CONFIG'] || 'opt' $LDFLAGS << ' -fprofile-arcs -ftest-coverage -rdynamic'
if ENV.key?('GRPC_LIB_DIR')
grpc_lib_dir = File.join(grpc_root, ENV['GRPC_LIB_DIR'])
else
grpc_lib_dir = File.join(File.join(grpc_root, 'libs'), grpc_config)
end
unless File.exist?(File.join(grpc_lib_dir, 'libgrpc.a'))
print "Building internal gRPC\n"
system("make -C #{grpc_root} static_c CONFIG=#{grpc_config}")
end
$CFLAGS << ' -I' + File.join(grpc_root, 'include')
$LDFLAGS << ' -L' + grpc_lib_dir
if grpc_config == 'gcov'
$CFLAGS << ' -O0 -fprofile-arcs -ftest-coverage'
$LDFLAGS << ' -fprofile-arcs -ftest-coverage -rdynamic'
end
raise 'gpr not found' unless have_library('gpr', 'gpr_now')
raise 'grpc not found' unless have_library('grpc', 'grpc_channel_destroy')
end
end end
$CFLAGS << ' -std=c99 ' $CFLAGS << ' -std=c99 '
@ -109,4 +86,7 @@ $CFLAGS << ' -Wextra '
$CFLAGS << ' -pedantic ' $CFLAGS << ' -pedantic '
$CFLAGS << ' -Werror ' $CFLAGS << ' -Werror '
$LDFLAGS << ' -lssl '
$LDFLAGS << ' -lcrypto '
create_makefile('grpc/grpc') create_makefile('grpc/grpc')

@ -34,7 +34,7 @@ set -ex
export GRPC_CONFIG=${CONFIG:-opt} export GRPC_CONFIG=${CONFIG:-opt}
# change to grpc's ruby directory # change to grpc's ruby directory
cd $(dirname $0)/../../src/ruby cd $(dirname $0)/../..
rm -rf ./tmp rm -rf ./tmp
rake compile:grpc rake compile:grpc

@ -31,6 +31,6 @@
set -ex set -ex
# change to grpc repo root # change to grpc repo root
cd $(dirname $0)/../../src/ruby cd $(dirname $0)/../..
rake rake

Loading…
Cancel
Save