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:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ffi-compiler/compile_task.rb', line 45

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(shellsplit(ENV['CFLAGS']) || DEFAULT_CFLAGS.dup)
  @cxxflags = Flags.new(shellsplit(ENV['CXXFLAGS']) || DEFAULT_CFLAGS.dup)
  @ldflags = Flags.new(shellsplit(ENV['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.



42
43
44
# File 'lib/ffi-compiler/compile_task.rb', line 42

def cflags
  @cflags
end

#cxxflagsObject (readonly)

Returns the value of attribute cxxflags.



42
43
44
# File 'lib/ffi-compiler/compile_task.rb', line 42

def cxxflags
  @cxxflags
end

#excludeObject

Returns the value of attribute exclude.



43
44
45
# File 'lib/ffi-compiler/compile_task.rb', line 43

def exclude
  @exclude
end

#ext_dirObject

Returns the value of attribute ext_dir.



43
44
45
# File 'lib/ffi-compiler/compile_task.rb', line 43

def ext_dir
  @ext_dir
end

#ldflagsObject (readonly)

Returns the value of attribute ldflags.



42
43
44
# File 'lib/ffi-compiler/compile_task.rb', line 42

def ldflags
  @ldflags
end

#libsObject (readonly)

Returns the value of attribute libs.



42
43
44
# File 'lib/ffi-compiler/compile_task.rb', line 42

def libs
  @libs
end

#nameObject

Returns the value of attribute name.



43
44
45
# File 'lib/ffi-compiler/compile_task.rb', line 43

def name
  @name
end

#platformObject (readonly)

Returns the value of attribute platform.



42
43
44
# File 'lib/ffi-compiler/compile_task.rb', line 42

def platform
  @platform
end

#source_dirsObject

Returns the value of attribute source_dirs.



43
44
45
# File 'lib/ffi-compiler/compile_task.rb', line 43

def source_dirs
  @source_dirs
end

Instance Method Details

#add_define(name, value = 1) ⇒ Object



71
72
73
# File 'lib/ffi-compiler/compile_task.rb', line 71

def add_define(name, value=1)
  @defines << "-D#{name}=#{value}"
end

#add_include_path(path) ⇒ Object



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

def add_include_path(path)
  @include_paths << path
end

#export(rb_file) ⇒ Object



104
105
106
# File 'lib/ffi-compiler/compile_task.rb', line 104

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



100
101
102
# File 'lib/ffi-compiler/compile_task.rb', line 100

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)


75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ffi-compiler/compile_task.rb', line 75

def have_func?(func)
  main = "extern void \#{func}();\nint main(int argc, char **argv) { \#{func}(); return 0; }\n"

  if try_compile(main)
    @functions << func
    return true
  end
  false
end

#have_header?(header, *paths) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/ffi-compiler/compile_task.rb', line 88

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

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



96
97
98
# File 'lib/ffi-compiler/compile_task.rb', line 96

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)


92
93
94
# File 'lib/ffi-compiler/compile_task.rb', line 92

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