Skip to content

Commit

Permalink
feat: Remove Ruby dependency to rutie.
Browse files Browse the repository at this point in the history
By removing the dependency to `rutie` for the Ruby code (not for the
Rust code!), we can simplify our Rust code, including the Rust
doctests:

* No need to emulate `RbConfig`,
* So no need to have a build script for `wasmer` (`build.rs`),
* No need to get `rbconfig` in `Rakefile`,
* No need to manually add `rutie` to `$LOAD_PATh` when doctesting.
  • Loading branch information
Hywan committed May 17, 2021
1 parent 408e41a commit d05d4cc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require "rbconfig"
require "bundler/gem_tasks"
require "rake/testtask"

Expand Down
7 changes: 0 additions & 7 deletions crates/rutie-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ root = File.expand_path("../..", ENV["CARGO_MANIFEST_DIR"])
Dir.chdir(root)
class RbConfig
CONFIG = {{
"host_os" => ENV["TARGET"]
}}
end
$LOAD_PATH.unshift(File.expand_path("lib", root))
$LOAD_PATH.unshift(File.expand_path("vendor/bundle/rutie/lib", root))
require "wasmer"
Expand Down
7 changes: 0 additions & 7 deletions crates/wasmer/build.rs

This file was deleted.

31 changes: 29 additions & 2 deletions lib/wasmer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
require "rutie"
require "fiddle"

module Wasmer
Rutie.new(:wasmer_ruby).init "init", __dir__
shared_library_name = :wasmer_ruby
init_function = :init

shared_library_prefix =
case RUBY_PLATFORM
when /windows|mswin|mingw/ then ""
when /cygwin/ then "cyg"
else "lib"
end

shared_library_suffix =
case RUBY_PLATFORM
when /darwin/ then "dylib"
when /windows|mswin|mingw|cygwin/ then "dll"
else "so"
end

shared_library_directory = File.expand_path "../target/release/", __dir__
shared_library_path = File.join(
shared_library_directory,
[shared_library_prefix, shared_library_name, ".", shared_library_suffix].join()
)

Fiddle::Function.new(
Fiddle::dlopen(shared_library_path)[init_function.to_s],
[],
Fiddle::TYPE_VOIDP
).call
end
3 changes: 1 addition & 2 deletions wasmer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ Gem::Specification.new do |spec|
spec.extensions = %w(Rakefile)

spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(examples|tests)/}) }
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(examples|tests|doc)/}) }
end

spec.require_paths = %w(lib)

spec.add_dependency "rutie", "~> 0.0.4"
spec.add_development_dependency "bundler", "~> 2.1"
spec.add_development_dependency "rake", "~> 13.0"
end

0 comments on commit d05d4cc

Please sign in to comment.