kompo 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +2 -4
- data/.devcontainer/devcontainer.json +2 -2
- data/.standard.yml +2 -0
- data/CHANGELOG.md +21 -0
- data/Gemfile +10 -2
- data/Gemfile.lock +115 -3
- data/README.md +117 -10
- data/Rakefile +12 -2
- data/docs/document.md.ja +31 -0
- data/exe/kompo +45 -14
- data/lib/fs.c.erb +6 -0
- data/lib/kompo/cache.rb +65 -0
- data/lib/kompo/kompo_ignore.rb +40 -0
- data/lib/kompo/tasks/build_native_gem.rb +191 -0
- data/lib/kompo/tasks/bundle_install.rb +224 -0
- data/lib/kompo/tasks/cargo_path.rb +59 -0
- data/lib/kompo/tasks/check_stdlibs.rb +58 -0
- data/lib/kompo/tasks/collect_dependencies.rb +101 -0
- data/lib/kompo/tasks/copy_gemfile.rb +46 -0
- data/lib/kompo/tasks/copy_project_files.rb +89 -0
- data/lib/kompo/tasks/find_native_extensions.rb +89 -0
- data/lib/kompo/tasks/homebrew.rb +83 -0
- data/lib/kompo/tasks/install_deps.rb +365 -0
- data/lib/kompo/tasks/install_ruby.rb +427 -0
- data/lib/kompo/tasks/kompo_vfs_path.rb +144 -0
- data/lib/kompo/tasks/kompo_vfs_version_check.rb +56 -0
- data/lib/kompo/tasks/make_fs_c.rb +202 -0
- data/lib/kompo/tasks/make_main_c.rb +65 -0
- data/lib/kompo/tasks/packing.rb +235 -0
- data/lib/kompo/tasks/ruby_build_path.rb +54 -0
- data/lib/kompo/tasks/work_dir.rb +84 -0
- data/lib/kompo/version.rb +2 -1
- data/lib/kompo.rb +47 -420
- data/lib/main.c.erb +28 -15
- data/rbs_collection.lock.yaml +116 -0
- data/rbs_collection.yaml +19 -0
- metadata +72 -8
- data/lib/kompo/kompo_fs.rb +0 -15
data/lib/kompo.rb
CHANGED
|
@@ -1,425 +1,52 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
|
|
5
|
-
require 'optparse'
|
|
6
|
-
require "fileutils"
|
|
7
|
-
require 'forwardable'
|
|
8
|
-
require_relative "kompo/version"
|
|
3
|
+
require 'taski'
|
|
4
|
+
require_relative 'kompo/version'
|
|
9
5
|
|
|
10
6
|
module Kompo
|
|
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
|
-
@opt.parse!(ARGV)
|
|
54
|
-
|
|
55
|
-
@args = convert_absolute_path_for ARGV
|
|
56
|
-
|
|
57
|
-
self
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
private
|
|
61
|
-
|
|
62
|
-
def convert_absolute_path_for(args)
|
|
63
|
-
args.map do |arg|
|
|
64
|
-
if File.absolute_path?(arg)
|
|
65
|
-
arg
|
|
66
|
-
else
|
|
67
|
-
Pathname.new(File.join(context, arg)).cleanpath.to_s
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
class Tasks
|
|
74
|
-
extend Forwardable
|
|
75
|
-
attr_reader :task, :fs, :work_dir, :ruby_src_dir, :ruby_pc, :ruby_bin, :extinit_o, :encinit_o, :lib_ruby_static_dir, :bundle_setup, :bundle_ruby, :std_libs, :gem_libs, :exts_libs
|
|
76
|
-
|
|
77
|
-
delegate %i[entrypoint output gemfile ignore_stdlib dyn_link_lib dest_dir ruby_src_path cache_bundle_path ruby_version compress context args use_group] => :@option
|
|
78
|
-
delegate %i[komop_cli lib_kompo_dir] => :@fs
|
|
79
|
-
|
|
80
|
-
def initialize(option, dir)
|
|
81
|
-
@option = option
|
|
82
|
-
@ruby_src_dir = File.expand_path(ruby_src_path || File.join(dir, 'ruby'))
|
|
83
|
-
@work_dir = dir
|
|
84
|
-
@fs = Fs.new
|
|
85
|
-
|
|
86
|
-
@ruby_bin = File.join(ruby_src_path || File.join(dir, 'dest_dir', 'bin'), 'ruby')
|
|
87
|
-
@ruby_pc = File.join(ruby_src_path || File.join(dir, 'dest_dir', 'lib', 'pkgconfig'), get_ruby_pc_name)
|
|
88
|
-
@extinit_o = File.join(ruby_src_dir, 'ext', 'extinit.o')
|
|
89
|
-
@encinit_o = File.join(ruby_src_dir, 'enc', 'encinit.o')
|
|
90
|
-
@lib_ruby_static_dir = ruby_src_path || File.join(dir, 'dest_dir', 'lib')
|
|
91
|
-
|
|
92
|
-
@std_libs = []
|
|
93
|
-
@gem_libs = []
|
|
94
|
-
@exts_libs = []
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def get_ruby_pc_name
|
|
98
|
-
return 'ruby.pc' unless ruby_src_path
|
|
99
|
-
|
|
100
|
-
command = [
|
|
101
|
-
ruby_bin,
|
|
102
|
-
'-e',
|
|
103
|
-
"'puts RbConfig::CONFIG[\"ruby_pc\"]'",
|
|
104
|
-
].join(' ')
|
|
105
|
-
|
|
106
|
-
exec_command command, 'get ruby.pc name', true
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def valid?
|
|
110
|
-
raise "kompo-cli not found. Please install 'kompo-cli'." unless komop_cli
|
|
111
|
-
raise "libkompo_fs.a not found. Please install 'kompo-cli'." unless lib_kompo_dir
|
|
112
|
-
raise "Entrypoint not found: '#{entrypoint}'. Please specify the entry file path with '-e' or '--entrypoint' option." unless File.exist?(entrypoint)
|
|
113
|
-
|
|
114
|
-
true
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def self.cd_work_dir(option)
|
|
118
|
-
Dir.mktmpdir do |dir|
|
|
119
|
-
task = new(option.build, dir)
|
|
120
|
-
task.valid?
|
|
121
|
-
FileUtils.cd(dir)
|
|
122
|
-
|
|
123
|
-
yield task
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def clone_ruby_src
|
|
128
|
-
if ruby_src_path.nil?
|
|
129
|
-
command = ['git', '-C', "#{work_dir}", 'clone', '-b', "#{ruby_version}", '--single-branch', '--depth=1', 'https://github.com/ruby/ruby.git'].join(' ')
|
|
130
|
-
exec_command command, 'git clone ruby.git'
|
|
131
|
-
|
|
132
|
-
Dir.chdir(ruby_src_dir) do
|
|
133
|
-
exec_command (File.exist?("#{ruby_src_dir}/autogen.sh") ? './autogen.sh' : "autoconf"), 'autoxxx'
|
|
134
|
-
|
|
135
|
-
command = [
|
|
136
|
-
'./configure',
|
|
137
|
-
"--prefix=#{work_dir}/dest_dir",
|
|
138
|
-
"--disable-install-doc",
|
|
139
|
-
"--disable-install-rdoc",
|
|
140
|
-
"--disable-install-capi",
|
|
141
|
-
"--with-static-linked-ext",
|
|
142
|
-
"--with-ruby-pc=ruby.pc",
|
|
143
|
-
"--with-ext=#{get_ruby_exts_dir}"
|
|
144
|
-
].join(' ')
|
|
145
|
-
exec_command command, 'configure'
|
|
146
|
-
|
|
147
|
-
exec_command ['make', 'install'].join(' '), 'build target version ruby'
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def get_from_ruby_pc(option)
|
|
153
|
-
command = [
|
|
154
|
-
'pkg-config',
|
|
155
|
-
"#{option}",
|
|
156
|
-
"#{ruby_pc}"
|
|
157
|
-
].join(' ')
|
|
158
|
-
|
|
159
|
-
exec_command(command, 'pkg-config', true)
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def bundle_install
|
|
163
|
-
if cache_bundle_path
|
|
164
|
-
FileUtils.cp_r(cache_bundle_path, work_dir)
|
|
165
|
-
@bundle_setup = File.join(cache_bundle_path, 'bundler', 'setup.rb')
|
|
166
|
-
@bundle_ruby = File.join(cache_bundle_path, 'ruby')
|
|
167
|
-
else
|
|
168
|
-
File.write('./bundler', File.read(`which bundle`.chomp).split("\n").tap { _1[0] = "#!#{ruby_bin}" }.join("\n"))
|
|
169
|
-
FileUtils.chmod(0755, './bundler')
|
|
170
|
-
|
|
171
|
-
command = [
|
|
172
|
-
'./bundler',
|
|
173
|
-
'install',
|
|
174
|
-
"--standalone=#{use_group}",
|
|
175
|
-
].join(' ')
|
|
176
|
-
|
|
177
|
-
exec_command command, 'bundle install'
|
|
178
|
-
|
|
179
|
-
@bundle_setup = File.join(work_dir, 'bundle', 'bundler', 'setup.rb')
|
|
180
|
-
@bundle_ruby = File.join(work_dir, 'bundle', 'ruby')
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
def fs_cli
|
|
185
|
-
command = [
|
|
186
|
-
komop_cli,
|
|
187
|
-
context,
|
|
188
|
-
args.join(' '),
|
|
189
|
-
get_load_paths,
|
|
190
|
-
"--entrypoint=#{entrypoint}",
|
|
191
|
-
].join(' ')
|
|
192
|
-
|
|
193
|
-
exec_command command, 'kompo-cli'
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def make_main_c
|
|
197
|
-
require 'erb'
|
|
198
|
-
|
|
199
|
-
exts = []
|
|
200
|
-
if gemfile
|
|
201
|
-
Dir.glob(File.join(bundle_ruby, get_semantic_ruby_version, 'gems/**/extconf.rb')).each do |makefile_dir|
|
|
202
|
-
dir_name = File.dirname(makefile_dir)
|
|
203
|
-
makefile = File.join(dir_name, 'Makefile')
|
|
204
|
-
if File.exist?(cargo_toml = File.join(dir_name, 'Cargo.toml'))
|
|
205
|
-
command = [
|
|
206
|
-
'cargo',
|
|
207
|
-
'rustc',
|
|
208
|
-
'--release',
|
|
209
|
-
'--crate-type=staticlib',
|
|
210
|
-
'--target-dir',
|
|
211
|
-
'target',
|
|
212
|
-
"--manifest-path=#{cargo_toml}",
|
|
213
|
-
].join(' ')
|
|
214
|
-
exec_command command, 'cargo build'
|
|
215
|
-
copy_targets = Dir.glob(File.join(dir_name, 'target/release/*.a'))
|
|
216
|
-
else
|
|
217
|
-
copy_targets = []
|
|
218
|
-
Dir.chdir(dir_name) {|path|
|
|
219
|
-
command = [
|
|
220
|
-
ruby_bin,
|
|
221
|
-
'extconf.rb',
|
|
222
|
-
].join(' ')
|
|
223
|
-
|
|
224
|
-
exec_command command, 'ruby extconf.rb'
|
|
225
|
-
|
|
226
|
-
objs = File.read('./Makefile').match(/OBJS = (.*\.o)/)[1]
|
|
227
|
-
|
|
228
|
-
command = ['make', objs, '--always-make'].join(' ')
|
|
229
|
-
|
|
230
|
-
exec_command command, 'make OBJS'
|
|
231
|
-
|
|
232
|
-
@exts_libs += File.read('./Makefile').match(/^libpath = (.*)/)[1].split(' ')
|
|
233
|
-
|
|
234
|
-
copy_targets = objs.split(' ').map { File.join(dir_name, _1) }
|
|
235
|
-
}
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
dir = FileUtils.mkdir_p('exts/' + File.basename(dir_name)).first
|
|
239
|
-
FileUtils.cp(copy_targets, dir)
|
|
240
|
-
prefix = File.read(makefile).scan(/target_prefix = (.*)/).join.delete_prefix('/')
|
|
241
|
-
target_name = File.read(makefile).scan(/TARGET_NAME = (.*)/).join
|
|
242
|
-
exts << [File.join(prefix, "#{target_name}.so").delete_prefix('/'), "Init_#{target_name}"]
|
|
243
|
-
end
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
File.write("main.c", ERB.new(File.read(File.join(__dir__, 'main.c.erb'))).result(binding))
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
def packing
|
|
250
|
-
command = [
|
|
251
|
-
'gcc',
|
|
252
|
-
'-O3',
|
|
253
|
-
'-Wall',
|
|
254
|
-
get_ruby_header,
|
|
255
|
-
"#{lib_ruby_static_dir.nil? ? '' : '-L' + lib_ruby_static_dir}",
|
|
256
|
-
"#{lib_kompo_dir.nil? ? '' : '-L' + lib_kompo_dir}",
|
|
257
|
-
"#{exts_libs.uniq.select{_1.start_with?('/')}.map{"-L#{_1}"}.join(' ')}",
|
|
258
|
-
'main.c',
|
|
259
|
-
'-Wl,--start-group',
|
|
260
|
-
Dir.glob('exts/**/*.o').join(' '),
|
|
261
|
-
'fs.o',
|
|
262
|
-
get_ruby_exts,
|
|
263
|
-
'-lkompo',
|
|
264
|
-
'-lruby-static',
|
|
265
|
-
get_libs,
|
|
266
|
-
'-Wl,--end-group',
|
|
267
|
-
'-o',
|
|
268
|
-
output
|
|
269
|
-
].join(' ')
|
|
270
|
-
|
|
271
|
-
exec_command command, 'Packing'
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
def copy_to_dest_dir
|
|
275
|
-
command = ['cp', '-f', output, dest_dir].join(' ')
|
|
276
|
-
exec_command command, 'Copy to dest dir'
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
private
|
|
280
|
-
|
|
281
|
-
def exec_command(command, info = nil, ret = false)
|
|
282
|
-
puts "exec: #{info}" if info
|
|
283
|
-
puts command
|
|
284
|
-
if ret
|
|
285
|
-
ret = `#{command}`.chomp
|
|
286
|
-
if $?.exited?
|
|
287
|
-
ret
|
|
288
|
-
else
|
|
289
|
-
raise "Failed to execute command: #{command}"
|
|
290
|
-
end
|
|
291
|
-
else
|
|
292
|
-
system command, exception: true
|
|
293
|
-
end
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
def get_ruby_exts
|
|
297
|
-
["#{extinit_o}", "#{encinit_o}", *(Dir.glob("#{ruby_src_dir}/ext/**/*.a") - ignore_stdlib_archives), *Dir.glob("#{ruby_src_dir}/enc/**/*.a")].join(' ')
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
def ignore_stdlib_archives
|
|
301
|
-
if ruby_src_path
|
|
302
|
-
ignore_stdlib.map do |stdlib|
|
|
303
|
-
File.join(ruby_src_path, 'ext', stdlib, File.basename(stdlib) + '.a')
|
|
304
|
-
end
|
|
305
|
-
else
|
|
306
|
-
[]
|
|
307
|
-
end
|
|
308
|
-
end
|
|
309
|
-
|
|
310
|
-
def extract_gem_libs
|
|
311
|
-
Dir.glob("bundle/ruby/#{get_semantic_ruby_version}/gems/*/ext/*/Makefile")
|
|
312
|
-
.flat_map{ File.read(_1)
|
|
313
|
-
.scan(/^LIBS = (.*)/)[0] }
|
|
314
|
-
.flat_map { _1.split(' ') }
|
|
315
|
-
.uniq
|
|
316
|
-
.flat_map { _1.start_with?("-l") ? _1 : "-l" + File.basename(_1, '.a').delete_prefix('lib') }
|
|
317
|
-
.join(" ")
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
def get_libs
|
|
321
|
-
main_lib = get_mainlibs
|
|
322
|
-
ext_libs = Dir.glob("#{ruby_src_dir}/ext/**/exts.mk").flat_map { File.read(_1).scan(/EXTLIBS = (.*)/) }.join(" ")
|
|
323
|
-
gem_libs = extract_gem_libs
|
|
324
|
-
dyn_link_libs = (['pthread', 'dl', 'm', 'c'] + dyn_link_lib).map { "-l" + _1 }
|
|
325
|
-
dyn, static = eval("%W[#{main_lib} #{ext_libs} #{gem_libs}]").uniq
|
|
326
|
-
.partition { dyn_link_libs.include?(_1) }
|
|
327
|
-
dyn.unshift "-Wl,-Bdynamic"
|
|
328
|
-
static.unshift "-Wl,-Bstatic"
|
|
329
|
-
|
|
330
|
-
static.join(" ") + " " + dyn.join(" ")
|
|
331
|
-
end
|
|
332
|
-
|
|
333
|
-
def get_ruby_header
|
|
334
|
-
get_from_ruby_pc('--cflags')
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
def get_semantic_ruby_version
|
|
338
|
-
get_from_ruby_pc('--variable=ruby_version')
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
def get_mainlibs
|
|
342
|
-
get_from_ruby_pc('--variable=MAINLIBS')
|
|
343
|
-
end
|
|
344
|
-
|
|
345
|
-
def get_load_paths
|
|
346
|
-
load_paths = []
|
|
347
|
-
if gemfile
|
|
348
|
-
load_paths += gem_libs
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
load_paths += std_libs
|
|
352
|
-
|
|
353
|
-
load_paths
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
def get_ruby_exts_dir
|
|
357
|
-
Dir.glob("#{ruby_src_dir}/**/extconf.rb")
|
|
358
|
-
.reject { _1 =~ /-test-/ }
|
|
359
|
-
.reject { _1 =~ /win32/ } # TODO
|
|
360
|
-
.map { File.dirname(_1) }
|
|
361
|
-
.map { _1.split("#{ruby_src_dir}/ext/")[1] }
|
|
362
|
-
.reject { ignore_stdlib.include?(_1) }
|
|
363
|
-
.join(',')
|
|
364
|
-
end
|
|
365
|
-
|
|
366
|
-
def std_libs
|
|
367
|
-
return @std_libs unless @std_libs.empty?
|
|
368
|
-
|
|
369
|
-
command = ["#{ruby_bin}", '-e', "'puts $:'"].join(' ')
|
|
370
|
-
|
|
371
|
-
@std_libs = exec_command(command, 'Check std_libs', true).split("\n")
|
|
372
|
-
end
|
|
373
|
-
|
|
374
|
-
def gem_libs
|
|
375
|
-
return [] unless gemfile
|
|
376
|
-
return @gem_libs unless @gem_libs.empty?
|
|
377
|
-
|
|
378
|
-
FileUtils.cp_r(File.join(context, 'Gemfile'), work_dir)
|
|
379
|
-
FileUtils.cp_r(File.join(context, 'Gemfile.lock'), work_dir)
|
|
380
|
-
|
|
381
|
-
bundle_install
|
|
382
|
-
|
|
383
|
-
command = [
|
|
384
|
-
"#{ruby_bin}",
|
|
385
|
-
'-r',
|
|
386
|
-
"#{bundle_setup}",
|
|
387
|
-
'-e',
|
|
388
|
-
"'puts $:'"
|
|
389
|
-
].join(' ')
|
|
390
|
-
|
|
391
|
-
@gem_libs = (exec_command(command, 'Check gem_libs', true).split("\n") - std_libs)
|
|
392
|
-
end
|
|
393
|
-
end
|
|
394
|
-
|
|
395
|
-
class Fs
|
|
396
|
-
attr_reader :komop_cli, :lib_kompo_dir
|
|
397
|
-
|
|
398
|
-
def initialize
|
|
399
|
-
@komop_cli = local_komop_cli || ENV['KOMPO_CLI']
|
|
400
|
-
@lib_kompo_dir = local_lib_kompo_dir || ENV['LIB_KOMPO_DIR']
|
|
401
|
-
end
|
|
402
|
-
|
|
403
|
-
def local_komop_cli
|
|
404
|
-
return nil if `which brew`.empty?
|
|
405
|
-
|
|
406
|
-
path = `brew --prefix kompo-vfs`.chomp + '/bin/kompo-cli'
|
|
407
|
-
if File.exist?(path)
|
|
408
|
-
path
|
|
409
|
-
else
|
|
410
|
-
nil
|
|
411
|
-
end
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
def local_lib_kompo_dir
|
|
415
|
-
return nil if `which brew`.empty?
|
|
416
|
-
|
|
417
|
-
path = `brew --prefix kompo-vfs`.chomp + '/lib'
|
|
418
|
-
if File.exist?(path)
|
|
419
|
-
path
|
|
420
|
-
else
|
|
421
|
-
nil
|
|
422
|
-
end
|
|
423
|
-
end
|
|
424
|
-
end
|
|
7
|
+
# Fixed path prefix for Ruby installation
|
|
8
|
+
# Using a fixed path ensures that cached Ruby binaries work correctly,
|
|
9
|
+
# since Ruby has hardcoded paths for standard library locations.
|
|
10
|
+
KOMPO_PREFIX = '/kompo'
|
|
11
|
+
|
|
12
|
+
# Utility classes
|
|
13
|
+
autoload :KompoIgnore, 'kompo/kompo_ignore'
|
|
14
|
+
|
|
15
|
+
# Struct to hold file data for embedding (used by MakeFsC)
|
|
16
|
+
autoload :KompoFile, 'kompo/tasks/make_fs_c'
|
|
17
|
+
|
|
18
|
+
# Core tasks
|
|
19
|
+
autoload :WorkDir, 'kompo/tasks/work_dir'
|
|
20
|
+
autoload :CopyProjectFiles, 'kompo/tasks/copy_project_files'
|
|
21
|
+
autoload :CopyGemfile, 'kompo/tasks/copy_gemfile'
|
|
22
|
+
autoload :MakeMainC, 'kompo/tasks/make_main_c'
|
|
23
|
+
autoload :MakeFsC, 'kompo/tasks/make_fs_c'
|
|
24
|
+
|
|
25
|
+
# Ruby installation
|
|
26
|
+
autoload :InstallRuby, 'kompo/tasks/install_ruby'
|
|
27
|
+
autoload :CheckStdlibs, 'kompo/tasks/check_stdlibs'
|
|
28
|
+
|
|
29
|
+
# Bundle and gem tasks
|
|
30
|
+
autoload :BundleInstall, 'kompo/tasks/bundle_install'
|
|
31
|
+
autoload :FindNativeExtensions, 'kompo/tasks/find_native_extensions'
|
|
32
|
+
autoload :BuildNativeGem, 'kompo/tasks/build_native_gem'
|
|
33
|
+
|
|
34
|
+
# Final packing (Section: macOS uses clang, Linux uses gcc)
|
|
35
|
+
autoload :CollectDependencies, 'kompo/tasks/collect_dependencies'
|
|
36
|
+
autoload :Packing, 'kompo/tasks/packing'
|
|
37
|
+
|
|
38
|
+
# Homebrew path (macOS)
|
|
39
|
+
autoload :HomebrewPath, 'kompo/tasks/homebrew'
|
|
40
|
+
|
|
41
|
+
# Platform-specific dependencies (Section: macOS uses Homebrew, Linux checks via pkg-config)
|
|
42
|
+
autoload :InstallDeps, 'kompo/tasks/install_deps'
|
|
43
|
+
|
|
44
|
+
# External tool paths
|
|
45
|
+
autoload :KompoVfsPath, 'kompo/tasks/kompo_vfs_path'
|
|
46
|
+
autoload :KompoVfsVersionCheck, 'kompo/tasks/kompo_vfs_version_check'
|
|
47
|
+
autoload :RubyBuildPath, 'kompo/tasks/ruby_build_path'
|
|
48
|
+
autoload :CargoPath, 'kompo/tasks/cargo_path'
|
|
425
49
|
end
|
|
50
|
+
|
|
51
|
+
# Load cache methods (module methods, not autoloadable)
|
|
52
|
+
require_relative 'kompo/cache'
|
data/lib/main.c.erb
CHANGED
|
@@ -1,45 +1,58 @@
|
|
|
1
1
|
#include <ruby.h>
|
|
2
2
|
|
|
3
|
-
extern char *get_kompo_patch(void);
|
|
4
3
|
extern void ruby_init_ext(const char *name, void (*init)(void));
|
|
5
4
|
extern void Init_kompo_fs(void);
|
|
6
|
-
extern char *
|
|
7
|
-
<% exts.each do |(_, func)| %>
|
|
5
|
+
extern void kompo_fs_set_entrypoint_dir(const char *entrypoint_path);
|
|
6
|
+
<% context.exts.each do |(_, func)| %>
|
|
8
7
|
extern void <%= func %>(void);
|
|
9
8
|
<% end %>
|
|
10
9
|
void Init_gems(void)
|
|
11
10
|
{
|
|
12
|
-
<% exts.each do |(
|
|
13
|
-
ruby_init_ext("<%=
|
|
11
|
+
<% context.exts.each do |(ext_path, func)| %>
|
|
12
|
+
ruby_init_ext("<%= ext_path %>.so", <%= func %>);
|
|
14
13
|
<% end %>
|
|
15
14
|
}
|
|
16
|
-
<% ignore_stdlib.each do |stdlib|%>
|
|
17
|
-
void <%= "Init_#{stdlib.gsub('/', '_')}" %>(void){}
|
|
18
|
-
<% end %>
|
|
19
15
|
|
|
20
16
|
int main(int argc, char **argv)
|
|
21
17
|
{
|
|
22
|
-
|
|
18
|
+
<% if context.has_gemfile %>
|
|
19
|
+
int c = argc + 3;
|
|
23
20
|
char *argv2[c];
|
|
24
21
|
|
|
25
22
|
argv2[0] = argv[0];
|
|
26
|
-
argv2[1] = "-
|
|
27
|
-
argv2[2] =
|
|
23
|
+
argv2[1] = (char *)"-r";
|
|
24
|
+
argv2[2] = (char *)"bundler/setup";
|
|
25
|
+
argv2[3] = (char *)"<%= context.work_dir_entrypoint %>";
|
|
28
26
|
for (int i = 1; i < argc; i++) {
|
|
29
|
-
argv2[i +
|
|
27
|
+
argv2[i + 3] = argv[i];
|
|
30
28
|
}
|
|
29
|
+
<% else %>
|
|
30
|
+
int c = argc + 1;
|
|
31
|
+
char *argv2[c];
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
argv2[0] = argv[0];
|
|
34
|
+
argv2[1] = (char *)"<%= context.work_dir_entrypoint %>";
|
|
35
|
+
for (int i = 1; i < argc; i++) {
|
|
36
|
+
argv2[i + 1] = argv[i];
|
|
37
|
+
}
|
|
38
|
+
<% end %>
|
|
39
|
+
|
|
40
|
+
char **argv2_ptr = argv2;
|
|
41
|
+
ruby_sysinit(&c, &argv2_ptr);
|
|
33
42
|
|
|
34
43
|
RUBY_INIT_STACK;
|
|
35
44
|
ruby_init();
|
|
36
45
|
|
|
37
46
|
Init_kompo_fs();
|
|
47
|
+
|
|
48
|
+
const char *entrypoint = "<%= context.work_dir_entrypoint %>";
|
|
49
|
+
kompo_fs_set_entrypoint_dir(entrypoint);
|
|
50
|
+
|
|
38
51
|
Init_gems();
|
|
39
52
|
|
|
40
|
-
void *node = ruby_options(c,
|
|
53
|
+
void *node = ruby_options(c, argv2_ptr);
|
|
41
54
|
|
|
42
55
|
// set $0
|
|
43
|
-
ruby_script(
|
|
56
|
+
ruby_script("<%= File.basename(context.project_dir) %>");
|
|
44
57
|
return ruby_run_node(node);
|
|
45
58
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
---
|
|
2
|
+
path: ".gem_rbs_collection"
|
|
3
|
+
gems:
|
|
4
|
+
- name: ast
|
|
5
|
+
version: '2.4'
|
|
6
|
+
source:
|
|
7
|
+
type: git
|
|
8
|
+
name: ruby/gem_rbs_collection
|
|
9
|
+
revision: 2813b6be44d7617d5defa2aaecdbd4540ee1c418
|
|
10
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
11
|
+
repo_dir: gems
|
|
12
|
+
- name: async
|
|
13
|
+
version: '2.12'
|
|
14
|
+
source:
|
|
15
|
+
type: git
|
|
16
|
+
name: ruby/gem_rbs_collection
|
|
17
|
+
revision: 2813b6be44d7617d5defa2aaecdbd4540ee1c418
|
|
18
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
19
|
+
repo_dir: gems
|
|
20
|
+
- name: fileutils
|
|
21
|
+
version: '0'
|
|
22
|
+
source:
|
|
23
|
+
type: stdlib
|
|
24
|
+
- name: json
|
|
25
|
+
version: '0'
|
|
26
|
+
source:
|
|
27
|
+
type: stdlib
|
|
28
|
+
- name: logger
|
|
29
|
+
version: '0'
|
|
30
|
+
source:
|
|
31
|
+
type: stdlib
|
|
32
|
+
- name: monitor
|
|
33
|
+
version: '0'
|
|
34
|
+
source:
|
|
35
|
+
type: stdlib
|
|
36
|
+
- name: optparse
|
|
37
|
+
version: '0'
|
|
38
|
+
source:
|
|
39
|
+
type: stdlib
|
|
40
|
+
- name: parallel
|
|
41
|
+
version: '1.20'
|
|
42
|
+
source:
|
|
43
|
+
type: git
|
|
44
|
+
name: ruby/gem_rbs_collection
|
|
45
|
+
revision: 2813b6be44d7617d5defa2aaecdbd4540ee1c418
|
|
46
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
47
|
+
repo_dir: gems
|
|
48
|
+
- name: parser
|
|
49
|
+
version: '3.2'
|
|
50
|
+
source:
|
|
51
|
+
type: git
|
|
52
|
+
name: ruby/gem_rbs_collection
|
|
53
|
+
revision: 2813b6be44d7617d5defa2aaecdbd4540ee1c418
|
|
54
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
55
|
+
repo_dir: gems
|
|
56
|
+
- name: pathname
|
|
57
|
+
version: '0'
|
|
58
|
+
source:
|
|
59
|
+
type: stdlib
|
|
60
|
+
- name: prism
|
|
61
|
+
version: 1.4.0
|
|
62
|
+
source:
|
|
63
|
+
type: rubygems
|
|
64
|
+
- name: rainbow
|
|
65
|
+
version: '3.0'
|
|
66
|
+
source:
|
|
67
|
+
type: git
|
|
68
|
+
name: ruby/gem_rbs_collection
|
|
69
|
+
revision: 2813b6be44d7617d5defa2aaecdbd4540ee1c418
|
|
70
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
71
|
+
repo_dir: gems
|
|
72
|
+
- name: rake
|
|
73
|
+
version: '13.0'
|
|
74
|
+
source:
|
|
75
|
+
type: git
|
|
76
|
+
name: ruby/gem_rbs_collection
|
|
77
|
+
revision: 2813b6be44d7617d5defa2aaecdbd4540ee1c418
|
|
78
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
79
|
+
repo_dir: gems
|
|
80
|
+
- name: rbs
|
|
81
|
+
version: 3.9.2
|
|
82
|
+
source:
|
|
83
|
+
type: rubygems
|
|
84
|
+
- name: rdoc
|
|
85
|
+
version: '0'
|
|
86
|
+
source:
|
|
87
|
+
type: stdlib
|
|
88
|
+
- name: regexp_parser
|
|
89
|
+
version: '2.8'
|
|
90
|
+
source:
|
|
91
|
+
type: git
|
|
92
|
+
name: ruby/gem_rbs_collection
|
|
93
|
+
revision: 2813b6be44d7617d5defa2aaecdbd4540ee1c418
|
|
94
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
95
|
+
repo_dir: gems
|
|
96
|
+
- name: rubocop
|
|
97
|
+
version: '1.57'
|
|
98
|
+
source:
|
|
99
|
+
type: git
|
|
100
|
+
name: ruby/gem_rbs_collection
|
|
101
|
+
revision: 2813b6be44d7617d5defa2aaecdbd4540ee1c418
|
|
102
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
103
|
+
repo_dir: gems
|
|
104
|
+
- name: rubocop-ast
|
|
105
|
+
version: '1.30'
|
|
106
|
+
source:
|
|
107
|
+
type: git
|
|
108
|
+
name: ruby/gem_rbs_collection
|
|
109
|
+
revision: 2813b6be44d7617d5defa2aaecdbd4540ee1c418
|
|
110
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
111
|
+
repo_dir: gems
|
|
112
|
+
- name: tsort
|
|
113
|
+
version: '0'
|
|
114
|
+
source:
|
|
115
|
+
type: stdlib
|
|
116
|
+
gemfile_lock_path: Gemfile.lock
|
data/rbs_collection.yaml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Download sources
|
|
2
|
+
sources:
|
|
3
|
+
- type: git
|
|
4
|
+
name: ruby/gem_rbs_collection
|
|
5
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
6
|
+
revision: main
|
|
7
|
+
repo_dir: gems
|
|
8
|
+
|
|
9
|
+
# You can specify local directories as sources also.
|
|
10
|
+
# - type: local
|
|
11
|
+
# path: path/to/your/local/repository
|
|
12
|
+
|
|
13
|
+
# A directory to install the downloaded RBSs
|
|
14
|
+
path: .gem_rbs_collection
|
|
15
|
+
|
|
16
|
+
# gems:
|
|
17
|
+
# # If you want to avoid installing rbs files for gems, you can specify them here.
|
|
18
|
+
# - name: GEM_NAME
|
|
19
|
+
# ignore: true
|