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

ICU-22838 Add WebAssembly/WASI cross-compilation support #3067

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kateinoigakukun
Copy link
Contributor

@kateinoigakukun kateinoigakukun commented Jul 25, 2024

With this patch, we can cross-compile ICU4C with wasi-sdk as follows:

$ mkdir tools
$ mkdir cross
$ cd tools
$ ../icu/icu4c/source/configure && make
$ cd ../cross
$ ../../icu/icu4c/source/configure --host=wasm32-unknown-wasi \
            --with-cross-build="$PWD/../tools" \
            --enable-static --disable-shared \
            --disable-tools --disable-tests \
            --disable-samples --disable-extras \
            --with-data-packaging=static \
            --prefix / \
            CC="$WASI_SDK_PATH/bin/clang" CXX="$WASI_SDK_PATH/bin/clang++" \
            AR="$WASI_SDK_PATH/bin/llvm-ar" RANLIB="$WASI_SDK_PATH/bin/llvm-ranlib" \
            CFLAGS="--sysroot $WASI_SDK_PATH/share/wasi-sysroot -D_WASI_EMULATED_SIGNAL" \
            CXXFLAGS="-fno-exceptions --sysroot $WASI_SDK_PATH/share/wasi-sysroot -D_WASI_EMULATED_SIGNAL"
$ make PKGDATA_OPTS="--without-assembly -O $PWD/data/icupkg.inc" -j16

Patch overview

  • Add config/mh-wasi and update configure script.

    WebAssembly/WASI does not support threads and dynamic linking, so
    the new mh-wasi file disables those features in ICU.
    The new config file mh-wasi is used when the target matches *-wasi*,
    which includes wasm32-unknown-wasi, wasm32-unknown-wasip1, and etc.

  • Teach platform.h not to define U_TZSET, U_TIMEZONE, and U_TZNAME for WASI

    WASI does not define timezone-related functionalities, and wasi-libc
    does not provide tzset, timezone, and tzname. This change teaches
    platform.h not to define U_TZSET, U_TIMEZONE, and U_TZNAME for WASI.

  • Add U_HAVE_ATOMICS and support platforms without atomics like WASI

    This change adds a new macro U_HAVE_ATOMICS to ICU. This macro is
    always defined to 1 except for platforms that do not support atomic
    operations like WASI. Due to the lack of threading support in WASI, the
    wasi-sdk does not provide std::atomic, std::mutex, and related
    types, so the new macro is used to disable the use of these types.

After #3066 and this are merged, I'd like to add CI check for WASI cross-compilation

Checklist
  • Required: Issue filed: https://unicode-org.atlassian.net/browse/ICU-22838
  • Required: The PR title must be prefixed with a JIRA Issue number.
  • Required: The PR description must include the link to the Jira Issue, for example by completing the URL in the first checklist item
  • Required: Each commit message must be prefixed with a JIRA Issue number.
  • Issue accepted (done by Technical Committee after discussion)
  • Tests included, if applicable
  • API docs and/or User Guide docs changed or added, if applicable

@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • icu4c/source/common/putilimp.h is different
  • icu4c/source/common/unicode/platform.h is now changed in the branch
  • icu4c/source/i18n/unicode/numberrangeformatter.h is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

* Add config/mh-wasi and update configure script.

  WebAssembly/WASI does not support threads and dynamic linking, so
  the new mh-wasi file disables those features in ICU.

* Teach putilimp.h not to define U_TZSET, U_TIMEZONE, and U_TZNAME for WASI

  WASI does not define timezone-related functionalities, and wasi-libc
  does not provide tzset, timezone, and tzname. This change teaches
  putilimp.h not to define U_TZSET, U_TIMEZONE, and U_TZNAME for WASI.

* Add `U_HAVE_ATOMICS` and support platforms without atomics like WASI

  This change adds a new macro `U_HAVE_ATOMICS` to ICU. This macro is
  always defined to 1 except for platforms that do not support atomic
  operations like WASI. Due to the lack of threading support in WASI, the
  wasi-sdk does not provide `std::atomic`, `std::mutex`, and related
  types, so the new macro is used to disable the use of these types.
@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • icu4c/source/i18n/number_mapper.h is different
  • icu4c/source/i18n/numrange_fluent.cpp is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

kateinoigakukun added a commit to kateinoigakukun/swift-foundation-icu that referenced this pull request Jul 26, 2024
The original patch is still under review in the upstream ICU project, but
it is needed to unblock the swift-foundation build on WebAssembly.

See unicode-org/icu#3067
@markusicu
Copy link
Member

@srl295 @sffc could you help review these changes?

kateinoigakukun added a commit to kateinoigakukun/swift-foundation-icu that referenced this pull request Aug 2, 2024
The original patch is still under review in the upstream ICU project, but
it is needed to unblock the swift-foundation build on WebAssembly.

See unicode-org/icu#3067
iCharlesHu pushed a commit to apple/swift-foundation-icu that referenced this pull request Aug 6, 2024
* Cherry-pick "ICU-22838 Add WebAssembly/WASI cross-compilation support"

The original patch is still under review in the upstream ICU project, but
it is needed to unblock the swift-foundation build on WebAssembly.

See unicode-org/icu#3067

* [Build] Update compile definitions for WASI target

`U_TIMEZONE` must not be defined and dynamic loading features must be
disabled for WASI target.
iCharlesHu pushed a commit to iCharlesHu/swift-foundation-icu that referenced this pull request Aug 6, 2024
* Cherry-pick "ICU-22838 Add WebAssembly/WASI cross-compilation support"

The original patch is still under review in the upstream ICU project, but
it is needed to unblock the swift-foundation build on WebAssembly.

See unicode-org/icu#3067

* [Build] Update compile definitions for WASI target

`U_TIMEZONE` must not be defined and dynamic loading features must be
disabled for WASI target.
iCharlesHu added a commit to apple/swift-foundation-icu that referenced this pull request Aug 7, 2024
* Cherry-pick "ICU-22838 Add WebAssembly/WASI cross-compilation support"

The original patch is still under review in the upstream ICU project, but
it is needed to unblock the swift-foundation build on WebAssembly.

See unicode-org/icu#3067

* [Build] Update compile definitions for WASI target

`U_TIMEZONE` must not be defined and dynamic loading features must be
disabled for WASI target.

Co-authored-by: Yuta Saito <kateinoigakukun@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants