kompo 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12a48f38a6abeb3b4587b542da43b0ecc1813a9c86db2104f162e706bb71a542
4
- data.tar.gz: 5c0b5d0b3c1fdd021482c4746befa09e699569e7c2fbe63ac746adae8656a6ba
3
+ metadata.gz: 824cb5818444206e527f8a70d899c53b922f05a2ee44b1433b9103e2bc00dec9
4
+ data.tar.gz: bc82fea90c7f254f3f1e2221cadd4dedb9ec0e0c64ae4a68163e5784a0de35d1
5
5
  SHA512:
6
- metadata.gz: 81f9ac47065c925cfcd51807123080fa0dd2304d75070bb7b44cfeba5c885ee7dd87d9498dde962d5dd48cb045af5deb62d438747f7e41d73925fd23412cfc5e
7
- data.tar.gz: 6d2c8f0613ce1ca07f28d364b8e37f306c7e0d0d760a5b11b88003c6198e19196f75dd807d4f413f9c39a5b5402c68d18995200a8169715eeb70c2e44e4272d5
6
+ metadata.gz: 164750a94ce03e80d4dbdbd6c88a33ea76e92e5ddcd0a7ee2170aa76e2c24c3471616739a21adcd37724a49a0af93bb3805b73e14446159dc218cb514fb0fc9a
7
+ data.tar.gz: 7668b48ea202b6f21dccceb8a67097d1df27b6661295c36b756f9a537c09f5479ed326f86c0374b7bb5fef860d62f54a599c520212798a31b02c03ddb6bc295a
data/README.md CHANGED
@@ -36,12 +36,11 @@ $ LIB_KOMPO_DIR=/path/to/kompo-vfs/target/release
36
36
  * simple hello world script.
37
37
  * sinatra_and_sqlite
38
38
  * sinatra app with sqlite3 with Gemfile.
39
-
39
+ * rails
40
+ * 🚧
40
41
 
41
42
  ## Development
42
43
 
43
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
-
45
44
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
45
 
47
46
  ## Contributing
data/exe/kompo CHANGED
@@ -3,17 +3,7 @@
3
3
  require_relative '../lib/kompo'
4
4
  require 'optparse'
5
5
 
6
- option = Kompo::Option.new
7
-
8
- option.on('-e VAL', '--entrypoint=VAL') { |v| option.entrypoint = v }
9
- option.on('-o VAL', '--output=VAL') { |v| option.output = v }
10
- option.on('--[no-]gemfile') { |v| option.gemfile = v }
11
- option.on('--[no-]stdlib') { |v| option.stdlib = v }
12
- option.on('--dest-dir=VAL') { |v| option.dest_dir = v }
13
- option.on('--ruby-src-path=VAL') { |v| option.ruby_src_path = v }
14
- option.on('--cache-bundle-path=VAL') { |v| option.cache_bundle_path = v }
15
- option.on('--ruby-version=VAL') { |v| option.ruby_version = v }
16
- # option.on('--compress') { |v| option.compress = v }
6
+ option = Kompo::Option.default
17
7
 
18
8
  Kompo::Tasks.cd_work_dir(option) do |task|
19
9
  task.clone_ruby_src
data/lib/kompo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kompo
4
- VERSION = "0.1.4"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/kompo.rb CHANGED
@@ -12,24 +12,43 @@ module Kompo
12
12
 
13
13
  class Option
14
14
  extend Forwardable
15
- attr_accessor :entrypoint, :output, :gemfile, :stdlib, :dest_dir, :ruby_src_path, :cache_bundle_path, :ruby_version, :compress, :context, :args
15
+ attr_accessor :entrypoint, :output, :gemfile, :ignore_stdlib, :dyn_link_lib, :dest_dir, :ruby_src_path, :cache_bundle_path, :ruby_version, :compress, :context, :args, :use_group
16
16
  delegate %i[on] => :@opt
17
17
 
18
18
  def initialize(dir = Dir.getwd, opt = OptionParser.new)
19
19
  @entrypoint = File.join(dir, 'main.rb')
20
20
  @output = File.basename(dir)
21
- @gemfile = File.exist?(File.join(Dir.pwd, 'Gemfile'))
22
- @stdlib = true
21
+ @gemfile = File.exist?(File.join(Dir.getwd, 'Gemfile'))
22
+ @ignore_stdlib = []
23
+ @dyn_link_lib = []
23
24
  @dest_dir = dir
24
25
  @ruby_src_path = nil
25
26
  @cache_bundle_path = nil
26
27
  @ruby_version = "v#{RUBY_VERSION.gsub('.', '_')}"
27
28
  @compress = false
29
+ @use_group = 'default'
28
30
 
29
31
  @context = dir
30
32
  @opt = opt
31
33
  end
32
34
 
35
+ def self.default
36
+ option = new
37
+ option.on('-e VAL', '--entrypoint=VAL', "File path to use for entry point. (default: \'./main.rb\')") { |v| option.entrypoint = v }
38
+ option.on('-o VAL', '--output=VAL', 'Name of the generated file. (default: current dir name)') { |v| option.output = v }
39
+ option.on('-g VAL', '--use-group=VAL', "Group name to use with \'bundle install\'. (default: \'default\')") { |v| option.use_group = v }
40
+ option.on('--[no-]gemfile', "Use gem in Gemfile. (default: automatically true if Gemfile is present)") { |v| option.gemfile = v }
41
+ option.on('--ignore-stdlib=VAL', Array, "Specify stdlibs not to include, separated by commas.") { |v| option.ignore_stdlib = v }
42
+ option.on('--dyn-link-lib=VAL', Array, "Specify libraries to be dynamic link, separated by commas.") { |v| option.dyn_link_lib = v }
43
+ option.on('--dest-dir=VAL', "Output directry path. (default: current dir)") { |v| option.dest_dir = v }
44
+ option.on('--ruby-src-path=VAL', "Your Ruby source directry. Must be compiled with \'--with-static-linked-ext\'.") { |v| option.ruby_src_path = v }
45
+ option.on('--cache-bundle-path=VAL', "Specify the directory created by \'bundle install --standalone\'.") { |v| option.cache_bundle_path = v }
46
+ option.on('--ruby-version=VAL', "Specify Ruby version. (default: current Ruby version)") { |v| option.ruby_version = v }
47
+ # option.on('--compress') { |v| option.compress = v }
48
+
49
+ option
50
+ end
51
+
33
52
  def build
34
53
  @opt.parse!(ARGV)
35
54
 
@@ -53,9 +72,9 @@ module Kompo
53
72
 
54
73
  class Tasks
55
74
  extend Forwardable
56
- 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
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
57
76
 
58
- delegate %i[entrypoint output gemfile stdlib dest_dir ruby_src_path cache_bundle_path ruby_version compress context args] => :@option
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
59
78
  delegate %i[komop_cli lib_kompo_dir] => :@fs
60
79
 
61
80
  def initialize(option, dir)
@@ -64,14 +83,27 @@ module Kompo
64
83
  @work_dir = dir
65
84
  @fs = Fs.new
66
85
 
67
- @ruby_pc = File.join(ruby_src_path || File.join(dir, 'dest_dir', 'lib', 'pkgconfig'), 'ruby.pc')
68
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)
69
88
  @extinit_o = File.join(ruby_src_dir, 'ext', 'extinit.o')
70
89
  @encinit_o = File.join(ruby_src_dir, 'enc', 'encinit.o')
71
90
  @lib_ruby_static_dir = ruby_src_path || File.join(dir, 'dest_dir', 'lib')
72
91
 
73
92
  @std_libs = []
74
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
75
107
  end
76
108
 
77
109
  def valid?
@@ -108,7 +140,7 @@ module Kompo
108
140
  "--disable-install-capi",
109
141
  "--with-static-linked-ext",
110
142
  "--with-ruby-pc=ruby.pc",
111
- "--with-ext=#{get_exts_dir}"
143
+ "--with-ext=#{get_ruby_exts_dir}"
112
144
  ].join(' ')
113
145
  exec_command command, 'configure'
114
146
 
@@ -139,7 +171,7 @@ module Kompo
139
171
  command = [
140
172
  './bundler',
141
173
  'install',
142
- '--standalone'
174
+ "--standalone=#{use_group}",
143
175
  ].join(' ')
144
176
 
145
177
  exec_command command, 'bundle install'
@@ -182,10 +214,25 @@ module Kompo
182
214
  exec_command command, 'cargo build'
183
215
  copy_targets = Dir.glob(File.join(dir_name, 'target/release/*.a'))
184
216
  else
185
- objs = File.read(makefile).scan(/OBJS = (.*\.o)/).join(' ')
186
- command = ['make', '-C', dir_name, objs, '--always-make'].join(' ')
187
- exec_command command, 'make'
188
- copy_targets = objs.split(' ').map { File.join(dir_name, _1) }
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
+ }
189
236
  end
190
237
 
191
238
  dir = FileUtils.mkdir_p('exts/' + File.basename(dir_name)).first
@@ -204,16 +251,19 @@ module Kompo
204
251
  'gcc',
205
252
  '-O3',
206
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(' ')}",
207
258
  'main.c',
259
+ '-Wl,--start-group',
208
260
  Dir.glob('exts/**/*.o').join(' '),
209
261
  'fs.o',
210
- "#{lib_ruby_static_dir.nil? ? '' : '-L' + lib_ruby_static_dir}",
211
- "#{lib_kompo_dir.nil? ? '' : '-L' + lib_kompo_dir}",
212
- get_ruby_header,
213
- get_exts,
262
+ get_ruby_exts,
214
263
  '-lkompo',
215
264
  '-lruby-static',
216
265
  get_libs,
266
+ '-Wl,--end-group',
217
267
  '-o',
218
268
  output
219
269
  ].join(' ')
@@ -243,16 +293,37 @@ module Kompo
243
293
  end
244
294
  end
245
295
 
246
- def get_exts
247
- ["#{extinit_o}", "#{encinit_o}", *Dir.glob("#{ruby_src_dir}/ext/**/*.a"), *Dir.glob("#{ruby_src_dir}/enc/**/*.a")].join(' ')
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(" ")
248
318
  end
249
319
 
250
320
  def get_libs
251
321
  main_lib = get_mainlibs
252
322
  ext_libs = Dir.glob("#{ruby_src_dir}/ext/**/exts.mk").flat_map { File.read(_1).scan(/EXTLIBS = (.*)/) }.join(" ")
253
- gem_libs = Dir.glob("bundle/ruby/#{get_semantic_ruby_version}/gems/*/ext/*/Makefile").flat_map{ File.read(_1).scan(/LIBS = (.*)/)}.join(" ")
323
+ gem_libs = extract_gem_libs
324
+ dyn_link_libs = (['pthread', 'dl', 'm', 'c'] + dyn_link_lib).map { "-l" + _1 }
254
325
  dyn, static = eval("%W[#{main_lib} #{ext_libs} #{gem_libs}]").uniq
255
- .partition { _1 == "-lpthread" || _1 == "-ldl" || _1 == "-lm" || _1 == "-lc" }
326
+ .partition { dyn_link_libs.include?(_1) }
256
327
  dyn.unshift "-Wl,-Bdynamic"
257
328
  static.unshift "-Wl,-Bstatic"
258
329
 
@@ -277,24 +348,22 @@ module Kompo
277
348
  load_paths += gem_libs
278
349
  end
279
350
 
280
- if stdlib
281
- load_paths += std_libs
282
- end
351
+ load_paths += std_libs
283
352
 
284
353
  load_paths
285
354
  end
286
355
 
287
- def get_exts_dir
356
+ def get_ruby_exts_dir
288
357
  Dir.glob("#{ruby_src_dir}/**/extconf.rb")
289
358
  .reject { _1 =~ /-test-/ }
290
359
  .reject { _1 =~ /win32/ } # TODO
291
360
  .map { File.dirname(_1) }
292
361
  .map { _1.split("#{ruby_src_dir}/ext/")[1] }
362
+ .reject { ignore_stdlib.include?(_1) }
293
363
  .join(',')
294
364
  end
295
365
 
296
366
  def std_libs
297
- return [] unless stdlib
298
367
  return @std_libs unless @std_libs.empty?
299
368
 
300
369
  command = ["#{ruby_bin}", '-e', "'puts $:'"].join(' ')
data/lib/main.c.erb CHANGED
@@ -1,5 +1,4 @@
1
1
  #include <ruby.h>
2
- #include <string.h>
3
2
 
4
3
  extern char *get_kompo_patch(void);
5
4
  extern void ruby_init_ext(const char *name, void (*init)(void));
@@ -14,14 +13,21 @@ void Init_gems(void)
14
13
  ruby_init_ext("<%= so_path %>", <%= func %>);
15
14
  <% end %>
16
15
  }
16
+ <% ignore_stdlib.each do |stdlib|%>
17
+ void <%= "Init_#{stdlib.gsub('/', '_')}" %>(void){}
18
+ <% end %>
17
19
 
18
20
  int main(int argc, char **argv)
19
21
  {
20
- int c = 3;
22
+ int c = argc + 2;
23
+ char *argv2[c];
21
24
 
22
- // HACK: argv[0] is rewritten and reused by setproctitle()
23
- argv[1] = "-e";
24
- argv[2] = get_kompo_patch();
25
+ argv2[0] = argv[0];
26
+ argv2[1] = "-e";
27
+ argv2[2] = get_kompo_patch();
28
+ for (int i = 1; i < argc; i++) {
29
+ argv2[i + 2] = argv[i];
30
+ }
25
31
 
26
32
  ruby_sysinit(&c, &argv);
27
33
 
@@ -31,7 +37,7 @@ int main(int argc, char **argv)
31
37
  Init_kompo_fs();
32
38
  Init_gems();
33
39
 
34
- void *node = ruby_options(c, argv);
40
+ void *node = ruby_options(c, argv2);
35
41
 
36
42
  // set $0
37
43
  ruby_script(get_start_file_name());
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kompo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Hirano
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-24 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mini_portile2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: A tool to pack Ruby and Ruby scripts in one binary. This tool is still
14
28
  under development.
15
29
  email: