Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 10, 2024

Conversation

stanhu
Copy link
Contributor

@stanhu stanhu commented Jan 30, 2023

Homebrew in macOS updates the icu4c library quite often, which often breaks this gem because the dynamically-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
Copy link
Contributor Author

stanhu commented Jan 30, 2023

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

@stanhu stanhu force-pushed the sh-add-static-linking-option branch from 462b89f to ecec7dc Compare February 1, 2023 07:50
@stanhu
Copy link
Contributor Author

stanhu commented Feb 2, 2023

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
Copy link
Contributor Author

stanhu commented Jul 18, 2023

@tenderlove What do you think of this change?

@stanhu stanhu force-pushed the sh-add-static-linking-option branch 5 times, most recently from 7b92381 to 43f7be7 Compare July 10, 2024 16:37
@stanhu
Copy link
Contributor Author

stanhu commented Jul 10, 2024

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

Homebrew in macOS updates the `icu4c` library quite often, which often
breaks this gem because the dynamically-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 stanhu force-pushed the sh-add-static-linking-option branch from 43f7be7 to cc93f88 Compare July 10, 2024 16:44
@tenderlove
Copy link
Collaborator

@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 tenderlove merged commit dcbf192 into brianmario:master Jul 10, 2024
7 checks passed
@stanhu
Copy link
Contributor Author

stanhu commented Jul 11, 2024

@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.

@tenderlove
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants