Skip to content

Statically link libicu for macOS for static_holmes gem

Stan Hu requested to merge sh-build-static-holmes-macos into main

What does this merge request 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)

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

Relates to #2062 (closed)

How to set up and validate locally

  1. On this branch 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 gitlab!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"}

Impacted categories

The following categories relate to this merge request:

Merge request checklist

  • This change is backward compatible. If not, please include steps to communicate to our users.
  • Tests added for new functionality. If not, please raise an issue to follow-up.
  • Documentation added/updated, if needed.
  • Announcement added, if change is notable.
  • gdk doctor test added, if needed.
  • Add the ~highlight label if this MR should be included in the CHANGELOG.md.
Edited by Stan Hu

Merge request reports