charlock_holmes icon indicating copy to clipboard operation
charlock_holmes copied to clipboard

Add --enable-static option to link icu4c libraries statically

Open stanhu opened this issue 2 years ago • 4 comments

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.

stanhu avatar Jan 30 '23 19:01 stanhu

@brianmario What do you think of this change? It would help fix #156 and #163.

stanhu avatar Jan 30 '23 19:01 stanhu

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

stanhu avatar Feb 02 '23 02:02 stanhu

@tenderlove What do you think of this change?

stanhu avatar Jul 18 '23 17:07 stanhu

@tenderlove Friendly ping. This would help close out #156 and #163. I've built on your macOS test to verify it works.

stanhu avatar Jul 10 '24 16:07 stanhu

@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 avatar Jul 10 '24 17:07 tenderlove

@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 avatar Jul 11 '24 05:07 stanhu

@stanhu wow. Thanks for doing this legwork. Seems like we probably shouldn't provide a binary gem then 😓

tenderlove avatar Jul 12 '24 00:07 tenderlove