wasify 0.1.1 → 0.1.2

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: f6c74bf50fb9cb72177396e5687833064870c6d6b7a4a9a4fac91056751312ed
4
- data.tar.gz: b164d1649f05462fa7ef8f2166e78bd305369c2905b098ec14ac2759148b341d
3
+ metadata.gz: 956439b8cb59f80aaf152c60599eea4fb4946edf6269f61c6ca457fdeef5650f
4
+ data.tar.gz: 72b83e12f5517a817d74445d94ce62073dd588d6266e70331175e3c9dee04e10
5
5
  SHA512:
6
- metadata.gz: 52df9a60f3c3c974ab0b129b17fb8df1762dca688d00ad981786d2eaa18a34508dcdde92419ff8af4f9bcedba26c3a795039a04644dec864467c0ef2c60006f7
7
- data.tar.gz: e42fcb4ec79e0c0748581b33cbfa7a11b5b701e4c7596d520d66cf72d1debf3c331cb6d3beb9875bb1a50805130ae55a907234e6e8dcbc289dbdf852569fb726
6
+ metadata.gz: 3261f2ad61f94f8cbdcd947f6e4db72735d12ff337a487f3ab7b941a18905e7ba860a8b5e968389572747a53e81e3f6e3a6ae43a15459e3817938667b888f351
7
+ data.tar.gz: 0c58d216c5d11b85d40107b7e0f5a0593e8cdbf96c246fa8946b858ee578569630b89a1fb73bdc4f2ef7989e28c51d70b23268a917cf7c934adf309456401e11
data/exe/wasify CHANGED
@@ -5,7 +5,10 @@ require 'wasify'
5
5
 
6
6
  raise 'Wrong number of arguments! Usage: wasify entrypoint.rb' if ARGV.length != 1
7
7
 
8
- if ARGV[0] == 'prepack'
8
+ if ARGV[0] == "-v"
9
+ require "wasify/version"
10
+ puts "Wasify version #{Wasify::VERSION}"
11
+ elsif ARGV[0] == 'prepack'
9
12
  Wasify.prepack
10
13
  else
11
14
  Wasify.pack
@@ -9,7 +9,7 @@ class Wasify
9
9
 
10
10
  def self.unzip_binary
11
11
  system('tar xfz ruby-3_2-wasm32-unknown-wasi-full-js.tar.gz')
12
- system('chmod u+rw 3_2-wasm32-unknown-wasi-full-js')
12
+ system('chmod -R u+rw 3_2-wasm32-unknown-wasi-full-js')
13
13
  end
14
14
 
15
15
  def self.move_binary
@@ -1,52 +1,92 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "fileutils"
4
+
3
5
  class Wasify
4
6
  # methods finding and copying dependecies
5
7
  class DepsManager
6
8
  def self.get_specs(deps)
7
- bundler_specs = Bundler.load.specs
8
- lf = bundler_specs.map(&:loaded_from)
9
- lf.select! { |item| !item.include?("/bundler-") && !item.include?("/wasify-") }
10
-
11
- spec_paths = []
12
- lf.each do |spec_path_str|
13
- if File.exist?(spec_path_str)
14
- spec_paths.append(spec_path_str)
15
- else
16
- loop do
17
- puts "#{spec_path_str} doesn't exist. Specify gemspec path or write 'skip' to skip specfile."
18
- path = $stdin.gets.chomp
19
- break if File.exist?(path) || (path == 'skip')
20
- end
21
- spec_paths.append(path) unless path == 'skip'
22
- end
9
+ # Bundler internals are annoying to look through. And mostly undocumented.
10
+ # It's amazing what you can find via "bundle exec irb" and then "Bundler.load".
11
+ bundler_specs = Bundler.load.requested_specs.to_a
12
+
13
+ # By default, Bundler only "installs" git: gems and path: gems partway.
14
+ # The specification remains dynamic. So if you require "lib/scarpe/version"
15
+ # in the gemspec, it breaks when vendored, because the specification is
16
+ # separated from the gem source (like lib/scarpe/version.rb). When
17
+ # a gem is built and installed, the gemspec is "baked" to a static version,
18
+ # either Ruby or YAML. But git: and path: gems don't do that. So we
19
+ # need to bake them ourselves using spec.to_ruby.
20
+ # (Thanks to Benedikt Deicke, who pointed out to_ruby.)
21
+
22
+ spec_contents = {}
23
+ bundler_specs.each do |spec|
24
+ next if ["bundler", "wasify"].include?(spec.name)
25
+
26
+ spec_contents["#{spec.full_name}.gemspec"] = spec.to_ruby
23
27
  end
24
- spec_paths
28
+ spec_contents
25
29
  end
26
30
 
27
31
  def self.get_deps
28
- deps = Bundler.load.specs.map(&:full_gem_path)
29
- modded_string_deps = []
30
- deps.each do |i|
31
- modded_string_deps.append(i)
32
+ return @all_gems if @all_gems
33
+
34
+ @all_gems = {}
35
+
36
+ # We don't want to copy random files (e.g. .git directories, .bundle) in a path: or git: gem dir.
37
+ # But also, Bundler has multiple kinds of specs. Installed baked specs often omit the file list
38
+ # or cut it down to just executables and top-level README-type files. So we have to do things
39
+ # differently for installed and non-installed specs :-(
40
+ specs = Bundler.load.requested_specs.to_a
41
+ specs.each do |spec|
42
+ root_path = File.expand_path spec.full_gem_path # Pretty sure the expand is unneeded
43
+
44
+ files = case spec
45
+ when Gem::Specification
46
+ #puts "#{spec.full_name} is a git: or path: gem"
47
+ spec.files
48
+ when Bundler::StubSpecification
49
+ # The specification file is wrong, but there should be only the right files already installed...
50
+ #puts "#{spec.full_name} is locally installed"
51
+ files = :all
52
+ else
53
+ raise "Not implemented! Figure out how to get Bundler data from a #{spec.class}!"
54
+ end
55
+
56
+ @all_gems[spec.full_name] = {
57
+ root: root_path,
58
+ files: files,
59
+ }
32
60
  end
33
- modded_string_deps
61
+
62
+ @all_gems
34
63
  end
35
64
 
36
65
  def self.copy_deps
37
- deps = get_deps
38
- deps.each do |i|
39
- status = system("cp -r #{i} ./3_2-wasm32-unknown-wasi-full-js/usr/local/lib/ruby/gems/3.2.0/gems")
40
- puts "Gem at #{i} not copied." unless status
66
+ get_deps.each do |gem_name, dep|
67
+ dest_dir = "./3_2-wasm32-unknown-wasi-full-js/usr/local/lib/ruby/gems/3.2.0/gems/#{gem_name}"
68
+ if dep[:files] == :all
69
+ FileUtils.cp_r dep[:root], dest_dir
70
+ elsif dep[:files].respond_to?(:each)
71
+ dep[:files].each do |file|
72
+ src = "#{dep[:root]}/#{file}"
73
+ dest = "#{dest_dir}/#{file}"
74
+ FileUtils.mkdir_p File.dirname(dest)
75
+ #STDERR.puts "cp: #{src.inspect} #{dest.inspect}"
76
+ FileUtils.cp src, dest
77
+ end
78
+ else
79
+ raise "Unexpected file list object!"
80
+ end
41
81
  end
42
82
  end
43
83
 
44
84
  def self.copy_specs
45
85
  deps = get_deps
46
86
  specs = get_specs(deps)
47
- specs.each do |s|
48
- status = system("cp #{s} ./3_2-wasm32-unknown-wasi-full-js/usr/local/lib/ruby/gems/3.2.0/specifications")
49
- puts "Specification at #{s} not copied." unless status
87
+ FileUtils.mkdir_p "./3_2-wasm32-unknown-wasi-full-js/usr/local/lib/ruby/gems/3.2.0/specifications/"
88
+ specs.each do |name, contents|
89
+ File.write("./3_2-wasm32-unknown-wasi-full-js/usr/local/lib/ruby/gems/3.2.0/specifications/#{name}", contents)
50
90
  end
51
91
  end
52
92
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Wasify
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wasify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Borgh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-09 00:00:00.000000000 Z
11
+ date: 2023-12-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -32,7 +32,6 @@ files:
32
32
  - lib/wasify/template.erb
33
33
  - lib/wasify/version.rb
34
34
  - sig/wasify.rbs
35
- - wasify.gemspec
36
35
  homepage: https://github.com/AlawysDelta/wasify
37
36
  licenses:
38
37
  - MIT
@@ -57,5 +56,5 @@ requirements: []
57
56
  rubygems_version: 3.4.1
58
57
  signing_key:
59
58
  specification_version: 4
60
- summary: Packs and run Ruby code on WASM
59
+ summary: Packs and runs Ruby code on WASM
61
60
  test_files: []
data/wasify.gemspec DELETED
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/wasify/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'wasify'
7
- spec.version = Wasify::VERSION
8
- spec.authors = ['Giovanni Borgh']
9
- spec.email = ['gio96b@gmail.com']
10
-
11
- spec.summary = 'Packs and run Ruby code on WASM'
12
- spec.license = 'MIT'
13
- spec.homepage = 'https://github.com/AlawysDelta/wasify'
14
- spec.required_ruby_version = '>= 3.2.0'
15
-
16
- spec.metadata['homepage_uri'] = spec.homepage
17
- spec.metadata['source_code_uri'] = 'https://github.com/AlawysDelta/wasify'
18
-
19
- # Specify which files should be added to the gem when it is released.
20
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(__dir__) do
22
- `git ls-files -z`.split("\x0").reject do |f|
23
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
24
- end
25
- end
26
- spec.bindir = 'exe'
27
- spec.executables = ['wasify']
28
- spec.require_paths = ['lib']
29
-
30
- # Uncomment to register a new dependency of your gem
31
- # spec.add_dependency "example-gem", "~> 1.0"
32
-
33
- # For more information and examples about making a new gem, check out our
34
- # guide at: https://bundler.io/guides/creating_gem.html
35
- end