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
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
4 changes: 0 additions & 4 deletions ext/herb/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
33 changes: 30 additions & 3 deletions lib/herb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 => e
raise LoadError, <<~MESSAGE
Failed to load the Herb native extension.

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})
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
Expand Down
Loading