Skip to content

Commit

Permalink
Add support for a custom ruby extension directory
Browse files Browse the repository at this point in the history
  • Loading branch information
malept committed Mar 9, 2018
1 parent 7ae5822 commit 7709bd2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ Possible options:
to `false`.
* `ruby_project_path` - the top-level directory of the Ruby gem's project. Defaults to the
current working directory.
* `ruby_extension_dir` - the directory relative to `ruby_project_path` where the extension is
located. Defaults to `lib`.

### Example

Expand Down
10 changes: 9 additions & 1 deletion lib/thermite/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,19 @@ def cargo_toml_path
end
end

#
# The relative directory where the Rust shared library resides, in the context of the Ruby
# project.
#
def ruby_extension_dir
@ruby_extension_dir ||= @options.fetch(:ruby_extension_dir, 'lib')
end

#
# Path to the Rust shared library in the context of the Ruby project.
#
def ruby_extension_path
ruby_path('lib', shared_library)
ruby_path(ruby_extension_dir, shared_library)
end

#
Expand Down
2 changes: 2 additions & 0 deletions lib/thermite/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class Tasks < Rake::TaskLib
# required. Defaults to `false`.
# * `ruby_project_path` - the toplevel directory of the Ruby gem's project. Defaults to the
# current working directory.
# * `ruby_extension_dir` - the directory relative to `ruby_project_path` where the extension is
# located. Defaults to `lib`.
#
# These values can be overridden by values with the same key name in the
# `package.metadata.thermite` section of `Cargo.toml`, if that section exists. The exceptions
Expand Down
7 changes: 7 additions & 0 deletions test/lib/thermite/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def test_ruby_extension_path
assert_equal '/tmp/foobar/lib/libfoo.ext', config.ruby_extension_path
end

def test_ruby_extension_path_with_custom_extension_dir
FileUtils.stubs(:pwd).returns('/tmp/foobar')
config.stubs(:ruby_extension_dir).returns('lib/ext')
config.stubs(:shared_library).returns('libfoo.ext')
assert_equal '/tmp/foobar/lib/ext/libfoo.ext', config.ruby_extension_path
end

def test_default_rust_toplevel_dir
FileUtils.stubs(:pwd).returns('/tmp/foobar')
assert_equal '/tmp/foobar', config.rust_toplevel_dir
Expand Down

0 comments on commit 7709bd2

Please sign in to comment.