Skip to content
Browse files

Add basic C extension

Signed-off-by: Alex Coles <alex@alexbcoles.com>
  • Loading branch information...
1 parent e5fc864 commit e305ba46246c616eb0ccb237460e18bae1d4b661 @myabc committed Apr 8, 2012
Showing with 18 additions and 2 deletions.
  1. +11 −2 ext/Rakefile
  2. +2 −0 ext/jrubytesting/extconf.rb
  3. +5 −0 ext/jrubytesting/test_jruby_library.c
View
13 ext/Rakefile
@@ -1,4 +1,4 @@
-task :simple_compile do
+task :java_compile do
# Pick the right class path, depending if we're using an rvm installed JRuby
jruby_cpath = ENV['MY_RUBY_HOME'] || ENV['JRUBY_HOME']
raise 'MY_RUBY_HOME or JRUBY_HOME are not set' unless jruby_cpath
@@ -9,4 +9,13 @@ task :simple_compile do
sh %(jar cf ../lib/jrubytesting/test_jruby_library.jar -C java jrubytesting/TestJrubyLibraryService.class)
puts
end
-task :default => :simple_compile
+
+task :c_compile do
+ ruby './jrubytesting/extconf.rb'
+end
+
+def is_jruby?
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
+end
+
+task :default => is_jruby? ? :java_compile : :c_compile
View
2 ext/jrubytesting/extconf.rb
@@ -0,0 +1,2 @@
+require 'mkmf'
+create_makefile 'Test'
View
5 ext/jrubytesting/test_jruby_library.c
@@ -0,0 +1,5 @@
+#include <stdio.h>
+
+void Init_test_jruby_library() {
+ printf("Hello from C\n");
+}

0 comments on commit e305ba4

Please sign in to comment.
Something went wrong with that request. Please try again.