From d7e1a10628b87d9437f15ffb44d74499345ba757 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 18 Dec 2015 11:16:16 -0800 Subject: Bundled C core with Ruby library --- .rspec | 6 ++++ Gemfile | 4 +++ Rakefile | 63 +++++++++++++++++++++++++++++++++++++++ grpc.gemspec | 48 ++++++++++++++++++++++++++++++ src/ruby/.rspec | 6 ---- src/ruby/Gemfile | 4 --- src/ruby/Rakefile | 58 ------------------------------------ src/ruby/ext/grpc/extconf.rb | 68 +++++++++++++++---------------------------- src/ruby/grpc.gemspec | 45 ---------------------------- tools/run_tests/build_ruby.sh | 2 +- tools/run_tests/run_ruby.sh | 2 +- 11 files changed, 147 insertions(+), 159 deletions(-) create mode 100755 .rspec create mode 100755 Gemfile create mode 100755 Rakefile create mode 100755 grpc.gemspec delete mode 100755 src/ruby/.rspec delete mode 100755 src/ruby/Gemfile delete mode 100755 src/ruby/Rakefile delete mode 100755 src/ruby/grpc.gemspec diff --git a/.rspec b/.rspec new file mode 100755 index 0000000000..b94d663c9a --- /dev/null +++ b/.rspec @@ -0,0 +1,6 @@ +-Isrc/ruby +-Isrc/ruby/pb +--backtrace +--require spec/spec_helper +--format documentation +--color diff --git a/Gemfile b/Gemfile new file mode 100755 index 0000000000..597a7d4f4b --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in grpc.gemspec +gemspec diff --git a/Rakefile b/Rakefile new file mode 100755 index 0000000000..079df67996 --- /dev/null +++ b/Rakefile @@ -0,0 +1,63 @@ +# -*- ruby -*- +require 'rake/extensiontask' +require 'rspec/core/rake_task' +require 'rubocop/rake_task' +require 'bundler/gem_tasks' + +# Add rubocop style checking tasks +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 +Rake::ExtensionTask.new 'grpc' do |ext| + ext.source_pattern = '**/*.{c,h}' + ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc') + ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc') +end + +# Define the test suites +SPEC_SUITES = [ + { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) }, + { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic), + tags: ['~bidi', '~server'] }, + { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic), + tag: 'bidi' }, + { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic), + tag: 'server' }, + { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) } +] +namespace :suite do + SPEC_SUITES.each do |suite| + desc "Run all specs in the #{suite[:title]} spec suite" + RSpec::Core::RakeTask.new(suite[:id]) do |t| + ENV['COVERAGE_NAME'] = suite[:id].to_s + spec_files = [] + suite[:files].each { |f| spec_files += Dir[f] } if suite[:files] + + if suite[:dir] + suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] } + end + helper = 'src/ruby/spec/spec_helper.rb' + spec_files << helper unless spec_files.include?(helper) + + t.pattern = spec_files + t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag] + if suite[:tags] + t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ') + end + end + end +end + +# Define dependencies between the suites. +task 'suite:wrapper' => [:compile, :rubocop] +task 'suite:idiomatic' => 'suite:wrapper' +task 'suite:bidi' => 'suite:wrapper' +task 'suite:server' => 'suite:wrapper' +task 'suite:pb' => 'suite:server' + +desc 'Compiles the gRPC extension then runs all the tests' +task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server'] +task default: :all diff --git a/grpc.gemspec b/grpc.gemspec new file mode 100755 index 0000000000..5526dbeb4f --- /dev/null +++ b/grpc.gemspec @@ -0,0 +1,48 @@ +# -*- ruby -*- +# encoding: utf-8 +$LOAD_PATH.push File.expand_path('../src/ruby/lib', __FILE__) +require 'grpc/version' + +Gem::Specification.new do |s| + s.name = 'grpc' + s.version = GRPC::VERSION + s.authors = ['gRPC Authors'] + s.email = 'temiola@google.com' + s.homepage = 'https://github.com/google/grpc/tree/master/src/ruby' + s.summary = 'GRPC system in Ruby' + s.description = 'Send RPCs from Ruby using GRPC' + s.license = 'BSD-3-Clause' + + s.required_ruby_version = '>= 2.0.0' + s.requirements << 'libgrpc ~> 0.11.0 needs to be installed' + + s.files = %w( Rakefile Makefile ) + s.files += Dir.glob('src/ruby/bin/**/*') + s.files += Dir.glob('src/ruby/ext/**/*') + s.files += Dir.glob('src/ruby/lib/**/*') + s.files += Dir.glob('src/ruby/pb/**/*') + 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| + s.executables += ["#{b}_client.rb", "#{b}_server.rb"] + end + s.executables += %w(grpc_ruby_interop_client grpc_ruby_interop_server) + s.require_paths = %w( src/ruby/bin src/ruby/lib src/ruby/pb ) + s.platform = Gem::Platform::RUBY + + s.add_dependency 'google-protobuf', '~> 3.0.0alpha.1.1' + s.add_dependency 'googleauth', '~> 0.4' + + s.add_development_dependency 'bundler', '~> 1.9' + s.add_development_dependency 'logging', '~> 2.0' + s.add_development_dependency 'simplecov', '~> 0.9' + s.add_development_dependency 'rake', '~> 10.4' + s.add_development_dependency 'rake-compiler', '~> 0.9' + s.add_development_dependency 'rspec', '~> 3.2' + s.add_development_dependency 'rubocop', '~> 0.30.0' + s.add_development_dependency 'signet', '~>0.6.0' + + s.extensions = %w(src/ruby/ext/grpc/extconf.rb) +end diff --git a/src/ruby/.rspec b/src/ruby/.rspec deleted file mode 100755 index efeee2c1d2..0000000000 --- a/src/ruby/.rspec +++ /dev/null @@ -1,6 +0,0 @@ --I. --Ipb ---backtrace ---require spec_helper ---format documentation ---color diff --git a/src/ruby/Gemfile b/src/ruby/Gemfile deleted file mode 100755 index 597a7d4f4b..0000000000 --- a/src/ruby/Gemfile +++ /dev/null @@ -1,4 +0,0 @@ -source 'https://rubygems.org' - -# Specify your gem's dependencies in grpc.gemspec -gemspec diff --git a/src/ruby/Rakefile b/src/ruby/Rakefile deleted file mode 100755 index cc7832b12d..0000000000 --- a/src/ruby/Rakefile +++ /dev/null @@ -1,58 +0,0 @@ -# -*- ruby -*- -require 'rake/extensiontask' -require 'rspec/core/rake_task' -require 'rubocop/rake_task' -require 'bundler/gem_tasks' - -# Add rubocop style checking tasks -RuboCop::RakeTask.new - -# Add the extension compiler task -Rake::ExtensionTask.new 'grpc' do |ext| - ext.lib_dir = File.join('lib', 'grpc') -end - -# Define the test suites -SPEC_SUITES = [ - { id: :wrapper, title: 'wrapper layer', files: %w(spec/*.rb) }, - { id: :idiomatic, title: 'idiomatic layer', dir: %w(spec/generic), - tags: ['~bidi', '~server'] }, - { id: :bidi, title: 'bidi tests', dir: %w(spec/generic), - tag: 'bidi' }, - { id: :server, title: 'rpc server thread tests', dir: %w(spec/generic), - tag: 'server' }, - { id: :pb, title: 'protobuf service tests', dir: %w(spec/pb) } -] -namespace :suite do - SPEC_SUITES.each do |suite| - desc "Run all specs in the #{suite[:title]} spec suite" - RSpec::Core::RakeTask.new(suite[:id]) do |t| - ENV['COVERAGE_NAME'] = suite[:id].to_s - spec_files = [] - suite[:files].each { |f| spec_files += Dir[f] } if suite[:files] - - if suite[:dir] - suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] } - end - helper = 'spec/spec_helper.rb' - spec_files << helper unless spec_files.include?(helper) - - t.pattern = spec_files - t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag] - if suite[:tags] - t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ') - end - end - end -end - -# Define dependencies between the suites. -task 'suite:wrapper' => [:compile, :rubocop] -task 'suite:idiomatic' => 'suite:wrapper' -task 'suite:bidi' => 'suite:wrapper' -task 'suite:server' => 'suite:wrapper' -task 'suite:pb' => 'suite:server' - -desc 'Compiles the gRPC extension then runs all the tests' -task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server'] -task default: :all diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index db9385e961..018353ce5d 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -54,53 +54,30 @@ LIB_DIRS = [ LIBDIR ] -def check_grpc_root - grpc_root = ENV['GRPC_ROOT'] - if grpc_root.nil? - r = 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 +fail 'libdl not found' unless have_library('dl', 'dlopen') +fail 'zlib not found' unless have_library('z', 'inflate') + +grpc_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..')) -grpc_pkg_config = system('pkg-config --exists grpc') +grpc_config = ENV['GRPC_CONFIG'] || 'opt' -if grpc_pkg_config - $CFLAGS << ' ' + `pkg-config --static --cflags grpc`.strip + ' ' - $LDFLAGS << ' ' + `pkg-config --static --libs grpc`.strip + ' ' +if ENV.key?('GRPC_LIB_DIR') + grpc_lib_dir = File.join(grpc_root, ENV['GRPC_LIB_DIR']) else - dir_config('grpc', HEADER_DIRS, LIB_DIRS) - fail 'libdl not found' unless have_library('dl', 'dlopen') - fail 'zlib not found' unless have_library('z', 'inflate') - begin - fail 'Fail' unless have_library('gpr', 'gpr_now') - fail 'Fail' unless have_library('grpc', 'grpc_channel_destroy') - rescue - # Check to see if GRPC_ROOT is defined or available - grpc_root = check_grpc_root - - # Stop if there is still no grpc_root - exit 1 if grpc_root.nil? - - grpc_config = ENV['GRPC_CONFIG'] || 'opt' - 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 + 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 << ' ' + File.join(grpc_lib_dir, 'libgrpc.a') +$LDFLAGS << ' ' + File.join(grpc_lib_dir, 'libgpr.a') +if grpc_config == 'gcov' + $CFLAGS << ' -O0 -fprofile-arcs -ftest-coverage' + $LDFLAGS << ' -fprofile-arcs -ftest-coverage -rdynamic' end $CFLAGS << ' -std=c99 ' @@ -109,4 +86,7 @@ $CFLAGS << ' -Wextra ' $CFLAGS << ' -pedantic ' $CFLAGS << ' -Werror ' +$LDFLAGS << ' -lssl ' +$LDFLAGS << ' -lcrypto ' + create_makefile('grpc/grpc') diff --git a/src/ruby/grpc.gemspec b/src/ruby/grpc.gemspec deleted file mode 100755 index 363abe9a46..0000000000 --- a/src/ruby/grpc.gemspec +++ /dev/null @@ -1,45 +0,0 @@ -# -*- ruby -*- -# encoding: utf-8 -$LOAD_PATH.push File.expand_path('../lib', __FILE__) -require 'grpc/version' - -Gem::Specification.new do |s| - s.name = 'grpc' - s.version = GRPC::VERSION - s.authors = ['gRPC Authors'] - s.email = 'temiola@google.com' - s.homepage = 'https://github.com/google/grpc/tree/master/src/ruby' - s.summary = 'GRPC system in Ruby' - s.description = 'Send RPCs from Ruby using GRPC' - s.license = 'BSD-3-Clause' - - s.required_ruby_version = '>= 2.0.0' - s.requirements << 'libgrpc ~> 0.11.0 needs to be installed' - - s.files = %w( Rakefile ) - s.files += Dir.glob('bin/**/*') - s.files += Dir.glob('ext/**/*') - s.files += Dir.glob('lib/**/*') - s.files += Dir.glob('pb/**/*') - s.test_files = Dir.glob('spec/**/*') - %w(math noproto).each do |b| - s.executables += ["#{b}_client.rb", "#{b}_server.rb"] - end - s.executables += %w(grpc_ruby_interop_client grpc_ruby_interop_server) - s.require_paths = %w( bin lib pb ) - s.platform = Gem::Platform::RUBY - - s.add_dependency 'google-protobuf', '~> 3.0.0alpha.1.1' - s.add_dependency 'googleauth', '~> 0.4' - - s.add_development_dependency 'bundler', '~> 1.9' - s.add_development_dependency 'logging', '~> 2.0' - s.add_development_dependency 'simplecov', '~> 0.9' - s.add_development_dependency 'rake', '~> 10.4' - s.add_development_dependency 'rake-compiler', '~> 0.9' - s.add_development_dependency 'rspec', '~> 3.2' - s.add_development_dependency 'rubocop', '~> 0.30.0' - s.add_development_dependency 'signet', '~>0.6.0' - - s.extensions = %w(ext/grpc/extconf.rb) -end diff --git a/tools/run_tests/build_ruby.sh b/tools/run_tests/build_ruby.sh index 6d23c316c5..8acb40dc62 100755 --- a/tools/run_tests/build_ruby.sh +++ b/tools/run_tests/build_ruby.sh @@ -34,7 +34,7 @@ set -ex export GRPC_CONFIG=${CONFIG:-opt} # change to grpc's ruby directory -cd $(dirname $0)/../../src/ruby +cd $(dirname $0)/../.. rm -rf ./tmp rake compile:grpc diff --git a/tools/run_tests/run_ruby.sh b/tools/run_tests/run_ruby.sh index b82ce52af3..73a84ac361 100755 --- a/tools/run_tests/run_ruby.sh +++ b/tools/run_tests/run_ruby.sh @@ -31,6 +31,6 @@ set -ex # change to grpc repo root -cd $(dirname $0)/../../src/ruby +cd $(dirname $0)/../.. rake -- cgit v1.2.3