Skip to content

Commit e26ae1c

Browse files
kateinoigakukunyonihemi
authored andcommitted
Simplify build script (#2733)
* [WASM] Simplify Foundation build script * [WASM] Remove WASI ICU related code from CMake build system * Refactoring build-toolchain script * [WASM] Fix prebuilt libraries path * [WASM] Always install ubuntu wasi-sdk * Fix unarchive command
1 parent 62fa9cb commit e26ae1c

File tree

12 files changed

+90
-92
lines changed

12 files changed

+90
-92
lines changed

CMakeLists.txt

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -903,36 +903,6 @@ function(swift_icu_variables_set sdk arch result)
903903
endif()
904904
endfunction()
905905

906-
if(SWIFT_PRIMARY_VARIANT_SDK STREQUAL "WASI")
907-
set(WASI_ICU_URL "" CACHE STRING
908-
"Download URL for the WASI ICU distribution")
909-
set(WASI_ICU_MD5 "" CACHE STRING
910-
"The expected MD5 hash of the WASI ICU distribution archive")
911-
912-
file(DOWNLOAD "${WASI_ICU_URL}" "${SWIFT_SOURCE_DIR}/../icu.tar.xz"
913-
EXPECTED_HASH MD5=${WASI_ICU_MD5})
914-
915-
get_filename_component(SWIFT_SOURCE_BASEDIR "${SWIFT_SOURCE_DIR}" DIRECTORY)
916-
set(WASI_ICU_OUT_LIB "${SWIFT_SOURCE_BASEDIR}/icu_out/lib")
917-
set(SWIFT_WASI_wasm32_ICU_UC_INCLUDE "${SWIFT_SOURCE_BASEDIR}/icu_out/include")
918-
set(SWIFT_WASI_wasm32_ICU_I18N_INCLUDE "${SWIFT_SOURCE_BASEDIR}/icu_out/include")
919-
set(SWIFT_WASI_wasm32_ICU_UC "${WASI_ICU_OUT_LIB}/libicuuc.a")
920-
set(SWIFT_WASI_wasm32_ICU_I18N "${WASI_ICU_OUT_LIB}/libicui18n.a")
921-
set(SWIFT_WASI_wasm32_ICU_DATA "${WASI_ICU_OUT_LIB}/libicudata.a")
922-
923-
set(WASI_ICU_DISTRIBUTION_TARGET)
924-
add_custom_command_target(WASI_ICU_DISTRIBUTION_TARGET
925-
COMMAND
926-
${CMAKE_COMMAND} -E
927-
tar xfv "${SWIFT_SOURCE_BASEDIR}/icu.tar.xz"
928-
WORKING_DIRECTORY
929-
"${SWIFT_SOURCE_BASEDIR}"
930-
OUTPUT
931-
"${SWIFT_WASI_wasm32_ICU_DATA}"
932-
"${SWIFT_WASI_wasm32_ICU_I18N}"
933-
"${SWIFT_WASI_wasm32_ICU_UC}")
934-
endif()
935-
936906
# ICU is provided through CoreFoundation on Darwin. On other hosts, if the ICU
937907
# unicode and i18n include and library paths are not defined, perform a standard
938908
# package lookup. Otherwise, rely on the paths specified by the user. These

cmake/caches/Runtime-WASI-wasm32.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,4 @@ set(SWIFT_STDLIB_STABLE_ABI YES CACHE BOOL "")
2626
# build with the host compiler
2727
set(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER YES CACHE BOOL "")
2828

29-
set(WASI_ICU_URL "https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz" CACHE STRING "")
30-
set(WASI_ICU_MD5 "25943864ebbfff15cf5aee8d9d5cc4d7" CACHE STRING "")
31-
32-
3329
set(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME YES CACHE BOOL "")

stdlib/public/stubs/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ 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-
3530
add_swift_target_library(swiftStdlibStubs
36-
DEPENDS
37-
${swift_stubs_dependencies}
3831
OBJECT_LIBRARY
3932
${swift_stubs_sources}
4033
${swift_stubs_objc_sources}

utils/webassembly/build-foundation.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ set -ex
33
DESTINATION_TOOLCHAIN=$1
44
WASI_SYSROOT_PATH=$2
55
SOURCE_PATH="$(cd "$(dirname $0)/../../.." && pwd)"
6+
BUILD_SDK_PATH="$SOURCE_PATH/build-sdk"
7+
LIBXML2_PATH="$BUILD_SDK_PATH/libxml2"
68

79
FOUNDATION_BUILD="$SOURCE_PATH/target-build/foundation-wasi-wasm32"
810

@@ -15,11 +17,15 @@ cmake -G Ninja \
1517
-DCMAKE_STAGING_PREFIX="$DESTINATION_TOOLCHAIN/usr" \
1618
-DCMAKE_TOOLCHAIN_FILE="$SOURCE_PATH/swift/utils/webassembly/toolchain-wasi.cmake" \
1719
-DLLVM_BIN="$DESTINATION_TOOLCHAIN/usr/bin" \
18-
-DICU_ROOT="$SOURCE_PATH/icu_out" \
20+
-DICU_ROOT="$BUILD_SDK_PATH/icu" \
21+
-DLIBXML2_INCLUDE_DIR="$LIBXML2_PATH/include/libxml2" \
22+
-DLIBXML2_LIBRARY="$LIBXML2_PATH/lib" \
1923
-DBUILD_SHARED_LIBS=OFF \
24+
-DBUILD_NETWORKING=OFF \
25+
-DBUILD_TOOLS=OFF \
26+
-DHAS_LIBDISPATCH_API=OFF \
2027
-DCMAKE_Swift_COMPILER_FORCED=ON \
21-
-DCMAKE_ASM_FLAGS="-target wasm32-unknown-wasi" \
2228
"${SOURCE_PATH}/swift-corelibs-foundation"
2329

24-
ninja -v
25-
ninja -v install
30+
ninja
31+
ninja install

utils/webassembly/build-presets.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#===----------------------------------------------------------------------===#
44

55
[preset: webassembly]
6-
cmake-c-launcher=%(C_CXX_LAUNCHER)s
7-
cmake-cxx-launcher=%(C_CXX_LAUNCHER)s
6+
sccache
87
skip-build-benchmarks
98
llvm-targets-to-build=X86;AArch64;WebAssembly
109
swift-darwin-supported-archs=%(HOST_ARCHITECTURE)s

utils/webassembly/build-toolchain.sh

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ set -ex
44
SOURCE_PATH="$(cd "$(dirname "$0")/../../.." && pwd)"
55
UTILS_PATH="$(cd "$(dirname "$0")" && pwd)"
66

7-
WASI_SDK_PATH="$SOURCE_PATH/wasi-sdk"
7+
BUILD_SDK_PATH="$SOURCE_PATH/build-sdk"
8+
WASI_SDK_PATH="$BUILD_SDK_PATH/wasi-sdk"
89
WASI_SYSROOT_PATH="$WASI_SDK_PATH/share/wasi-sysroot"
910

1011
case $(uname -s) in
@@ -31,6 +32,21 @@ case $(uname -s) in
3132
;;
3233
esac
3334

35+
BUILD_HOST_TOOLCHAIN=1
36+
37+
while [ $# -ne 0 ]; do
38+
case "$1" in
39+
--skip-build-host-toolchain)
40+
BUILD_HOST_TOOLCHAIN=0
41+
;;
42+
*)
43+
echo "Unrecognised argument \"$1\""
44+
exit 1
45+
;;
46+
esac
47+
shift
48+
done
49+
3450
YEAR=$(date +"%Y")
3551
MONTH=$(date +"%m")
3652
DAY=$(date +"%d")
@@ -54,15 +70,12 @@ build_host_toolchain() {
5470
--preset-file="$UTILS_PATH/build-presets.ini" \
5571
--preset=$HOST_PRESET \
5672
--build-dir="$HOST_BUILD_DIR" \
57-
HOST_ARCHITECTURE=$(uname -m) \
73+
HOST_ARCHITECTURE="$(uname -m)" \
5874
INSTALL_DESTDIR="$HOST_TOOLCHAIN_DESTDIR" \
59-
TOOLCHAIN_NAME="$TOOLCHAIN_NAME" \
60-
C_CXX_LAUNCHER="$(which sccache)"
75+
TOOLCHAIN_NAME="$TOOLCHAIN_NAME"
6176
}
6277

6378
build_target_toolchain() {
64-
rm -rf "$DIST_TOOLCHAIN_DESTDIR"
65-
rsync -a "$HOST_TOOLCHAIN_DESTDIR/" "$DIST_TOOLCHAIN_DESTDIR"
6679

6780
COMPILER_RT_BUILD_DIR="$TARGET_BUILD_ROOT/compiler-rt-wasi-wasm32"
6881
cmake -B "$COMPILER_RT_BUILD_DIR" \
@@ -95,6 +108,11 @@ build_target_toolchain() {
95108
-D LLVM_DIR="$HOST_BUILD_DIR/llvm-$HOST_SUFFIX/lib/cmake/llvm/" \
96109
-D SWIFT_NATIVE_SWIFT_TOOLS_PATH="$HOST_BUILD_DIR/swift-$HOST_SUFFIX/bin" \
97110
-D SWIFT_WASI_SYSROOT_PATH="$WASI_SYSROOT_PATH" \
111+
-D SWIFT_WASI_wasm32_ICU_UC_INCLUDE="$BUILD_SDK_PATH/icu/include" \
112+
-D SWIFT_WASI_wasm32_ICU_UC="$BUILD_SDK_PATH/icu/lib/libicuuc.a" \
113+
-D SWIFT_WASI_wasm32_ICU_I18N_INCLUDE="$BUILD_SDK_PATH/icu/include" \
114+
-D SWIFT_WASI_wasm32_ICU_I18N="$BUILD_SDK_PATH/icu/lib/libicui18n.a" \
115+
-D SWIFT_WASI_wasm32_ICU_DATA="$BUILD_SDK_PATH/icu/lib/libicudata.a" \
98116
-G Ninja \
99117
-S "$SOURCE_PATH/swift"
100118

@@ -167,7 +185,12 @@ create_darwin_info_plist() {
167185
chmod a+r "${DARWIN_TOOLCHAIN_INFO_PLIST}"
168186
}
169187

170-
build_host_toolchain
188+
if [ ${BUILD_HOST_TOOLCHAIN} -eq 1 ]; then
189+
build_host_toolchain
190+
rm -rf "$DIST_TOOLCHAIN_DESTDIR"
191+
rsync -a "$HOST_TOOLCHAIN_DESTDIR/" "$DIST_TOOLCHAIN_DESTDIR"
192+
fi
193+
171194
build_target_toolchain
172195

173196
embed_wasi_sysroot

utils/webassembly/ci.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ RUN_TEST_BIN=$SWIFT_PATH/utils/run-test
2626
TARGET_STDLIB_BUILD_DIR=$SOURCE_PATH/target-build/swift-stdlib-wasi-wasm32
2727

2828
$DEPENDENCIES_SCRIPT
29+
$UTILS_PATH/install-build-sdk.sh
2930

3031
export PATH="$HOME/.wasmer/bin:$PATH"
3132

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
5+
SOURCE_PATH="$( cd "$(dirname "$0")/../../../" && pwd )"
6+
BUILD_SDK_PATH="$SOURCE_PATH/build-sdk"
7+
8+
install_libxml2() {
9+
LIBXML2_URL="https://github.com/swiftwasm/libxml2-wasm/releases/download/1.0.0/libxml2-wasm32-unknown-wasi.tar.gz"
10+
curl -L "$LIBXML2_URL" | tar xz
11+
rm -rf "$BUILD_SDK_PATH/libxml2"
12+
mv libxml2-wasm32-unknown-wasi "$BUILD_SDK_PATH/libxml2"
13+
}
14+
15+
install_icu() {
16+
ICU_URL="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
17+
curl -L "$ICU_URL" | tar Jx
18+
rm -rf "$BUILD_SDK_PATH/icu"
19+
mv icu_out "$BUILD_SDK_PATH/icu"
20+
}
21+
22+
install_wasi-sdk() {
23+
# We only use wasi-sysroot and do not use binaries in wasi-sdk,
24+
# so build machine's os and wasi-sdk's host os don't have to be matched
25+
WASI_SDK_URL="https://github.com/swiftwasm/wasi-sdk/releases/download/0.2.2-swiftwasm/dist-ubuntu-18.04.zip"
26+
27+
curl -L -o dist-wasi-sdk.zip "$WASI_SDK_URL"
28+
unzip -u dist-wasi-sdk.zip -d .
29+
30+
WASI_SDK_TAR_PATH=$(find . -type f -name "wasi-sdk-*")
31+
WASI_SDK_FULL_NAME=$(basename "$WASI_SDK_TAR_PATH" -linux.tar.gz)
32+
tar xfz "$WASI_SDK_TAR_PATH"
33+
34+
rm -rf "$BUILD_SDK_PATH/wasi-sdk"
35+
mv "$WASI_SDK_FULL_NAME" "$BUILD_SDK_PATH/wasi-sdk"
36+
}
37+
38+
workdir=$(mktemp -d)
39+
pushd "$workdir"
40+
41+
mkdir -p "$BUILD_SDK_PATH"
42+
43+
install_libxml2
44+
install_icu
45+
install_wasi-sdk

utils/webassembly/install-wasi-sdk.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

utils/webassembly/linux/install-dependencies.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ fi
5252

5353
cmake --version
5454

55-
$SWIFT_PATH/utils/webassembly/install-wasi-sdk.sh linux ubuntu-18.04
56-
57-
# Link wasm32-wasi-unknown to wasm32-wasi because clang finds crt1.o from sysroot
58-
# with os and environment name `getMultiarchTriple`.
59-
ln -s wasm32-wasi wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi-unknown
60-
6155
# Install sccache
6256

6357
if [ -z $(which sccache) ]; then

0 commit comments

Comments
 (0)