tree: 84f2b1fdb74571ff19505811b116cf2fdcd60df8 [path history] [tgz]
  1. rust_icu_common/
  2. rust_icu_sys/
  3. rust_icu_ucal/
  4. rust_icu_udat/
  5. rust_icu_udata/
  6. rust_icu_uenum/
  7. rust_icu_uloc/
  8. rust_icu_ustring/
  9. rust_icu_utext/
  10. BUILD.gn
  11. OWNERS
  12. README.md
src/lib/icu/rust/README.md

rust_icu: rust bindings for the ICU4C library

This directory contains the rust bindings for the ICU4C library as used in Fuchsia.

The library does not offer full ICU feature parity. At the moment it is a subset that is immediately needed for rust in Fuchsia.

The bindings need some maintenance to keep the binding library in sync with the ICU library in use by fuchsia (at //third_party/icu). However, since changes to that library should be infrequent, we expect not to need to update the bindings frequently. Should that change, we may revisit and set up a more automated update approach.

Updating the bindings

You would want to update the bindings in one of the following cases:

  • You add functionality to the library.
  • Major version number of the library is updated in the Fuchsia tree.
  • Some other library change causes the generated binding not to be appropriate.

The bindings are currently generated out of tree because of Fuchsia‘s policy of fixing the binding code. Chances are that until BUG 13551 is fixed, this won’t change.

At the moment, the directory ./rust_icu_sys/bindgen contains files that were generated by running bindgen on the ICU4C library version 64, which is the one in current use.

Currently the binding generation process is manual. Refer to ./rust_icu_sys/bindgen/config for information on the bindgen configuration that was used to generate the bindings.

Use the script ./rust_icu_sys/bindgen/run_bindgen.sh to update the bindings when you need to. The update script requires that you have an ICU4C library built and installed on your workstation such that the headers can be accessed.

Run the script from the directory it is located in.

The generator script uses icu-config, which is installed as part of the ICU installation to pick up the location of ICU4C headers needed to autogenerate the bindings.

Updating the binding macros

We also use the macros.rs file that provides versioned_function!, a macro that handles ICU function renaming. ICU renames functions in the compiled library by default, by appending the major version number at the end of each function. So, a function that would be called foo_bar in the header would actually be called say foo_bar_64 in the library.

The C headers add #define directives that ensure this renaming is not observed by the users of the library. But the rust linker has to know.

This behavior can be turned off: you need to pass an additional flag --disable-renaming to the script runConfigureICU (see below) when running it, and recompile the library.

In that case the macros library has to be different. Two versions of lib.rs are provided in ./rs_icu_sys/src: one that renames the functions, and one that does not.

ICU installation instructions

These instructions are the minimal extraction of the “out-of-tree” build instructions from the ICU repository. The instructions below are not self-contained: they assume that you have your system set up such that you can follow the ICU build instructions.

mkdir -p $HOME/local
mkdir -p $HOME/tmp
cd $HOME/tmp
git clone export https://github.com/unicode-org/icu.git
mkdir icu4c-build
cd icu4c-build
../icu/icu4c/source/runConfigureICU Linux \
  --prefix=$HOME/local \
  --enable-static
make check
make install
make doc