ffi-inline 0.0.4 → 0.0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ffi/inline/compilers/gcc.rb +42 -40
- data/lib/ffi/inline/compilers/tcc.rb +43 -40
- data/lib/ffi/inline/version.rb +1 -1
- data/spec/inliner_spec.rb +4 -9
- metadata +3 -3
@@ -11,57 +11,59 @@
|
|
11
11
|
module FFI; module Inline
|
12
12
|
|
13
13
|
Compiler.define :gcc do
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def exists?
|
15
|
+
`gcc -v 2>&1'`; $?.success?
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def compile (code, libraries = [])
|
19
|
+
@code = code
|
20
|
+
@libraries = libraries
|
21
21
|
|
22
|
-
|
22
|
+
return output if File.exists?(output)
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
cmd = if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
|
25
|
+
"sh -c '#{ldshared} #{ENV['CFLAGS']} -o #{output.shellescape} #{input.shellescape} #{libs}' 2>>#{log.shellescape}"
|
26
|
+
else
|
27
|
+
"#{ldshared} #{ENV['CFLAGS']} -o #{output.shellescape} #{input.shellescape} #{libs} 2>>#{log.shellescape}"
|
28
|
+
end
|
29
|
+
File.write(log, cmd + "\n")
|
30
|
+
unless system(cmd)
|
31
|
+
raise CompilationError.new(log)
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
+
output
|
35
|
+
end
|
34
36
|
|
35
37
|
private
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
def digest
|
39
|
+
Digest::SHA1.hexdigest(@code + @libraries.to_s + @options.to_s)
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
def input
|
43
|
+
File.join(Inliner.directory, "#{digest}.c").tap {|path|
|
44
|
+
File.open(path, 'w') { |f| f.write(@code) } unless File.exists?(path)
|
45
|
+
}
|
46
|
+
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
def output
|
49
|
+
File.join(Inliner.directory, "#{digest}.#{Compiler::Extension}")
|
50
|
+
end
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
def log
|
53
|
+
File.join(Inliner.directory, "#{digest}.log")
|
54
|
+
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
def ldshared
|
57
|
+
if RbConfig::CONFIG['target_os'] =~ /darwin/
|
58
|
+
"gcc -dynamic -bundle -fPIC #{options} #{ENV['LDFLAGS']}"
|
59
|
+
else
|
60
|
+
"gcc -shared -fPIC #{options} #{ENV['LDFLAGS']}"
|
61
|
+
end
|
62
|
+
end
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
|
64
|
+
def libs
|
65
|
+
@libraries.map { |lib| "-l#{lib}".shellescape }.join(' ')
|
66
|
+
end
|
65
67
|
end
|
66
68
|
|
67
69
|
end; end
|
@@ -11,57 +11,60 @@
|
|
11
11
|
module FFI; module Inline
|
12
12
|
|
13
13
|
Compiler.define :tcc do
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def exists?
|
15
|
+
`tcc -v 2>&1'`; $?.success?
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def compile (code, libraries = [])
|
19
|
+
@code = code
|
20
|
+
@libraries = libraries
|
21
21
|
|
22
|
-
|
22
|
+
return output if File.exists?(output)
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
cmd = if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
|
25
|
+
"sh -c '#{ldshared} #{ENV['CFLAGS']} #{libs} -o #{output.shellescape} #{input.shellescape}' 2>>#{log.shellescape}"
|
26
|
+
else
|
27
|
+
"#{ldshared} #{ENV['CFLAGS']} #{libs} -o #{output.shellescape} #{input.shellescape} 2>>#{log.shellescape}"
|
28
|
+
end
|
29
|
+
File.write(log, cmd + "\n")
|
30
|
+
unless system(cmd)
|
31
|
+
raise CompilationError.new(log)
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
+
output
|
35
|
+
end
|
34
36
|
|
35
37
|
private
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
def digest
|
39
|
+
Digest::SHA1.hexdigest(@code + @libraries.to_s + @options.to_s)
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
def input
|
43
|
+
File.join(Inliner.directory, "#{digest}.c").tap {|path|
|
44
|
+
File.open(path, 'w') { |f| f.write(@code) } unless File.exists?(path)
|
45
|
+
}
|
46
|
+
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
def output
|
49
|
+
File.join(Inliner.directory, "#{digest}.#{Compiler::Extension}")
|
50
|
+
end
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
def log
|
53
|
+
File.join(Inliner.directory, "#{digest}.log")
|
54
|
+
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
def ldshared
|
57
|
+
if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
|
58
|
+
"tcc -rdynamic -shared -fPIC #{options} #{ENV['LDFLAGS']}"
|
59
|
+
else
|
60
|
+
"tcc -shared #{options} #{ENV['LDFLAGS']}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def libs
|
65
|
+
@libraries.map { |lib| "-l#{lib}".shellescape }.join(' ')
|
66
|
+
end
|
61
67
|
|
62
|
-
def libs
|
63
|
-
@libraries.map { |lib| "-l#{lib}".shellescape }.join(' ')
|
64
|
-
end
|
65
68
|
end
|
66
69
|
|
67
70
|
end; end
|
data/lib/ffi/inline/version.rb
CHANGED
data/spec/inliner_spec.rb
CHANGED
@@ -115,7 +115,7 @@ describe FFI::Inliner do
|
|
115
115
|
end
|
116
116
|
module Foo
|
117
117
|
inline do |builder|
|
118
|
-
builder.map 'my_struct_t *' =>
|
118
|
+
builder.map 'my_struct_t *' => :pointer
|
119
119
|
|
120
120
|
builder.raw %q{
|
121
121
|
typedef struct {
|
@@ -258,20 +258,15 @@ EOC
|
|
258
258
|
module Foo
|
259
259
|
inline :cpp do |builder|
|
260
260
|
builder.raw %{
|
261
|
-
#include <iostream>
|
262
|
-
#include <string>
|
263
|
-
|
264
|
-
using namespace std;
|
265
|
-
|
266
261
|
class Greeter
|
267
262
|
{
|
268
263
|
public:
|
269
264
|
Greeter();
|
270
|
-
|
265
|
+
const char *say_hello();
|
271
266
|
};
|
272
267
|
|
273
268
|
Greeter::Greeter () { };
|
274
|
-
|
269
|
+
const char *Greeter::say_hello ()
|
275
270
|
{
|
276
271
|
return "Hello foos!";
|
277
272
|
};
|
@@ -281,7 +276,7 @@ EOC
|
|
281
276
|
const char* say_hello () {
|
282
277
|
Greeter greeter;
|
283
278
|
|
284
|
-
return greeter.say_hello()
|
279
|
+
return greeter.say_hello();
|
285
280
|
}
|
286
281
|
}, return: :string
|
287
282
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-inline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.4
|
4
|
+
version: 0.0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project:
|
103
|
-
rubygems_version: 1.8.
|
103
|
+
rubygems_version: 1.8.24
|
104
104
|
signing_key:
|
105
105
|
specification_version: 3
|
106
106
|
summary: Inline C/C++ in Ruby easily and cleanly.
|