|
1 | | -## ICU for iOS, watchOS, tvOS, visionOS, macOS, Catalyst, Simulators - Intel(x86_64) / Apple Silicon(arm64) |
| 1 | +## ICU for iOS, watchOS, tvOS, visionOS, macOS, Mac Catalyst, and Simulators - Intel(x86_64) / Apple Silicon(arm64) |
2 | 2 |
|
3 | | -Supported versions: 78.1 |
| 3 | +This repository provides a universal build script for creating **static ICU libraries** for iOS, watchOS, tvOS, visionOS, macOS, and Mac Catalyst. |
4 | 4 |
|
5 | | -This repo provides a universal script for building static ICU libraries for use in iOS, watchOS, tvOS, visionOS, and macOS applications. The actual ICU library version is taken from https://github.com/unicode-org/icu . The branches of the repository generally correspond to the branches of the ICU repository. E.g. "78" branch corresponds to "maint/maint-78" branch. |
| 5 | +The ICU source code is taken from the official Unicode ICU repository: |
| 6 | +https://github.com/unicode-org/icu |
6 | 7 |
|
7 | | -# Prerequisites |
8 | | - 1) Xcode must be installed as xcodebuild is used to create xcframeworks |
9 | | - 2) ```xcode-select -p``` must point to the Xcode app developer directory (by default e.g. /Applications/Xcode.app/Contents/Developer). If it points to the CommandLineTools directory you should run: |
10 | | - ```sudo xcode-select --reset``` or ```sudo xcode-select -s /Applications/Xcode.app/Contents/Developer``` |
11 | | - |
12 | | -# Build Manually |
13 | | -``` |
14 | | - # clone the repo |
15 | | - git clone -b 78 https://github.com/apotocki/icu4c-iosx |
16 | | - |
17 | | - # build libraries |
18 | | - cd icu4c-iosx |
19 | | - scripts/build.sh |
| 8 | +Repository branches generally correspond to ICU maintenance branches. For example, the `78` branch corresponds to the `maint/maint-78` branch in the ICU repository. |
20 | 9 |
|
21 | | - # have fun, the result artifacts will be located in 'product' folder. |
22 | | -``` |
23 | | -# Selecting Platforms and Architectures |
24 | | -build.sh without arguments will build xcframeworks for iOS, macOS, and also for watchOS, tvOS, visionOS if their SDKs are installed on the system. It will also build xcframeworks for their simulators with the architecture (arm64 or x86_64) depending on the current host. |
25 | | -If you are interested in a specific set of platforms and architectures, you can specify them explicitly using the -p argument, for example: |
| 10 | +### Supported ICU Version: 78.1 |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## Prerequisites |
| 15 | + |
| 16 | +1. **Xcode** must be installed, as `xcodebuild` is used to create XCFrameworks. |
| 17 | +2. `xcode-select -p` must point to the Xcode developer directory (for example, `/Applications/Xcode.app/Contents/Developer`). |
| 18 | + |
| 19 | + If it points to the CommandLineTools directory, run one of the following commands: |
| 20 | + ```bash |
| 21 | + sudo xcode-select --reset |
| 22 | + # or |
| 23 | + sudo xcode-select -s /Applications/Xcode.app/Contents/Developer |
| 24 | + ``` |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## Build Manually |
| 29 | + |
| 30 | +```bash |
| 31 | +# Clone the repository |
| 32 | +git clone -b 78.1.3 https://github.com/apotocki/icu4c-iosx |
| 33 | + |
| 34 | +# Build libraries |
| 35 | +cd icu4c-iosx |
| 36 | +scripts/build.sh |
26 | 37 | ``` |
| 38 | + |
| 39 | +The resulting artifacts will be located in the `product` directory. |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +## Selecting Platforms and Architectures |
| 44 | + |
| 45 | +Running `build.sh` without arguments builds XCFrameworks for **iOS** and **macOS**, and also for **watchOS**, **tvOS**, and **visionOS** if their SDKs are installed. Simulator XCFrameworks are built for the current host architecture (`arm64` or `x86_64`). |
| 46 | + |
| 47 | +To build a specific set of platforms or architectures, use the `-p` option: |
| 48 | + |
| 49 | +```bash |
27 | 50 | scripts/build.sh -p=ios,iossim-x86_64 |
28 | | -# builts xcframeworks only for iOS and iOS Simulator with x86_64 architecture |
29 | | -``` |
30 | | -Here is a list of all possible values for '-p' option: |
31 | | -``` |
32 | | -macosx,macosx-arm64,macosx-x86_64,macosx-both,ios,iossim,iossim-arm64,iossim-x86_64,iossim-both,catalyst,catalyst-arm64,catalyst-x86_64,catalyst-both,xros,xrossim,xrossim-arm64,xrossim-x86_64,xrossim-both,tvos,tvossim,tvossim-both,tvossim-arm64,tvossim-x86_64,watchos,watchossim,watchossim-both,watchossim-arm64,watchossim-x86_64 |
| 51 | +# Builds XCFrameworks only for iOS and the iOS Simulator (x86_64) |
33 | 52 | ``` |
34 | | -Suffix '-both' means that xcframeworks will be built for both arm64 and x86_64 architectures. |
35 | | -The platform names for macosx and simulators without an architecture suffix (e.g. macosx, iossim, tvossim) mean that xcframeworks are only built for the current host architecture. |
36 | 53 |
|
37 | | -# ICU Data Archive |
38 | | -The build.sh script builds the following xcframeworks: icudata, icui18n, icuio, and icuuc. |
39 | | -By default, 'icudata' is built with the --with-data-packaging=static option (see https://unicode-org.github.io/icu/userguide/icu_data/). So all the metadata (locales, tables, etc) is placed into icudata library making it quite large (~32MB). Since xcframework may contain libraries for multiple platforms and architectures this metadata is duplicated multiple times wasting space. Therefore, ICU allows to move the metadata to a separate platform-independent file that must be loaded during the library initialization. To activate this option you can specify -d=archive : |
| 54 | +### Available `-p` Values |
| 55 | + |
| 56 | +```text |
| 57 | +macosx,macosx-arm64,macosx-x86_64,macosx-both, |
| 58 | +ios,iossim,iossim-arm64,iossim-x86_64,iossim-both, |
| 59 | +catalyst,catalyst-arm64,catalyst-x86_64,catalyst-both, |
| 60 | +xros,xrossim,xrossim-arm64,xrossim-x86_64,xrossim-both, |
| 61 | +tvos,tvossim,tvossim-arm64,tvossim-x86_64,tvossim-both, |
| 62 | +watchos,watchossim,watchossim-arm64,watchossim-x86_64,watchossim-both |
40 | 63 | ``` |
| 64 | + |
| 65 | +- The `-both` suffix builds XCFrameworks for both `arm64` and `x86_64`. |
| 66 | +- Platform names without an architecture suffix (for example, `macosx`, `iossim`) build only for the current host architecture. |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## ICU Data Archive |
| 71 | + |
| 72 | +The `build.sh` script builds the following XCFrameworks: |
| 73 | + |
| 74 | +- `icudata` |
| 75 | +- `icui18n` |
| 76 | +- `icuio` |
| 77 | +- `icuuc` |
| 78 | + |
| 79 | +By default, `icudata` is built with `--with-data-packaging=static` (see the ICU data documentation). All ICU metadata (locales, tables, rules, etc.) is embedded directly into the `icudata` library, making it relatively large (~32 MB). |
| 80 | + |
| 81 | +Because an XCFramework may include multiple platforms and architectures, this metadata is duplicated several times, increasing the overall size. ICU allows this data to be moved into a separate, platform-independent archive that is loaded at runtime. |
| 82 | + |
| 83 | +To enable this option, use `-d=archive`: |
| 84 | + |
| 85 | +```bash |
41 | 86 | scripts/build.sh -p=ios,iossim-x86_64 -d=archive |
42 | | -# builts xcframeworks for iOS and iOS Simulator with x86_64 architecture |
43 | | -# datafile path is product/share/icu/78.1/icudt78l.dat |
| 87 | +# Builds XCFrameworks for iOS and the iOS Simulator (x86_64) |
| 88 | +# Data file path: product/share/icu/78.1/icudt78l.dat |
44 | 89 | ``` |
45 | | -In that case, during the ICU initialization procedure you have to specify ICU data directory before u_init() call: |
46 | 90 |
|
47 | | -``` |
| 91 | +During ICU initialization, you must specify the ICU data directory **before** calling `u_init()`: |
| 92 | +
|
| 93 | +```c |
48 | 94 | #include <unicode/putil.h> |
| 95 | +#include <unicode/uclean.h> |
| 96 | + |
| 97 | +// Specify the directory containing the ICU data file |
| 98 | +u_setDataDirectory("PATH_TO_DIRECTORY_CONTAINING_icudt78l.dat"); |
| 99 | + |
| 100 | +UErrorCode errCode = U_ZERO_ERROR; |
| 101 | +u_init(&errCode); |
| 102 | +if (U_FAILURE(errCode)) { |
| 103 | + // Handle initialization error |
| 104 | + ... |
| 105 | +} |
49 | 106 |
|
50 | | -... // somewhere in ICU initialization procedure before u_init call |
51 | | -u_setDataDirectory("PATH TO THE DIRECTORY WHERE icudt78l.dat is located"); |
| 107 | +// Use ICU API... |
| 108 | + |
| 109 | +u_cleanup(); // Optional: release ICU resources |
52 | 110 |
|
53 | | -u_init(code) |
54 | | -... |
55 | 111 | ``` |
56 | 112 |
|
| 113 | +--- |
| 114 | +
|
57 | 115 | ## ICU Data Filtering |
58 | | -ICU metadata is a rather large set of different locales, tables, rules and so on. It's very likely that you won't need all of them in your application. Fortunately, we can filter the data we need when building the icudata library by specifying the filter with the -f option: |
59 | | -``` |
| 116 | +
|
| 117 | +ICU metadata includes a large collection of locales, tables, and rules. In most applications, only a subset of this data is required. |
| 118 | +
|
| 119 | +You can reduce the size of `icudata` by applying a data filter using the `-f` option: |
| 120 | +
|
| 121 | +```bash |
60 | 122 | scripts/build.sh -p=ios,iossim-x86_64 -f=path_to_filter.json |
61 | | -# builts xcframeworks for iOS and iOS Simulator with x86_64 architecture |
| 123 | +# Builds XCFrameworks for iOS and the iOS Simulator (x86_64) |
62 | 124 | ``` |
63 | | -The format of the filter is described at https://unicode-org.github.io/icu/userguide/icu_data/buildtool.html |
64 | 125 |
|
65 | | -## Rebuild option |
66 | | -To rebuild the library without using the results of previous builds, use the --rebuild option |
67 | | -``` |
68 | | -scripts/build.sh -p=ios,iossim-x86_64 --rebuild |
| 126 | +The filter format is described in the official ICU documentation: |
| 127 | +https://unicode-org.github.io/icu/userguide/icu_data/buildtool.html |
69 | 128 |
|
70 | | -``` |
| 129 | +--- |
| 130 | +
|
| 131 | +## Rebuild Option |
71 | 132 |
|
72 | | -# Build Using Cocoapods. |
73 | | -Add the following lines into your project's Podfile: |
| 133 | +To rebuild the libraries without using artifacts from previous builds, use the `--rebuild` option: |
| 134 | +
|
| 135 | +```bash |
| 136 | +scripts/build.sh -p=ios,iossim-x86_64 --rebuild |
74 | 137 | ``` |
75 | | - use_frameworks! |
76 | | - pod 'icu4c-iosx', '~> 78.1' |
77 | | - |
78 | | - # or optionally more precisely |
79 | | - # pod 'icu4c-iosx', :git => 'https://github.com/apotocki/icu4c-iosx', :tag => '78.1.2' |
| 138 | +
|
| 139 | +--- |
| 140 | +
|
| 141 | +## Build Using CocoaPods |
| 142 | +
|
| 143 | +Add the following to your `Podfile`: |
| 144 | +
|
| 145 | +```ruby |
| 146 | +use_frameworks! |
| 147 | +pod 'icu4c-iosx', '~> 78.1' |
| 148 | + |
| 149 | +# Or explicitly reference the repository |
| 150 | +# pod 'icu4c-iosx', :git => 'https://github.com/apotocki/icu4c-iosx', :tag => '78.1.3' |
80 | 151 | ``` |
81 | | -install new dependency: |
82 | | -``` |
| 152 | +
|
| 153 | +Install the dependency: |
| 154 | +```bash |
83 | 155 | pod install --verbose |
84 | 156 | ``` |
85 | 157 |
|
86 | | -## As advertising... |
87 | | -The ICU libraries that have been built by this project are being used in my iOS application on the App Store: |
| 158 | +--- |
| 159 | +
|
| 160 | +## Used in Production |
| 161 | +
|
| 162 | +The ICU libraries built by this project are used in my iOS application available on the App Store: |
88 | 163 |
|
89 | 164 | [<table align="center" border=0 cellspacing=0 cellpadding=0><tr><td><img src="https://is4-ssl.mzstatic.com/image/thumb/Purple112/v4/78/d6/f8/78d6f802-78f6-267a-8018-751111f52c10/AppIcon-0-1x_U007emarketing-0-10-0-85-220.png/460x0w.webp" width="70"/></td><td><a href="https://apps.apple.com/us/app/potohex/id1620963302">PotoHEX</a><br>HEX File Viewer & Editor</td><tr></table>]() |
90 | 165 |
|
91 | | -This application is designed to view and edit files at the byte or character level; calculate different hashes, encode/decode, and compress/decompress desired byte regions. |
92 | | - |
93 | | -You can support my open-source development by trying the [App](https://apps.apple.com/us/app/potohex/id1620963302). |
| 166 | +PotoHEX is designed for viewing and editing files at the byte or character level, calculating hashes, encoding/decoding data, and compressing/decompressing selected byte ranges. |
| 167 | +
|
| 168 | +If you find this project useful, you can support my open-source work by trying the [App](https://apps.apple.com/us/app/potohex/id1620963302). |
| 169 | +
|
| 170 | +--- |
94 | 171 |
|
95 | 172 | Feedback is welcome! |
0 commit comments