kompo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.devcontainer/Dockerfile +11 -0
- data/.devcontainer/devcontainer.json +29 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +20 -0
- data/README.md +47 -0
- data/Rakefile +4 -0
- data/exe/kompo +48 -0
- data/lib/kompo/kompo_fs.rb +15 -0
- data/lib/kompo/version.rb +5 -0
- data/lib/kompo.rb +354 -0
- data/lib/main.c.erb +39 -0
- data/sample/Gemfile +8 -0
- data/sample/Gemfile.lock +48 -0
- data/sample/hello.rb +3 -0
- data/sample/main.rb +33 -0
- data/sig/kompo.rbs +4 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5dbdc8dbc6a43df828ee1915e06cd8bd0e18830c4fadc2405f0d74f4f5c8ee63
|
4
|
+
data.tar.gz: 2a6f1cee640f70c3b4662373bc8d8c0a223ca58dfe041a3666b97561b7be2541
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b22210acb628093c71f0094c8e55c9c06009ef1c223c18ce5c3edf99f08b0526a2b0fc40f68181132549927aa70e29c663eb8c56f02b5ffb63ca92b005828c5
|
7
|
+
data.tar.gz: cf8d83c95ebb2d4791aa7edcf7f0ce2553d21b835747ca02ebc001657edb2628ab87c530bde44d2ed288e65f0df77ab2ac8eba90e32fd5838c691b4b06d25f5f
|
@@ -0,0 +1,11 @@
|
|
1
|
+
FROM mcr.microsoft.com/devcontainers/base:ubuntu
|
2
|
+
# Install the xz-utils package
|
3
|
+
RUN apt-get update && apt-get install -y clang
|
4
|
+
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
|
5
|
+
ENV PATH="/root/.cargo/bin:$PATH"
|
6
|
+
RUN git clone https://github.com/ahogappa0613/kompo-vfs.git && \
|
7
|
+
cd kompo-vfs && \
|
8
|
+
sudo /root/.cargo/bin/cargo build --release && \
|
9
|
+
sudo cp target/release/kompo-cli /usr/local/bin && \
|
10
|
+
sudo cp target/release/libkompo.a /usr/local/lib
|
11
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
2
|
+
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
|
3
|
+
{
|
4
|
+
"name": "Ubuntu",
|
5
|
+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
6
|
+
"build": {
|
7
|
+
// Path is relative to the devcontainer.json file.
|
8
|
+
"dockerfile": "Dockerfile"
|
9
|
+
},
|
10
|
+
"features": {
|
11
|
+
"ghcr.io/devcontainers/features/ruby:1": {},
|
12
|
+
// "ghcr.io/devcontainers/features/rust:1": {},
|
13
|
+
},
|
14
|
+
"containerEnv": {
|
15
|
+
// "PATH": "/usr/local/cargo/bin:${containerEnv:PATH}",
|
16
|
+
"KOMPO_CLI": "/usr/local/bin/kompo-cli",
|
17
|
+
"LIB_KOMPO_DIR": "/usr/local/lib",
|
18
|
+
},
|
19
|
+
// Features to add to the dev container. More info: https://containers.dev/features.
|
20
|
+
// "features": {},
|
21
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
22
|
+
// "forwardPorts": [],
|
23
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
24
|
+
// "postCreateCommand": "uname -a",
|
25
|
+
// Configure tool-specific properties.
|
26
|
+
// "customizations": {},
|
27
|
+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
28
|
+
// "remoteUser": "root"
|
29
|
+
}
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Kompo
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kompo`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### prerequisites
|
22
|
+
Install [komp-vfs](https://github.com/ahogappa0613/kompo-vfs).
|
23
|
+
|
24
|
+
#### Homebrew
|
25
|
+
```sh
|
26
|
+
$ brew tap ahogappa0613/kompo-vfs https://github.com/ahogappa0613/kompo-vfs.git
|
27
|
+
$ brew install ahogappa0613/kompo-vfs/kompo-vfs
|
28
|
+
```
|
29
|
+
|
30
|
+
### Quick Start
|
31
|
+
If you want to try it out, `cd` to the `sample/` directory and execute the following:
|
32
|
+
```sh
|
33
|
+
$ kompo
|
34
|
+
```
|
35
|
+
This will read the Gemfile in the directory and create an executable file with `main.rb` as the entry point in the same directory as `./sample` in the same directory.
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
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.
|
42
|
+
|
43
|
+
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).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ahogappa0613/kompo.
|
data/Rakefile
ADDED
data/exe/kompo
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/kompo'
|
4
|
+
require 'optparse'
|
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 }
|
17
|
+
|
18
|
+
Kompo::Tasks.cd_work_dir(option) do |task|
|
19
|
+
task.clone_ruby_src
|
20
|
+
|
21
|
+
task.fs_cli
|
22
|
+
|
23
|
+
task.make_main_c
|
24
|
+
|
25
|
+
task.packing
|
26
|
+
|
27
|
+
task.copy_to_dest_dir
|
28
|
+
end
|
29
|
+
|
30
|
+
puts 'info: Finish kompo!'
|
31
|
+
|
32
|
+
require 'debug'
|
33
|
+
module Kernel
|
34
|
+
def require(path)
|
35
|
+
debugger
|
36
|
+
end
|
37
|
+
def autoload(const, file)
|
38
|
+
Object.autoload(const, file)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Module
|
43
|
+
alias original_autoload autoload
|
44
|
+
def autoload(const_name, file)
|
45
|
+
original_autoload(const_name, file)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
autoload(:Hoge, 'make_main.rb')
|
data/lib/kompo.rb
ADDED
@@ -0,0 +1,354 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tmpdir"
|
4
|
+
require 'pathname'
|
5
|
+
require 'optparse'
|
6
|
+
require "fileutils"
|
7
|
+
require 'forwardable'
|
8
|
+
require_relative "kompo/version"
|
9
|
+
|
10
|
+
module Kompo
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
13
|
+
class Option
|
14
|
+
extend Forwardable
|
15
|
+
attr_accessor :entrypoint, :output_name, :gemfile, :stdlib, :dest_dir, :ruby_src_path, :cache_bundle_path, :ruby_version, :compress, :context, :args
|
16
|
+
delegate %i[on] => :@opt
|
17
|
+
|
18
|
+
def initialize(dir = Dir.getwd, opt = OptionParser.new)
|
19
|
+
@entrypoint = File.join(dir, 'main.rb')
|
20
|
+
@output_name = File.basename(dir)
|
21
|
+
@gemfile = true
|
22
|
+
@stdlib = true
|
23
|
+
@dest_dir = dir
|
24
|
+
@ruby_src_path = nil
|
25
|
+
@cache_bundle_path = nil
|
26
|
+
@ruby_version = "v#{RUBY_VERSION.gsub('.', '_')}"
|
27
|
+
@compress = false
|
28
|
+
|
29
|
+
@context = dir
|
30
|
+
@opt = opt
|
31
|
+
end
|
32
|
+
|
33
|
+
def build
|
34
|
+
@opt.parse!(ARGV)
|
35
|
+
|
36
|
+
@args = convert_absolute_path_for ARGV
|
37
|
+
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def convert_absolute_path_for(args)
|
44
|
+
args.map do |arg|
|
45
|
+
if File.absolute_path?(arg)
|
46
|
+
arg
|
47
|
+
else
|
48
|
+
Pathname.new(File.join(context, arg)).cleanpath.to_s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Tasks
|
55
|
+
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
|
57
|
+
|
58
|
+
delegate %i[entrypoint output_name gemfile stdlib dest_dir ruby_src_path cache_bundle_path ruby_version compress context args] => :@option
|
59
|
+
delegate %i[komop_cli lib_kompo_dir] => :@fs
|
60
|
+
|
61
|
+
def initialize(option, dir)
|
62
|
+
@option = option
|
63
|
+
@ruby_src_dir = File.expand_path(ruby_src_path || File.join(dir, 'ruby'))
|
64
|
+
@work_dir = dir
|
65
|
+
@fs = Fs.new
|
66
|
+
|
67
|
+
@ruby_pc = File.join(ruby_src_path || File.join(dir, 'dest_dir', 'lib', 'pkgconfig'), 'ruby.pc')
|
68
|
+
@ruby_bin = File.join(ruby_src_path || File.join(dir, 'dest_dir', 'bin'), 'ruby')
|
69
|
+
@extinit_o = File.join(ruby_src_dir, 'ext', 'extinit.o')
|
70
|
+
@encinit_o = File.join(ruby_src_dir, 'enc', 'encinit.o')
|
71
|
+
@lib_ruby_static_dir = ruby_src_path || File.join(dir, 'dest_dir', 'lib')
|
72
|
+
|
73
|
+
@std_libs = []
|
74
|
+
@gem_libs = []
|
75
|
+
end
|
76
|
+
|
77
|
+
def valid?
|
78
|
+
raise "kompo-cli not found. Please install 'kompo-cli'." unless komop_cli
|
79
|
+
raise "libkompo_fs.a not found. Please install 'kompo-cli'." unless lib_kompo_dir
|
80
|
+
raise "Entrypoint not found: '#{entrypoint}'. Please specify the entry file path with '-e' or '--entrypoint' option." unless File.exist?(entrypoint)
|
81
|
+
|
82
|
+
true
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.cd_work_dir(option)
|
86
|
+
Dir.mktmpdir do |dir|
|
87
|
+
task = new(option.build, dir)
|
88
|
+
task.valid?
|
89
|
+
FileUtils.cd(dir)
|
90
|
+
|
91
|
+
yield task
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def clone_ruby_src
|
96
|
+
if ruby_src_path.nil?
|
97
|
+
command = ['git', '-C', "#{work_dir}", 'clone', '-b', "#{ruby_version}", '--single-branch', '--depth=1', 'https://github.com/ruby/ruby.git'].join(' ')
|
98
|
+
exec_command command, 'git clone ruby.git'
|
99
|
+
|
100
|
+
Dir.chdir(ruby_src_dir) do
|
101
|
+
exec_command (File.exist?("#{ruby_src_dir}/autogen.sh") ? './autogen.sh' : "autoconf"), 'autoxxx'
|
102
|
+
|
103
|
+
command = [
|
104
|
+
'./configure',
|
105
|
+
"--prefix=#{work_dir}/dest_dir",
|
106
|
+
"--disable-install-doc",
|
107
|
+
"--disable-install-rdoc",
|
108
|
+
"--disable-install-capi",
|
109
|
+
"--with-static-linked-ext",
|
110
|
+
"--with-ruby-pc=ruby.pc",
|
111
|
+
"--with-ext=#{get_exts_dir}"
|
112
|
+
].join(' ')
|
113
|
+
exec_command command, 'configure'
|
114
|
+
|
115
|
+
exec_command ['make', 'install'].join(' '), 'build target version ruby'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def get_from_ruby_pc(option)
|
121
|
+
command = [
|
122
|
+
'pkg-config',
|
123
|
+
"#{option}",
|
124
|
+
"#{ruby_pc}"
|
125
|
+
].join(' ')
|
126
|
+
|
127
|
+
exec_command(command, 'pkg-config', true)
|
128
|
+
end
|
129
|
+
|
130
|
+
def bundle_install
|
131
|
+
if cache_bundle_path
|
132
|
+
FileUtils.cp_r(cache_bundle_path, work_dir)
|
133
|
+
@bundle_setup = File.join(cache_bundle_path, 'bundler', 'setup.rb')
|
134
|
+
@bundle_ruby = File.join(cache_bundle_path, 'ruby')
|
135
|
+
else
|
136
|
+
File.write('./bundler', File.read(`which bundle`.chomp).split("\n").tap { _1[0] = "#!#{ruby_bin}" }.join("\n"))
|
137
|
+
FileUtils.chmod(0755, './bundler')
|
138
|
+
|
139
|
+
command = [
|
140
|
+
'./bundler',
|
141
|
+
'install',
|
142
|
+
'--standalone'
|
143
|
+
].join(' ')
|
144
|
+
|
145
|
+
exec_command command, 'bundle install'
|
146
|
+
|
147
|
+
@bundle_setup = File.join(work_dir, 'bundle', 'bundler', 'setup.rb')
|
148
|
+
@bundle_ruby = File.join(work_dir, 'bundle', 'ruby')
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def fs_cli
|
153
|
+
command = [
|
154
|
+
komop_cli,
|
155
|
+
context,
|
156
|
+
args.join(' '),
|
157
|
+
get_load_paths,
|
158
|
+
"--entrypoint=#{entrypoint}",
|
159
|
+
].join(' ')
|
160
|
+
|
161
|
+
exec_command command, 'kompo-cli'
|
162
|
+
end
|
163
|
+
|
164
|
+
def make_main_c
|
165
|
+
require 'erb'
|
166
|
+
|
167
|
+
exts = []
|
168
|
+
Dir.glob(File.join(bundle_ruby, get_semantic_ruby_version, 'gems/**/extconf.rb')).each do |makefile_dir|
|
169
|
+
dir_name = File.dirname(makefile_dir)
|
170
|
+
makefile = File.join(dir_name, 'Makefile')
|
171
|
+
if File.exist?(cargo_toml = File.join(dir_name, 'Cargo.toml'))
|
172
|
+
command = [
|
173
|
+
'cargo',
|
174
|
+
'rustc',
|
175
|
+
'--release',
|
176
|
+
'--crate-type=staticlib',
|
177
|
+
'--target-dir',
|
178
|
+
'target',
|
179
|
+
"--manifest-path=#{cargo_toml}",
|
180
|
+
].join(' ')
|
181
|
+
exec_command command, 'cargo build'
|
182
|
+
copy_targets = Dir.glob(File.join(dir_name, 'target/release/*.a'))
|
183
|
+
else
|
184
|
+
objs = File.read(makefile).scan(/OBJS = (.*\.o)/).join(' ')
|
185
|
+
command = ['make', '-C', dir_name, objs, '--always-make'].join(' ')
|
186
|
+
exec_command command, 'make'
|
187
|
+
copy_targets = objs.split(' ').map { File.join(dir_name, _1) }
|
188
|
+
end
|
189
|
+
|
190
|
+
dir = FileUtils.mkdir_p('exts/' + File.basename(dir_name)).first
|
191
|
+
FileUtils.cp(copy_targets, dir)
|
192
|
+
prefix = File.read(makefile).scan(/target_prefix = (.*)/).join.delete_prefix('/')
|
193
|
+
target_name = File.read(makefile).scan(/TARGET_NAME = (.*)/).join
|
194
|
+
exts << [File.join(prefix, "#{target_name}.so").delete_prefix('/'), "Init_#{target_name}"]
|
195
|
+
end
|
196
|
+
|
197
|
+
File.write("main.c", ERB.new(File.read(File.join(__dir__, 'main.c.erb'))).result(binding))
|
198
|
+
end
|
199
|
+
|
200
|
+
def packing
|
201
|
+
command = [
|
202
|
+
'gcc',
|
203
|
+
'-O3',
|
204
|
+
'-Wall',
|
205
|
+
'main.c',
|
206
|
+
'exts/**/*.o',
|
207
|
+
'fs.o',
|
208
|
+
"#{lib_ruby_static_dir.nil? ? '' : '-L' + lib_ruby_static_dir}",
|
209
|
+
"#{lib_kompo_dir.nil? ? '' : '-L' + lib_kompo_dir}",
|
210
|
+
get_ruby_header,
|
211
|
+
get_exts,
|
212
|
+
'-lkompo',
|
213
|
+
'-lruby-static',
|
214
|
+
get_libs,
|
215
|
+
'-o',
|
216
|
+
output_name
|
217
|
+
].join(' ')
|
218
|
+
|
219
|
+
exec_command command, 'Packing'
|
220
|
+
end
|
221
|
+
|
222
|
+
def copy_to_dest_dir
|
223
|
+
command = ['cp', '-f', output_name, dest_dir].join(' ')
|
224
|
+
exec_command command, 'Copy to dest dir'
|
225
|
+
end
|
226
|
+
|
227
|
+
private
|
228
|
+
|
229
|
+
def exec_command(command, info = nil, ret = false)
|
230
|
+
puts "exec: #{info}" if info
|
231
|
+
puts command
|
232
|
+
if ret
|
233
|
+
ret = `#{command}`.chomp
|
234
|
+
if $?.exited?
|
235
|
+
ret
|
236
|
+
else
|
237
|
+
raise "Failed to execute command: #{command}"
|
238
|
+
end
|
239
|
+
else
|
240
|
+
system command, exception: true
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def get_exts
|
245
|
+
["#{extinit_o}", "#{encinit_o}", *Dir.glob("#{ruby_src_dir}/ext/**/*.a"), *Dir.glob("#{ruby_src_dir}/enc/**/*.a")].join(' ')
|
246
|
+
end
|
247
|
+
|
248
|
+
def get_libs
|
249
|
+
main_lib = get_mainlibs
|
250
|
+
ext_libs = Dir.glob("#{ruby_src_dir}/ext/**/exts.mk").flat_map { File.read(_1).scan(/EXTLIBS = (.*)/) }.join(" ")
|
251
|
+
gem_libs = Dir.glob("bundle/ruby/#{get_semantic_ruby_version}/gems/*/ext/*/Makefile").flat_map{ File.read(_1).scan(/LIBS = (.*)/)}.join(" ")
|
252
|
+
dyn, static = eval("%W[#{main_lib} #{ext_libs} #{gem_libs}]").uniq
|
253
|
+
.partition { _1 == "-lpthread" || _1 == "-ldl" || _1 == "-lm" || _1 == "-lc" }
|
254
|
+
dyn.unshift "-Wl,-Bdynamic"
|
255
|
+
static.unshift "-Wl,-Bstatic"
|
256
|
+
|
257
|
+
static.join(" ") + " " + dyn.join(" ")
|
258
|
+
end
|
259
|
+
|
260
|
+
def get_ruby_header
|
261
|
+
get_from_ruby_pc('--cflags')
|
262
|
+
end
|
263
|
+
|
264
|
+
def get_semantic_ruby_version
|
265
|
+
get_from_ruby_pc('--variable=ruby_version')
|
266
|
+
end
|
267
|
+
|
268
|
+
def get_mainlibs
|
269
|
+
get_from_ruby_pc('--variable=MAINLIBS')
|
270
|
+
end
|
271
|
+
|
272
|
+
def get_load_paths
|
273
|
+
load_paths = []
|
274
|
+
if gemfile
|
275
|
+
load_paths += gem_libs
|
276
|
+
end
|
277
|
+
|
278
|
+
if stdlib
|
279
|
+
load_paths += std_libs
|
280
|
+
end
|
281
|
+
|
282
|
+
load_paths
|
283
|
+
end
|
284
|
+
|
285
|
+
def get_exts_dir
|
286
|
+
Dir.glob("#{ruby_src_dir}/**/extconf.rb")
|
287
|
+
.reject { _1 =~ /-test-/ }
|
288
|
+
.reject { _1 =~ /win32/ } # TODO
|
289
|
+
.map { File.dirname(_1) }
|
290
|
+
.map { _1.split("#{ruby_src_dir}/ext/")[1] }
|
291
|
+
.join(',')
|
292
|
+
end
|
293
|
+
|
294
|
+
def std_libs
|
295
|
+
return [] unless stdlib
|
296
|
+
return @std_libs unless @std_libs.empty?
|
297
|
+
|
298
|
+
command = ["#{ruby_bin}", '-e', "'puts $:'"].join(' ')
|
299
|
+
|
300
|
+
@std_libs = exec_command(command, 'Check std_libs', true).split("\n")
|
301
|
+
end
|
302
|
+
|
303
|
+
def gem_libs
|
304
|
+
return [] unless gemfile
|
305
|
+
return @gem_libs unless @gem_libs.empty?
|
306
|
+
|
307
|
+
FileUtils.cp_r(File.join(context, 'Gemfile'), work_dir)
|
308
|
+
FileUtils.cp_r(File.join(context, 'Gemfile.lock'), work_dir)
|
309
|
+
|
310
|
+
bundle_install
|
311
|
+
|
312
|
+
command = [
|
313
|
+
"#{ruby_bin}",
|
314
|
+
'-r',
|
315
|
+
"#{bundle_setup}",
|
316
|
+
'-e',
|
317
|
+
"'puts $:'"
|
318
|
+
].join(' ')
|
319
|
+
|
320
|
+
@gem_libs = (exec_command(command, 'Check gem_libs', true).split("\n") - std_libs)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
class Fs
|
325
|
+
attr_reader :komop_cli, :lib_kompo_dir
|
326
|
+
|
327
|
+
def initialize
|
328
|
+
@komop_cli = local_komop_cli || ENV['KOMPO_CLI']
|
329
|
+
@lib_kompo_dir = local_lib_kompo_dir || ENV['LIB_KOMPO_DIR']
|
330
|
+
end
|
331
|
+
|
332
|
+
def local_komop_cli
|
333
|
+
return nil if `which brew`.empty?
|
334
|
+
|
335
|
+
path = `brew --prefix kompo-vfs`.chomp + '/bin/kompo-cli'
|
336
|
+
if File.exist?(path)
|
337
|
+
path
|
338
|
+
else
|
339
|
+
nil
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
def local_lib_kompo_dir
|
344
|
+
return nil if `which brew`.empty?
|
345
|
+
|
346
|
+
path = `brew --prefix kompo-vfs`.chomp + '/lib'
|
347
|
+
if File.exist?(path)
|
348
|
+
path
|
349
|
+
else
|
350
|
+
nil
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
data/lib/main.c.erb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <string.h>
|
3
|
+
|
4
|
+
extern char *get_kompo_patch(void);
|
5
|
+
extern void ruby_init_ext(const char *name, void (*init)(void));
|
6
|
+
extern void Init_kompo_fs(void);
|
7
|
+
extern char *get_start_file_name(void);
|
8
|
+
<% exts.each do |(_, func)| %>
|
9
|
+
extern void <%= func %>(void);
|
10
|
+
<% end %>
|
11
|
+
void Init_gems(void)
|
12
|
+
{
|
13
|
+
<% exts.each do |(so_path, func)| %>
|
14
|
+
ruby_init_ext("<%= so_path %>", <%= func %>);
|
15
|
+
<% end %>
|
16
|
+
}
|
17
|
+
|
18
|
+
int main(int argc, char **argv)
|
19
|
+
{
|
20
|
+
int c = 3;
|
21
|
+
|
22
|
+
// HACK: argv[0] is rewritten and reused by setproctitle()
|
23
|
+
argv[1] = "-e";
|
24
|
+
argv[2] = get_kompo_patch();
|
25
|
+
|
26
|
+
ruby_sysinit(&c, &argv);
|
27
|
+
|
28
|
+
RUBY_INIT_STACK;
|
29
|
+
ruby_init();
|
30
|
+
|
31
|
+
Init_kompo_fs();
|
32
|
+
Init_gems();
|
33
|
+
|
34
|
+
void *node = ruby_options(c, argv);
|
35
|
+
|
36
|
+
// set $0
|
37
|
+
ruby_script(get_start_file_name());
|
38
|
+
return ruby_run_node(node);
|
39
|
+
}
|
data/sample/Gemfile
ADDED
data/sample/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
base64 (0.2.0)
|
5
|
+
mini_portile2 (2.8.5)
|
6
|
+
mustermann (3.0.0)
|
7
|
+
ruby2_keywords (~> 0.0.1)
|
8
|
+
nio4r (2.7.0)
|
9
|
+
puma (6.4.2)
|
10
|
+
nio4r (~> 2.0)
|
11
|
+
rack (3.0.9.1)
|
12
|
+
rack-protection (4.0.0)
|
13
|
+
base64 (>= 0.1.0)
|
14
|
+
rack (>= 3.0.0, < 4)
|
15
|
+
rack-session (2.0.0)
|
16
|
+
rack (>= 3.0.0)
|
17
|
+
rackup (2.1.0)
|
18
|
+
rack (>= 3)
|
19
|
+
webrick (~> 1.8)
|
20
|
+
ruby2_keywords (0.0.5)
|
21
|
+
sinatra (4.0.0)
|
22
|
+
mustermann (~> 3.0)
|
23
|
+
rack (>= 3.0.0, < 4)
|
24
|
+
rack-protection (= 4.0.0)
|
25
|
+
rack-session (>= 2.0.0, < 3)
|
26
|
+
tilt (~> 2.0)
|
27
|
+
sqlite3 (1.7.2)
|
28
|
+
mini_portile2 (~> 2.8.0)
|
29
|
+
tilt (2.3.0)
|
30
|
+
webrick (1.8.1)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
aarch64-linux
|
34
|
+
arm-linux
|
35
|
+
arm64-darwin
|
36
|
+
ruby
|
37
|
+
x86-linux
|
38
|
+
x86_64-darwin
|
39
|
+
x86_64-linux
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
puma
|
43
|
+
rackup
|
44
|
+
sinatra
|
45
|
+
sqlite3
|
46
|
+
|
47
|
+
BUNDLED WITH
|
48
|
+
2.5.3
|
data/sample/hello.rb
ADDED
data/sample/main.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'sqlite3'
|
2
|
+
require 'sinatra'
|
3
|
+
|
4
|
+
require_relative './hello'
|
5
|
+
|
6
|
+
File.delete("sample.db") if File.exist?("sample.db")
|
7
|
+
|
8
|
+
db = SQLite3::Database.new "sample.db"
|
9
|
+
|
10
|
+
rows = db.execute <<-SQL
|
11
|
+
create table numbers (
|
12
|
+
name varchar(30),
|
13
|
+
val int
|
14
|
+
);
|
15
|
+
SQL
|
16
|
+
|
17
|
+
{
|
18
|
+
"one" => 1,
|
19
|
+
"two" => 2,
|
20
|
+
}.each do |pair|
|
21
|
+
db.execute "insert into numbers values ( ?, ? )", pair
|
22
|
+
end
|
23
|
+
|
24
|
+
set :bind, '0.0.0.0'
|
25
|
+
|
26
|
+
get '/' do
|
27
|
+
rows = db.execute 'select * from numbers;'
|
28
|
+
rows.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
get '/hello' do
|
32
|
+
Hello::World
|
33
|
+
end
|
data/sig/kompo.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kompo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sho Hirano
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Write a longer description or delete this line.
|
14
|
+
email:
|
15
|
+
- ahogappa@gmail.com
|
16
|
+
executables:
|
17
|
+
- kompo
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".devcontainer/Dockerfile"
|
22
|
+
- ".devcontainer/devcontainer.json"
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- exe/kompo
|
28
|
+
- lib/kompo.rb
|
29
|
+
- lib/kompo/kompo_fs.rb
|
30
|
+
- lib/kompo/version.rb
|
31
|
+
- lib/main.c.erb
|
32
|
+
- sample/Gemfile
|
33
|
+
- sample/Gemfile.lock
|
34
|
+
- sample/hello.rb
|
35
|
+
- sample/main.rb
|
36
|
+
- sig/kompo.rbs
|
37
|
+
homepage: https://github.com/ahogappa0613/kompo
|
38
|
+
licenses: []
|
39
|
+
metadata:
|
40
|
+
homepage_uri: https://github.com/ahogappa0613/kompo
|
41
|
+
source_code_uri: https://github.com/ahogappa0613/kompo
|
42
|
+
changelog_uri: https://github.com/ahogappa0613/kompo
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 2.6.0
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 3.3.11
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.4.10
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Write a short summary, because RubyGems requires one.
|
62
|
+
test_files: []
|