From 565e87ebaa228e904c93e2be3f33c2bd32af308e Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sun, 18 Jan 2026 02:26:27 +0100 Subject: [PATCH 1/3] Ruby: Improve native extension loading for preview versions --- ext/herb/extconf.rb | 4 ---- lib/herb.rb | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/ext/herb/extconf.rb b/ext/herb/extconf.rb index 3e07accf6..08dc712cb 100644 --- a/ext/herb/extconf.rb +++ b/ext/herb/extconf.rb @@ -2,10 +2,6 @@ require "mkmf" -Dir.chdir(File.expand_path("../..", __dir__)) do - system("rake templates", exception: true) -end - extension_name = "herb" include_path = File.expand_path("../../src/include", __dir__) diff --git a/lib/herb.rb b/lib/herb.rb index 9840251d5..c9b6460fd 100644 --- a/lib/herb.rb +++ b/lib/herb.rb @@ -31,9 +31,36 @@ begin major, minor, _patch = RUBY_VERSION.split(".") #: [String, String, String] - require_relative "herb/#{major}.#{minor}/herb" -rescue LoadError - require_relative "herb/herb" + + if RUBY_PATCHLEVEL == -1 + require_relative "herb/herb" + else + begin + require_relative "herb/#{major}.#{minor}/herb" + rescue LoadError + require_relative "herb/herb" + end + end +rescue LoadError => error + raise LoadError, <<~MESSAGE + Failed to load the Herb native extension. + + Tried to load: #{error.message.split(" -- ").last} + + This can happen when: + 1. You're using a preview/development version of Ruby (RUBY_PATCHLEVEL=#{RUBY_PATCHLEVEL}) + 2. The native extension wasn't compiled during gem installation + 3. Required build tools (C compiler) were missing during installation + + To fix, try reinstalling with source compilation: + gem install herb --platform ruby + + If compilation fails, install a C compiler first: + - macOS: xcode-select --install + - Ubuntu/Debian: apt-get install build-essential + - Fedora/RHEL: dnf install make gcc + - Alpine: apk add build-base + MESSAGE end module Herb From d5bb9ff99e4b3ca738622eb37f4f8808cf2bca0e Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sun, 18 Jan 2026 02:33:48 +0100 Subject: [PATCH 2/3] RuboCop --- lib/herb.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/herb.rb b/lib/herb.rb index c9b6460fd..9e7ae98da 100644 --- a/lib/herb.rb +++ b/lib/herb.rb @@ -41,11 +41,11 @@ require_relative "herb/herb" end end -rescue LoadError => error +rescue LoadError => e raise LoadError, <<~MESSAGE Failed to load the Herb native extension. - Tried to load: #{error.message.split(" -- ").last} + Tried to load: #{e.message.split(" -- ").last} This can happen when: 1. You're using a preview/development version of Ruby (RUBY_PATCHLEVEL=#{RUBY_PATCHLEVEL}) From 6e125bbb09a5d8b173e9f128843ff2956c3a7e40 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sun, 18 Jan 2026 02:38:40 +0100 Subject: [PATCH 3/3] Add fallback template generator for vendored prsim files if they don't exist yet --- Rakefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Rakefile b/Rakefile index 4f78fec4d..19e8dc6a2 100644 --- a/Rakefile +++ b/Rakefile @@ -159,6 +159,13 @@ namespace :prism do puts "Vendoring '#{file}' Prism file to #{vendored_file_path}" FileUtils.cp_r(prism_bundle_path + "/#{file}", prism_vendor_path) end + + prism_ast_header = "#{prism_vendor_path}/include/prism/ast.h" + + unless File.exist?(prism_ast_header) + puts "Generating Prism template files..." + system("ruby #{prism_vendor_path}/templates/template.rb", exception: true) + end end desc "Clean vendored Prism in vendor/prism/"