ryb 0.1.3.1 → 0.2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +36 -47
- data/NOTES +0 -0
- data/README.md +3 -1
- data/TODO +4 -0
- data/bin/ryb +2 -42
- data/lib/ryb.rb +31 -20
- data/lib/ryb/cli.rb +103 -0
- data/lib/ryb/code.rb +7 -0
- data/lib/ryb/configuration.rb +18 -12
- data/lib/ryb/configurations.rb +9 -0
- data/lib/ryb/dependencies.rb +7 -0
- data/lib/ryb/dependency.rb +30 -0
- data/lib/ryb/dsl.rb +280 -0
- data/lib/ryb/environment.rb +9 -0
- data/lib/ryb/flags.rb +17 -0
- data/lib/ryb/gem.rb +58 -0
- data/lib/ryb/helpers/defaults.rb +26 -0
- data/lib/ryb/helpers/pretty_string.rb +47 -0
- data/lib/ryb/languages.rb +13 -0
- data/lib/ryb/name.rb +3 -5
- data/lib/ryb/ninja.rb +257 -200
- data/lib/ryb/paths.rb +7 -0
- data/lib/ryb/preprocessor.rb +10 -0
- data/lib/ryb/product.rb +31 -0
- data/lib/ryb/project.rb +6 -29
- data/lib/ryb/source_file.rb +62 -0
- data/lib/ryb/visual_studio.rb +93 -57
- data/lib/rybfile.rb +30 -10
- data/lib/rybfile/walker.rb +202 -0
- data/lib/yb.rb +4 -0
- data/lib/ybfile.rb +3 -0
- data/ryb.gemspec +18 -13
- data/ryb.sublime-project +18 -17
- metadata +45 -31
- data/lib/ryb/application.rb +0 -24
- data/lib/ryb/architecture.rb +0 -16
- data/lib/ryb/architectures/x86.rb +0 -11
- data/lib/ryb/architectures/x86_64.rb +0 -11
- data/lib/ryb/library.rb +0 -29
- data/lib/ryb/properties.rb +0 -10
- data/lib/ryb/properties/architectures.rb +0 -32
- data/lib/ryb/properties/configurations.rb +0 -29
- data/lib/ryb/properties/defines.rb +0 -31
- data/lib/ryb/properties/dependencies.rb +0 -23
- data/lib/ryb/properties/files.rb +0 -25
- data/lib/ryb/properties/flags.rb +0 -33
- data/lib/ryb/properties/named.rb +0 -17
- data/lib/ryb/properties/paths.rb +0 -37
- data/lib/ryb/properties/suffix.rb +0 -17
- data/lib/ryb/properties/targets.rb +0 -36
- data/lib/ryb/target.rb +0 -16
- data/lib/ryb/targets/linux.rb +0 -11
- data/lib/ryb/targets/macosx.rb +0 -33
- data/lib/ryb/targets/windows.rb +0 -13
- data/lib/ryb/version.rb +0 -11
- data/lib/ryb/windows.rb +0 -40
- data/lib/ryb/xcode.rb +0 -145
data/lib/ryb/name.rb
CHANGED
data/lib/ryb/ninja.rb
CHANGED
@@ -1,200 +1,257 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
1
|
+
module Ryb
|
2
|
+
module Ninja
|
3
|
+
class Generator
|
4
|
+
def initialize(rybfile, opts)
|
5
|
+
@rybfile = rybfile
|
6
|
+
@root = opts.fetch(:root, '.')
|
7
|
+
@build = opts.fetch(:build, '_build')
|
8
|
+
@ninjafile = ::Ninja::File.new
|
9
|
+
@path = opts.fetch(:ninjafile, "#{@root}/build.ninja")
|
10
|
+
|
11
|
+
# HACK(mtwilliams): Create directory structure.
|
12
|
+
require 'fileutils'
|
13
|
+
FileUtils.mkdir_p(["#@build/bin", "#@build/lib", "#@build/obj"])
|
14
|
+
|
15
|
+
# HACK(mtwilliams): Assume VisualStudio.
|
16
|
+
@vs = ::VisualStudio.latest
|
17
|
+
@vc = @vs.products[:c_and_cpp]
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate
|
21
|
+
@ninjafile.save(@path)
|
22
|
+
end
|
23
|
+
|
24
|
+
# TODO(mtwilliams): Generate phony commands that proxy to all triplets.
|
25
|
+
def on_project(project)
|
26
|
+
puts "=> #{project.name.pretty || project.name}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def on_product(project, product)
|
30
|
+
puts " -> Generating for #{product.name.pretty || product.name}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def on_project_triplet(project, tripletised)
|
34
|
+
end
|
35
|
+
|
36
|
+
def on_product_triplet(project, product, tripletised)
|
37
|
+
tripletised = tripletised.()
|
38
|
+
|
39
|
+
config = tripletised.configuration.name.to_sym
|
40
|
+
platform = tripletised.platform.name.to_sym
|
41
|
+
arch = tripletised.architecture.name.to_sym
|
42
|
+
|
43
|
+
puts " ~> #{config} for #{platform} (#{arch})"
|
44
|
+
|
45
|
+
name = product.name.canonicalize
|
46
|
+
namespace = "#{name}_#{tripletised.triplet.join('_')}"
|
47
|
+
|
48
|
+
sdk = @vc.sdks[:windows].select{|sdk| sdk.version == '7.1'}.first
|
49
|
+
sys_include_paths = @vc.includes + sdk.includes
|
50
|
+
sys_lib_paths = @vc.libraries[arch] + sdk.libraries[arch]
|
51
|
+
|
52
|
+
@ninjafile.variable "#{namespace}_cflags_sys", VisualStudio::Compiler.include_paths_to_flags(sys_include_paths).join(' ')
|
53
|
+
@ninjafile.variable "#{namespace}_ldflags_sys", VisualStudio::Linker.library_paths_to_flags(sys_lib_paths).join(' ')
|
54
|
+
|
55
|
+
cflags = cflags_for_product(project, product, tripletised)
|
56
|
+
arflags = arflags_for_product(project, product, tripletised)
|
57
|
+
ldflags = ldflags_for_product(project, product, tripletised)
|
58
|
+
|
59
|
+
@ninjafile.variable "#{namespace}_cflags", cflags.join(' ')
|
60
|
+
@ninjafile.variable "#{namespace}_cxxflags", "$#{namespace}_cflags"
|
61
|
+
@ninjafile.variable "#{namespace}_arflags", arflags.join(' ')
|
62
|
+
@ninjafile.variable "#{namespace}_ldflags", ldflags.join(' ')
|
63
|
+
|
64
|
+
sources = sources_for_product(product, tripletised)
|
65
|
+
@ninjafile.variable "#{namespace}_sources", sources.map{|src| "#@root/#{src.path}"}.join(' ')
|
66
|
+
|
67
|
+
deps = deps_for_product(product, tripletised)
|
68
|
+
@ninjafile.variable "#{namespace}_deps", deps.join(' ')
|
69
|
+
|
70
|
+
artifacts = artifacts_for_product(product, tripletised)
|
71
|
+
@ninjafile.variable "#{namespace}_artifacts", artifacts.join(' ')
|
72
|
+
@ninjafile.variable("#{namespace}_as_linkable", artifacts[0]) if product.is_a? Ryb::Library
|
73
|
+
@ninjafile.variable "#{namespace}_symbols", artifacts[0].gsub(/\.(exe|lib|dll)/, ".pdb")
|
74
|
+
|
75
|
+
# https://github.com/ninja-build/ninja/blob/d1763746b65cc7349d4ed9478befdb651aa24589/src/msvc_helper_main-win32.cc#L38
|
76
|
+
# ninja -t msvc -e _build/#{namespace}.env -- cl.exe ...
|
77
|
+
env_block = "#@build/#{namespace}.env_block"
|
78
|
+
env = @vc.environment(target: {platform: :windows, architecture: arch})
|
79
|
+
# "PATH=#{(@vc.binaries[arch] + sdk.binaries[arch]).join(';')}\0"
|
80
|
+
File.write(env_block, env.map{|env_var, value| "#{env_var}=#{value}"}.join("\0"))
|
81
|
+
|
82
|
+
@ninjafile.rule(
|
83
|
+
"cc_#{namespace}",
|
84
|
+
"ninja -t msvc -e #{env_block} -- cl.exe $#{namespace}_cflags_sys $#{namespace}_cflags /Fd$#{namespace}_symbols /Fo$out /Tc$in"
|
85
|
+
)
|
86
|
+
|
87
|
+
@ninjafile.rule(
|
88
|
+
"cxx_#{namespace}",
|
89
|
+
"ninja -t msvc -e #{env_block} -- cl.exe $#{namespace}_cxxflags_sys $#{namespace}_cxxflags /Fd$#{namespace}_symbols /Fo$out /Tp$in"
|
90
|
+
)
|
91
|
+
|
92
|
+
@ninjafile.rule(
|
93
|
+
"ar_#{namespace}",
|
94
|
+
"ninja -t msvc -e #{env_block} -- lib.exe $#{namespace}_arflags /OUT:$out $in"
|
95
|
+
)
|
96
|
+
|
97
|
+
@ninjafile.rule(
|
98
|
+
"ld_#{namespace}",
|
99
|
+
"ninja -t msvc -e #{env_block} -- link.exe $#{namespace}_ldflags_sys $#{namespace}_ldflags /OUT:$out $#{namespace}_deps $in"
|
100
|
+
)
|
101
|
+
|
102
|
+
@ninjafile.rule(
|
103
|
+
"so_#{namespace}",
|
104
|
+
"ninja -t msvc -e #{env_block} -- link.exe $#{namespace}_ldflags_sys $#{namespace}_ldflags /DLL /OUT:$out $#{namespace}_deps $in"
|
105
|
+
)
|
106
|
+
|
107
|
+
c_sources = sources.select{|src| src.language == :c}.map(&:path).map{|src| "#@root/#{src}"}
|
108
|
+
c_objects = c_sources.map{|src| src.gsub(/\.(c)/, ".#{namespace}.obj")}.map{|obj| "#@build/obj/#{obj}"}
|
109
|
+
cxx_sources = sources.select{|src| src.language == :cpp}.map(&:path).map{|src| "#@root/#{src}"}
|
110
|
+
cxx_objects = cxx_sources.map{|src| src.gsub(/\.(cc|cpp|cxx|c++)/, ".#{namespace}.obj")}.map{|obj| "#@build/obj/#{obj}"}
|
111
|
+
|
112
|
+
@ninjafile.build "cc_#{namespace}", Hash[c_objects.zip(c_sources)]
|
113
|
+
@ninjafile.build "cxx_#{namespace}", Hash[cxx_objects.zip(cxx_sources)]
|
114
|
+
|
115
|
+
case product
|
116
|
+
when Ryb::Application
|
117
|
+
@ninjafile.build "ld_#{namespace}", {artifacts[0] => c_objects + cxx_objects}
|
118
|
+
when Ryb::Library
|
119
|
+
case product.linkage
|
120
|
+
when :static
|
121
|
+
@ninjafile.build "ar_#{namespace}", {artifacts[0] => c_objects + cxx_objects}
|
122
|
+
when :dynamic
|
123
|
+
@ninjafile.build "so_#{namespace}", {artifacts[1] => c_objects + cxx_objects}
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
def sources_for_product(product, tripletised)
|
130
|
+
sources = [*product.sources] |
|
131
|
+
[*tripletised.configuration.sources] |
|
132
|
+
[*tripletised.platform.sources] |
|
133
|
+
[*tripletised.architecture.sources]
|
134
|
+
sources.reject{|src| src.inconsequential}.compact.uniq
|
135
|
+
end
|
136
|
+
|
137
|
+
def deps_for_product(product, tripletised)
|
138
|
+
deps = [*product.dependencies] |
|
139
|
+
[*tripletised.configuration.dependencies] |
|
140
|
+
[*tripletised.platform.dependencies] |
|
141
|
+
[*tripletised.architecture.dependencies]
|
142
|
+
deps.map do |dep|
|
143
|
+
case dep
|
144
|
+
when Ryb::InternalDependency
|
145
|
+
"${#{dep.product}_#{tripletised.triplet.join('_')}_as_linkable}"
|
146
|
+
when Ryb::ExternalDependency
|
147
|
+
dep.lib_or_framework
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def artifacts_for_product(product, tripletised)
|
153
|
+
name = product.name.canonicalize
|
154
|
+
config_suffix = tripletised.configuration.suffix || "_#{tripletised.configuration.name}"
|
155
|
+
platform_suffix = tripletised.platform.suffix || "_#{tripletised.platform.name}"
|
156
|
+
arch_suffix = tripletised.architecture.suffix || "_#{tripletised.architecture.name}"
|
157
|
+
suffix = [config_suffix, platform_suffix, arch_suffix].join('')
|
158
|
+
|
159
|
+
if product.is_a? Ryb::Application
|
160
|
+
["#@build/bin/#{name}#{suffix}.exe"]
|
161
|
+
elsif product.is_a? Ryb::Library
|
162
|
+
case product.linkage
|
163
|
+
when :static
|
164
|
+
["#@build/lib/#{name}#{suffix}.lib"]
|
165
|
+
when :dynamic
|
166
|
+
["#@build/lib/#{name}#{suffix}.lib", "#@build/bin/#{name}#{suffix}.dll"]
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
private
|
172
|
+
def cflags_for_product(project, product, tripletised)
|
173
|
+
flags = VisualStudio::Compiler::STANDARD_FLAGS +
|
174
|
+
cflags_for_configuration(tripletised.configuration) +
|
175
|
+
cflags_for_platform(tripletised.platform) +
|
176
|
+
cflags_for_architecture(tripletised.architecture)
|
177
|
+
flags += VisualStudio::Compiler.include_paths_to_flags(product.paths.includes) if product.paths
|
178
|
+
flags += VisualStudio::Compiler.defines_to_flags(project.defines)
|
179
|
+
flags += VisualStudio::Compiler.architecture_to_flags(tripletised.architecture.name.to_sym)
|
180
|
+
flags
|
181
|
+
end
|
182
|
+
|
183
|
+
def arflags_for_product(_project, _product, _tripletised)
|
184
|
+
%w{/nologo}
|
185
|
+
end
|
186
|
+
|
187
|
+
def ldflags_for_product(_project, product, tripletised)
|
188
|
+
flags = VisualStudio::Linker::STANDARD_FLAGS +
|
189
|
+
ldflags_for_configuration(tripletised.configuration) +
|
190
|
+
ldflags_for_platform(tripletised.platform) +
|
191
|
+
ldflags_for_architecture(tripletised.architecture)
|
192
|
+
flags += VisualStudio::Linker.architecture_to_flags(tripletised.architecture.name.to_sym)
|
193
|
+
# TODO: Linkage.
|
194
|
+
flags
|
195
|
+
end
|
196
|
+
|
197
|
+
private
|
198
|
+
def cflags_for_configuration(config)
|
199
|
+
flags = []
|
200
|
+
# TODO(mtwilliams): @toolchains.for(target)
|
201
|
+
flags += VisualStudio::Compiler.include_paths_to_flags(config.paths.includes) if config.paths
|
202
|
+
flags += VisualStudio::Compiler.defines_to_flags(config.defines)
|
203
|
+
flags += VisualStudio::Compiler.treat_warnings_as_errors_to_flag(config.treat_warnings_as_errors)
|
204
|
+
flags += VisualStudio::Compiler.generate_debug_symbols_to_flag(config.generate_debug_symbols)
|
205
|
+
flags += VisualStudio::Compiler.optimization_to_flags(config.optimize)
|
206
|
+
flags
|
207
|
+
end
|
208
|
+
|
209
|
+
def cflags_for_platform(platform)
|
210
|
+
flags = []
|
211
|
+
# TODO(mtwilliams): @toolchains.for(target)
|
212
|
+
flags += VisualStudio::Compiler.include_paths_to_flags(platform.paths.includes) if platform.paths
|
213
|
+
flags += VisualStudio::Compiler.defines_to_flags(platform.defines)
|
214
|
+
flags
|
215
|
+
end
|
216
|
+
|
217
|
+
def cflags_for_architecture(arch)
|
218
|
+
flags = []
|
219
|
+
# TODO(mtwilliams): @toolchains.for(target)
|
220
|
+
flags += VisualStudio::Compiler.architecture_to_flags(arch.name.canonicalize.to_sym)
|
221
|
+
flags += VisualStudio::Compiler.include_paths_to_flags(arch.paths.includes) if arch.paths
|
222
|
+
flags += VisualStudio::Compiler.defines_to_flags(arch.defines)
|
223
|
+
flags
|
224
|
+
end
|
225
|
+
|
226
|
+
def ldflags_for_configuration(config)
|
227
|
+
flags = []
|
228
|
+
# TODO(mtwilliams): @toolchains.for(target)
|
229
|
+
flags += VisualStudio::Linker.library_paths_to_flags(config.paths.libraries) if config.paths
|
230
|
+
flags += VisualStudio::Linker.generate_debug_symbols_to_flag(config.generate_debug_symbols)
|
231
|
+
flags
|
232
|
+
end
|
233
|
+
|
234
|
+
def ldflags_for_platform(platform)
|
235
|
+
flags = []
|
236
|
+
# TODO(mtwilliams): @toolchains.for(target)
|
237
|
+
flags += VisualStudio::Linker.library_paths_to_flags(platform.paths.libraries) if platform.paths
|
238
|
+
flags
|
239
|
+
end
|
240
|
+
|
241
|
+
def ldflags_for_architecture(arch)
|
242
|
+
flags = []
|
243
|
+
# TODO(mtwilliams): @toolchains.for(target)
|
244
|
+
flags += VisualStudio::Linker.library_paths_to_flags(arch.paths.libraries) if arch.paths
|
245
|
+
flags
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def self.generate_from(rybfile, opts={})
|
250
|
+
puts "Generating..."
|
251
|
+
generator = ::Ryb::Ninja::Generator.new(rybfile, opts)
|
252
|
+
::Rybfile::Walker.new(generator, rybfile, opts).walk
|
253
|
+
generator.generate
|
254
|
+
puts "Done!"
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|