diff --git a/.github/workflows/icu4c.yml b/.github/workflows/icu4c.yml index 71900dbde83e..f36f1dc75b50 100644 --- a/.github/workflows/icu4c.yml +++ b/.github/workflows/icu4c.yml @@ -532,6 +532,50 @@ jobs: set PATH=C:\tools\msys64\mingw64\bin;%PATH% .\icuinfo.exe + # WebAssembly build using the WASI SDK. + wasm-wasi-sdk: + runs-on: ubuntu-22.04 # Updated in BRS + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Install WASI SDK + env: + WASI_SDK_DOWNLOAD_URL: https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-27/wasi-sdk-27.0-x86_64-linux.deb + WASI_SDK_DOWNLOAD_SHA256: 3ed68fc89e3299c0e2333360efac89ec60fbc01870732a486ab386267355cc80 + run: | + wget -O /tmp/wasi-sdk.deb "${WASI_SDK_DOWNLOAD_URL}" + echo "${WASI_SDK_DOWNLOAD_SHA256} /tmp/wasi-sdk.deb" | sha256sum -c - + sudo apt-get install /tmp/wasi-sdk.deb + echo "WASI_SDK_PATH=/opt/wasi-sdk" >> $GITHUB_ENV + + - name: Build tools for host system + run: | + TOOLS_BUILD_DIR="$PWD/build/tools"; + mkdir -p "$TOOLS_BUILD_DIR"; + pushd "$TOOLS_BUILD_DIR"; + ../../icu4c/source/configure + make -j$(nproc) + echo "TOOLS_BUILD_DIR=$TOOLS_BUILD_DIR" >> $GITHUB_ENV + + - name: Cross-build for WebAssembly with WASI SDK + run: | + CROSS_BUILD_DIR="$PWD/build/cross"; + mkdir -p "$CROSS_BUILD_DIR"; + pushd "$CROSS_BUILD_DIR"; + ../../icu4c/source/configure --host=wasm32-unknown-wasip1 \ + --with-cross-build="$TOOLS_BUILD_DIR" \ + --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="-D_WASI_EMULATED_SIGNAL" \ + CXXFLAGS="-fno-exceptions -D_WASI_EMULATED_SIGNAL" + make -j$(nproc) PKGDATA_OPTS="--without-assembly -O $CROSS_BUILD_DIR/data/icupkg.inc" + make install DESTDIR="$CROSS_BUILD_DIR/install" + # Run ICU4C tests with stubdata. run-with-stubdata: runs-on: ubuntu-22.04 # Updated in BRS diff --git a/icu4c/source/acinclude.m4 b/icu4c/source/acinclude.m4 index da29400a7160..9636a4b2be03 100644 --- a/icu4c/source/acinclude.m4 +++ b/icu4c/source/acinclude.m4 @@ -85,6 +85,7 @@ powerpc*-apple-darwin*) icu_cv_host_frag=mh-darwin-ppc ;; *-dec-osf*) icu_cv_host_frag=mh-alpha-osf ;; *-*-nto*) icu_cv_host_frag=mh-qnx ;; *-ncr-*) icu_cv_host_frag=mh-mpras ;; +*-wasi*) icu_cv_host_frag=mh-wasi ;; *) icu_cv_host_frag=mh-unknown ;; esac ] diff --git a/icu4c/source/common/putilimp.h b/icu4c/source/common/putilimp.h index 8a8ff5008118..03f588a1a7a3 100644 --- a/icu4c/source/common/putilimp.h +++ b/icu4c/source/common/putilimp.h @@ -107,6 +107,8 @@ typedef size_t uintptr_t; /* not defined */ #elif U_PLATFORM == U_PF_HAIKU /* not defined */ +#elif defined(__wasi__) + /* not defined */ #else # define U_TZSET tzset #endif @@ -132,6 +134,8 @@ typedef size_t uintptr_t; /* not defined */ #elif U_PLATFORM == U_PF_IPHONE /* not defined */ +#elif defined(__wasi__) + /* not defined */ #else # define U_TIMEZONE timezone #endif @@ -147,6 +151,8 @@ typedef size_t uintptr_t; /* not defined */ #elif U_PLATFORM == U_PF_HAIKU /* not defined, (well it is but a loop back to icu) */ +#elif defined(__wasi__) + /* not defined */ #else # define U_TZNAME tzname #endif diff --git a/icu4c/source/config/mh-wasi b/icu4c/source/config/mh-wasi new file mode 100644 index 000000000000..a8d776684f2f --- /dev/null +++ b/icu4c/source/config/mh-wasi @@ -0,0 +1,76 @@ +## -*-makefile-*- +## Copyright (C) 2024 and later: Unicode, Inc. and others. +## License & terms of use: http://www.unicode.org/copyright.html +## WASI-specific setup + +## Commands to generate dependency files +GEN_DEPS.c= $(CC) -E -MM $(DEFS) $(CPPFLAGS) +GEN_DEPS.cc= $(CXX) -E -MM $(DEFS) $(CPPFLAGS) $(CXXFLAGS) + +## Flags for position independent code +SHAREDLIBCFLAGS = -fPIC +SHAREDLIBCXXFLAGS = -fPIC +SHAREDLIBCPPFLAGS = -DPIC + +## Additional flags when building libraries and with threads +# WASI Preview 1 without wasi-threads does not support threads +THREADSCPPFLAGS = +LIBCPPFLAGS = + +## Compiler switch to embed a runtime search path +LD_RPATH= +LD_RPATH_PRE = + +## These are the library specific LDFLAGS +LDFLAGSICUDT=-nodefaultlibs -nostdlib + +## Shared object suffix +SO = so +## Non-shared intermediate object suffix +STATIC_O = ao + +## Compilation rules +%.$(STATIC_O): $(srcdir)/%.c + $(call SILENT_COMPILE,$(strip $(COMPILE.c) $(STATICCPPFLAGS) $(STATICCFLAGS)) -o $@ $<) +%.o: $(srcdir)/%.c + $(call SILENT_COMPILE,$(strip $(COMPILE.c) $(DYNAMICCPPFLAGS) $(DYNAMICCFLAGS)) -o $@ $<) + +%.$(STATIC_O): $(srcdir)/%.cpp + $(call SILENT_COMPILE,$(strip $(COMPILE.cc) $(STATICCPPFLAGS) $(STATICCXXFLAGS)) -o $@ $<) +%.o: $(srcdir)/%.cpp + $(call SILENT_COMPILE,$(strip $(COMPILE.cc) $(DYNAMICCPPFLAGS) $(DYNAMICCXXFLAGS)) -o $@ $<) + + +## Dependency rules +%.d: $(srcdir)/%.c + $(call ICU_MSG,(deps)) $< + @$(SHELL) -ec '$(GEN_DEPS.c) $< \ + | sed '\''s%\($*\)\.o[ :]*%\1.o $@ : %g'\'' > $@; \ + [ -s $@ ] || rm -f $@' + +%.d: $(srcdir)/%.cpp + $(call ICU_MSG,(deps)) $< + @$(SHELL) -ec '$(GEN_DEPS.cc) $< \ + | sed '\''s%\($*\)\.o[ :]*%\1.o $@ : %g'\'' > $@; \ + [ -s $@ ] || rm -f $@' + +## Versioned libraries rules + +%.$(SO).$(SO_TARGET_VERSION_MAJOR): %.$(SO).$(SO_TARGET_VERSION) + $(RM) $@ && ln -s ${