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

[SR-1359] Android: ICU should be statically linked (and patch to make static linking possible) #43968

Open
swift-ci opened this issue Apr 29, 2016 · 2 comments
Labels
Android Platform: Android compiler The Swift compiler in itself ICU improvement

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1359
Radar None
Original Reporter ewmailing (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Improvement, Android, ICU
Assignee jblatecky (JIRA)
Priority Medium

md5: 57cffc55e2d8137ac432f00b13ecc676

Issue Description:

This merges with my prior FindICU.cmake general patch which allow for ICU to be
static libraries. (See https://bugs.swift.org/browse/SR-1358)

This change is needed for Android because dynamically linking libicu is
not reliable on Android. There are multiple problems:

  • libICU is sometimes an internal/private component on Android. In some
    cases it appears that tryiing to LoadLibrary on libICU will silently
    skip because the OS already has one loaded. If the symbol names don't
    match, you get unresolved symbol errors at runtime resulting from a
    crash without a good understanding why. (This happened to me on my Nexus
    7 2013 with 5.0.2). And if the symbols match, but the versions are
    different, you may have even tougher problems.
  • If your application needs ICU, you now run the risk of having
    conflicting versions of ICU. This is a particular risk for middleware
    where the user may have not built Swift themselves.
  • Dealing with loading the ICU dependencies is annoying on Android
    because you must write Java code to load all the libraries, and in the
    correct order. And your build process must also be aware of all the
    dependencies so all the .so's get packaged.

So static linking ICU solves all these problems.

But additionally, the issue of linking the C++ standard library becomes
an issue. Again, there are similar issues with dynamically linking
because Android doesn't provide a pre-installed system-wide one we can
rely on. Additionally:

  • Android actually provides 3 or 4 different C++ standard libraries you
    can pick from, all of which are incompatible with each other.
  • Every new NDK release risks a new version of each of the standard
    libraries which breaks binary compatibility. If the user is just using
    the Swift compiler and doesn't think about these issues, this may cause
    hard problems.
  • Also, statically linking ICU caused building command line executables
    (tests) to fail with unresolved symbols. Statically linking C++ fixes
    this problem and the original behavior is preserved.

So static linking solves these problems too.

Two new switches are needed to build for Android:
--android-icu-data-include /path/to/include
--android-icu-data /path/to/libicudata

My patch is here:
ewmailing@8af36d6

@swift-ci
Copy link
Collaborator Author

Comment by Amr Aboelela (JIRA)

I tried to link it statically to libswiftCore.so but it didn't work well.

@finagolfin
Copy link
Contributor

The libicu dependency of the standard library was removed last month:

#40340

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Platform: Android compiler The Swift compiler in itself ICU improvement
Projects
None yet
Development

No branches or pull requests

2 participants