Skip to content

Commit d7e1a10

Browse files
committed
Bundled C core with Ruby library
1 parent 08ae945 commit d7e1a10

File tree

8 files changed

+57
-69
lines changed

8 files changed

+57
-69
lines changed

.rspec

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-Isrc/ruby
2+
-Isrc/ruby/pb
3+
--backtrace
4+
--require spec/spec_helper
5+
--format documentation
6+
--color

src/ruby/Gemfile Gemfile

File renamed without changes.

src/ruby/Rakefile Rakefile

+13-8
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@ require 'rubocop/rake_task'
55
require 'bundler/gem_tasks'
66

77
# Add rubocop style checking tasks
8-
RuboCop::RakeTask.new
8+
RuboCop::RakeTask.new(:rubocop) do |task|
9+
task.options = ['-c', 'src/ruby/.rubocop.yml']
10+
task.patterns = ['src/ruby/{lib,spec}/**/*.rb']
11+
end
912

1013
# Add the extension compiler task
1114
Rake::ExtensionTask.new 'grpc' do |ext|
12-
ext.lib_dir = File.join('lib', 'grpc')
15+
ext.source_pattern = '**/*.{c,h}'
16+
ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc')
17+
ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc')
1318
end
1419

1520
# Define the test suites
1621
SPEC_SUITES = [
17-
{ id: :wrapper, title: 'wrapper layer', files: %w(spec/*.rb) },
18-
{ id: :idiomatic, title: 'idiomatic layer', dir: %w(spec/generic),
22+
{ id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) },
23+
{ id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic),
1924
tags: ['~bidi', '~server'] },
20-
{ id: :bidi, title: 'bidi tests', dir: %w(spec/generic),
25+
{ id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic),
2126
tag: 'bidi' },
22-
{ id: :server, title: 'rpc server thread tests', dir: %w(spec/generic),
27+
{ id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic),
2328
tag: 'server' },
24-
{ id: :pb, title: 'protobuf service tests', dir: %w(spec/pb) }
29+
{ id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) }
2530
]
2631
namespace :suite do
2732
SPEC_SUITES.each do |suite|
@@ -34,7 +39,7 @@ namespace :suite do
3439
if suite[:dir]
3540
suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] }
3641
end
37-
helper = 'spec/spec_helper.rb'
42+
helper = 'src/ruby/spec/spec_helper.rb'
3843
spec_files << helper unless spec_files.include?(helper)
3944

4045
t.pattern = spec_files

src/ruby/grpc.gemspec grpc.gemspec

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- ruby -*-
22
# encoding: utf-8
3-
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.push File.expand_path('../src/ruby/lib', __FILE__)
44
require 'grpc/version'
55

66
Gem::Specification.new do |s|
@@ -16,17 +16,20 @@ Gem::Specification.new do |s|
1616
s.required_ruby_version = '>= 2.0.0'
1717
s.requirements << 'libgrpc ~> 0.11.0 needs to be installed'
1818

19-
s.files = %w( Rakefile )
20-
s.files += Dir.glob('bin/**/*')
21-
s.files += Dir.glob('ext/**/*')
22-
s.files += Dir.glob('lib/**/*')
23-
s.files += Dir.glob('pb/**/*')
24-
s.test_files = Dir.glob('spec/**/*')
19+
s.files = %w( Rakefile Makefile )
20+
s.files += Dir.glob('src/ruby/bin/**/*')
21+
s.files += Dir.glob('src/ruby/ext/**/*')
22+
s.files += Dir.glob('src/ruby/lib/**/*')
23+
s.files += Dir.glob('src/ruby/pb/**/*')
24+
s.files += Dir.glob('include/grpc/**/*')
25+
s.files += Dir.glob('src/core/**/*')
26+
s.test_files = Dir.glob('src/ruby/spec/**/*')
27+
s.bindir = 'src/ruby/bin'
2528
%w(math noproto).each do |b|
2629
s.executables += ["#{b}_client.rb", "#{b}_server.rb"]
2730
end
2831
s.executables += %w(grpc_ruby_interop_client grpc_ruby_interop_server)
29-
s.require_paths = %w( bin lib pb )
32+
s.require_paths = %w( src/ruby/bin src/ruby/lib src/ruby/pb )
3033
s.platform = Gem::Platform::RUBY
3134

3235
s.add_dependency 'google-protobuf', '~> 3.0.0alpha.1.1'
@@ -41,5 +44,5 @@ Gem::Specification.new do |s|
4144
s.add_development_dependency 'rubocop', '~> 0.30.0'
4245
s.add_development_dependency 'signet', '~>0.6.0'
4346

44-
s.extensions = %w(ext/grpc/extconf.rb)
47+
s.extensions = %w(src/ruby/ext/grpc/extconf.rb)
4548
end

src/ruby/.rspec

-6
This file was deleted.

src/ruby/ext/grpc/extconf.rb

+24-44
Original file line numberDiff line numberDiff line change
@@ -54,53 +54,30 @@
5454
LIBDIR
5555
]
5656

57-
def check_grpc_root
58-
grpc_root = ENV['GRPC_ROOT']
59-
if grpc_root.nil?
60-
r = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
61-
grpc_root = r if File.exist?(File.join(r, 'include/grpc/grpc.h'))
62-
end
63-
grpc_root
64-
end
57+
fail 'libdl not found' unless have_library('dl', 'dlopen')
58+
fail 'zlib not found' unless have_library('z', 'inflate')
59+
60+
grpc_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
6561

66-
grpc_pkg_config = system('pkg-config --exists grpc')
62+
grpc_config = ENV['GRPC_CONFIG'] || 'opt'
6763

68-
if grpc_pkg_config
69-
$CFLAGS << ' ' + `pkg-config --static --cflags grpc`.strip + ' '
70-
$LDFLAGS << ' ' + `pkg-config --static --libs grpc`.strip + ' '
64+
if ENV.key?('GRPC_LIB_DIR')
65+
grpc_lib_dir = File.join(grpc_root, ENV['GRPC_LIB_DIR'])
7166
else
72-
dir_config('grpc', HEADER_DIRS, LIB_DIRS)
73-
fail 'libdl not found' unless have_library('dl', 'dlopen')
74-
fail 'zlib not found' unless have_library('z', 'inflate')
75-
begin
76-
fail 'Fail' unless have_library('gpr', 'gpr_now')
77-
fail 'Fail' unless have_library('grpc', 'grpc_channel_destroy')
78-
rescue
79-
# Check to see if GRPC_ROOT is defined or available
80-
grpc_root = check_grpc_root
81-
82-
# Stop if there is still no grpc_root
83-
exit 1 if grpc_root.nil?
84-
85-
grpc_config = ENV['GRPC_CONFIG'] || 'opt'
86-
if ENV.key?('GRPC_LIB_DIR')
87-
grpc_lib_dir = File.join(grpc_root, ENV['GRPC_LIB_DIR'])
88-
else
89-
grpc_lib_dir = File.join(File.join(grpc_root, 'libs'), grpc_config)
90-
end
91-
unless File.exist?(File.join(grpc_lib_dir, 'libgrpc.a'))
92-
print "Building internal gRPC\n"
93-
system("make -C #{grpc_root} static_c CONFIG=#{grpc_config}")
94-
end
95-
$CFLAGS << ' -I' + File.join(grpc_root, 'include')
96-
$LDFLAGS << ' -L' + grpc_lib_dir
97-
if grpc_config == 'gcov'
98-
$CFLAGS << ' -O0 -fprofile-arcs -ftest-coverage'
99-
$LDFLAGS << ' -fprofile-arcs -ftest-coverage -rdynamic'
100-
end
101-
raise 'gpr not found' unless have_library('gpr', 'gpr_now')
102-
raise 'grpc not found' unless have_library('grpc', 'grpc_channel_destroy')
103-
end
67+
grpc_lib_dir = File.join(File.join(grpc_root, 'libs'), grpc_config)
68+
end
69+
70+
unless File.exist?(File.join(grpc_lib_dir, 'libgrpc.a'))
71+
print "Building internal gRPC\n"
72+
system("make -C #{grpc_root} static_c CONFIG=#{grpc_config}")
73+
end
74+
75+
$CFLAGS << ' -I' + File.join(grpc_root, 'include')
76+
$LDFLAGS << ' ' + File.join(grpc_lib_dir, 'libgrpc.a')
77+
$LDFLAGS << ' ' + File.join(grpc_lib_dir, 'libgpr.a')
78+
if grpc_config == 'gcov'
79+
$CFLAGS << ' -O0 -fprofile-arcs -ftest-coverage'
80+
$LDFLAGS << ' -fprofile-arcs -ftest-coverage -rdynamic'
10481
end
10582

10683
$CFLAGS << ' -std=c99 '
@@ -109,4 +86,7 @@ def check_grpc_root
10986
$CFLAGS << ' -pedantic '
11087
$CFLAGS << ' -Werror '
11188

89+
$LDFLAGS << ' -lssl '
90+
$LDFLAGS << ' -lcrypto '
91+
11292
create_makefile('grpc/grpc')

tools/run_tests/build_ruby.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ set -ex
3434
export GRPC_CONFIG=${CONFIG:-opt}
3535

3636
# change to grpc's ruby directory
37-
cd $(dirname $0)/../../src/ruby
37+
cd $(dirname $0)/../..
3838

3939
rm -rf ./tmp
4040
rake compile:grpc

tools/run_tests/run_ruby.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
set -ex
3232

3333
# change to grpc repo root
34-
cd $(dirname $0)/../../src/ruby
34+
cd $(dirname $0)/../..
3535

3636
rake

0 commit comments

Comments
 (0)