Skip to content

Commit 97e31ef

Browse files
committed
Build both host and target toolchains
Resolves #1365. # Conflicts: # utils/build-presets.ini # utils/webassembly/build-toolchain.sh # utils/webassembly/install-nightly-toolchain.sh
1 parent 6166408 commit 97e31ef

10 files changed

+181
-225
lines changed

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/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-swiftpm.sh

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

utils/webassembly/build-toolchain.sh

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ WASI_SDK_PATH=$SOURCE_PATH/wasi-sdk
99
case $(uname -s) in
1010
Darwin)
1111
OS_SUFFIX=osx
12-
BUILD_SCRIPT=$UTILS_PATH/build-mac.sh
12+
HOST_PRESET=webassembly-host
13+
TARGET_PRESET=webassembly-macos-target
1314
;;
1415
Linux)
1516
OS_SUFFIX=linux
16-
BUILD_SCRIPT=$UTILS_PATH/build-linux.sh
17+
HOST_PRESET=webassembly-linux-host
18+
TARGET_PRESET=webassembly-linux-target
1719
;;
1820
*)
1921
echo "Unrecognised platform $(uname -s)"
@@ -35,51 +37,52 @@ BUNDLE_IDENTIFIER="swiftwasm.5.3-${YEAR}${MONTH}${DAY}"
3537
DISPLAY_NAME_SHORT="Swift for WebAssembly 5.3 Snapshot"
3638
DISPLAY_NAME="${DISPLAY_NAME_SHORT} ${YEAR}-${MONTH}-${DAY}"
3739

38-
# Just a hack, spent enough time investigating this,
39-
# but somehow `master` is able to work without this `mkdir`.
40-
mkdir -p $SOURCE_PATH/install/$TOOLCHAIN_NAME/usr/lib/clang/10.0.0
41-
$BUILD_SCRIPT \
42-
--install_destdir="$SOURCE_PATH/install" \
43-
--installable_package="$INSTALLABLE_PACKAGE" \
44-
--install-prefix=/$TOOLCHAIN_NAME/usr \
45-
--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" \
46-
--llvm-install-components "clang" \
47-
--install-swift \
48-
--darwin-toolchain-bundle-identifier="${BUNDLE_IDENTIFIER}" \
49-
--darwin-toolchain-display-name="${DISPLAY_NAME}" \
50-
--darwin-toolchain-display-name-short="${DISPLAY_NAME_SHORT}" \
51-
--darwin-toolchain-name="${TOOLCHAIN_NAME}" \
52-
--darwin-toolchain-version="${TOOLCHAIN_VERSION}" \
53-
--darwin-toolchain-alias="swift" \
54-
"$@"
55-
56-
57-
NIGHTLY_TOOLCHAIN=$SOURCE_PATH/swift-nightly-toolchain
58-
if [ ! -e $NIGHTLY_TOOLCHAIN ]; then
59-
$UTILS_PATH/install-nightly-toolchain.sh
60-
fi
61-
62-
TMP_DIR=$(mktemp -d)
63-
cd $TMP_DIR
64-
tar xfz $INSTALLABLE_PACKAGE $TOOLCHAIN_NAME
65-
cd $TMP_DIR/$TOOLCHAIN_NAME
66-
67-
# Merge wasi-sdk and toolchain
68-
cp -r $WASI_SDK_PATH/lib/clang usr/lib
69-
cp -a $WASI_SDK_PATH/bin/{*ld,llvm-ar} usr/bin
70-
cp -r $WASI_SDK_PATH/share/wasi-sysroot usr/share
71-
72-
# Build SwiftPM and install it into toolchain
73-
$UTILS_PATH/build-swiftpm.sh $TMP_DIR/$TOOLCHAIN_NAME
40+
HOST_TOOLCHAIN_DESTDIR=$SOURCE_PATH/host-toolchain-sdk
41+
HOST_TOOLCHAIN_SDK=$HOST_TOOLCHAIN_DESTDIR/$TOOLCHAIN_NAME
42+
43+
# Avoid clang headers symlink issues
44+
mkdir -p $HOST_TOOLCHAIN_SDK/usr/lib/clang/10.0.0
45+
46+
# Build the host toolchain and SDK first.
47+
$SOURCE_PATH/swift/utils/build-script \
48+
--preset=$HOST_PRESET \
49+
INSTALL_DESTDIR="$HOST_TOOLCHAIN_DESTDIR" \
50+
TOOLCHAIN_NAME="$TOOLCHAIN_NAME" \
51+
C_CXX_LAUNCHER="$(which sccache)"
52+
53+
# Clean up the host toolchain build directory so that the next
54+
# `build-script` invocation doesn't pick up wrong CMake config files.
55+
# For some reason passing `--reconfigure` to `build-script` won't do this.
56+
rm -rf $SOURCE_PATH/build/Ninja-ReleaseAssert/swift-*
57+
58+
# build the cross-compilled toolchain
59+
$SOURCE_PATH/swift/utils/build-script \
60+
--preset=$TARGET_PRESET \
61+
INSTALL_DESTDIR="$SOURCE_PATH/install" \
62+
SOURCE_PATH="$SOURCE_PATH" \
63+
BUNDLE_IDENTIFIER="${BUNDLE_IDENTIFIER}" \
64+
DISPLAY_NAME="${DISPLAY_NAME}" \
65+
DISPLAY_NAME_SHORT="${DISPLAY_NAME_SHORT}" \
66+
TOOLCHAIN_NAME="${TOOLCHAIN_NAME}" \
67+
TOOLCHAIN_VERSION="${TOOLCHAIN_VERSION}" \
68+
C_CXX_LAUNCHER="$(which sccache)"
69+
70+
# Merge wasi-sdk and the toolchain
71+
cp -a $WASI_SDK_PATH/lib/clang $HOST_TOOLCHAIN_SDK/usr/lib
72+
cp -a $WASI_SDK_PATH/bin/{*ld,llvm-ar} $HOST_TOOLCHAIN_SDK/usr/bin
73+
cp -r $WASI_SDK_PATH/share/wasi-sysroot $HOST_TOOLCHAIN_SDK/usr/share
7474

7575
# Replace absolute sysroot path with relative path
76-
sed -i -e "s@\".*/include@\"../../../../share/wasi-sysroot/include@g" $TMP_DIR/$TOOLCHAIN_NAME/usr/lib/swift/wasi/wasm32/glibc.modulemap
76+
sed -i -e "s@\".*/include@\"../../../../share/wasi-sysroot/include@g" $SOURCE_PATH/install/$TOOLCHAIN_NAME/usr/lib/swift/wasi/wasm32/glibc.modulemap
7777

78-
# Copy nightly-toolchain's host environment stdlib into toolchain
78+
# Copy the target environment stdlib into the toolchain
7979

8080
# Avoid copying usr/lib/swift/clang because our toolchain's one is a directory
81-
# but nightly's one is symbolic link, simple copy fails to merge them.
82-
rsync -a $NIGHTLY_TOOLCHAIN/usr/lib/ $TMP_DIR/$TOOLCHAIN_NAME/usr/lib/ --exclude 'swift/clang'
81+
# but nightly's one is symbolic link. A simple copy fails to merge them.
82+
rsync -v -a $SOURCE_PATH/install/$TOOLCHAIN_NAME/usr/lib/ $HOST_TOOLCHAIN_SDK/usr/lib/ --exclude 'swift/clang'
8383

84-
cd $TMP_DIR
84+
$UTILS_PATH/build-foundation.sh $HOST_TOOLCHAIN_SDK
85+
$UTILS_PATH/build-xctest.sh $HOST_TOOLCHAIN_SDK
86+
87+
cd $HOST_TOOLCHAIN_DESTDIR
8588
tar cfz $PACKAGE_ARTIFACT $TOOLCHAIN_NAME

utils/webassembly/install-nightly-toolchain.sh

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

utils/webassembly/install-wasi-sdk.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#/bin/bash
2+
3+
set -ex
4+
5+
SOURCE_PATH="$( cd "$(dirname $0)/../../../" && pwd )"
6+
7+
cd $SOURCE_PATH
8+
9+
WASI_SDK_URL="https://github.com/swiftwasm/wasi-sdk/releases/download/0.2.0-swiftwasm/dist-$2-latest.tgz.zip"
10+
11+
[ ! -e dist-wasi-sdk.tgz.zip ] && \
12+
wget -O dist-wasi-sdk.tgz.zip $WASI_SDK_URL
13+
unzip -u dist-wasi-sdk.tgz.zip -d .
14+
WASI_SDK_TAR_PATH=$(find . -type f -name "wasi-sdk-*")
15+
WASI_SDK_FULL_NAME=$(basename $WASI_SDK_TAR_PATH -$1.tar.gz)
16+
tar xfz $WASI_SDK_TAR_PATH
17+
rm -rf ./wasi-sdk
18+
mv $WASI_SDK_FULL_NAME ./wasi-sdk

0 commit comments

Comments
 (0)