Class: FFI::Compiler::CompileTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- FFI::Compiler::CompileTask
- Defined in:
- lib/ffi-compiler/compile_task.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cflags ⇒ Object
readonly
Returns the value of attribute cflags.
-
#cxxflags ⇒ Object
readonly
Returns the value of attribute cxxflags.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#ext_dir ⇒ Object
Returns the value of attribute ext_dir.
-
#ldflags ⇒ Object
readonly
Returns the value of attribute ldflags.
-
#libs ⇒ Object
readonly
Returns the value of attribute libs.
-
#name ⇒ Object
Returns the value of attribute name.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#source_dirs ⇒ Object
Returns the value of attribute source_dirs.
Instance Method Summary collapse
- #add_define(name, value = 1) ⇒ Object
- #add_include_path(path) ⇒ Object
- #export(rb_file) ⇒ Object
- #find_library(lib, func, *paths) ⇒ Object
- #have_func?(func) ⇒ Boolean
- #have_header?(header, *paths) ⇒ Boolean
- #have_library(lib, func = nil, headers = nil, &b) ⇒ Object
- #have_library?(libname, *paths) ⇒ Boolean
-
#initialize(name) {|_self| ... } ⇒ CompileTask
constructor
A new instance of CompileTask.
Constructor Details
#initialize(name) {|_self| ... } ⇒ CompileTask
Returns a new instance of CompileTask.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ffi-compiler/compile_task.rb', line 44 def initialize(name) @name = File.basename(name) @ext_dir = File.dirname(name) @source_dirs = [@ext_dir] @exclude = [] @defines = [] @include_paths = [] @library_paths = [] @libraries = [] @headers = [] @functions = [] @cflags = Flags.new(ENV['CFLAGS']&.shellsplit || DEFAULT_CFLAGS.dup) @cxxflags = Flags.new(ENV['CXXFLAGS']&.shellsplit || DEFAULT_CFLAGS.dup) @ldflags = Flags.new(ENV['LDFLAGS']&.shellsplit || DEFAULT_LDFLAGS.dup) @libs = [] @platform = Platform.system @exports = [] yield self if block_given? define_task! end |
Instance Attribute Details
#cflags ⇒ Object (readonly)
Returns the value of attribute cflags.
41 42 43 |
# File 'lib/ffi-compiler/compile_task.rb', line 41 def cflags @cflags end |
#cxxflags ⇒ Object (readonly)
Returns the value of attribute cxxflags.
41 42 43 |
# File 'lib/ffi-compiler/compile_task.rb', line 41 def cxxflags @cxxflags end |
#exclude ⇒ Object
Returns the value of attribute exclude.
42 43 44 |
# File 'lib/ffi-compiler/compile_task.rb', line 42 def exclude @exclude end |
#ext_dir ⇒ Object
Returns the value of attribute ext_dir.
42 43 44 |
# File 'lib/ffi-compiler/compile_task.rb', line 42 def ext_dir @ext_dir end |
#ldflags ⇒ Object (readonly)
Returns the value of attribute ldflags.
41 42 43 |
# File 'lib/ffi-compiler/compile_task.rb', line 41 def ldflags @ldflags end |
#libs ⇒ Object (readonly)
Returns the value of attribute libs.
41 42 43 |
# File 'lib/ffi-compiler/compile_task.rb', line 41 def libs @libs end |
#name ⇒ Object
Returns the value of attribute name.
42 43 44 |
# File 'lib/ffi-compiler/compile_task.rb', line 42 def name @name end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
41 42 43 |
# File 'lib/ffi-compiler/compile_task.rb', line 41 def platform @platform end |
#source_dirs ⇒ Object
Returns the value of attribute source_dirs.
42 43 44 |
# File 'lib/ffi-compiler/compile_task.rb', line 42 def source_dirs @source_dirs end |
Instance Method Details
#add_define(name, value = 1) ⇒ Object
70 71 72 |
# File 'lib/ffi-compiler/compile_task.rb', line 70 def add_define(name, value=1) @defines << "-D#{name}=#{value}" end |
#add_include_path(path) ⇒ Object
66 67 68 |
# File 'lib/ffi-compiler/compile_task.rb', line 66 def add_include_path(path) @include_paths << path end |
#export(rb_file) ⇒ Object
103 104 105 |
# File 'lib/ffi-compiler/compile_task.rb', line 103 def export(rb_file) @exports << { :rb_file => rb_file, :header => File.join(@ext_dir, File.basename(rb_file).sub(/\.rb$/, '.h')) } end |
#find_library(lib, func, *paths) ⇒ Object
99 100 101 |
# File 'lib/ffi-compiler/compile_task.rb', line 99 def find_library(lib, func, *paths) try_library(lib, function: func, paths: @library_paths) || try_library(libname, function: func, paths: paths) end |
#have_func?(func) ⇒ Boolean
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ffi-compiler/compile_task.rb', line 74 def have_func?(func) main = <<-C_FILE extern void #{func}(); int main(int argc, char **argv) { #{func}(); return 0; } C_FILE if try_compile(main) @functions << func return true end false end |
#have_header?(header, *paths) ⇒ Boolean
87 88 89 |
# File 'lib/ffi-compiler/compile_task.rb', line 87 def have_header?(header, *paths) try_header(header, @include_paths) || try_header(header, paths) end |
#have_library(lib, func = nil, headers = nil, &b) ⇒ Object
95 96 97 |
# File 'lib/ffi-compiler/compile_task.rb', line 95 def have_library(lib, func = nil, headers = nil, &b) try_library(lib, function: func, headers: headers, paths: @library_paths) end |
#have_library?(libname, *paths) ⇒ Boolean
91 92 93 |
# File 'lib/ffi-compiler/compile_task.rb', line 91 def have_library?(libname, *paths) try_library(libname, paths: @library_paths) || try_library(libname, paths: paths) end |