thermite-ruby3-fork-dont-use 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.rubocop.yml +29 -0
- data/.ruby-version +1 -0
- data/.yardopts +2 -0
- data/CONTRIBUTING.md +67 -0
- data/Gemfile +9 -0
- data/LICENSE +9 -0
- data/NEWS.md +180 -0
- data/README.md +144 -0
- data/Rakefile +32 -0
- data/lib/thermite/cargo.rb +125 -0
- data/lib/thermite/config.rb +293 -0
- data/lib/thermite/custom_binary.rb +66 -0
- data/lib/thermite/fiddle.rb +45 -0
- data/lib/thermite/github_release_binary.rb +125 -0
- data/lib/thermite/package.rb +96 -0
- data/lib/thermite/semver.rb +50 -0
- data/lib/thermite/tasks.rb +160 -0
- data/lib/thermite/util.rb +59 -0
- data/test/fixtures/config/Cargo.toml +5 -0
- data/test/fixtures/github/releases.atom +30 -0
- data/test/lib/thermite/cargo_test.rb +95 -0
- data/test/lib/thermite/config_test.rb +239 -0
- data/test/lib/thermite/custom_binary_test.rb +59 -0
- data/test/lib/thermite/github_release_binary_test.rb +160 -0
- data/test/lib/thermite/package_test.rb +119 -0
- data/test/lib/thermite/semver_test.rb +58 -0
- data/test/lib/thermite/util_test.rb +55 -0
- data/test/test_helper.rb +57 -0
- data/thermite.gemspec +27 -0
- metadata +184 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ed53eae0c2cb3dd09ac7c8ee028a1c667065073cff21931350c192b4a00f96ac
|
4
|
+
data.tar.gz: a5ed946ee565c0bf3b4bb6262c13bcc4bb2e273ef65cefa2a62ff1c705224921
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7f7697b9b290b1fc617e384f05d9e3bdf695989780a9084483ff56fb4f150937a77fde711484a3cd660b16aed16178375281cb07d83e7016c32bc9feff82995f
|
7
|
+
data.tar.gz: ab10ac152fcef4eddd137e49b7becb585189702bb5c0d25de25dc66df5d7275e3b61e5977d095d4b35b59f247ffe36b553e90c463dcdad5974b9fa02ce20a3bf
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "vendor/**/*"
|
4
|
+
TargetRubyVersion: 2.7
|
5
|
+
|
6
|
+
Layout/EmptyLineAfterMagicComment:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Lint/EndAlignment:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyleAlignWith: variable
|
12
|
+
|
13
|
+
Metrics/AbcSize:
|
14
|
+
Max: 20
|
15
|
+
|
16
|
+
Metrics/ClassLength:
|
17
|
+
Exclude:
|
18
|
+
- "test/**/*"
|
19
|
+
Max: 150
|
20
|
+
|
21
|
+
Metrics/LineLength:
|
22
|
+
Max: 100
|
23
|
+
AllowURI: true
|
24
|
+
URISchemes:
|
25
|
+
- http
|
26
|
+
- https
|
27
|
+
|
28
|
+
Metrics/MethodLength:
|
29
|
+
Max: 20
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/.yardopts
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Contributing to Thermite
|
2
|
+
|
3
|
+
Thermite is a part of the Rust ecosystem. As such, all contributions to this project follow the
|
4
|
+
[Rust language's code of conduct](https://www.rust-lang.org/conduct.html) where appropriate.
|
5
|
+
|
6
|
+
This project is hosted at [GitHub](https://github.com/malept/thermite). Both pull requests and
|
7
|
+
issues of many different kinds are accepted.
|
8
|
+
|
9
|
+
## Filing Issues
|
10
|
+
|
11
|
+
Issues include bugs, questions, feedback, and feature requests. Before you file a new issue, please
|
12
|
+
make sure that your issue has not already been filed by someone else.
|
13
|
+
|
14
|
+
### Filing Bugs
|
15
|
+
|
16
|
+
When filing a bug, please include the following information:
|
17
|
+
|
18
|
+
* Operating system and version. If on Linux, please also include the distribution name.
|
19
|
+
* System architecture. Examples include: x86-64, x86, and ARMv7.
|
20
|
+
* Ruby and Rake versions that run Thermite.
|
21
|
+
* The version (and/or git revision) of Thermite.
|
22
|
+
* If it's an error related to Rust, the version of Rust, Cargo, and how you installed it.
|
23
|
+
* A detailed list of steps to reproduce the bug. A minimal testcase would be very helpful,
|
24
|
+
if possible.
|
25
|
+
* If there are any error messages in the console, copying them in the bug summary will be
|
26
|
+
very helpful.
|
27
|
+
|
28
|
+
## Filing Pull Requests
|
29
|
+
|
30
|
+
Here are some things to keep in mind as you file a pull request to fix a bug, add a new feature,
|
31
|
+
etc.:
|
32
|
+
|
33
|
+
* Travis CI is used to make sure that the project conforms to the coding standards.
|
34
|
+
* If your PR changes the behavior of an existing feature, or adds a new feature, please add/edit
|
35
|
+
the RDoc inline documentation (using the Markdown format). You can see what it looks like in the
|
36
|
+
rendered documentation by running `bundle exec rake rdoc`.
|
37
|
+
* Please ensure that your changes follow the Rubocop-enforced coding standard, by running
|
38
|
+
`bundle exec rake rubocop`.
|
39
|
+
* If you are contributing a nontrivial change, please add an entry to `NEWS.md`. The format is
|
40
|
+
similar to the one described at [Keep a Changelog](http://keepachangelog.com/).
|
41
|
+
* Please make sure your commits are rebased onto the latest commit in the master branch, and that
|
42
|
+
you limit/squash the number of commits created to a "feature"-level. For instance:
|
43
|
+
|
44
|
+
bad:
|
45
|
+
|
46
|
+
```
|
47
|
+
commit 1: add foo
|
48
|
+
commit 2: run rubocop
|
49
|
+
commit 3: add test
|
50
|
+
commit 4: add docs
|
51
|
+
commit 5: add bar
|
52
|
+
commit 6: add test + docs
|
53
|
+
```
|
54
|
+
|
55
|
+
good:
|
56
|
+
|
57
|
+
```
|
58
|
+
commit 1: add foo
|
59
|
+
commit 2: add bar
|
60
|
+
```
|
61
|
+
|
62
|
+
Squashing commits during discussion of the pull request is almost always unnecessary, and makes it
|
63
|
+
more difficult for both the submitters and reviewers to understand what changed in between comments.
|
64
|
+
However, rebasing is encouraged when practical, particularly when there's a merge conflict.
|
65
|
+
|
66
|
+
If you are continuing the work of another person's PR and need to rebase/squash, please retain the
|
67
|
+
attribution of the original author(s) and continue the work in subsequent commits.
|
data/Gemfile
ADDED
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/NEWS.md
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
# Changes by Version
|
2
|
+
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
|
7
|
+
## [0.14.0] - 2023-12-21
|
8
|
+
|
9
|
+
* Make fork to keep gem usable on Ruby 3+
|
10
|
+
* The default `git_tag_regex` conforms more to the semantic versioning 2.0.0 spec (#46)
|
11
|
+
|
12
|
+
## [0.13.0] - 2017-10-05
|
13
|
+
|
14
|
+
### Added
|
15
|
+
|
16
|
+
* Support for building static libraries (#22, #41):
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
|
20
|
+
* Always pass `--lib` to `cargo with `link-args` (#40)
|
21
|
+
|
22
|
+
## [0.12.1] - 2017-04-06
|
23
|
+
|
24
|
+
### Fixed
|
25
|
+
|
26
|
+
* Default target directory (when the CARGO_TARGET_DIR is not set)
|
27
|
+
|
28
|
+
## [0.12.0] - 2017-04-05
|
29
|
+
|
30
|
+
### Added
|
31
|
+
|
32
|
+
* Support for CARGO_TARGET_DIR environment variable (#33)
|
33
|
+
|
34
|
+
### Fixed
|
35
|
+
|
36
|
+
* Cargo executable and arguments with paths using spaces are supported properly
|
37
|
+
|
38
|
+
### Changed
|
39
|
+
|
40
|
+
* CARGO_TARGET is now CARGO_PROFILE, for less confusion (#35)
|
41
|
+
|
42
|
+
## [0.11.1] - 2017-02-04
|
43
|
+
|
44
|
+
### Fixed
|
45
|
+
|
46
|
+
* Add support for Cargo workspaces to `thermite:clean` and `thermite:test`
|
47
|
+
|
48
|
+
## [0.11.0] - 2017-02-03
|
49
|
+
|
50
|
+
### Added
|
51
|
+
|
52
|
+
* Add support for Cargo workspaces (#30)
|
53
|
+
|
54
|
+
## [0.10.0] - 2017-01-22
|
55
|
+
|
56
|
+
### Fixed
|
57
|
+
|
58
|
+
* Adjust OSX dylib library paths upon installation (#28)
|
59
|
+
* Don't use UNIX shell escaping on Windows
|
60
|
+
|
61
|
+
### Changed
|
62
|
+
|
63
|
+
* `cargo build` has been replaced by `cargo rustc` - non-Windows builds use DLDFLAGS as linker
|
64
|
+
arguments (#27)
|
65
|
+
|
66
|
+
## [0.9.0] - 2017-01-18
|
67
|
+
|
68
|
+
### Fixed
|
69
|
+
|
70
|
+
* The library name is consistent with how Cargo handles hyphens (#19)
|
71
|
+
* Raise error if using GitHub Releases & repository not in `Cargo.toml` (#18)
|
72
|
+
|
73
|
+
## [0.8.0] - 2016-12-05
|
74
|
+
|
75
|
+
### Added
|
76
|
+
|
77
|
+
* Support for binary download URIs from non-GitHub sources (#17)
|
78
|
+
|
79
|
+
### Changed
|
80
|
+
|
81
|
+
* Tarballs are installed relative to `ruby_project_path`
|
82
|
+
|
83
|
+
## [0.7.0] - 2016-09-26
|
84
|
+
|
85
|
+
### Added
|
86
|
+
|
87
|
+
* Helper module for loading extensions via Fiddle (#13)
|
88
|
+
|
89
|
+
## [0.6.0] - 2016-09-12
|
90
|
+
|
91
|
+
### Added
|
92
|
+
|
93
|
+
* `optional_rust_extension` option - prints a warning to STDERR instead of raising an exception, if
|
94
|
+
Cargo is unavailable and `github_releases` is either disabled or unavailable. Useful for projects
|
95
|
+
where either fallback code exists, or a native extension is desirable but not required. (#4, #6)
|
96
|
+
|
97
|
+
### Fixed
|
98
|
+
|
99
|
+
* `cargo` was not being run in the context of the rust project toplevel directory (#7, #8)
|
100
|
+
|
101
|
+
## [0.5.0] - 2016-07-18
|
102
|
+
|
103
|
+
### Added
|
104
|
+
|
105
|
+
* Unit tests and code coverage (including new development dependencies)
|
106
|
+
* CI support on OSX and Windows in addition to Linux
|
107
|
+
* Successful CI builds on Linux trigger rusty_blank CI builds on Linux/OSX/Windows
|
108
|
+
|
109
|
+
### Changed
|
110
|
+
|
111
|
+
* Documentation uses YARD instead of RDoc
|
112
|
+
* `unpack_tarball` is a public method
|
113
|
+
|
114
|
+
### Fixed
|
115
|
+
|
116
|
+
* Documentation for `debug`
|
117
|
+
* Windows platform support
|
118
|
+
|
119
|
+
## [0.4.0] - 2016-07-12
|
120
|
+
|
121
|
+
### Added
|
122
|
+
|
123
|
+
* Write debug output to file, if the `THERMITE_DEBUG_FILENAME` environment variable is set
|
124
|
+
|
125
|
+
### Changed
|
126
|
+
|
127
|
+
* Relaxed rake version requirement
|
128
|
+
* Ruby version (major + minor) is considered when generating tarball names
|
129
|
+
|
130
|
+
### Fixed
|
131
|
+
|
132
|
+
* The library path in the generated tarballs is relative
|
133
|
+
|
134
|
+
## [0.3.0] - 2016-07-03
|
135
|
+
|
136
|
+
### Added
|
137
|
+
|
138
|
+
* `github_release_type`, to add `'cargo'` releases via `Cargo.toml` (default) in addition to the
|
139
|
+
existing `'latest'` functionality
|
140
|
+
|
141
|
+
### Changed
|
142
|
+
|
143
|
+
* `git_tag_format` option introduced in 0.2.0 renamed to `git_tag_regex` - `git_tag_format` is
|
144
|
+
specific to `github_release_type: 'cargo'`, while `git_tag_regex` is specific to
|
145
|
+
`github_release_type: 'latest'`
|
146
|
+
|
147
|
+
## [0.2.0] - 2016-06-30
|
148
|
+
|
149
|
+
### Added
|
150
|
+
|
151
|
+
* Config options can be set in `Cargo.toml` (and overrides the options set in the `Thermite::Tasks`
|
152
|
+
constructor)
|
153
|
+
|
154
|
+
### Changed
|
155
|
+
|
156
|
+
* Git tag formats are configurable via `git_tag_format` - defaults to basic semver format
|
157
|
+
|
158
|
+
### Fixed
|
159
|
+
|
160
|
+
* Accessing the TOML config file when searching for Rust binaries
|
161
|
+
|
162
|
+
## [0.1.0] - 2016-06-28
|
163
|
+
|
164
|
+
Initial release.
|
165
|
+
|
166
|
+
[0.13.0]: https://github.com/malept/thermite/compare/v0.12.1...v0.13.0
|
167
|
+
[0.12.1]: https://github.com/malept/thermite/compare/v0.12.0...v0.12.1
|
168
|
+
[0.12.0]: https://github.com/malept/thermite/compare/v0.11.1...v0.12.0
|
169
|
+
[0.11.1]: https://github.com/malept/thermite/compare/v0.11.0...v0.11.1
|
170
|
+
[0.11.0]: https://github.com/malept/thermite/compare/v0.10.0...v0.11.0
|
171
|
+
[0.10.0]: https://github.com/malept/thermite/compare/v0.9.0...v0.10.0
|
172
|
+
[0.9.0]: https://github.com/malept/thermite/compare/v0.8.0...v0.9.0
|
173
|
+
[0.8.0]: https://github.com/malept/thermite/compare/v0.7.0...v0.8.0
|
174
|
+
[0.7.0]: https://github.com/malept/thermite/compare/v0.6.0...v0.7.0
|
175
|
+
[0.6.0]: https://github.com/malept/thermite/compare/v0.5.0...v0.6.0
|
176
|
+
[0.5.0]: https://github.com/malept/thermite/compare/v0.4.0...v0.5.0
|
177
|
+
[0.4.0]: https://github.com/malept/thermite/compare/v0.3.0...v0.4.0
|
178
|
+
[0.3.0]: https://github.com/malept/thermite/compare/v0.2.0...v0.3.0
|
179
|
+
[0.2.0]: https://github.com/malept/thermite/compare/v0.1.0...v0.2.0
|
180
|
+
[0.1.0]: https://github.com/malept/thermite/releases/tag/v0.1.0
|
data/README.md
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# Thermite
|
2
|
+
|
3
|
+
[![Linux/OSX build status](https://travis-ci.org/malept/thermite.svg?branch=master)](https://travis-ci.org/malept/thermite)
|
4
|
+
[![Windows build status](https://ci.appveyor.com/api/projects/status/kneo890m3ypoxril?svg=true)](https://ci.appveyor.com/project/malept/thermite)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/malept/thermite/badges/gpa.svg)](https://codeclimate.com/github/malept/thermite)
|
6
|
+
[![Test coverage](https://codeclimate.com/github/malept/thermite/badges/coverage.svg)](https://codeclimate.com/github/malept/thermite/coverage)
|
7
|
+
[![Inline docs](http://inch-ci.org/github/malept/thermite.svg?branch=master)](http://inch-ci.org/github/malept/thermite)
|
8
|
+
[![Gem](https://img.shields.io/gem/v/thermite.svg?maxAge=30000)](https://rubygems.org/gems/thermite)
|
9
|
+
|
10
|
+
Thermite is a Rake-based helper for building and distributing Rust-based Ruby extensions.
|
11
|
+
|
12
|
+
## Features
|
13
|
+
|
14
|
+
* Provides wrappers for `cargo` commands.
|
15
|
+
* Handles non-standard `cargo` installations via the `CARGO` environment variable.
|
16
|
+
* Opt-in to allow users to install pre-compiled Rust extensions hosted on GitHub releases.
|
17
|
+
* Opt-in to allow users to install pre-compiled Rust extensions hosted on a third party server.
|
18
|
+
* Provides a wrapper for initializing a Rust extension via Fiddle.
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
1. Add the following to your gemspec file:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
spec.extensions << 'ext/Rakefile'
|
26
|
+
spec.add_runtime_dependency 'thermite', '~> 0'
|
27
|
+
```
|
28
|
+
|
29
|
+
2. Create `ext/Rakefile` with the following code, assuming that the Cargo project root is the same
|
30
|
+
as the Ruby project root:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'thermite/tasks'
|
34
|
+
|
35
|
+
project_dir = File.dirname(File.dirname(__FILE__))
|
36
|
+
Thermite::Tasks.new(cargo_project_path: project_dir, ruby_project_path: project_dir)
|
37
|
+
task default: %w(thermite:build)
|
38
|
+
```
|
39
|
+
|
40
|
+
3. In `Rakefile`, integrate Thermite into your build-test workflow:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'thermite/tasks'
|
44
|
+
|
45
|
+
Thermite::Tasks.new
|
46
|
+
|
47
|
+
desc 'Run Rust & Ruby testsuites'
|
48
|
+
task test: ['thermite:build', 'thermite:test'] do
|
49
|
+
# …
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
Run `rake -T thermite` to view all of the available tasks in the `thermite` namespace.
|
54
|
+
|
55
|
+
### Configuration
|
56
|
+
|
57
|
+
Task configuration for your project can be set in two ways:
|
58
|
+
|
59
|
+
* passing arguments to `Thermite::Tasks.new`
|
60
|
+
* adding a `package.metadata.thermite` section to `Cargo.toml`. These settings override the
|
61
|
+
arguments passed to the `Tasks` class. Due to the conflict, it is infeasible for
|
62
|
+
`cargo_project_path` or `cargo_workspace_member` to be set in this way. Example section:
|
63
|
+
|
64
|
+
```toml
|
65
|
+
[package.metadata.thermite]
|
66
|
+
|
67
|
+
github_releases = true
|
68
|
+
```
|
69
|
+
|
70
|
+
Possible options:
|
71
|
+
|
72
|
+
* `binary_uri_format` - if set, the interpolation-formatted string used to construct the download
|
73
|
+
URI for the pre-built native extension. If the environment variable `THERMITE_BINARY_URI_FORMAT`
|
74
|
+
is set, it takes precedence over this option. Either method of setting this option overrides the
|
75
|
+
`github_releases` option.
|
76
|
+
Example: `https://example.com/download/%{version}/%{filename}`. Replacement variables:
|
77
|
+
- `filename` - The value of `Config.tarball_filename`
|
78
|
+
- `version` - the crate version from `Cargo.toml`
|
79
|
+
* `cargo_project_path` - the path to the top-level Cargo project. Defaults to the current working
|
80
|
+
directory.
|
81
|
+
* `cargo_workspace_member` - if set, the relative path to the Cargo workspace member. Usually used
|
82
|
+
when it is part of a repository containing multiple crates.
|
83
|
+
* `github_releases` - whether to look for Rust binaries via GitHub releases when installing
|
84
|
+
the gem, and `cargo` is not found. Defaults to `false`.
|
85
|
+
* `github_release_type` - when `github_releases` is `true`, the mode to use to download the Rust
|
86
|
+
binary from GitHub releases. `'cargo'` (the default) uses the version in `Cargo.toml`, along with
|
87
|
+
the `git_tag_format` option (described below) to determine the download URI. `'latest'` takes the
|
88
|
+
latest release matching the `git_tag_regex` option (described below) to determine the download
|
89
|
+
URI.
|
90
|
+
* `git_tag_format` - when `github_release_type` is `'cargo'` (the default), the
|
91
|
+
[format string](http://ruby-doc.org/core/String.html#method-i-25) used to determine the tag used
|
92
|
+
in the GitHub download URI. Defaults to `v%s`, where `%s` is the version in `Cargo.toml`.
|
93
|
+
* `git_tag_regex` - when `github_releases` is enabled and `github_release_type` is `'latest'`, a
|
94
|
+
regular expression (expressed as a `String`) that determines which tagged releases to look for
|
95
|
+
precompiled Rust tarballs. One group must be specified that indicates the version number to be
|
96
|
+
used in the tarball filename. Defaults to the [semantic versioning 2.0.0
|
97
|
+
format](https://semver.org/spec/v2.0.0.html). In this case, the group is around the entire
|
98
|
+
expression.
|
99
|
+
* `optional_rust_extension` - prints a warning to STDERR instead of raising an exception, if Cargo
|
100
|
+
is unavailable and `github_releases` is either disabled or unavailable. Useful for projects where
|
101
|
+
either fallback code exists, or a native extension is desirable but not required. Defaults
|
102
|
+
to `false`.
|
103
|
+
* `ruby_project_path` - the top-level directory of the Ruby gem's project. Defaults to the
|
104
|
+
current working directory.
|
105
|
+
* `ruby_extension_dir` - the directory relative to `ruby_project_path` where the extension is
|
106
|
+
located. Defaults to `lib`.
|
107
|
+
|
108
|
+
### Example
|
109
|
+
|
110
|
+
Using the cliché Rust+Ruby example, the [`rusty_blank`](https://github.com/malept/rusty_blank)
|
111
|
+
repository contains an example of using Thermite with [ruru](https://github.com/d-unseductable/ruru)
|
112
|
+
to provide a `String.blank?` speedup extension. While the example uses ruru, this gem should be
|
113
|
+
usable with any method of integrating Rust and Ruby that you choose.
|
114
|
+
|
115
|
+
### Debug / release build
|
116
|
+
|
117
|
+
By default Thermite will do a release build of your Rust code. To do a debug build instead,
|
118
|
+
set the `CARGO_PROFILE` environment variable to `debug`.
|
119
|
+
|
120
|
+
For example, you can run `CARGO_PROFILE=debug rake thermite:build`.
|
121
|
+
|
122
|
+
### Troubleshooting
|
123
|
+
|
124
|
+
Debug statements can be written to a file specified by the `THERMITE_DEBUG_FILENAME` environment
|
125
|
+
variable.
|
126
|
+
|
127
|
+
## FAQ
|
128
|
+
|
129
|
+
### Why is it named Thermite?
|
130
|
+
|
131
|
+
According to Wikipedia:
|
132
|
+
|
133
|
+
* The chemical formula for ruby includes Al<sub>2</sub>O<sub>3</sub>, or aluminum oxide.
|
134
|
+
* Rust is iron oxide, or Fe<sub>2</sub>O<sub>3</sub>.
|
135
|
+
* A common thermite reaction uses iron oxide and aluminum to produce iron and aluminum oxide:
|
136
|
+
Fe<sub>2</sub>O<sub>3</sub> + 2Al → 2Fe + Al<sub>2</sub>O<sub>3</sub>
|
137
|
+
|
138
|
+
## [Release Notes](https://github.com/malept/thermite/blob/master/NEWS.md)
|
139
|
+
|
140
|
+
## [Contributing](https://github.com/malept/thermite/blob/master/CONTRIBUTING.md)
|
141
|
+
|
142
|
+
## Legal
|
143
|
+
|
144
|
+
This gem is licensed under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
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
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'bundler/gem_tasks'
|
21
|
+
require 'rake/testtask'
|
22
|
+
require 'rubocop/rake_task'
|
23
|
+
require 'yard'
|
24
|
+
|
25
|
+
Rake::TestTask.new do |t|
|
26
|
+
t.libs << 'test'
|
27
|
+
t.test_files = FileList['test/**/*_test.rb']
|
28
|
+
end
|
29
|
+
YARD::Rake::YardocTask.new
|
30
|
+
RuboCop::RakeTask.new
|
31
|
+
|
32
|
+
task default: %w[rubocop yard test]
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
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
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'mkmf'
|
21
|
+
|
22
|
+
module Thermite
|
23
|
+
#
|
24
|
+
# Cargo helpers
|
25
|
+
#
|
26
|
+
module Cargo
|
27
|
+
#
|
28
|
+
# Path to `cargo`. Can be overwritten by using the `CARGO` environment variable.
|
29
|
+
#
|
30
|
+
def cargo
|
31
|
+
@cargo ||= find_executable(ENV.fetch('CARGO', 'cargo'))
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Run `cargo` with the given `args` and return `STDOUT`.
|
36
|
+
#
|
37
|
+
def run_cargo(*args)
|
38
|
+
Dir.chdir(config.rust_toplevel_dir) do
|
39
|
+
sh cargo, *args
|
40
|
+
end
|
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 rustc`, given a target (i.e., `release` [default] or `debug`).
|
52
|
+
#
|
53
|
+
def run_cargo_rustc(target)
|
54
|
+
cargo_args = %w[rustc]
|
55
|
+
cargo_args.push(*cargo_manifest_path_args)
|
56
|
+
cargo_args << '--release' if target == 'release'
|
57
|
+
cargo_args.push(*cargo_rustc_args)
|
58
|
+
run_cargo(*cargo_args)
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# If the `cargo_workspace_member` option is set, the `--manifest-path` argument to `cargo`.
|
63
|
+
#
|
64
|
+
def cargo_manifest_path_args
|
65
|
+
return [] unless config.cargo_workspace_member
|
66
|
+
|
67
|
+
manifest = File.join(config.cargo_workspace_member, 'Cargo.toml')
|
68
|
+
['--manifest-path', manifest]
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Inform the user about cargo if it doesn't exist.
|
73
|
+
#
|
74
|
+
# If `optional_rust_extension` is true, print message to STDERR. Otherwise, raise an exception.
|
75
|
+
#
|
76
|
+
def inform_user_about_cargo
|
77
|
+
raise cargo_required_msg unless options[:optional_rust_extension]
|
78
|
+
|
79
|
+
$stderr.write(cargo_recommended_msg)
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Message used when cargo is not found.
|
84
|
+
#
|
85
|
+
# `require_severity` is the verb that indicates how important Rust is to the library.
|
86
|
+
#
|
87
|
+
def cargo_msg(require_severity)
|
88
|
+
<<~MESSAGE
|
89
|
+
****
|
90
|
+
Rust's Cargo is #{require_severity} to build this extension. Please install
|
91
|
+
Rust and put it in the PATH, or set the CARGO environment variable appropriately.
|
92
|
+
****
|
93
|
+
MESSAGE
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
# Message used when cargo is required but not found.
|
98
|
+
#
|
99
|
+
def cargo_required_msg
|
100
|
+
cargo_msg('required')
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# Message used when cargo is recommended but not found.
|
105
|
+
#
|
106
|
+
def cargo_recommended_msg
|
107
|
+
cargo_msg('recommended (but not required)')
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def cargo_rustc_args
|
113
|
+
if config.dynamic_linker_flags == '' || config.target_os == 'mingw32'
|
114
|
+
[]
|
115
|
+
else
|
116
|
+
[
|
117
|
+
'--lib',
|
118
|
+
'--',
|
119
|
+
'-C',
|
120
|
+
"link-args=#{config.dynamic_linker_flags}"
|
121
|
+
]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|