ffi-compiler2 2.0.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/LICENSE +1 -1
- data/ffi-compiler.gemspec +2 -2
- data/lib/ffi-compiler/compile_task.rb +42 -16
- data/lib/ffi-compiler/shell.rb +24 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7298668a9fdd9774299a0e8f7db5f707a5ddfe07dec06fa4386a01bcee7db5a5
|
4
|
+
data.tar.gz: ce654d24c586edaa2dc571d7a71548bd15a64576367ae8b0e0a97df44e29454f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bee061257b683286b3caea10927543ca3d554500facb5f6465710652c23dd0ebbc287ac0e4abed006a6cdc27b5c3eeb1645cda97e325468316d508b89bf6f360
|
7
|
+
data.tar.gz: 98550ca8ca4c4ba8bcb8ccc7b979b8365143037d87169f7ca821d74fe4a61c45d2a969ef21f9d1e92da59e3ffcb8302872b25c657e351224c88860ac0a4eafad
|
data/Gemfile
ADDED
data/LICENSE
CHANGED
@@ -187,7 +187,7 @@
|
|
187
187
|
same "printed page" as the copyright notice for easier
|
188
188
|
identification within third-party archives.
|
189
189
|
|
190
|
-
Copyright
|
190
|
+
Copyright 2020 FFI
|
191
191
|
|
192
192
|
Licensed under the Apache License, Version 2.0 (the "License");
|
193
193
|
you may not use this file except in compliance with the License.
|
data/ffi-compiler.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'ffi-compiler2'
|
3
|
-
s.version = '2.
|
3
|
+
s.version = '2.2.2'
|
4
4
|
s.author = 'Dāvis'
|
5
5
|
s.email = 'davispuh@gmail.com'
|
6
6
|
s.homepage = 'https://gitlab.com/davispuh/ffi-compiler'
|
7
7
|
s.summary = 'Ruby FFI Rakefile generator'
|
8
8
|
s.description = 'Ruby FFI library'
|
9
|
-
s.files = %w(ffi-compiler.gemspec README.md
|
9
|
+
s.files = %w(ffi-compiler.gemspec Gemfile Rakefile README.md LICENSE) + Dir.glob("{lib,spec}/**/*")
|
10
10
|
s.license = 'Apache-2.0'
|
11
11
|
s.required_ruby_version = '>= 1.9'
|
12
12
|
s.add_dependency 'rake'
|
@@ -5,12 +5,38 @@ require 'ffi'
|
|
5
5
|
require 'tmpdir'
|
6
6
|
require 'rbconfig'
|
7
7
|
require_relative 'platform'
|
8
|
+
require_relative 'shell'
|
8
9
|
|
9
10
|
module FFI
|
10
11
|
module Compiler
|
11
12
|
DEFAULT_CFLAGS = %w(-fexceptions -O -fno-omit-frame-pointer -fno-strict-aliasing)
|
12
13
|
DEFAULT_LDFLAGS = %w(-fexceptions)
|
13
14
|
|
15
|
+
class Flags
|
16
|
+
attr_accessor :raw
|
17
|
+
|
18
|
+
def initialize(flags)
|
19
|
+
@flags = flags
|
20
|
+
@raw = true # For backward compatibility
|
21
|
+
end
|
22
|
+
|
23
|
+
def <<(flag)
|
24
|
+
if @raw
|
25
|
+
@flags += shellsplit(flag.to_s)
|
26
|
+
else
|
27
|
+
@flags << flag
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_a
|
32
|
+
@flags
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
shelljoin(@flags)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
14
40
|
class CompileTask < Rake::TaskLib
|
15
41
|
attr_reader :cflags, :cxxflags, :ldflags, :libs, :platform
|
16
42
|
attr_accessor :name, :ext_dir, :source_dirs, :exclude
|
@@ -26,9 +52,9 @@ module FFI
|
|
26
52
|
@libraries = []
|
27
53
|
@headers = []
|
28
54
|
@functions = []
|
29
|
-
@cflags = DEFAULT_CFLAGS.dup
|
30
|
-
@cxxflags = DEFAULT_CFLAGS.dup
|
31
|
-
@ldflags = DEFAULT_LDFLAGS.dup
|
55
|
+
@cflags = Flags.new(shellsplit(ENV['CFLAGS']) || DEFAULT_CFLAGS.dup)
|
56
|
+
@cxxflags = Flags.new(shellsplit(ENV['CXXFLAGS']) || DEFAULT_CFLAGS.dup)
|
57
|
+
@ldflags = Flags.new(shellsplit(ENV['LDFLAGS']) || DEFAULT_LDFLAGS.dup)
|
32
58
|
@libs = []
|
33
59
|
@platform = Platform.system
|
34
60
|
@exports = []
|
@@ -93,7 +119,7 @@ module FFI
|
|
93
119
|
else
|
94
120
|
so_flags << '-shared'
|
95
121
|
end
|
96
|
-
so_flags = so_flags
|
122
|
+
so_flags = shelljoin(so_flags)
|
97
123
|
|
98
124
|
out_dir = "#{@platform.arch}-#{@platform.os}"
|
99
125
|
if @ext_dir != '.'
|
@@ -106,13 +132,13 @@ module FFI
|
|
106
132
|
lib_name = File.join(out_dir, Platform.system.map_library_name(@name))
|
107
133
|
|
108
134
|
iflags = @include_paths.uniq.map { |p| "-I#{p}" }
|
109
|
-
@defines
|
110
|
-
@defines
|
135
|
+
@defines += @functions.uniq.map { |f| "-DHAVE_#{f.upcase}=1" }
|
136
|
+
@defines += @headers.uniq.map { |h| "-DHAVE_#{h.upcase.sub(/\./, '_')}=1" }
|
111
137
|
|
112
|
-
cflags = (@cflags + pic_flags + iflags + @defines)
|
113
|
-
cxxflags = (@cxxflags + @cflags + pic_flags + iflags + @defines)
|
114
|
-
ld_flags = (@library_paths.map { |path| "-L#{path}" } + @ldflags
|
115
|
-
libs = (@libraries.map { |l| "-l#{l}" } + @libs)
|
138
|
+
cflags = shelljoin(@cflags.to_a + pic_flags + iflags + @defines)
|
139
|
+
cxxflags = shelljoin(@cxxflags.to_a + @cflags.to_a + pic_flags + iflags + @defines)
|
140
|
+
ld_flags = shelljoin(@library_paths.map { |path| "-L#{path}" } + @ldflags.to_a)
|
141
|
+
libs = shelljoin(@libraries.map { |l| "-l#{l}" } + @libs)
|
116
142
|
|
117
143
|
src_files = []
|
118
144
|
obj_files = []
|
@@ -130,12 +156,12 @@ module FFI
|
|
130
156
|
obj_file = obj_files[index]
|
131
157
|
if src =~ /\.c$/
|
132
158
|
file obj_file => [ src, File.dirname(obj_file) ] do |t|
|
133
|
-
sh "#{cc} #{cflags} -o #{t.name} -c #{t.prerequisites[0]}"
|
159
|
+
sh "#{cc} #{cflags} -o #{shellescape(t.name)} -c #{shellescape(t.prerequisites[0])}"
|
134
160
|
end
|
135
161
|
|
136
162
|
else
|
137
163
|
file obj_file => [ src, File.dirname(obj_file) ] do |t|
|
138
|
-
sh "#{cxx} #{cxxflags} -o #{t.name} -c #{t.prerequisites[0]}"
|
164
|
+
sh "#{cxx} #{cxxflags} -o #{shellescape(t.name)} -c #{shellescape(t.prerequisites[0])}"
|
139
165
|
end
|
140
166
|
end
|
141
167
|
|
@@ -150,14 +176,14 @@ module FFI
|
|
150
176
|
|
151
177
|
desc "Build dynamic library"
|
152
178
|
file lib_name => obj_files do |t|
|
153
|
-
sh "#{ld} #{so_flags} -o #{t.name} #{t.prerequisites
|
179
|
+
sh "#{ld} #{so_flags} -o #{shellescape(t.name)} #{shelljoin(t.prerequisites)} #{ld_flags} #{libs}"
|
154
180
|
end
|
155
181
|
CLEAN.include(lib_name)
|
156
182
|
|
157
183
|
@exports.each do |e|
|
158
184
|
desc "Export #{e[:rb_file]}"
|
159
185
|
file e[:header] => [ e[:rb_file] ] do |t|
|
160
|
-
ruby "-I#{File.join(File.dirname(__FILE__), 'fake_ffi')} -I#{File.dirname(t.prerequisites[0])} #{File.join(File.dirname(__FILE__), 'exporter.rb')} #{t.prerequisites[0]} #{t.name}"
|
186
|
+
ruby "-I#{File.join(File.dirname(__FILE__), 'fake_ffi')} -I#{File.dirname(t.prerequisites[0])} #{File.join(File.dirname(__FILE__), 'exporter.rb')} #{shellescape(t.prerequisites[0])} #{shellescape(t.name)}"
|
161
187
|
end
|
162
188
|
|
163
189
|
obj_files.each { |o| file o => [ e[:header] ] }
|
@@ -221,10 +247,10 @@ module FFI
|
|
221
247
|
File.open(path, 'w') do |f|
|
222
248
|
f << src
|
223
249
|
end
|
224
|
-
cflags = opts
|
250
|
+
cflags = shelljoin(opts)
|
225
251
|
output = File.join(dir, 'ffi-test')
|
226
252
|
begin
|
227
|
-
return system "#{cc} #{cflags} -o #{output} -c #{path} > #{path}.log 2>&1"
|
253
|
+
return system "#{cc} #{cflags} -o #{shellescape(output)} -c #{shellescape(path)} > #{shellescape(path)}.log 2>&1"
|
228
254
|
rescue
|
229
255
|
return false
|
230
256
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
def shellescape(str)
|
5
|
+
return str unless str
|
6
|
+
if FFI::Platform::OS == 'windows'
|
7
|
+
'"' + str.gsub('"', '""') + '"'
|
8
|
+
else
|
9
|
+
str.shellescape
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def shelljoin(args)
|
14
|
+
if FFI::Platform::OS == 'windows'
|
15
|
+
args.reduce { |cmd, arg| cmd + ' "' + arg.gsub('"', '""') + '"' }
|
16
|
+
else
|
17
|
+
args.shelljoin
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def shellsplit(str)
|
22
|
+
return str unless str
|
23
|
+
str.shellsplit
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-compiler2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dāvis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -72,6 +72,7 @@ executables: []
|
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
|
+
- Gemfile
|
75
76
|
- LICENSE
|
76
77
|
- README.md
|
77
78
|
- Rakefile
|
@@ -83,6 +84,7 @@ files:
|
|
83
84
|
- lib/ffi-compiler/fake_ffi/ffi.rb
|
84
85
|
- lib/ffi-compiler/loader.rb
|
85
86
|
- lib/ffi-compiler/platform.rb
|
87
|
+
- lib/ffi-compiler/shell.rb
|
86
88
|
- lib/ffi-compiler/task.rb
|
87
89
|
homepage: https://gitlab.com/davispuh/ffi-compiler
|
88
90
|
licenses:
|
@@ -103,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
105
|
- !ruby/object:Gem::Version
|
104
106
|
version: '0'
|
105
107
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
108
|
+
rubygems_version: 3.5.6
|
107
109
|
signing_key:
|
108
110
|
specification_version: 4
|
109
111
|
summary: Ruby FFI Rakefile generator
|