Skip to content

Commit b8d6c85

Browse files
authored
Merge pull request #1398 from swiftwasm/maxd/5.3-build-host
Build both host and target toolchains in 5.3 branch
2 parents 6166408 + c6274c5 commit b8d6c85

18 files changed

+304
-269
lines changed

CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,36 @@ function(swift_icu_variables_set sdk arch result)
897897
endif()
898898
endfunction()
899899

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

stdlib/public/stubs/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,3 +2414,98 @@ no-assertions
24142414
mixin-preset=source_compat_suite_linux_base
24152415
debug
24162416
no-assertions
2417+
2418+
#===----------------------------------------------------------------------===#
2419+
# Preset for the WebAssembly toolchain and SDK
2420+
#===----------------------------------------------------------------------===#
2421+
2422+
[preset: webassembly]
2423+
2424+
release
2425+
cmake-c-launcher=%(C_CXX_LAUNCHER)s
2426+
cmake-cxx-launcher=%(C_CXX_LAUNCHER)s
2427+
skip-build-benchmarks
2428+
llvm-targets-to-build=X86;WebAssembly
2429+
install-destdir=%(INSTALL_DESTDIR)s
2430+
swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;sdk-overlay;parser-lib;editor-integration;tools;testsuite-tools;toolchain-tools;license;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers;clang-resource-dir-symlink
2431+
llvm-install-components=clang
2432+
install-swift
2433+
install-prefix=/%(TOOLCHAIN_NAME)s/usr
2434+
2435+
[preset: webassembly-host]
2436+
2437+
mixin-preset=webassembly
2438+
extra-cmake-options=
2439+
-DSWIFT_BUILD_SOURCEKIT=FALSE
2440+
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE
2441+
-DSWIFT_BUILD_SYNTAXPARSERLIB=FALSE
2442+
2443+
llbuild
2444+
swiftpm
2445+
2446+
install-llvm
2447+
install-swift
2448+
install-llbuild
2449+
install-swiftpm
2450+
2451+
[preset: webassembly-linux-host]
2452+
2453+
mixin-preset=webassembly-host
2454+
2455+
libdispatch
2456+
libicu
2457+
foundation
2458+
xctest
2459+
2460+
install-libicu
2461+
install-foundation
2462+
install-libdispatch
2463+
install-xctest
2464+
2465+
skip-test-libicu
2466+
skip-test-foundation
2467+
skip-test-libdispatch
2468+
skip-test-xctest
2469+
2470+
[preset: webassembly-target]
2471+
2472+
mixin-preset=webassembly
2473+
wasm
2474+
verbose
2475+
build-stdlib-deployment-targets=wasi-wasm32
2476+
build-swift-dynamic-sdk-overlay=false
2477+
build-swift-dynamic-stdlib=false
2478+
build-swift-static-sdk-overlay
2479+
build-swift-static-stdlib
2480+
stdlib-deployment-targets=wasi-wasm32
2481+
wasi-sdk=%(SOURCE_PATH)s/wasi-sdk
2482+
2483+
[preset: webassembly-linux-target]
2484+
2485+
mixin-preset=webassembly-target
2486+
extra-cmake-options=
2487+
-DWASI_ICU_URL:STRING="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
2488+
-DWASI_ICU_MD5:STRING="25943864ebbfff15cf5aee8d9d5cc4d7"
2489+
-DSWIFT_PRIMARY_VARIANT_SDK:STRING=WASI
2490+
-DSWIFT_PRIMARY_VARIANT_ARCH:STRING=wasm32
2491+
-DSWIFT_SDKS='WASI;LINUX'
2492+
-DSWIFT_BUILD_SOURCEKIT=FALSE
2493+
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE
2494+
-DSWIFT_BUILD_SYNTAXPARSERLIB=FALSE
2495+
-DCMAKE_AR="%(SOURCE_PATH)s/wasi-sdk/bin/llvm-ar"
2496+
-DCMAKE_RANLIB="%(SOURCE_PATH)s/wasi-sdk/bin/llvm-ranlib"
2497+
2498+
[preset: webassembly-macos-target]
2499+
2500+
mixin-preset=webassembly-target
2501+
extra-cmake-options=
2502+
-DWASI_ICU_URL:STRING="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
2503+
-DWASI_ICU_MD5:STRING="25943864ebbfff15cf5aee8d9d5cc4d7"
2504+
-DSWIFT_PRIMARY_VARIANT_SDK:STRING=WASI
2505+
-DSWIFT_PRIMARY_VARIANT_ARCH:STRING=wasm32
2506+
-DSWIFT_OSX_x86_64_ICU_STATICLIB=TRUE
2507+
-DSWIFT_BUILD_SOURCEKIT=FALSE
2508+
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE
2509+
-DSWIFT_BUILD_SYNTAXPARSERLIB=FALSE
2510+
-DCMAKE_AR='/usr/local/opt/llvm/bin/llvm-ar'
2511+
-DCMAKE_RANLIB='/usr/local/opt/llvm/bin/llvm-ranlib'

utils/build-script

Lines changed: 3 additions & 17 deletions
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:
224-
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")
218+
if args.wasi_sdk is None:
219+
fatal_error(
220+
"when building for WebAssembly, --wasi-sdk must be specified")
230221

231222
targets_needing_toolchain = [
232223
'build_indexstoredb',
@@ -708,11 +699,6 @@ class BuildScriptInvocation(object):
708699
if args.wasm:
709700
impl_args += [
710701
"--wasi-sdk", args.wasi_sdk,
711-
"--wasi-icu-uc", args.wasi_icu_uc,
712-
"--wasi-icu-uc-include", args.wasi_icu_uc_include,
713-
"--wasi-icu-i18n", args.wasi_icu_i18n,
714-
"--wasi-icu-i18n-include", args.wasi_icu_i18n_include,
715-
"--wasi-icu-data", args.wasi_icu_data,
716702
]
717703

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

utils/build-script-impl

Lines changed: 0 additions & 10 deletions
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"
@@ -1694,11 +1689,6 @@ for host in "${ALL_HOSTS[@]}"; do
16941689
cmake_options=(
16951690
"${cmake_options[@]}"
16961691
-DSWIFT_WASI_SDK_PATH:STRING="${WASI_SDK}"
1697-
-DSWIFT_WASI_wasm32_ICU_UC:STRING="${WASI_ICU_UC}"
1698-
-DSWIFT_WASI_wasm32_ICU_UC_INCLUDE:STRING="${WASI_ICU_UC_INCLUDE}"
1699-
-DSWIFT_WASI_wasm32_ICU_I18N:STRING="${WASI_ICU_I18N}"
1700-
-DSWIFT_WASI_wasm32_ICU_I18N_INCLUDE:STRING="${WASI_ICU_I18N_INCLUDE}"
1701-
-DSWIFT_WASI_wasm32_ICU_DATA:STRING="${WASI_ICU_DATA}"
17021692
)
17031693
fi
17041694

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,17 +1095,6 @@ def create_argument_parser():
10951095
help='An absolute path to WASI SDK that will be used as a libc '
10961096
'implementation for Wasm builds')
10971097

1098-
option('--wasi-icu-uc', store_path,
1099-
help='Path to libicuuc.so')
1100-
option('--wasi-icu-uc-include', store_path,
1101-
help='Path to a directory containing headers for libicuuc')
1102-
option('--wasi-icu-i18n', store_path,
1103-
help='Path to libicui18n.so')
1104-
option('--wasi-icu-i18n-include', store_path,
1105-
help='Path to a directory containing headers libicui18n')
1106-
option('--wasi-icu-data', store_path,
1107-
help='Path to libicudata.so')
1108-
11091098
# -------------------------------------------------------------------------
11101099
in_group('Experimental language features')
11111100

utils/update_checkout/update-checkout-config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"swift": "swiftwasm",
6060
"cmark": "master",
6161
"llbuild": "master",
62+
"swift-tools-support-core": "master",
6263
"swiftpm": "swiftwasm",
6364
"swift-syntax": "master",
6465
"swift-stress-tester": "master",
@@ -82,6 +83,7 @@
8283
"swift": "swiftwasm-release/5.3",
8384
"cmark": "release/5.3",
8485
"llbuild": "release/5.3",
86+
"swift-tools-support-core": "release/5.3",
8587
"swiftpm": "swiftwasm-release/5.3",
8688
"swift-syntax": "release/5.3",
8789
"swift-stress-tester": "release/5.3",

utils/webassembly/build-foundation.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
set -ex
3+
DESTINATION_TOOLCHAIN=$1
4+
SOURCE_PATH="$(cd "$(dirname $0)/../../.." && pwd)"
5+
6+
# Remove host CoreFoundation (which can be different from the target) headers
7+
# to avoid shadowing the wasm32 target CoreFoundation
8+
rm -rf $DESTINATION_TOOLCHAIN/usr/lib/swift/CoreFoundation
9+
10+
FOUNDATION_BUILD="$SOURCE_PATH/build/Ninja-ReleaseAssert/foundation-wasi-wasm32"
11+
12+
mkdir -p $FOUNDATION_BUILD
13+
cd $FOUNDATION_BUILD
14+
15+
cmake -G Ninja \
16+
-DCMAKE_Swift_COMPILER="$DESTINATION_TOOLCHAIN/usr/bin/swiftc" \
17+
-DCMAKE_STAGING_PREFIX="$DESTINATION_TOOLCHAIN/usr" \
18+
-DCMAKE_TOOLCHAIN_FILE="$SOURCE_PATH/swift/utils/webassembly/toolchain-wasi.cmake" \
19+
-DWASI_SDK_PATH="$SOURCE_PATH/wasi-sdk" \
20+
-DICU_ROOT="$SOURCE_PATH/icu_out" \
21+
-DBUILD_SHARED_LIBS=OFF \
22+
"${SOURCE_PATH}/swift-corelibs-foundation"
23+
24+
ninja -v
25+
ninja -v install
26+
27+
# On macOS the target CoreFoundation shadows the CoreFoundation suppplied by Xcode.
28+
# On Linux though there's no system CoreFoundation, its headers have to be shipped
29+
# in the installable archive and serve for both host and target.
30+
if [[ "$(uname)" == "Darwin" ]]; then
31+
mv $DESTINATION_TOOLCHAIN/usr/lib/swift/CoreFoundation \
32+
$DESTINATION_TOOLCHAIN/usr/lib/swift/wasi/wasm32/CoreFoundation
33+
fi

utils/webassembly/build-swiftpm.sh

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

0 commit comments

Comments
 (0)