thermite 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3eebbdde4fa61f1296c77482a2829de788c43af6
4
+ data.tar.gz: c18fc5b50c72c8a2df3f715a31e2ccdce1e3f0e0
5
+ SHA512:
6
+ metadata.gz: cc80fcb27a298be17c79241672c905f4d45f4eb9de4d660398e16e0bbea81b22edfee06611327436772d828066989d5a7f6d84cda6f16e7b6421f5baf73dd275
7
+ data.tar.gz: 7405ebd134cc09ae927c4a81aa5790ddfcb9feac862f9de455273d46a1e28b4de5f8acf94fab914e8b10a7af4d31fdb814cece4c32dcc343e339344b267bb1ac
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ doc
4
+ html
data/.rdoc_options ADDED
@@ -0,0 +1,24 @@
1
+ --- !ruby/object:RDoc::Options
2
+ encoding: UTF-8
3
+ static_path: []
4
+ rdoc_include:
5
+ - "lib/thermite/*.rb"
6
+ - "README.md"
7
+ charset: UTF-8
8
+ exclude:
9
+ - vendor/bundle
10
+ hyperlink_all: false
11
+ line_numbers: true
12
+ locale:
13
+ locale_dir: locale
14
+ locale_name:
15
+ main_page: README.md
16
+ markup: markdown
17
+ output_decoration: true
18
+ page_dir:
19
+ show_hash: false
20
+ tab_width: 2
21
+ template_stylesheets: []
22
+ title:
23
+ visibility: :protected
24
+ webcvs: https://github.com/malept/thermite/tree/master
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ Metrics/AbcSize:
2
+ Max: 20
3
+
4
+ Metrics/LineLength:
5
+ Max: 100
6
+ AllowURI: true
7
+ URISchemes:
8
+ - http
9
+ - https
10
+
11
+ Metrics/MethodLength:
12
+ Max: 20
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm: 2.3.1
3
+ cache: bundler
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --charset utf-8
2
+ --markup markdown
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+
4
+ source 'https://rubygems.org'
5
+
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Mark Lee and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Thermite
2
+
3
+ [![Build Status](https://travis-ci.org/malept/thermite.svg?branch=master)](https://travis-ci.org/malept/thermite)
4
+ [![Inline docs](http://inch-ci.org/github/malept/thermite.svg?branch=master)](http://inch-ci.org/github/malept/thermite)
5
+
6
+ Thermite is a Rake-based helper for building and distributing Rust-based Ruby extensions.
7
+
8
+ ## Features
9
+
10
+ * Provides wrappers for `cargo` commands.
11
+ * Handles non-standard `cargo` installations via the `CARGO` environment variable.
12
+ * Opt-in to allow users to install pre-compiled Rust extensions hosted on GitHub releases.
13
+
14
+ ## Usage
15
+
16
+ 1. Add `thermite` as a runtime dependency in your gem.
17
+ 2. In your gemspec, add `Rakefile` to the specification's `extensions` list.
18
+ 3. In `Rakefile`, add `require 'thermite/tasks'` and then add the tasks to the file by running:
19
+
20
+ ```ruby
21
+ Thermite::Tasks.new
22
+ ```
23
+
24
+ Run `rake -T` to view all of the available tasks in the `thermite` namespace.
25
+
26
+ You can optionally pass arguments to `Thermite::Tasks.new`, which configure the tasks for your
27
+ specific project:
28
+
29
+ * `cargo_project_path` - the path to the Cargo project. Defaults to the current working directory.
30
+ * `github_releases` - whether to look for Rust binaries via GitHub releases when installing
31
+ the gem, and `cargo` is not found. Defaults to `false`.
32
+ * `ruby_project_path` - the top-level directory of the Ruby gem's project. Defaults to the
33
+ current working directory.
34
+
35
+ ### Example
36
+
37
+ Using the cliché Rust+Ruby example, the [`rusty_blank`](https://github.com/malept/rusty_blank)
38
+ repository contains an example of using Thermite with [ruru](https://github.com/d-unseductable/ruru)
39
+ to provide a `String.blank?` speedup extension. While the example uses ruru, this gem should be
40
+ usable with any method of integrating Rust and Ruby that you choose.
41
+
42
+ ## FAQ
43
+
44
+ ### Why is it named Thermite?
45
+
46
+ According to Wikipedia:
47
+
48
+ * The chemical formula for ruby includes Al<sub>2</sub>O<sub>3</sub>, or aluminum oxide.
49
+ * Rust is iron oxide, or Fe<sub>2</sub>O<sub>3</sub>.
50
+ * A common thermite reaction uses iron oxide and aluminum to produce iron and aluminum oxide:
51
+ Fe<sub>2</sub>O<sub>3</sub> + 2Al → 2Fe + Al<sub>2</sub>O<sub>3</sub>
52
+
53
+ ## Legal
54
+
55
+ This gem is licensed under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
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 'bundler/gem_tasks'
22
+ require 'rdoc/task'
23
+ require 'rubocop/rake_task'
24
+
25
+ RDoc::Task.new
26
+ RuboCop::RakeTask.new
27
+
28
+ task default: %w(rubocop rdoc)
@@ -0,0 +1,71 @@
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 'mkmf'
22
+ require 'shellwords'
23
+
24
+ module Thermite
25
+ #
26
+ # Cargo helpers
27
+ #
28
+ module Cargo
29
+ #
30
+ # Path to `cargo`. Can be overwritten by using the `CARGO` environment variable.
31
+ #
32
+ def cargo
33
+ @cargo ||= find_executable(ENV.fetch('CARGO', 'cargo'))
34
+ end
35
+
36
+ #
37
+ # Run `cargo` with the given `args` and return `STDOUT`.
38
+ #
39
+ def run_cargo(*args)
40
+ sh "#{cargo} #{Shellwords.join(args)}"
41
+ end
42
+
43
+ #
44
+ # Only `run_cargo` if it is found in the executable paths.
45
+ #
46
+ def run_cargo_if_exists(*args)
47
+ run_cargo(*args) if cargo
48
+ end
49
+
50
+ #
51
+ # Run `cargo build`, given a target (i.e., `release` [default] or `debug`).
52
+ #
53
+ def run_cargo_build(target)
54
+ cargo_args = %w(build)
55
+ cargo_args << '--release' if target == 'release'
56
+ run_cargo(*cargo_args)
57
+ end
58
+
59
+ #
60
+ # Message used when cargo is required but not found.
61
+ #
62
+ def cargo_required_msg
63
+ <<EOM
64
+ ****
65
+ Rust's Cargo is required to build this extension. Please install Rust and put
66
+ it in the PATH, or set the CARGO environment variable appropriately.
67
+ ****
68
+ EOM
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,144 @@
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 'fileutils'
22
+ require 'rbconfig'
23
+ require 'tomlrb'
24
+
25
+ module Thermite
26
+ #
27
+ # Configuration helper
28
+ #
29
+ class Config
30
+ #
31
+ # Creates a new configuration object.
32
+ #
33
+ # `options` is the same as the `Thermite::Tasks.new` parameter.
34
+ #
35
+ def initialize(options = {})
36
+ @options = options
37
+ end
38
+
39
+ #
40
+ # The file extension of the compiled shared Rust library.
41
+ #
42
+ def shared_ext
43
+ @shared_ext ||= begin
44
+ if RbConfig::CONFIG['DLEXT'] == 'bundle'
45
+ 'dylib'
46
+ elsif Gem.win_platform?
47
+ 'dll'
48
+ else
49
+ RbConfig::CONFIG['DLEXT']
50
+ end
51
+ end
52
+ end
53
+
54
+ #
55
+ # Alias for `RbConfig::CONFIG['target_os']`.
56
+ #
57
+ def target_os
58
+ @target_os ||= RbConfig::CONFIG['target_os']
59
+ end
60
+
61
+ #
62
+ # Alias for `RbConfig::CONFIG['target_cpu']`.
63
+ #
64
+ def target_arch
65
+ @target_arch ||= RbConfig::CONFIG['target_cpu']
66
+ end
67
+
68
+ #
69
+ # The name of the library compiled by Rust.
70
+ #
71
+ def library_name
72
+ @library_name ||= begin
73
+ if toml[:lib] && toml[:lib][:name]
74
+ toml[:lib][:name]
75
+ else
76
+ toml[:package][:name]
77
+ end
78
+ end
79
+ end
80
+
81
+ #
82
+ # The basename of the Rust shared library.
83
+ #
84
+ def shared_library
85
+ @shared_library ||= begin
86
+ filename = "#{library_name}.#{shared_ext}"
87
+ filename = "lib#{filename}" unless Gem.win_platform?
88
+ filename
89
+ end
90
+ end
91
+
92
+ #
93
+ # Return the basename of the tarball generated by the `thermite:tarball` Rake task, given a
94
+ # package `version`.
95
+ #
96
+ def tarball_filename(version)
97
+ "#{library_name}-#{version}-#{target_os}-#{target_arch}.tar.gz"
98
+ end
99
+
100
+ #
101
+ # The top-level directory of the Ruby project. Defaults to the current working directory.
102
+ #
103
+ def ruby_toplevel_dir
104
+ @ruby_toplevel_dir ||= @options.fetch(:ruby_project_path, FileUtils.pwd)
105
+ end
106
+
107
+ #
108
+ # Generate a path relative to `ruby_toplevel_dir`, given the `path_components` that are passed
109
+ # to `File.join`.
110
+ #
111
+ def ruby_path(*path_components)
112
+ File.join(ruby_toplevel_dir, *path_components)
113
+ end
114
+
115
+ #
116
+ # The top-level directory of the Cargo project. Defaults to the current working directory.
117
+ #
118
+ def rust_toplevel_dir
119
+ @rust_toplevel_dir ||= @options.fetch(:cargo_project_path, FileUtils.pwd)
120
+ end
121
+
122
+ #
123
+ # Generate a path relative to `rust_toplevel_dir`, given the `path_components` that are
124
+ # passed to `File.join`.
125
+ #
126
+ def rust_path(*path_components)
127
+ File.join(rust_toplevel_dir, *path_components)
128
+ end
129
+
130
+ #
131
+ # Path to the Rust shared library in the context of the Ruby project.
132
+ #
133
+ def ruby_extension_path
134
+ ruby_path('lib', shared_library)
135
+ end
136
+
137
+ #
138
+ # Parsed TOML object (courtesy of `tomlrb`).
139
+ #
140
+ def toml
141
+ @toml ||= Tomlrb.load_file(rust_path('Cargo.toml'), symbolize_keys: true)
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,98 @@
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 'net/http'
22
+ require 'rexml/document'
23
+ require 'rubygems/package'
24
+ require 'uri'
25
+ require 'zlib'
26
+
27
+ module Thermite
28
+ #
29
+ # GitHub releases binary helpers.
30
+ #
31
+ module GithubReleaseBinary
32
+ #
33
+ # Downloads and unpacks the latest binary from GitHub releases, given the target OS
34
+ # and architecture.
35
+ #
36
+ # Requires the `github_releases` option to be `true`. It uses the `repository` value in the
37
+ # project's `Cargo.toml` (in the `package` section) to determine where the releases
38
+ # are located.
39
+ #
40
+ # Returns whether a binary was found and unpacked.
41
+ #
42
+ def download_latest_binary_from_github_release
43
+ return false unless options[:github_releases]
44
+ installed_binary = false
45
+ github_uri = toml[:package][:repository]
46
+ each_github_release(github_uri) do |version, download_uri|
47
+ tgz = download_binary_from_github_release(download_uri, version)
48
+ next unless tgz
49
+ unpack_tarball(tgz)
50
+ installed_binary = true
51
+ break
52
+ end
53
+
54
+ installed_binary
55
+ end
56
+
57
+ private
58
+
59
+ def http_get(uri)
60
+ Net::HTTP.get(URI(uri))
61
+ end
62
+
63
+ def each_github_release(github_uri)
64
+ releases_uri = "#{github_uri}/releases.atom"
65
+ feed = REXML::Document.new(http_get(releases_uri))
66
+ REXML::XPath.each(feed, '//entry/title[contains(.,"-rust")]/text()') do |tag|
67
+ version = tag.to_s.slice(1..-6)
68
+ download_uri = "#{github_uri}/releases/download/#{tag}/#{config.tarball_filename(version)}"
69
+
70
+ yield(version, download_uri)
71
+ end
72
+ end
73
+
74
+ def download_binary_from_github_release(uri, version)
75
+ case (response = Net::HTTP.get_response(URI(uri)))
76
+ when Net::HTTPClientError
77
+ nil
78
+ when Net::HTTPServerError
79
+ raise response
80
+ else
81
+ puts "Downloading latest compiled version (#{version}) from GitHub"
82
+ StringIO.new(http_get(response['location']))
83
+ end
84
+ end
85
+
86
+ def unpack_tarball(tgz)
87
+ gz = Zlib::GzipReader.new(tgz)
88
+ tar = Gem::Package::TarReader.new(gz)
89
+ tar.each do |entry|
90
+ path = entry.header.name
91
+ next if path.end_with?('/')
92
+ File.open(path, 'wb') do |f|
93
+ f.write(entry.read)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,38 @@
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 'archive/tar/minitar'
22
+ require 'zlib'
23
+
24
+ module Thermite
25
+ #
26
+ # Helpers to package the Rust library, using FPM.
27
+ #
28
+ module Package
29
+ #
30
+ # Builds a tarball of the Rust-compiled shared library.
31
+ #
32
+ def build_package
33
+ filename = config.tarball_filename(config.toml[:package][:version])
34
+ tgz = Zlib::GzipWriter.new(File.open(filename, 'wb'))
35
+ Archive::Tar::Minitar.pack(config.ruby_extension_path, tgz)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,121 @@
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 'fileutils'
22
+ require 'rake/tasklib'
23
+ require 'thermite/cargo'
24
+ require 'thermite/config'
25
+ require 'thermite/github_release_binary'
26
+ require 'thermite/package'
27
+
28
+ #
29
+ # Helpers for Rust-based Ruby extensions.
30
+ #
31
+ module Thermite
32
+ #
33
+ # Create the following rake tasks:
34
+ #
35
+ # * `thermite:build`
36
+ # * `thermite:clean`
37
+ # * `thermite:test`
38
+ # * `thermite:tarball`
39
+ #
40
+ class Tasks < Rake::TaskLib
41
+ include Thermite::Cargo
42
+ include Thermite::GithubReleaseBinary
43
+ include Thermite::Package
44
+
45
+ #
46
+ # The configuration used for the Rake tasks.
47
+ #
48
+ attr_reader :config
49
+
50
+ #
51
+ # Possible configuration options for Thermite tasks:
52
+ #
53
+ # * `cargo_project_path` - the path to the Cargo project. Defaults to the current
54
+ # working directory.
55
+ # * `github_releases` - whether to look for rust binaries via GitHub releases when installing
56
+ # the gem, and `cargo` is not found. Defaults to `false`.
57
+ # * `ruby_project_path` - the toplevel directory of the Ruby gem's project. Defaults to the
58
+ # current working directory.
59
+ #
60
+ attr_reader :options
61
+
62
+ #
63
+ # Define the Thermite tasks with the given configuration parameters (see `options`).
64
+ #
65
+ # Example:
66
+ #
67
+ # ```ruby
68
+ # Thermite::Tasks.new(cargo_project_path: 'rust')
69
+ # ```
70
+ #
71
+ def initialize(options = {})
72
+ @options = options
73
+ @config = Config.new(options)
74
+ define_build_task
75
+ define_clean_task
76
+ define_test_task
77
+ define_package_task
78
+ end
79
+
80
+ private
81
+
82
+ def define_build_task
83
+ desc 'Build or download the Rust shared library: CARGO_TARGET controls Cargo target'
84
+ task 'thermite:build' do
85
+ # if cargo found, build. Otherwise, grab binary (when github_releases is enabled).
86
+ if cargo
87
+ target = ENV.fetch('CARGO_TARGET', 'release')
88
+ run_cargo_build(target)
89
+ FileUtils.cp(config.rust_path('target', target, config.shared_library),
90
+ config.ruby_path('lib'))
91
+ elsif !download_latest_binary_from_github_release
92
+ raise cargo_required_msg
93
+ end
94
+ end
95
+ end
96
+
97
+ def define_clean_task
98
+ desc 'Clean up after thermite:build task'
99
+ task 'thermite:clean' do
100
+ FileUtils.rm(config.ruby_extension_path, force: true)
101
+ run_cargo_if_exists 'clean'
102
+ end
103
+ end
104
+
105
+ def define_test_task
106
+ desc 'Run Rust testsuite'
107
+ task 'thermite:test' do
108
+ run_cargo_if_exists 'test'
109
+ end
110
+ end
111
+
112
+ def define_package_task
113
+ namespace :thermite do
114
+ desc 'Package rust library in a tarball'
115
+ task tarball: %w(thermite:build) do
116
+ build_package
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
data/thermite.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'English'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'thermite'
6
+ s.version = '0.1.0'
7
+ s.summary = 'Rake helpers for Rust+Ruby'
8
+ s.description = 'A Rake-based helper for building and distributing Rust-based Ruby extensions'
9
+
10
+ s.authors = ['Mark Lee']
11
+ s.email = 'malept@users.noreply.github.com'
12
+ s.homepage = 'https://github.com/malept/thermite'
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
16
+ s.require_paths = %w(lib)
17
+
18
+ s.add_runtime_dependency 'rake', '~> 11'
19
+ s.add_runtime_dependency 'minitar', '~> 0.5'
20
+ s.add_runtime_dependency 'tomlrb', '~> 1.2'
21
+ s.add_development_dependency 'rdoc', '~> 4.2'
22
+ s.add_development_dependency 'rubocop', '~> 0.40'
23
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thermite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Lee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitar
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tomlrb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.40'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.40'
83
+ description: A Rake-based helper for building and distributing Rust-based Ruby extensions
84
+ email: malept@users.noreply.github.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rdoc_options"
91
+ - ".rubocop.yml"
92
+ - ".travis.yml"
93
+ - ".yardopts"
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - lib/thermite/cargo.rb
99
+ - lib/thermite/config.rb
100
+ - lib/thermite/github_release_binary.rb
101
+ - lib/thermite/package.rb
102
+ - lib/thermite/tasks.rb
103
+ - thermite.gemspec
104
+ homepage: https://github.com/malept/thermite
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.5.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Rake helpers for Rust+Ruby
128
+ test_files: []