Add --enable-static option to link icu4c libraries statically
Homebrew in macOS updates the icu4c library quite often, which often breaks this gem because the dyanmically-loaded library no longer exists.
To avoid this hassle, this gem can be compiled with --enable-static so that the resulting charlock_holmes.bundle will have all the required libraries statically linked.
@brianmario What do you think of this change? It would help fix #156 and #163.
Unfortunately this change doesn't work with Ubuntu out of the box because the shared libraries aren't compiled with -fPIC:
g++ -shared -o charlock_holmes.so converter.o encoding_detector.o ext.o transliterator.o -L. -L/home/stanhu/.rbenv/versions/2.7.7/lib -Wl,-rpath,/home/stanhu/.rbenv/versions/2.7.7/lib -L. -L/home/stanhu/.rbenv/versions/2.7.7/lib -fstack-protector-strong -rdynamic -Wl,-export-dynamic -L/home/stanhu/.rbenv/versions/2.7.7/lib -Wl,--compress-debug-sections=zlib -Wl,-rpath,/home/stanhu/.rbenv/versions/2.7.7/lib -L/home/stanhu/.rbenv/versions/2.7.7/lib -lruby -lz /usr/lib/x86_64-linux-gnu/libicui18n.a /usr/lib/x86_64-linux-gnu/libicuuc.a /usr/lib/x86_64-linux-gnu/libicudata.a /usr/lib/x86_64-linux-gnu/libicuio.a -lm -lc
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libicui18n.a(translit.ao): relocation R_X86_64_PC32 against symbol `_ZTVN6icu_6613UnicodeStringE' can not be used when making a shared object; recompile with -fPIC
@tenderlove What do you think of this change?
@tenderlove Friendly ping. This would help close out #156 and #163. I've built on your macOS test to verify it works.
@stanhu great, thank you. Yes, I think this is fine. TBH we should probably distribute statically built binary versions of the gem, but I'm a bit lazy for that 😅
@tenderlove I actually spent a while trying to build a precompiled gem, and I got it working for x86. However, the problem is that if you want to cross-compile ICU for other platforms, it requires even more steps: https://unicode-org.github.io/icu/userguide/icu4c/build.html#how-to-cross-compile-icu.
Even if you were to get that all working each resulting gem was over 100 MB, since the statically-built library was about 30 MB * the number of Ruby versions supported in the gem.
@stanhu wow. Thanks for doing this legwork. Seems like we probably shouldn't provide a binary gem then 😓