Class: Rust::Rustc
- Inherits:
-
Object
- Object
- Rust::Rustc
- Defined in:
- lib/rust_require/rustc.rb
Overview
A Wrapper to use rustc
Constant Summary collapse
- SOURCE_ANALYZER =
Path of rustc lint plugin to gather information about .rs files
Gem::Specification.find_by_name('rust_require').full_gem_path + '/ext/source_analyzer/lib/libsource_analyzer.so'
- RUSTC_CMD =
default rustc command
'rustc --crate-type dylib -A dead_code -A unused_features'
Instance Attribute Summary collapse
-
#info_file_path ⇒ Object
Returns the value of attribute info_file_path.
-
#output_path ⇒ Object
@output_path: output path for library generated by Rustc.
-
#subdir ⇒ Object
writeonly
Sets the attribute subdir.
Instance Method Summary collapse
-
#compile ⇒ Object
Compiles file @input_path with rustc.
-
#create_wrapper ⇒ Object
creates a c-wrapper for file at @input_path returns info.json, parsed with JSON.
-
#initialize(input) ⇒ Rustc
constructor
input is a String object containing the absolute path to an input file.
Constructor Details
#initialize(input) ⇒ Rustc
input is a String object containing the absolute path to an input file
20 21 22 |
# File 'lib/rust_require/rustc.rb', line 20 def initialize(input) @input_path = input end |
Instance Attribute Details
#info_file_path ⇒ Object
Returns the value of attribute info_file_path.
14 15 16 |
# File 'lib/rust_require/rustc.rb', line 14 def info_file_path @info_file_path end |
#output_path ⇒ Object
@output_path: output path for library generated by Rustc
11 12 13 |
# File 'lib/rust_require/rustc.rb', line 11 def output_path @output_path end |
#subdir=(value) ⇒ Object (writeonly)
Sets the attribute subdir
17 18 19 |
# File 'lib/rust_require/rustc.rb', line 17 def subdir=(value) @subdir = value end |
Instance Method Details
#compile ⇒ Object
Compiles file @input_path with rustc
55 56 57 58 59 |
# File 'lib/rust_require/rustc.rb', line 55 def compile print `#{RUSTC_CMD} -L #{File.dirname(@input_path)} #{@tempfile} -o #{@output_path}` raise "rust compiler error" if $? != 0 `rm #{@tempfile}` end |
#create_wrapper ⇒ Object
creates a c-wrapper for file at @input_path returns info.json, parsed with JSON
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rust_require/rustc.rb', line 26 def create_wrapper # @input_path with wrappers added @tempfile = "#{File.dirname(@input_path)}/#{File.basename(@input_path, ".*")}_wrapper.rs" analyze_tempfile # parse info.json info_file = JSON.parse File.open(@info_file_path, 'r').read gen = CWrapperGenerator.new(info_file) File.open(@tempfile, "w+") do |f| # add necessary extern crate definitions f << <<-SRC #![feature(alloc)] SRC # add the actual file content File.open(@input_path, "r") { |input| f << input.read } # add wrappers f << gen.generate_wrapper end # return info_file for further use info_file end |