Skip to content

Commit 79b5d32

Browse files
committed
Specs with native extensions passing on MRI, JRuby, and Rubinius.
Added fake_build hook back to extconf.rb
1 parent 443417f commit 79b5d32

File tree

5 files changed

+56
-38
lines changed

5 files changed

+56
-38
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ tmtags
2323
*.sw?
2424
.idea
2525
.rbx/*
26-
lib/*.jar
2726
lib/*.bundle
27+
lib/*.so
28+
lib/*.jar
2829
ext/*.bundle
2930
ext/*.so
3031
ext/*.jar

.travis.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
language: ruby
22
rvm:
3-
- 2.1.0
3+
- 2.1.2
44
- 2.0.0
55
- 1.9.3
66
- ruby-head
77
- jruby-19mode
88
- jruby-head
99
- rbx-2
1010
jdk:
11-
- openjdk7
12-
- openjdk8
13-
- oraclejdk7
1411
- oraclejdk8
1512
branches:
1613
only:
1714
- master
18-
- atomic-reference
1915
matrix:
2016
allow_failures:
2117
- rvm: ruby-head

Rakefile

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ task :bench do
1818
exec "ruby -Ilib -Iext examples/bench_atomic.rb"
1919
end
2020

21+
desc 'Clean up build artifacts'
22+
task :clean do
23+
rm_rf 'pkg/classes'
24+
rm_f 'lib/*.jar'
25+
rm_rf '**/*.{o,so,bundle}'
26+
end
27+
2128
if defined?(JRUBY_VERSION)
2229
require 'ant'
2330

2431
EXTENSION_NAME = 'concurrent_jruby'
2532

2633
directory 'pkg/classes'
2734

28-
desc 'Clean up build artifacts'
29-
task :clean do
30-
rm_rf 'pkg/classes'
31-
rm_rf "lib/#{EXTENSION_NAME}.jar"
32-
end
33-
3435
desc 'Compile the extension'
3536
task :compile => 'pkg/classes' do |t|
3637
ant.javac :srcdir => 'ext', :destdir => t.prerequisites.first,
@@ -51,17 +52,19 @@ elsif use_c_extensions?
5152

5253
require 'rake/extensiontask'
5354

54-
CLEAN.include Rake::FileList['**/*.so', '**/*.bundle', '**/*.o', '**/mkmf.log', '**/Makefile']
55-
5655
spec = Gem::Specification.load('concurrent-ruby.gemspec')
5756
Rake::ExtensionTask.new(EXTENSION_NAME, spec) do |ext|
5857
ext.ext_dir = 'ext'
5958
ext.name = EXTENSION_NAME
6059
ext.source_pattern = "**/*.{h,c,cpp}"
6160
end
6261

62+
task :return_dummy_makefile do
63+
sh "git co ext/Makefile"
64+
end
65+
6366
desc 'Clean, compile, and build the extension from scratch'
64-
task :compile_c => [ :clean, :compile ]
67+
task :compile_c => [ :clean, :compile, :return_dummy_makefile ]
6568

6669
task :irb => [:compile] do
6770
sh "irb -r ./lib/#{EXTENSION_NAME}.bundle -I #{File.join(File.dirname(__FILE__), 'lib')}"
@@ -77,5 +80,5 @@ if defined?(JRUBY_VERSION)
7780
elsif use_c_extensions?
7881
task :default => [:compile_c, :travis_spec]
7982
else
80-
task :default => [:travis_spec]
83+
task :default => [:clean, :travis_spec]
8184
end

ext/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
all:
2+
true
3+
4+
install:
5+
true

ext/extconf.rb

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,58 @@
1+
require 'fileutils'
12
require_relative '../lib/extension_helper'
23

4+
EXTENSION_NAME = 'concurrent_cruby'
5+
36
if defined?(JRUBY_VERSION)
47
puts 'JRuby detected. Pure Java optimizations will be used.'
58
elsif ! use_c_extensions?
69
puts 'C optimizations are only supported on MRI 2.0 and above.'
710
else
811

9-
require 'mkmf'
12+
def fake_build
13+
# http://yorickpeterse.com/articles/hacking-extconf-rb/
14+
FileUtils.touch(File.join(Dir.pwd, EXTENSION_NAME + '.' + RbConfig::CONFIG['DLEXT']))
15+
$makefile_created = true
16+
end
17+
18+
begin
1019

11-
extension_name = 'concurrent_cruby'
12-
dir_config(extension_name)
20+
require 'mkmf'
21+
dir_config(EXTENSION_NAME)
1322

14-
have_header "libkern/OSAtomic.h"
23+
have_header "libkern/OSAtomic.h"
1524

16-
def compiler_is_gcc
17-
if CONFIG["GCC"] && CONFIG["GCC"] != ""
18-
return true
19-
elsif ( # This could stand to be more generic... but I am afraid.
20-
CONFIG["CC"] =~ /\bgcc\b/
21-
)
22-
return true
25+
def compiler_is_gcc
26+
if CONFIG["GCC"] && CONFIG["GCC"] != ""
27+
return true
28+
elsif ( # This could stand to be more generic... but I am afraid.
29+
CONFIG["CC"] =~ /\bgcc\b/
30+
)
31+
return true
32+
end
33+
return false
2334
end
24-
return false
25-
end
2635

27-
if compiler_is_gcc
28-
case CONFIG["arch"]
29-
when /mswin32|mingw|solaris/
30-
$CFLAGS += " -march=native"
31-
when 'i686-linux'
32-
$CFLAGS += " -march=i686"
36+
if compiler_is_gcc
37+
case CONFIG["arch"]
38+
when /mswin32|mingw|solaris/
39+
$CFLAGS += " -march=native"
40+
when 'i686-linux'
41+
$CFLAGS += " -march=i686"
42+
end
3343
end
34-
end
3544

36-
try_run(<<CODE,$CFLAGS) && ($defs << '-DHAVE_GCC_CAS')
45+
try_run(<<CODE,$CFLAGS) && ($defs << '-DHAVE_GCC_CAS')
3746
int main() {
3847
int i = 1;
3948
__sync_bool_compare_and_swap(&i, 1, 4);
4049
return (i != 4);
4150
}
4251
CODE
4352

44-
create_makefile(extension_name)
53+
create_makefile(EXTENSION_NAME)
54+
rescue
55+
puts 'C optimizations are not supported on this version of Ruby.'
56+
fake_build
57+
end
4558
end

0 commit comments

Comments
 (0)