Skip to content

Commit

Permalink
Merge pull request #52 from Hywan/feat-remove-rutie-rb
Browse files Browse the repository at this point in the history
feat: Remove Ruby dependency to `rutie`
  • Loading branch information
Hywan authored May 17, 2021
2 parents 408e41a + d05d4cc commit b036a50
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 b036a50

Please sign in to comment.