wasmtime 0.1.0.alpha.2 → 0.1.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: 31e7ebaaa71bf16ca32bfbe4e5bb00c01c89da46871a546b59b317df42d6b945
4
- data.tar.gz: 3e475f5ea5b96f2b05c7ddc57d201099d3e834f3122b1f1bcef91c68e0a9e779
3
+ metadata.gz: 278e090fef9ae4f35850cc892273ddbe94b2b838b0fc619ca835a17505129957
4
+ data.tar.gz: fbafd3a60ace1ec5f4806ac94d86e73264feb16e5b4f781c09ad9927c070758e
5
5
  SHA512:
6
- metadata.gz: 495c7b203e4290403b2562014964ab37bea64d70ed4dba91119e9d37fd8d73b32de20724df1b65f57cddb8bde8a4abaf325443f19df9fca6ce8d10e701a8a86b
7
- data.tar.gz: e830188f74778df480edb8bd37372ef9f3d5870060625897b2cb693ff954139db8ae594e3f558abc86843d5df4592d27bf85855c7506d56d6dd5f1f883ca90a8
6
+ metadata.gz: '016450946bf0d7ee92ffbc44bdc1be90a83602a14a209e3c24e7cc438883845b0b19aa173288169beb5248a080205c8b1d9abe46b373868b72e5caed3e5831bb'
7
+ data.tar.gz: 8dda113d2501e84a1222dd5ccbc1683cc84490d30628f98f489c681db4e2712d0aa24d65261ae0f223377602d74293472e56166d6aae55d9253bebc78ce1d17d
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2020-05-07
11
+
12
+ ### Added
13
+
14
+ - Initial release.
15
+ - Support for calling exported functions on a module.
16
+ - Support for 32 and 64-bit integers and floats in arguments and as return values.
17
+ - Require patch for defining a Ruby module with functions for each export.
18
+
19
+ [unreleased]: https://github.com/dtcristo/wasmtime-ruby/compare/v0.1.0...HEAD
20
+ [0.1.0]: https://github.com/dtcristo/wasmtime-ruby/releases/tag/v0.1.0
data/README.md CHANGED
@@ -42,13 +42,32 @@ Install the `wasmtime` gem. Pre-compiled binaries are available for
42
42
  gem install wasmtime
43
43
  ```
44
44
 
45
- Given a you have WASM module in your current directory, such as the example
46
- `fibonacci.wasm` built from [here](https://github.com/dtcristo/wasmtime-ruby/tree/master/wasm/fibonacci).
45
+ WASM has two formats `*.wasm` (binary) and `*.wat` (human-readable text). Both
46
+ formats are supported. With the following `fibonacci.wat` file in your current
47
+ directory.
48
+
49
+ ```wat
50
+ ;; fibonacci.wat
51
+ (module
52
+ (export "fib" (func $fib))
53
+ (func $fib (param $n i32) (result i32)
54
+ (if (i32.lt_s (get_local $n) (i32.const 2))
55
+ (return (i32.const 1))
56
+ )
57
+ (return
58
+ (i32.add
59
+ (call $fib (i32.sub (get_local $n) (i32.const 2)))
60
+ (call $fib (i32.sub (get_local $n) (i32.const 1)))
61
+ )
62
+ )
63
+ )
64
+ )
65
+ ```
47
66
 
48
- First `require 'wasmtime/require'` to activate the Wasmtime require patch,
49
- allowing you to require any `*.wasm` module as if it were a Ruby file. Doing so
50
- will internally create a `Wasmtime::Instance` and define a Ruby module with
51
- functions for each export.
67
+ In a ruby file, `require 'wasmtime/require'` to activate the Wasmtime require
68
+ patch, allowing you to require any `*.wasm` or `*.wat` module as if it were a
69
+ Ruby file. Doing so will internally create a `Wasmtime::Instance` and define a
70
+ Ruby module with functions for each export.
52
71
 
53
72
  Finally, invoke the `fib` export like so.
54
73
 
@@ -66,14 +85,18 @@ use this approach too.
66
85
  ```rb
67
86
  require 'wasmtime'
68
87
 
69
- instance = Wasmtime::Instance.new('fibonacci.wasm')
88
+ instance = Wasmtime::Instance.new('fibonacci.wat')
70
89
  puts instance.funcs[:fib].call(11) #=> 89
71
90
  ```
72
91
 
92
+ ## Benchmarks
93
+
94
+ None yet. But they will be impressive.
95
+
73
96
  ## Examples
74
97
 
75
- More usage examples are provided in `examples/`. To run these, you first need to
76
- compiling the test WASM modules.
98
+ More usage examples are provided in `examples/`. To run some of these, you first
99
+ need to compile the test WASM modules.
77
100
 
78
101
  Install some Rust tools.
79
102
 
@@ -13,16 +13,24 @@ module Kernel
13
13
  def require(path)
14
14
  wasmtime_original_require(path)
15
15
  rescue LoadError => load_error
16
- path = "#{path}.wasm" unless path.end_with?('.wasm')
16
+ try_load =
17
+ Proc.new do |path, extention|
18
+ path_with_extention =
19
+ path.end_with?(".#{extention}") ? path : "#{path}.#{extention}"
20
+
21
+ if path_with_extention.start_with?('.', '/', '~')
22
+ absolute_path = File.expand_path(path_with_extention)
23
+ return Wasmtime.load(absolute_path) if File.file?(absolute_path)
24
+ end
25
+ $LOAD_PATH.each do |load_dir|
26
+ absolute_path = File.expand_path(path_with_extention, load_dir)
27
+ return Wasmtime.load(absolute_path) if File.file?(absolute_path)
28
+ end
29
+ end
30
+
31
+ try_load.call(path, 'wasm')
32
+ try_load.call(path, 'wat')
17
33
 
18
- if path.start_with?('.', '/', '~')
19
- absolute_path = File.expand_path(path)
20
- return Wasmtime.load(absolute_path) if File.file?(absolute_path)
21
- end
22
- $LOAD_PATH.each do |load_dir|
23
- absolute_path = File.expand_path(path, load_dir)
24
- return Wasmtime.load(absolute_path) if File.file?(absolute_path)
25
- end
26
34
  raise load_error
27
35
  end
28
36
 
@@ -43,12 +51,17 @@ module Wasmtime
43
51
 
44
52
  def load(absolute_path)
45
53
  return false if $LOADED_FEATURES.include?(absolute_path)
46
- const =
47
- absolute_path.split(File::SEPARATOR).last.delete_suffix('.wasm').camelize
48
- mod = Object.const_set(const, Module.new)
54
+ filename = absolute_path.split(File::SEPARATOR).last
55
+ module_name =
56
+ if filename.end_with?('.wasm')
57
+ filename.delete_suffix('.wasm')
58
+ else
59
+ filename.delete_suffix('.wat')
60
+ end
61
+ mod = Object.const_set(module_name.camelize, Module.new)
49
62
  instance = Wasmtime::Instance.new(absolute_path)
50
63
  instance.funcs.each do |name, func|
51
- mod.define_singleton_method(name) { |args| func.call(args) }
64
+ mod.define_singleton_method(name) { |*args| func.call(*args) }
52
65
  end
53
66
  $LOADED_FEATURES << absolute_path
54
67
  true
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wasmtime
4
- VERSION = '0.1.0.alpha.2'
4
+ VERSION = '0.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wasmtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cristofaro
@@ -20,6 +20,7 @@ extensions:
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - ".cargo/config"
23
+ - CHANGELOG.md
23
24
  - Cargo.lock
24
25
  - Cargo.toml
25
26
  - LICENSE
@@ -42,6 +43,7 @@ licenses:
42
43
  - Apache-2.0 WITH LLVM-exception
43
44
  metadata:
44
45
  source_code_uri: https://github.com/dtcristo/wasmtime-ruby
46
+ changelog_uri: https://github.com/dtcristo/wasmtime-ruby/blob/master/CHANGELOG.md
45
47
  post_install_message:
46
48
  rdoc_options: []
47
49
  require_paths:
@@ -53,9 +55,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
55
  version: 2.5.0
54
56
  required_rubygems_version: !ruby/object:Gem::Requirement
55
57
  requirements:
56
- - - ">"
58
+ - - ">="
57
59
  - !ruby/object:Gem::Version
58
- version: 1.3.1
60
+ version: '0'
59
61
  requirements: []
60
62
  rubygems_version: 3.1.2
61
63
  signing_key: