From d4bbb1bdc19ee17e99fc863b40be3644399eebe2 Mon Sep 17 00:00:00 2001 From: "Daniel P. Clark" <6ftdan@gmail.com> Date: Wed, 7 Oct 2026 19:45:03 +0000 Subject: [PATCH 1/2] Build and load the extension with the rutie gem instead of thermite thermite was the gem's one dependency that could not be satisfied from rubygems.org: the fork it needed is not the published gem, and a gemspec cannot point at a repository. Everything faster_path used it for, the rutie gem already provides. `Rutie::RakeTask` builds the extension with Cargo (`rutie:build`), with the same macOS linking as before, and `Rutie#init` loads it; ext/Rakefile points Cargo at the gem's Cargo.toml since RubyGems runs it from ext/, builds against the installing Ruby through the RUBY variable, and keeps only the built library in lib/faster_path, so an installed gem is under a megabyte instead of carrying Cargo's whole output. In a checkout the library is loaded from target/release, where `rake rutie:build` leaves it. With that go thermite's REXML and tomlrb dependencies, the Cargo.toml metadata for its GitHub-release downloads, and the CI job that built the release tarballs: the gem is built from source with Cargo at install time. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01CXvfgWzuq28ewqT3AyhX4Z --- .github/workflows/ci.yml | 29 ----------------------------- Cargo.toml | 3 --- Gemfile | 3 --- README.md | 8 +++++--- Rakefile | 11 ++++------- ext/Rakefile | 19 ++++++++++++------- faster_path.gemspec | 8 +++----- lib/faster_path.rb | 18 +++++++----------- lib/faster_path/build_task.rb | 32 ++++++++++++++++++++++++++++++++ test/build_test.rb | 28 ++++++++++++++++++++++++++++ test/thermite_test.rb | 30 ------------------------------ 11 files changed, 91 insertions(+), 98 deletions(-) create mode 100644 lib/faster_path/build_task.rb create mode 100644 test/build_test.rb delete mode 100644 test/thermite_test.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73a77d1..3ce08d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,6 @@ name: CI on: push: branches: [master] - tags: ['v*'] pull_request: workflow_dispatch: @@ -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 diff --git a/Cargo.toml b/Cargo.toml index ef15e93..09dc8b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/Gemfile b/Gemfile index b48de51..b806447 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/README.md b/README.md index 7ea200e..72cf169 100644 --- a/README.md +++ b/README.md @@ -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) @@ -115,7 +114,8 @@ 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 @@ -286,7 +286,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 diff --git a/Rakefile b/Rakefile index ba69c32..e3f886a 100644 --- a/Rakefile +++ b/Rakefile @@ -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 @@ -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 @@ -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 diff --git a/ext/Rakefile b/ext/Rakefile index 4fd6dfc..bdbe7f4 100644 --- a/ext/Rakefile +++ b/ext/Rakefile @@ -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 diff --git a/faster_path.gemspec b/faster_path.gemspec index 1fbb0d5..718323e 100644 --- a/faster_path.gemspec +++ b/faster_path.gemspec @@ -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/**/*'] @@ -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' diff --git a/lib/faster_path.rb b/lib/faster_path.rb index 3ff060a..b5b907f 100644 --- a/lib/faster_path.rb +++ b/lib/faster_path.rb @@ -1,6 +1,6 @@ require 'faster_path/version' require 'pathname' -require 'thermite/config' +require 'rutie' require 'fiddle' require 'fiddle/import' @@ -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 diff --git a/lib/faster_path/build_task.rb b/lib/faster_path/build_task.rb new file mode 100644 index 0000000..560aa27 --- /dev/null +++ b/lib/faster_path/build_task.rb @@ -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 diff --git a/test/build_test.rb b/test/build_test.rb new file mode 100644 index 0000000..bcecc94 --- /dev/null +++ b/test/build_test.rb @@ -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 diff --git a/test/thermite_test.rb b/test/thermite_test.rb deleted file mode 100644 index e6f0ae9..0000000 --- a/test/thermite_test.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'test_helper' -require 'thermite/tasks' - -# What the Rakefiles rely on in thermite -class ThermiteTest < Minitest::Test - def setup - project_toplevel_dir = File.dirname(__dir__) - @thermite = Thermite::Tasks.new(cargo_project_path: project_toplevel_dir, - ruby_project_path: project_toplevel_dir, - version: FasterPath::VERSION) - end - - def test_release_tarballs_are_named_after_the_gem_version - config = @thermite.config - - assert_equal FasterPath::VERSION, config.version - refute_equal config.crate_version, config.version - - tarball = config.tarball_filename(config.version) - - assert_match(/\Afaster_path-#{Regexp.escape(FasterPath::VERSION)}-/, tarball) - # The Ruby's major and minor version only: the extension works on every patch release - assert_match(/-ruby\d\d-/, tarball) - assert_match(/\.tar\.gz\z/, tarball) - end - - def test_build_lib_can_clean_the_cargo_target - assert_respond_to Thermite::Cargo.new(@thermite.config), :clean - end -end From 52331633a05f83a0ae13e6c6a9301e865cb7962a Mon Sep 17 00:00:00 2001 From: "Daniel P. Clark" <6ftdan@gmail.com> Date: Wed, 7 Oct 2026 19:48:10 +0000 Subject: [PATCH 2/2] Say in the README what installing builds, and link Rust's current install page Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01CXvfgWzuq28ewqT3AyhX4Z --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 72cf169..8ee8b00 100644 --- a/README.md +++ b/README.md @@ -119,9 +119,9 @@ As mentioned earlier Sprockets, which handles assets, changed away from using `P ## 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 @@ -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.