Module: Rust
- Defined in:
- lib/rust_require.rb,
lib/rust_require/rustc.rb,
lib/rust_require/types.rb,
lib/rust_require/rust_require.rb,
lib/rust_require/types/string.rb,
lib/rust_require/types/primitives.rb,
lib/rust_require/c_wrapper_generator.rb,
lib/rust_require/c_wrapper_generator.rb,
lib/rust_require/ruby_wrapper_generator.rb
Overview
Libs
Defined Under Namespace
Modules: Types Classes: CWrapperGenerator, RubyWrapperGenerator, Rustc, Slice
Constant Summary collapse
- ALREADY_REQUIRED =
Hash to keep record of already required files
Hash.new(false)
Class Method Summary collapse
-
.require_rust_file(file_path, mod) ⇒ Object
file_path: String (path to .rs file) mod: Module/Class (Module which requires the .rs file).
Class Method Details
.require_rust_file(file_path, mod) ⇒ Object
file_path: String (path to .rs file) mod: Module/Class (Module which requires the .rs file)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 53 54 55 56 57 58 59 60 61 |
# File 'lib/rust_require/rust_require.rb', line 12 def self.require_rust_file(file_path, mod) # type check haha check_file file_path # make the path absolute file_path = File.absolute_path file_path # check if the file was already required by mod return if already_required? [file_path,mod] register_file [file_path,mod] # compute rust crate name # file name without .rs extension crate_name = File.basename(file_path, '.rs') # path of dir containing file_name dir_name = File.dirname(file_path) # in case of ../blabla/mod.rs if crate_name == 'mod' crate_name = dir_name.split("/").last end # create .rust_require/#{file_name} subfolder subdir = create_subfolder(crate_name, dir_name) # TODO: insert check for unmodified input here # location of info.json info_file_path = "#{subdir}/info.json" # Use Rustc to create wrappers and compile the file + wrappers rustc = Rustc.new(file_path) rustc.subdir = subdir rustc.info_file_path = info_file_path rustc.output_path = "#{subdir}/lib#{File.basename(file_path, '.rs')}.so" info_file = rustc.create_wrapper rustc.compile # Use RubyWrapperGenerator to make items from the compiled # lib available in mod gen = RubyWrapperGenerator.new gen.info_file = info_file gen.rust_lib = rustc.output_path gen.include_lib(mod) true #explicit return value end |