From 0bb147b4f309becb0b3f970697e7940ad6f68b96 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Sat, 14 Nov 2009 09:27:24 +0100 Subject: [PATCH] Fix Issue #2: TCC generated shared libraries do not work in Windows --- .gitignore | 1 + lib/ffi-inliner/inliner.rb | 6 +++++- spec/ffi-inliner/inliner_spec.rb | 19 +++++++++---------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 9923aad..398f918 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ ^# pkg announcement.txt +cache diff --git a/lib/ffi-inliner/inliner.rb b/lib/ffi-inliner/inliner.rb index 0ca9547..db62feb 100644 --- a/lib/ffi-inliner/inliner.rb +++ b/lib/ffi-inliner/inliner.rb @@ -112,7 +112,11 @@ def exists? IO.popen("#{@progname}") { |f| f.gets } ? true : false end def cmd - "tcc -shared #{libs} -o \"#{@fm.so_fn}\" \"#{@fm.c_fn}\" 2>\"#{@fm.log_fn}\"" + if Config::CONFIG['target_os'] =~ /mswin|mingw/ + "tcc -rdynamic -shared #{libs} -o \"#{@fm.so_fn}\" \"#{@fm.c_fn}\" 2>\"#{@fm.log_fn}\"" + else + "tcc -shared #{libs} -o \"#{@fm.so_fn}\" \"#{@fm.c_fn}\" 2>\"#{@fm.log_fn}\"" + end end end end diff --git a/spec/ffi-inliner/inliner_spec.rb b/spec/ffi-inliner/inliner_spec.rb index aeb4071..a3ba71a 100644 --- a/spec/ffi-inliner/inliner_spec.rb +++ b/spec/ffi-inliner/inliner_spec.rb @@ -159,16 +159,15 @@ module Foo end end end -# it 'should use different compiler as specified in the configuration block' do -# tcc = mock('tcc', :exists? => true, :compile => nil) -# Inliner::Compilers::TCC.should_receive(:new).and_return(tcc) -# module Foo -# inline do |builder| -# builder.code = "int func_1() { return 0; }" -# builder.compiler = Inliner::Compilers::TCC -# end -# end -# end + it 'should use different compiler as specified in the configuration block' do + module Foo + inline do |builder| + builder.compiler Inliner::Compilers::TCC + builder.c "int func_1() { return 1 + 1; }" + end + end + Foo.func_1.should == 2 + end # it 'should be configured using the hash form' do # tcc = mock('tcc', :exists? => true, :compile => nil)