remogatto / ffi-inliner Goto Github PK
View Code? Open in Web Editor NEWMix C in (J)Ruby and gulp it on the fly!
Mix C in (J)Ruby and gulp it on the fly!
It should be nice to migrate from MrBones to a more modern solution like Jeweler or similar.
Currently with this code:
module MyCLib extend Inliner inline do |builder| builder.library 'Winmm2' builder.c 'int func_1() { return 0; }' end end
If you run it the first time it fails (there is no Winmm2 library).
Removing the offending line and running it again and it still fails, though in reality it should recompile and succeed.
It doesn't appear as an option for some reason...I'd be happy to refactor the rakefile to use jeweler if that would help the situation.
-r
When using TCC as compiler for TCC, I found that symbols do not get exported automatically.
Symbols needs to be exported so FFI can find them:
ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]
C:/Users/Luis/.gem/ruby/1.8/gems/ffi-inliner-0.2.2/lib/ffi-inliner/inliner.rb:141:in `build': C:/Users/Luis/.gem/ruby/1.8/gems/ffi-0.5.1-x86-mingw32/lib/ffi/library.rb:77:in `attach_function': Function 'say_hello' not found in [C:/Users/Luis/.ffi-inliner/MyLib_92ce.dll] (FFI::NotFoundError)
from (eval):4:in `build'
from C:/Users/Luis/.gem/ruby/1.8/gems/ffi-inliner-0.2.2/lib/ffi-inliner/inliner.rb:248:in `inline'
from inliner-test.rb:7
Since TCC do not offer a two step compiler linker process, the option is use -rdynamic parameter which is going to export all the symbols defined as inlined functions.
Thank you
## C:/installs/ruby-1.9.1-p243-tweaked/lib/ruby/gems/1.9.1/gems/sane-0.11.0/lib/sane/hash_set_operators_bug_fix.rb:4: warning: method redefined; discarding old ``` # uninitialized constant Inliner::FileUtils ``` C:/installs/ruby-1.9.1-p243-tweaked/lib/ruby/gems/1.9.1/gems/ffi-inliner-0.2.2/lib/ffi-inliner/inliner.rb:254:in `__inliner_make_directory'
With 1.8.6 and 1.9.x, mingw, the gplusplus example yields:
C:\dev\digitalarchive_trunk>ruby -v go_ffi.rb ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32] C:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/gems/1.8/gems/ffi-inliner-0.2.3/lib/ffi-inliner/inliner.rb:76:in `compile': Compile error! See C:/Users/packrd/.ffi-inliner/Foo_e888.log (RuntimeError) from C:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/gems/1.8/gems/ffi-inliner-0.2.3/lib/ffi-inliner/inliner.rb:174:in `build' from C:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/gems/1.8/gems/ffi-inliner-0.2.3/lib/ffi-inliner/inliner.rb:291:in `inline' from go_ffi.rb:5 C:\dev\digitalarchive_trunk>ruby -v go_ffi.rb ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32] C:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/gems/1.8/gems/ffi-inliner-0.2.3/lib/ffi-inliner/inliner.rb:177:in `build': C:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/gems/1.8/ge (LoadError)-x86-mingw32/lib/ffi/library.rb:61:in `ffi_lib': Could not open library 'C:/Users/packrd/.ffi-inliner/Foo_e888.dll': The specified module could not be found. from C:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/gems/1.8/gems/ffi-0.6.3-x86-mingw32/lib/ffi/library.rb:43:in `map' from C:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/gems/1.8/gems/ffi-0.6.3-x86-mingw32/lib/ffi/library.rb:43:in `ffi_lib' from (eval):2:in `build' from C:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/gems/1.8/gems/ffi-inliner-0.2.3/lib/ffi-inliner/inliner.rb:291:in `inline' from go_ffi.rb:5
Not sure exaclty why.
C:\dev\digitalarchive_trunk>cat C:/Users/packrd/.ffi-inliner/Foo_e888.log Access is denied.
Hmm.
c:/ruby18/lib/ruby/gems/1.8/gems/sane-0.9.4/lib/sane/hash_set_operators_bug_fix.rb:4: warning: method redefined; discarding old - ``` # uninitialized constant Inliner::Compilers::GPlusPlus ``` test2.rb:6 builder.use_compiler Inliner::Compilers::GPlusPlus c:/ruby18/lib/ruby/gems/1.8/gems/ffi-inliner-0.2.2/lib/ffi-inliner/inliner.rb:247:in `inline' yield builder if block_given? test2.rb:5
class MyStruct < FFI::Struct
layout :a, :int, :b, :int
end
inline do |builder|
builder.struct MyStruct
builder.c %q{
void inspect_my_struct(my_struct_t *my_struct)
{
printf("a: %d b: %d", my_struct->a, my_struct->b");
}
}
end
perhaps I'm just clueless here, but installing the bones gem seems to need a specific version, perhaps?
(in C:/dev/ruby/ffi-inliner) C:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/gems/1.8/gems/loquacious-1.6.4/lib/loquacious/undefined.rb:87: warning: parenthesize argument(s) for future version rake aborted! undefined method `setup' for Bones:Module C:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile' (See full trace by running task with --trace)
Currently when a C file fails, the log file generated shows error line numbers based on the C file, which don't map easily to the ruby file they came with.
This is a feature request to map them a bit closer.
I believe the pre processor macro desired is something like
#2 "C:/Users/packrd/.ffi-inliner/MyCLib_f925.rb" 2
Though I've never used it before...
module MyCLib extend Inliner inline do |builder| builder.c <<-CODE int func_1() { return 0; } CODE end end
fails to parse for some reason.
module MyCLib extend Inliner inline do |builder| builder.c <<-CODE int func_1() { return 0; } CODE end end
works though.
I tried install gem 'tesseract-ocr', I added 'tesseract-ocr' to Gemfile and ran 'bundle update' with succesful.
When I trying run 'rails console' I have an error as below:
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in require': no such file to load -- ffi/inliner (LoadError) from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in
block in require'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in block in load_dependency' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:in
new_constants_in'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in load_dependency' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in
require'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/tesseract-ocr-0.1.1/lib/tesseract/c.rb:27:in <top (required)>' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in
require'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in block in require' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in
block in load_dependency'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:in new_constants_in' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in
load_dependency'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in require' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/tesseract-ocr-0.1.1/lib/tesseract/api.rb:26:in
<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in require' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in
block in require'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in block in load_dependency' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:in
new_constants_in'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in load_dependency' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in
require'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/tesseract-ocr-0.1.1/lib/tesseract-ocr.rb:25:in <top (required)>' from /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in
require'
from /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in block (2 levels) in require' from /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in
each'
from /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in block in require' from /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in
each'
from /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in require' from /usr/local/rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler.rb:122:in
require'
from /opt/rails_apps/intranet/config/application.rb:7:in <top (required)>' from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands.rb:21:in
require'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands.rb:21:in <top (required)>' from script/rails:6:in
require'
from script/rails:6:in `
What is wrong? I tried run on Windows 7 and Centos 6 - error is the same.
C:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/gems/1.8/gems/ffi-inliner-0.2.3/lib/ffi-inliner/inliner.rb:170: warning: instance variable @libraries not initialized
Seems this does nothing with regard to Winmm?
inline 'int func_1() { return 1; }', :library => 'Winmm'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.