Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: CI
on:
push:
branches: [master]
tags: ['v*']
pull_request:
workflow_dispatch:

Expand Down Expand Up @@ -52,31 +51,3 @@ jobs:
run: bundle exec rake sysinfo
- name: Test (cargo, minitest, rubocop, pbench, mspec)
run: env ${{ matrix.suite.env }} bundle exec rake test

# Builds the precompiled extension tarballs that `gem install` downloads,
# and attaches them to the GitHub release of a version tag.
release:
name: Release tarball for Ruby ${{ matrix.ruby }} on ${{ matrix.os }}
if: startsWith(github.ref, 'refs/tags/v')
needs: [test]
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
matrix:
os: [ubuntu-22.04]
ruby: ['3.2', '3.3', '3.4']
include:
- os: macos-latest
ruby: '3.4'
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle exec rake thermite:tarball
- uses: softprops/action-gh-release@v2
with:
files: faster_path-*.tar.gz
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ license = "MIT OR Apache-2.0"
readme = "README.md"
edition = "2021"

[package.metadata.thermite]
github_releases = true

[lib]
name = "faster_path"
crate-type = ["cdylib"]
Expand Down
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in faster_path.gemspec

# Until thermite 0.14.0 is on rubygems.org
gem 'thermite', github: 'danielpclark/thermite', branch: 'master'
gemspec
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[![CI](https://github.com/danielpclark/faster_path/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/danielpclark/faster_path/actions/workflows/ci.yml)
[![Latest Tag](https://img.shields.io/github/tag/danielpclark/faster_path.svg)](https://github.com/danielpclark/faster_path/tags)
[![Commits Since Last Release](https://img.shields.io/github/commits-since/danielpclark/faster_path/v0.3.10.svg)](https://github.com/danielpclark/faster_path/pulse)
[![Binary Release](https://img.shields.io/github/release/danielpclark/faster_path.svg)](https://github.com/danielpclark/faster_path/releases)
[![Inline docs](http://inch-ci.org/github/danielpclark/faster_path.svg?branch=master)](http://inch-ci.org/github/danielpclark/faster_path)
[![Code Triagers Badge](https://www.codetriage.com/danielpclark/faster_path/badges/users.svg)](https://www.codetriage.com/danielpclark/faster_path)

Expand Down Expand Up @@ -115,13 +114,14 @@ As mentioned earlier Sprockets, which handles assets, changed away from using `P
## Requirements

* Ruby 3.2, 3.3 or 3.4 (the Rust extension is built with [Rutie](https://github.com/danielpclark/rutie) 0.13, which supports these)
* Rust 1.71 or later
* Rust 1.71 or later: `gem install` builds the extension with Cargo (through the
[rutie](https://rubygems.org/gems/rutie) gem's Rake task) and keeps only the built library

## Installation

Ensure Rust is installed:
Ensure Rust is installed, with `cargo` on your `PATH`:

[Rust Downloads](https://www.rust-lang.org/downloads.html)
[Install Rust](https://www.rust-lang.org/tools/install)

```
curl -sSf https://sh.rustup.rs | sh
Expand All @@ -141,6 +141,12 @@ Or install it yourself as:

$ gem install faster_path

Installing compiles the Rust extension for the Ruby doing the installing ("Building native
extensions. This could take a while..."), which takes about a minute the first time while Cargo
fetches and builds the dependencies. If Rust is missing, the install fails at that step with
Cargo not being found; install Rust and run it again. Nothing is downloaded from GitHub: there are
no prebuilt binaries.

## Visual Benchmarks

Benchmarks in Faster Path now produce visual graph charts of performance improvements.
Expand Down Expand Up @@ -286,7 +292,9 @@ Rust method like `!absolute?` _(not absolute)_ drops 39% of the performance alre
Whenever feasible implement it in Rust.

After checking out the repo, make sure you have Rust installed, then run `bundle`.
Run `rake test` to run the tests, and `rake bench` for benchmarks.
Run `rake test` to run the tests, and `rake bench` for benchmarks. Both build the extension
first (`rake rutie:build`, into `target/release`, which is where `require 'faster_path'` loads it
from in a checkout).

### Building and running tests

Expand Down
11 changes: 4 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'thermite/tasks'
require 'faster_path/version'
require 'faster_path/build_task'

desc 'System Details'
task :sysinfo do
Expand All @@ -22,8 +22,7 @@ task :sysinfo do
puts "RAKE\n #{Rake::VERSION}"
end

# The gem's version names the release tarballs, not the crate's
thermite = Thermite::Tasks.new(version: FasterPath::VERSION)
FasterPath::BuildTask.define

desc "Generate Contriburs.md Manifest"
task :contrib do
Expand All @@ -32,10 +31,8 @@ task :contrib do
' > Contributors.md;git shortlog -s -n -e | sed 's/^......./- /' >> Contributors.md"
end

desc 'Build + clean up Rust extension'
task build_lib: 'thermite:build' do
Thermite::Cargo.new(thermite.config).clean
end
desc 'Build the Rust extension'
task build_lib: 'rutie:build'

desc 'Code Quality Check'
task :lint do
Expand Down
19 changes: 12 additions & 7 deletions ext/Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
require 'thermite/tasks'
require_relative '../lib/faster_path/version'
require 'fileutils'
require_relative '../lib/faster_path/build_task'

project_toplevel_dir = File.dirname(__dir__)
Thermite::Tasks.new(cargo_project_path: project_toplevel_dir,
ruby_project_path: project_toplevel_dir,
version: FasterPath::VERSION)
FasterPath::BuildTask.define

task default: 'thermite:build'
# Keeps the built library (in lib/faster_path, where FasterPath loads it from)
# and removes the rest of Cargo's output from the installed gem.
task install_library: 'rutie:build' do
FileUtils.mkdir_p(FasterPath::BuildTask::INSTALLED_LIBRARY_DIR)
FileUtils.cp(FasterPath::BuildTask.built_library, FasterPath::BuildTask::INSTALLED_LIBRARY_DIR)
Rake::Task['rutie:clean'].invoke
end

task default: :install_library
8 changes: 3 additions & 5 deletions faster_path.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
spec.files = [
'Cargo.lock', 'Cargo.toml', 'Gemfile', 'MIT-LICENSE.txt', 'README.md', 'Rakefile',
'bin/console', 'bin/setup', 'ext/Rakefile', 'faster_path.gemspec', 'lib/faster_path.rb',
'lib/faster_path/version.rb',
'lib/faster_path/version.rb', 'lib/faster_path/build_task.rb',
'lib/faster_path/optional/monkeypatches.rb', 'lib/faster_path/optional/refinements.rb'
]
spec.files += Dir['src/**/*']
Expand All @@ -27,11 +27,9 @@ Gem::Specification.new do |spec|
# Rutie 0.13, which the Rust extension is built with, supports Ruby 3.2 to 3.4
spec.required_ruby_version = ['>= 3.2', '< 3.5']

spec.add_dependency 'bundler', '>= 1.12'
# The extension is built at install time with Rutie's Rake task and loaded with Rutie
spec.add_dependency 'rake', '>= 12.3'
spec.add_dependency 'thermite', '~> 0.14'
# thermite reads GitHub release feeds with REXML, a bundled gem since Ruby 3.0
spec.add_dependency 'rexml', '~> 3.2'
spec.add_dependency 'rutie', '~> 0.0.5'
spec.add_development_dependency 'read_source', '~> 0.2.6'
spec.add_development_dependency 'minitest', '~> 5.11'
spec.add_development_dependency 'minitest-reporters', '~> 1.1'
Expand Down
18 changes: 7 additions & 11 deletions lib/faster_path.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'faster_path/version'
require 'pathname'
require 'thermite/config'
require 'rutie'
require 'fiddle'
require 'fiddle/import'

Expand All @@ -13,16 +13,12 @@
# existing code ecosystem. To do so you will need to
# `require 'faster_path/optional/monkeypatches'` beforehand.
module FasterPath
FFI_LIBRARY = begin
toplevel_dir = File.dirname(__dir__)
config = Thermite::Config.new(cargo_project_path: toplevel_dir,
ruby_project_path: toplevel_dir)
config.ruby_extension_path
end

Fiddle::Function.
new(Fiddle.dlopen(FFI_LIBRARY)['Init_faster_pathname'], [], Fiddle::TYPE_VOID).
call
# The Rust extension: in the project's target/release after `rake rutie:build`,
# or in lib/faster_path, where `gem install` puts it (see ext/Rakefile)
RUTIE = [Rutie.new(:faster_path), Rutie.new(:faster_path, lib_path: 'faster_path')].
find { |rutie| File.exist?(rutie.ffi_library(__dir__)) } || Rutie.new(:faster_path)
FFI_LIBRARY = RUTIE.ffi_library(__dir__)
RUTIE.init('Init_faster_pathname', __dir__)

Public.class_eval do
private_class_method :basename
Expand Down
32 changes: 32 additions & 0 deletions lib/faster_path/build_task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'rbconfig'
require 'rutie'
require 'rutie/rake_task'

module FasterPath
# Defines `rutie:build` and `rutie:clean`, which build the Rust extension
# with Cargo. Used by the Rakefile and by ext/Rakefile when the gem is
# installed; both may run from another directory, so Cargo is pointed at
# the gem's Cargo.toml.
#
# The Rakefile leaves the library in target/release, where Rutie loads it
# from; ext/Rakefile moves it to lib/faster_path so that the installed gem
# keeps nothing else of the build.
module BuildTask
PROJECT_DIR = File.expand_path('../..', __dir__)
# Where `gem install` puts the built library
INSTALLED_LIBRARY_DIR = File.join(PROJECT_DIR, 'lib', 'faster_path')

def self.define
# Rutie's build script links the extension to the Ruby named by RUBY,
# or the first `ruby` on the PATH; make it the Ruby running Rake.
ENV['RUBY'] ||= File.join(RbConfig::CONFIG['bindir'],
RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT'])
Rutie::RakeTask.new(cargo_args: ['--manifest-path', File.join(PROJECT_DIR, 'Cargo.toml')])
end

# The library `rutie:build` builds, in the project's target/release
def self.built_library
Rutie.new(:faster_path).ffi_library(File.join(PROJECT_DIR, 'lib'))
end
end
end
28 changes: 28 additions & 0 deletions test/build_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'test_helper'
require 'faster_path/build_task'

# How the extension is built and found
class BuildTest < Minitest::Test
def test_the_extension_is_loaded_from_the_project_s_target_directory
assert_equal FasterPath::BuildTask.built_library, FasterPath::FFI_LIBRARY
assert_equal File.join(FasterPath::BuildTask::PROJECT_DIR, 'target', 'release'),
File.dirname(FasterPath::FFI_LIBRARY)
assert File.exist?(FasterPath::FFI_LIBRARY)
end

def test_an_installed_gem_loads_the_library_from_lib
installed = Rutie.new(:faster_path, lib_path: 'faster_path').ffi_library(File.join(FasterPath::BuildTask::PROJECT_DIR, 'lib'))

assert_equal FasterPath::BuildTask::INSTALLED_LIBRARY_DIR, File.dirname(installed)
assert_equal File.basename(FasterPath::FFI_LIBRARY), File.basename(installed)
end

def test_the_build_task_points_cargo_at_the_gem_s_manifest
_env, *command = FasterPath::BuildTask.define.build_command

assert_equal File.join(FasterPath::BuildTask::PROJECT_DIR, 'Cargo.toml'),
command[command.index('--manifest-path') + 1]
assert_equal File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']),
ENV['RUBY'].sub(/#{Regexp.escape(RbConfig::CONFIG['EXEEXT'])}\z/, '')
end
end
30 changes: 0 additions & 30 deletions test/thermite_test.rb

This file was deleted.

Loading