Skip to content

Commit 9fe521e

Browse files
authored
Merge pull request #944 from swiftwasm/maxd/cmake-icu
Install WASI ICU dependency with CMake
2 parents 0851f5d + cfb9992 commit 9fe521e

File tree

9 files changed

+45
-50
lines changed

9 files changed

+45
-50
lines changed

CMakeLists.txt

+30
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,36 @@ function(swift_icu_variables_set sdk arch result)
887887
endif()
888888
endfunction()
889889

890+
if(SWIFT_PRIMARY_VARIANT_SDK STREQUAL "WASI")
891+
set(WASI_ICU_URL "" CACHE STRING
892+
"Download URL for the WASI ICU distribution")
893+
set(WASI_ICU_MD5 "" CACHE STRING
894+
"The expected MD5 hash of the WASI ICU distribution archive")
895+
896+
file(DOWNLOAD "${WASI_ICU_URL}" "${SWIFT_SOURCE_DIR}/../icu.tar.xz"
897+
EXPECTED_HASH MD5=${WASI_ICU_MD5})
898+
899+
get_filename_component(SWIFT_SOURCE_BASEDIR "${SWIFT_SOURCE_DIR}" DIRECTORY)
900+
set(WASI_ICU_OUT_LIB "${SWIFT_SOURCE_BASEDIR}/icu_out/lib")
901+
set(SWIFT_WASI_wasm32_ICU_UC_INCLUDE "${SWIFT_SOURCE_BASEDIR}/icu_out/include")
902+
set(SWIFT_WASI_wasm32_ICU_I18N_INCLUDE "${SWIFT_SOURCE_BASEDIR}/icu_out/include")
903+
set(SWIFT_WASI_wasm32_ICU_UC "${WASI_ICU_OUT_LIB}/libicuuc.a")
904+
set(SWIFT_WASI_wasm32_ICU_I18N "${WASI_ICU_OUT_LIB}/libicui18n.a")
905+
set(SWIFT_WASI_wasm32_ICU_DATA "${WASI_ICU_OUT_LIB}/libicudata.a")
906+
907+
set(WASI_ICU_DISTRIBUTION_TARGET)
908+
add_custom_command_target(WASI_ICU_DISTRIBUTION_TARGET
909+
COMMAND
910+
${CMAKE_COMMAND} -E
911+
tar xfv "${SWIFT_SOURCE_BASEDIR}/icu.tar.xz"
912+
WORKING_DIRECTORY
913+
"${SWIFT_SOURCE_BASEDIR}"
914+
OUTPUT
915+
"${SWIFT_WASI_wasm32_ICU_DATA}"
916+
"${SWIFT_WASI_wasm32_ICU_I18N}"
917+
"${SWIFT_WASI_wasm32_ICU_UC}")
918+
endif()
919+
890920
# ICU is provided through CoreFoundation on Darwin. On other hosts, if the ICU
891921
# unicode and i18n include and library paths are not defined, perform a standard
892922
# package lookup. Otherwise, rely on the paths specified by the user. These

stdlib/public/runtime/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ foreach(sdk ${SWIFT_CONFIGURED_SDKS})
358358
add_custom_command_target(swift_static_stdlib_${sdk}_args
359359
COMMAND
360360
"${CMAKE_COMMAND}" -E copy
361-
"${linkfile_src}"
362-
"${SWIFTSTATICLIB_DIR}/${linkfile}"
361+
"${linkfile_src}"
362+
"${SWIFTSTATICLIB_DIR}/${linkfile}"
363363
OUTPUT
364364
"${SWIFTSTATICLIB_DIR}/${linkfile}"
365365
DEPENDS

stdlib/public/stubs/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ set(swift_stubs_c_compile_flags ${SWIFT_RUNTIME_CORE_CXX_FLAGS})
2727
list(APPEND swift_stubs_c_compile_flags -DswiftCore_EXPORTS)
2828
list(APPEND swift_stubs_c_compile_flags -I${SWIFT_SOURCE_DIR}/include)
2929

30+
set(swift_stubs_dependencies)
31+
if(SWIFT_PRIMARY_VARIANT_SDK STREQUAL "WASI")
32+
list(APPEND swift_stubs_dependencies ${WASI_ICU_DISTRIBUTION_TARGET})
33+
endif()
34+
3035
add_swift_target_library(swiftStdlibStubs
36+
DEPENDS
37+
${swift_stubs_dependencies}
3138
OBJECT_LIBRARY
3239
${swift_stubs_sources}
3340
${swift_stubs_objc_sources}

utils/build-presets.ini

+4-5
Original file line numberDiff line numberDiff line change
@@ -2447,11 +2447,6 @@ build-swift-static-sdk-overlay
24472447
build-swift-static-stdlib
24482448
llvm-targets-to-build=X86;WebAssembly
24492449
stdlib-deployment-targets=wasi-wasm32
2450-
wasi-icu-data=%(SOURCE_PATH)s/icu_out/lib/libicudata.a
2451-
wasi-icu-i18n=%(SOURCE_PATH)s/icu_out/lib/libicui18n.a
2452-
wasi-icu-i18n-include=%(SOURCE_PATH)s/icu_out/include
2453-
wasi-icu-uc=%(SOURCE_PATH)s/icu_out/lib/libicuuc.a
2454-
wasi-icu-uc-include=%(SOURCE_PATH)s/icu_out/include
24552450
wasi-sdk=%(SOURCE_PATH)s/wasi-sdk
24562451

24572452
[preset: webassembly-installable]
@@ -2473,6 +2468,8 @@ darwin-toolchain-alias=swift
24732468

24742469
mixin-preset=webassembly
24752470
extra-cmake-options=
2471+
-DWASI_ICU_URL:STRING="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
2472+
-DWASI_ICU_MD5:STRING="25943864ebbfff15cf5aee8d9d5cc4d7"
24762473
-DSWIFT_PRIMARY_VARIANT_SDK:STRING=WASI
24772474
-DSWIFT_PRIMARY_VARIANT_ARCH:STRING=wasm32
24782475
-DSWIFT_SDKS='WASI;LINUX'
@@ -2486,6 +2483,8 @@ extra-cmake-options=
24862483

24872484
mixin-preset=webassembly
24882485
extra-cmake-options=
2486+
-DWASI_ICU_URL:STRING="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
2487+
-DWASI_ICU_MD5:STRING="25943864ebbfff15cf5aee8d9d5cc4d7"
24892488
-DSWIFT_PRIMARY_VARIANT_SDK:STRING=WASI
24902489
-DSWIFT_PRIMARY_VARIANT_ARCH:STRING=wasm32
24912490
-DSWIFT_OSX_x86_64_ICU_STATICLIB=TRUE

utils/build-script

+2-16
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,9 @@ def validate_arguments(toolchain, args):
215215
"--android-icu-i18n-include, and --android-icu-data "
216216
"must be specified")
217217
if args.wasm:
218-
if args.wasi_sdk is None or \
219-
args.wasi_icu_uc is None or \
220-
args.wasi_icu_uc_include is None or \
221-
args.wasi_icu_i18n is None or \
222-
args.wasi_icu_i18n_include is None or \
223-
args.wasi_icu_data is None:
218+
if args.wasi_sdk is None:
224219
diagnostics.fatal(
225-
"when building for WebAssembly, --wasi-sdk, "
226-
"--wasi-icu-uc, "
227-
"--wasi-icu-uc-include, --wasi-icu-i18n, "
228-
"--wasi-icu-i18n-include, and --wasi-icu-data "
229-
"must be specified")
220+
"when building for WebAssembly, --wasi-sdk must be specified")
230221

231222
targets_needing_toolchain = [
232223
'build_indexstoredb',
@@ -696,11 +687,6 @@ class BuildScriptInvocation(object):
696687
if args.wasm:
697688
impl_args += [
698689
"--wasi-sdk", args.wasi_sdk,
699-
"--wasi-icu-uc", args.wasi_icu_uc,
700-
"--wasi-icu-uc-include", args.wasi_icu_uc_include,
701-
"--wasi-icu-i18n", args.wasi_icu_i18n,
702-
"--wasi-icu-i18n-include", args.wasi_icu_i18n_include,
703-
"--wasi-icu-data", args.wasi_icu_data,
704690
]
705691

706692
if platform.system() == 'Darwin':

utils/build-script-impl

-10
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ KNOWN_SETTINGS=(
118118

119119
## WebAssembly/WASI Options
120120
wasi-sdk "" "An absolute path to the WASI SDK that will be used as a libc implementation for Wasm builds"
121-
wasi-icu-uc "" "Path to libicuuc.so"
122-
wasi-icu-uc-include "" "Path to a directory containing headers for libicuuc"
123-
wasi-icu-i18n "" "Path to libicui18n.so"
124-
wasi-icu-i18n-include "" "Path to a directory containing headers libicui18n"
125-
wasi-icu-data "" "Path to libicudata.so"
126121

127122
## Build Types for Components
128123
swift-stdlib-build-type "Debug" "the CMake build variant for Swift"
@@ -1622,11 +1617,6 @@ for host in "${ALL_HOSTS[@]}"; do
16221617
cmake_options=(
16231618
"${cmake_options[@]}"
16241619
-DSWIFT_WASI_SDK_PATH:STRING="${WASI_SDK}"
1625-
-DSWIFT_WASI_wasm32_ICU_UC:STRING="${WASI_ICU_UC}"
1626-
-DSWIFT_WASI_wasm32_ICU_UC_INCLUDE:STRING="${WASI_ICU_UC_INCLUDE}"
1627-
-DSWIFT_WASI_wasm32_ICU_I18N:STRING="${WASI_ICU_I18N}"
1628-
-DSWIFT_WASI_wasm32_ICU_I18N_INCLUDE:STRING="${WASI_ICU_I18N_INCLUDE}"
1629-
-DSWIFT_WASI_wasm32_ICU_DATA:STRING="${WASI_ICU_DATA}"
16301620
)
16311621
fi
16321622

utils/build_swift/build_swift/driver_arguments.py

-11
Original file line numberDiff line numberDiff line change
@@ -1098,17 +1098,6 @@ def create_argument_parser():
10981098
help='An absolute path to WASI SDK that will be used as a libc '
10991099
'implementation for Wasm builds')
11001100

1101-
option('--wasi-icu-uc', store_path,
1102-
help='Path to libicuuc.so')
1103-
option('--wasi-icu-uc-include', store_path,
1104-
help='Path to a directory containing headers for libicuuc')
1105-
option('--wasi-icu-i18n', store_path,
1106-
help='Path to libicui18n.so')
1107-
option('--wasi-icu-i18n-include', store_path,
1108-
help='Path to a directory containing headers libicui18n')
1109-
option('--wasi-icu-data', store_path,
1110-
help='Path to libicudata.so')
1111-
11121101
# -------------------------------------------------------------------------
11131102
in_group('Experimental language features')
11141103

utils/webassembly/linux/install-dependencies.sh

-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ mv $WASI_SDK_FULL_NAME ./wasi-sdk
4242
# with os and environment name `getMultiarchTriple`.
4343
ln -s wasm32-wasi wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi-unknown
4444

45-
wget -O icu.tar.xz "https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
46-
tar xf icu.tar.xz
47-
4845
# Install sccache
4946

5047
sudo mkdir /opt/sccache && cd /opt/sccache

utils/webassembly/macos/install-dependencies.sh

-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,3 @@ ln -s ../include wasi-sdk/share/wasi-sysroot/usr/include
2727
# Link wasm32-wasi-unknown to wasm32-wasi because clang finds crt1.o from sysroot
2828
# with os and environment name `getMultiarchTriple`.
2929
ln -s wasm32-wasi wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi-unknown
30-
31-
wget -O icu.tar.xz "https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
32-
tar xf icu.tar.xz

0 commit comments

Comments
 (0)