thermite 0.6.0 → 0.7.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
  SHA1:
3
- metadata.gz: de41ccc420e335d2285e1a8d803e4ce55c669564
4
- data.tar.gz: 360be899c1e2c3e5162017de866811e50c7381de
3
+ metadata.gz: 39f322b4da859f7e40da6a34e28af9cece1266d1
4
+ data.tar.gz: f185a33fa330c7e8e9bd79f3b6e006a8a64dc5f9
5
5
  SHA512:
6
- metadata.gz: ada2a16519da8c1fd2361ec8b364bd0e3aaea4c6e750a6a8f877bfcf87275b590203df1bcc2ee33047e17c19fd34501c746667f4cc137361cd4baf39fbaee841
7
- data.tar.gz: 3966c01620f0e8d0b214c87c92c5731c5b5d0b164b685d7083a8eebdefe52512c132b1daa4b74251507fac0dfa285497e95a579411c8fd594c3ec9257353370c
6
+ metadata.gz: 27c5e1722048accc76e5cc6f92609aaf1e2a83188d4a19953158fb67d95b0de30333919d8acecf6604f08768ea84379d34878344af462cda96e4999ccd480acd
7
+ data.tar.gz: 1442ca9c640268a5905ffce5735f23e8b77680253c342ae242ca7e5a633b3d44a29da8f6f051b6fbb9e14eafd3780e1c05992e6755c7eaed75d3d629f9f6c076
data/NEWS.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.7.0] - 2016-09-26
6
+
7
+ ### Added
8
+
9
+ * Helper module for loading extensions via Fiddle (#13)
10
+
5
11
  ## [0.6.0] - 2016-09-12
6
12
 
7
13
  ### Added
@@ -79,6 +85,8 @@
79
85
 
80
86
  Initial release.
81
87
 
88
+ [0.7.0]: https://github.com/malept/thermite/compare/v0.6.0...v0.7.0
89
+ [0.6.0]: https://github.com/malept/thermite/compare/v0.5.0...v0.6.0
82
90
  [0.5.0]: https://github.com/malept/thermite/compare/v0.4.0...v0.5.0
83
91
  [0.4.0]: https://github.com/malept/thermite/compare/v0.3.0...v0.4.0
84
92
  [0.3.0]: https://github.com/malept/thermite/compare/v0.2.0...v0.3.0
data/README.md CHANGED
@@ -14,16 +14,40 @@ Thermite is a Rake-based helper for building and distributing Rust-based Ruby ex
14
14
  * Provides wrappers for `cargo` commands.
15
15
  * Handles non-standard `cargo` installations via the `CARGO` environment variable.
16
16
  * Opt-in to allow users to install pre-compiled Rust extensions hosted on GitHub releases.
17
+ * Provides a wrapper for initializing a Rust extension via Fiddle.
17
18
 
18
19
  ## Usage
19
20
 
20
- 1. Add `thermite` as a runtime dependency in your gem.
21
- 2. In your gemspec, add `Rakefile` to the specification's `extensions` list.
22
- 3. In `Rakefile`, add `require 'thermite/tasks'` and then add the tasks to the file by running:
21
+ 1. Add the following to your gemspec file:
23
22
 
24
- ```ruby
25
- Thermite::Tasks.new
26
- ```
23
+ ```ruby
24
+ spec.extensions << 'ext/Rakefile'
25
+ spec.add_runtime_dependency 'thermite', '~> 0'
26
+ ```
27
+
28
+ 2. Create `ext/Rakefile` with the following code, assuming that the Cargo project root is the same
29
+ as the Ruby project root:
30
+
31
+ ```ruby
32
+ require 'thermite/tasks'
33
+
34
+ project_dir = File.dirname(File.dirname(__FILE__))
35
+ Thermite::Tasks.new(cargo_project_path: project_dir, ruby_project_path: project_dir)
36
+ task default: %w(thermite:build)
37
+ ```
38
+
39
+ 3. In `Rakefile`, integrate Thermite into your build-test workflow:
40
+
41
+ ```ruby
42
+ require 'thermite/tasks'
43
+
44
+ Thermite::Tasks.new
45
+
46
+ desc 'Run Rust & Ruby testsuites'
47
+ task test: ['thermite:build', 'thermite:test'] do
48
+ # …
49
+ end
50
+ ```
27
51
 
28
52
  Run `rake -T` to view all of the available tasks in the `thermite` namespace.
29
53
 
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+ #
4
+ # Copyright (c) 2016 Mark Lee and contributors
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
7
+ # associated documentation files (the "Software"), to deal in the Software without restriction,
8
+ # including without limitation the rights to use, copy, modify, merge, publish, distribute,
9
+ # sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all copies or
13
+ # substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
16
+ # NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
19
+ # OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+
21
+ require 'fiddle'
22
+ require 'thermite/config'
23
+
24
+ module Thermite
25
+ #
26
+ # Fiddle helper functions.
27
+ #
28
+ module Fiddle
29
+ #
30
+ # Loads a native extension using {Thermite::Config} and the builtin `Fiddle` extension.
31
+ #
32
+ # @param init_function_name [String] the name of the native function that initializes
33
+ # the extension
34
+ # @param config_options [Hash] {Thermite::Tasks#options options} passed to {Thermite::Config}.
35
+ # Options likely needed to be set:
36
+ # `cargo_project_path`, `ruby_project_path`
37
+ #
38
+ def self.load_module(init_function_name, config_options)
39
+ config = Thermite::Config.new(config_options)
40
+ library = ::Fiddle.dlopen(config.ruby_extension_path)
41
+ func = ::Fiddle::Function.new(library[init_function_name],
42
+ [], ::Fiddle::TYPE_VOIDP)
43
+ func.call
44
+ end
45
+ end
46
+ end
@@ -57,11 +57,11 @@ module Thermite
57
57
  version = config.toml[:package][:version]
58
58
  tag = options.fetch(:git_tag_format, 'v%s') % version
59
59
  uri = github_download_uri(tag, version)
60
- if (tgz = download_binary_from_github_release(uri, version))
61
- debug "Unpacking GitHub release from Cargo version: #{File.basename(uri)}"
62
- unpack_tarball(tgz)
63
- true
64
- end
60
+ return unless (tgz = download_binary_from_github_release(uri, version))
61
+
62
+ debug "Unpacking GitHub release from Cargo version: #{File.basename(uri)}"
63
+ unpack_tarball(tgz)
64
+ true
65
65
  end
66
66
 
67
67
  #
data/lib/thermite/util.rb CHANGED
@@ -28,10 +28,10 @@ module Thermite
28
28
  #
29
29
  def debug(msg)
30
30
  # Should probably replace with a Logger
31
- if config.debug_filename
32
- @debug ||= File.open(config.debug_filename, 'w')
33
- @debug.write("#{msg}\n")
34
- end
31
+ return unless config.debug_filename
32
+
33
+ @debug ||= File.open(config.debug_filename, 'w')
34
+ @debug.write("#{msg}\n")
35
35
  end
36
36
  end
37
37
  end
data/test/test_helper.rb CHANGED
@@ -5,6 +5,7 @@ else
5
5
  require 'simplecov'
6
6
  SimpleCov.start do
7
7
  load_profile 'test_frameworks'
8
+ add_filter 'lib/thermite/fiddle.rb'
8
9
  add_filter 'lib/thermite/tasks.rb'
9
10
  track_files 'lib/**/*.rb'
10
11
  end
data/thermite.gemspec CHANGED
@@ -3,7 +3,7 @@ require 'English'
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'thermite'
6
- s.version = '0.6.0'
6
+ s.version = '0.7.0'
7
7
  s.summary = 'Rake helpers for Rust+Ruby'
8
8
  s.description = 'A Rake-based helper for building and distributing Rust-based Ruby extensions'
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thermite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-13 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -128,6 +128,7 @@ files:
128
128
  - ci/after_success.py
129
129
  - lib/thermite/cargo.rb
130
130
  - lib/thermite/config.rb
131
+ - lib/thermite/fiddle.rb
131
132
  - lib/thermite/github_release_binary.rb
132
133
  - lib/thermite/package.rb
133
134
  - lib/thermite/tasks.rb