Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove Ruby dependency to rutie #52

Merged
merged 1 commit into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: Remove Ruby dependency to rutie.
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
commit d05d4cc0838d42e903fec5ffed17a8cb380b74e2
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