ICU is now namespaced in Foundation!

Hello Swift developers,

ICU is an extremely commonly used library, and is often shipped as part of the OS (be it Linux, Windows, or macOS at least). As Foundation uses ICU internally to work with some of the data types and as such links against ICU. The ICU that Foundation uses is not a stock ICU version and more importantly, ICU itself does not have a stable ABI, so you cannot simply update the Foundation library without concerns around data layout changes.

ICU is well aware of this limitation and offers a solution of namespacing itself, that is, it allows for adding a prefix to the symbols.

As part of the efforts to support static linking on Windows, the Clang Importer was improved to support macro based aliases from C, e.g.

#define CFunction CFunctionW

As a result, we are now able to actually take advantage of the symbol renaming and namespace the ICU library on the non-Apple platforms. This means that Foundation now safely links against the copy of ICU it is built against and even if another version of ICU somehow ends up in the address space, it should be safe and not crash due to the ABI concerns.

Thanks to @jmschonfeld, @icharleshu, and @Tony_Parker for the help in getting this enabled.

28 Likes

Thank you for fixing this @compnerd!

2 Likes