Class: FFI::Compiler::CompileTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/ffi-compiler/compile_task.rb

Direct Known Subclasses

Task

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) {|_self| ... } ⇒ CompileTask

Returns a new instance of CompileTask.

Yields:

  • (_self)

Yield Parameters:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ffi-compiler/compile_task.rb', line 17

def initialize(name)
  @name = File.basename(name)
  @ext_dir = File.dirname(name)
  @defines = []
  @include_paths = []
  @library_paths = []
  @libraries = []
  @headers = []
  @functions = []
  @cflags = DEFAULT_CFLAGS.dup
  @cxxflags = DEFAULT_CFLAGS.dup
  @ldflags = DEFAULT_LDFLAGS.dup
  @libs = []
  @platform = Platform.system
  @exports = []

  yield self if block_given?
  define_task!
end

Instance Attribute Details

#cflagsObject (readonly)

Returns the value of attribute cflags.



15
16
17
# File 'lib/ffi-compiler/compile_task.rb', line 15

def cflags
  @cflags
end

#cxxflagsObject (readonly)

Returns the value of attribute cxxflags.



15
16
17
# File 'lib/ffi-compiler/compile_task.rb', line 15

def cxxflags
  @cxxflags
end

#ldflagsObject (readonly)

Returns the value of attribute ldflags.



15
16
17
# File 'lib/ffi-compiler/compile_task.rb', line 15

def ldflags
  @ldflags
end

#libsObject (readonly)

Returns the value of attribute libs.



15
16
17
# File 'lib/ffi-compiler/compile_task.rb', line 15

def libs
  @libs
end

#platformObject (readonly)

Returns the value of attribute platform.



15
16
17
# File 'lib/ffi-compiler/compile_task.rb', line 15

def platform
  @platform
end

Instance Method Details

#export(rb_file) ⇒ Object



66
67
68
# File 'lib/ffi-compiler/compile_task.rb', line 66

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



62
63
64
# File 'lib/ffi-compiler/compile_task.rb', line 62

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

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ffi-compiler/compile_task.rb', line 37

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

Returns:

  • (Boolean)


50
51
52
# File 'lib/ffi-compiler/compile_task.rb', line 50

def have_header?(header, *paths)
  try_header(header, @include_paths) || try_header(header, paths)
end

#have_library(lib, func = nil, headers = nil, &b) ⇒ Object



58
59
60
# File 'lib/ffi-compiler/compile_task.rb', line 58

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

Returns:

  • (Boolean)


54
55
56
# File 'lib/ffi-compiler/compile_task.rb', line 54

def have_library?(libname, *paths)
  try_library(libname, paths: @library_paths) || try_library(libname, paths: paths)
end