A Rake-based helper for building and distributing Rust-based Ruby extensions
MIT License
Thermite is a Rake-based helper for building and distributing Rust-based Ruby extensions.
cargo
commands.cargo
installations via the CARGO
environment variable.spec.extensions << 'ext/Rakefile'
spec.add_runtime_dependency 'thermite', '~> 0'
ext/Rakefile
with the following code, assuming that the Cargo project root is the samerequire 'thermite/tasks'
project_dir = File.dirname(File.dirname(__FILE__))
Thermite::Tasks.new(cargo_project_path: project_dir, ruby_project_path: project_dir)
task default: %w(thermite:build)
Rakefile
, integrate Thermite into your build-test workflow:require 'thermite/tasks'
Thermite::Tasks.new
desc 'Run Rust & Ruby testsuites'
task test: ['thermite:build', 'thermite:test'] do
# …
end
Run rake -T thermite
to view all of the available tasks in the thermite
namespace.
Task configuration for your project can be set in two ways:
Thermite::Tasks.new
package.metadata.thermite
section to Cargo.toml
. These settings override theTasks
class. Due to the conflict, it is infeasible forcargo_project_path
or cargo_workspace_member
to be set in this way. Example section:[package.metadata.thermite]
github_releases = true
Possible options:
binary_uri_format
- if set, the interpolation-formatted string used to construct the downloadTHERMITE_BINARY_URI_FORMAT
github_releases
option.https://example.com/download/%{version}/%{filename}
. Replacement variables:
filename
- The value of Config.tarball_filename
version
- the crate version from Cargo.toml
cargo_project_path
- the path to the top-level Cargo project. Defaults to the current workingcargo_workspace_member
- if set, the relative path to the Cargo workspace member. Usually usedgithub_releases
- whether to look for Rust binaries via GitHub releases when installingcargo
is not found. Defaults to false
.github_release_type
- when github_releases
is true
, the mode to use to download the Rust'cargo'
(the default) uses the version in Cargo.toml
, along withgit_tag_format
option (described below) to determine the download URI. 'latest'
takes thegit_tag_regex
option (described below) to determine the downloadgit_tag_format
- when github_release_type
is 'cargo'
(the default), thev%s
, where %s
is the version in Cargo.toml
.git_tag_regex
- when github_releases
is enabled and github_release_type
is 'latest'
, aString
) that determines which tagged releases to look foroptional_rust_extension
- prints a warning to STDERR instead of raising an exception, if Cargogithub_releases
is either disabled or unavailable. Useful for projects wherefalse
.ruby_project_path
- the top-level directory of the Ruby gem's project. Defaults to theruby_extension_dir
- the directory relative to ruby_project_path
where the extension islib
.Using the cliché Rust+Ruby example, the rusty_blank
repository contains an example of using Thermite with ruru
to provide a String.blank?
speedup extension. While the example uses ruru, this gem should be
usable with any method of integrating Rust and Ruby that you choose.
By default Thermite will do a release build of your Rust code. To do a debug build instead,
set the CARGO_PROFILE
environment variable to debug
.
For example, you can run CARGO_PROFILE=debug rake thermite:build
.
Debug statements can be written to a file specified by the THERMITE_DEBUG_FILENAME
environment
variable.
According to Wikipedia:
This gem is licensed under the MIT license.