rust_require 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/source_analyzer/lib/libsource_analyzer.so +0 -0
- data/lib/rust_require/c_wrapper_generator.rb +1 -1
- data/lib/rust_require/ruby_wrapper_generator.rb +17 -1
- data/lib/rust_require/rustc.rb +4 -4
- data/lib/rust_require/types/string.rb +16 -1
- data/lib/rust_require/version.rb +1 -1
- data/lib/rust_require.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a3163feda277069a1e4aaaebc61c95fb3e8f851
|
4
|
+
data.tar.gz: df216541319d78028d4bb3f63dd57a99ec7684d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 439bcf99dbcd0f22c975b91c2359bc79498ca2fe0ca73e8c1d95012bfa36777f85cfb212d163d96570ad47dbc6b189733444a797415871a5cf705a4b50295a92
|
7
|
+
data.tar.gz: 3a56fc6b74bf27b9d9c254486638a8189f7c44e24665f1b41f6afb2b309a56533c14f42dbfbc1b9b825630dbf7769af5d5fdecaf2590ca01fb47dcaa347bc2c8
|
Binary file
|
@@ -27,7 +27,7 @@ module Rust
|
|
27
27
|
w << generate_fns(mod['fn_headers'], submod_string)
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
# Generates wrapper fns for fn_headers (String)
|
31
31
|
def generate_fns(fn_headers, submod_string)
|
32
32
|
fn_headers.map do |fn|
|
33
33
|
WrapperFn.new(submod_string + fn['name'], fn['inputs'], fn['output']).to_s
|
@@ -28,9 +28,10 @@ module Rust
|
|
28
28
|
end
|
29
29
|
|
30
30
|
attach_fns(rust_module['fn_headers'], mod, mod_string)
|
31
|
+
attach_structs(rust_module['structs'], mod)
|
31
32
|
end
|
32
33
|
|
33
|
-
# attaches
|
34
|
+
# attaches fns via FFI to mod
|
34
35
|
def attach_fns(fn_headers, mod, mod_string)
|
35
36
|
# add ffi and the rust lib to mod
|
36
37
|
mod.extend FFI::Library
|
@@ -68,5 +69,20 @@ module Rust
|
|
68
69
|
end
|
69
70
|
end
|
70
71
|
end
|
72
|
+
|
73
|
+
# attaches structs via FFI to mod
|
74
|
+
def attach_structs(struct_defs, mod)
|
75
|
+
struct_defs.each do |s|
|
76
|
+
fields = s['fields'].map do |name, type|
|
77
|
+
type = Rust::Types.find_type(type)
|
78
|
+
[name.to_sym, type.ffi_output_type]
|
79
|
+
end.flatten
|
80
|
+
|
81
|
+
struct = Class.new(FFI::Struct)
|
82
|
+
struct.layout *fields
|
83
|
+
|
84
|
+
mod.const_set(s['name'], struct)
|
85
|
+
end
|
86
|
+
end
|
71
87
|
end
|
72
88
|
end
|
data/lib/rust_require/rustc.rb
CHANGED
@@ -5,7 +5,7 @@ module Rust
|
|
5
5
|
SOURCE_ANALYZER = Gem::Specification.find_by_name('rust_require').full_gem_path + '/ext/source_analyzer/lib/libsource_analyzer.so'
|
6
6
|
|
7
7
|
# default rustc command
|
8
|
-
RUSTC_CMD = 'rustc --crate-type dylib -A dead_code'
|
8
|
+
RUSTC_CMD = 'rustc --crate-type dylib -A dead_code -A unused_features'
|
9
9
|
|
10
10
|
# @output_path: output path for library generated by Rustc
|
11
11
|
attr_accessor :output_path
|
@@ -35,9 +35,9 @@ module Rust
|
|
35
35
|
gen = CWrapperGenerator.new(info_file)
|
36
36
|
|
37
37
|
File.open(@tempfile, "w+") do |f|
|
38
|
-
# add necessary extern crate definitions
|
38
|
+
# add necessary extern crate definitions
|
39
39
|
f << <<-SRC
|
40
|
-
|
40
|
+
#![feature(alloc)]
|
41
41
|
SRC
|
42
42
|
|
43
43
|
# add the actual file content
|
@@ -70,7 +70,7 @@ module Rust
|
|
70
70
|
File.open(@input_path, "r") { |input| f << input.read }
|
71
71
|
end
|
72
72
|
|
73
|
-
# use the lint to just parse the file (no
|
73
|
+
# use the lint to just parse the file (no code generation)
|
74
74
|
print `RUST_REQUIRE_FILE=#{@info_file_path} #{RUSTC_CMD} -Z no-trans -L #{File.dirname(@input_path)} -L #{File.dirname(SOURCE_ANALYZER)} #{@tempfile}`
|
75
75
|
raise "rust compiler error" if $? != 0
|
76
76
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# deactivated for now, maybe reactivated later with explicit conversion
|
2
|
+
|
1
3
|
module Rust
|
2
4
|
module Types
|
3
5
|
class String < Type
|
@@ -17,7 +19,19 @@ module Rust
|
|
17
19
|
<<-CODE
|
18
20
|
{
|
19
21
|
let mut #{name} = #{name};
|
20
|
-
|
22
|
+
|
23
|
+
// deallocate unused capacity if any
|
24
|
+
if #{name}.len() != #{name}.capacity() {
|
25
|
+
unsafe {
|
26
|
+
let ptr = #{name}.as_mut_vec().as_mut_ptr();
|
27
|
+
std::rt::heap::deallocate(
|
28
|
+
ptr.offset(#{name}.len() as isize),
|
29
|
+
#{name}.capacity() - #{name}.len(),
|
30
|
+
std::mem::min_align_of::<u8>()
|
31
|
+
);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
21
35
|
let tuple = (#{name}.as_ptr(), #{name}.len());
|
22
36
|
std::mem::forget(#{name});
|
23
37
|
tuple
|
@@ -72,6 +86,7 @@ module Rust
|
|
72
86
|
str.encode!(Encoding::UTF_8)
|
73
87
|
len = str.bytesize
|
74
88
|
start = FFI::MemoryPointer.from_string(str)
|
89
|
+
start.autorelease = false # no GC
|
75
90
|
Rust::Slice.from(start.address, len)
|
76
91
|
end
|
77
92
|
end
|
data/lib/rust_require/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
VERSION = "0.2.
|
1
|
+
VERSION = "0.2.2"
|
data/lib/rust_require.rb
CHANGED
@@ -15,7 +15,9 @@ require_relative 'rust_require/ruby_wrapper_generator.rb'
|
|
15
15
|
|
16
16
|
# Types
|
17
17
|
require_relative 'rust_require/types/primitives.rb'
|
18
|
-
|
18
|
+
|
19
|
+
# deactivated for now, maybe reactivated later with explicit conversion
|
20
|
+
# require_relative 'rust_require/types/string.rb'
|
19
21
|
|
20
22
|
class Module
|
21
23
|
def rust_require(file)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rust_require
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Lackner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|