Skip to content

Use static_holmes instead of charlock_holmes

Stan Hu requested to merge sh-use-static-holmes into master

What does this MR do and why?

static_holmes is a fork of the charlock_holmes gem with a single change to make it possible to statically link icu4c libraries via the --enable-static config option: gitlab-org/ruby/gems/charlock_holmes!2 (merged)

For macOS users, whenever Homebrew updates icu4c, charlock_holmes gem stops working because the old dynamically linked library is removed. With this change, those upgrade problems will go away.

Note that --enable-static only works on macOS and Homebrew. Ubuntu Linux doesn't compile the static library with position-independent code (-fPIC), so link errors result if --enable-static is used.

Relates to gitlab-development-kit#2062 (closed)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. With the GDK gitlab-development-kit!3631 (merged), run make gitlab-bundle-prepare. This should set --enable-static for static_holmes.
  2. In your gitlab dir, run git fetch && git checkout sh-use-static-holmes to check out !147721 (merged).
  3. Run bundle install.
  4. On macOS, take a look at the installed library:
% ls -al ~/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/static_holmes-0.7.7/lib/charlock_holmes/charlock_holmes.bundle
-rwxr-xr-x  1 stanhu  staff  34866664 Mar 22 17:37 /Users/stanhu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/static_holmes-0.7.7/lib/charlock_holmes/charlock_holmes.bundle

Compare that to the original library:

% ls -al ~/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/charlock_holmes-0.7.7/lib/charlock_holmes/charlock_holmes.bundle
-rwxr-xr-x  1 stanhu  staff  64664 Feb 29 09:27 /Users/stanhu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/charlock_holmes-0.7.7/lib/charlock_holmes/charlock_holmes.bundle
  1. Run bundle exec irb and make sure charlock_holmes still works:
irb(main):001:0> require 'charlock_holmes'
=> true
irb(main):002:0> CharlockHolmes::EncodingDetector.detect('hello world')
=> {:type=>:text, :encoding=>"ISO-8859-1", :ruby_encoding=>"ISO-8859-1", :confidence=>25, :language=>"it"}

Numbered steps to set up and validate the change are strongly suggested.

Edited by Stan Hu

Merge request reports