Skip to content

Commit 1afa4c6

Browse files
committed
Build host toolchain w/o copying it from snapshots
1 parent 7ed2e2e commit 1afa4c6

File tree

3 files changed

+57
-121
lines changed

3 files changed

+57
-121
lines changed

utils/build-presets.ini

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,39 +2437,44 @@ no-assertions
24372437

24382438
[preset: webassembly]
24392439

2440-
wasm
24412440
release
2442-
verbose
24432441
cmake-c-launcher=%(C_CXX_LAUNCHER)s
24442442
cmake-cxx-launcher=%(C_CXX_LAUNCHER)s
24452443
skip-build-benchmarks
2444+
llvm-targets-to-build=X86;WebAssembly
2445+
install-destdir=%(INSTALL_DESTDIR)s
2446+
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
2447+
llvm-install-components=clang
2448+
install-swift
2449+
install-prefix=/%(TOOLCHAIN_NAME)s/usr
2450+
2451+
[preset: webassembly-host]
2452+
2453+
mixin-preset=webassembly
2454+
llbuild
2455+
swiftpm
2456+
install-swiftpm
2457+
extra-cmake-options=
2458+
-DSWIFT_BUILD_SOURCEKIT=FALSE
2459+
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE
2460+
-DSWIFT_BUILD_SYNTAXPARSERLIB=FALSE
2461+
2462+
[preset: webassembly-target]
2463+
2464+
mixin-preset=webassembly
2465+
wasm
2466+
verbose
24462467
build-stdlib-deployment-targets=wasi-wasm32
24472468
build-swift-dynamic-sdk-overlay=false
24482469
build-swift-dynamic-stdlib=false
24492470
build-swift-static-sdk-overlay
24502471
build-swift-static-stdlib
2451-
llvm-targets-to-build=X86;WebAssembly
24522472
stdlib-deployment-targets=wasi-wasm32
24532473
wasi-sdk=%(SOURCE_PATH)s/wasi-sdk
24542474

2455-
[preset: webassembly-installable]
2456-
2457-
install_destdir=%(SOURCE_PATH)s/install
2458-
installable_package=%(INSTALLABLE_PACKAGE)s
2459-
install-prefix=/%(TOOLCHAIN_NAME)s/usr
2460-
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
2461-
llvm-install-components=clang
2462-
install-swift
2463-
darwin-toolchain-bundle-identifier=%(BUNDLE_IDENTIFIER)s
2464-
darwin-toolchain-display-name=%(DISPLAY_NAME)s
2465-
darwin-toolchain-display-name-short=%(DISPLAY_NAME_SHORT)s
2466-
darwin-toolchain-name=%(TOOLCHAIN_NAME)s
2467-
darwin-toolchain-version=%(TOOLCHAIN_VERSION)s
2468-
darwin-toolchain-alias=swift
2469-
24702475
[preset: webassembly-linux]
24712476

2472-
mixin-preset=webassembly
2477+
mixin-preset=webassembly-target
24732478
extra-cmake-options=
24742479
-DWASI_ICU_URL:STRING="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
24752480
-DWASI_ICU_MD5:STRING="25943864ebbfff15cf5aee8d9d5cc4d7"
@@ -2484,7 +2489,7 @@ extra-cmake-options=
24842489

24852490
[preset: webassembly-macos]
24862491

2487-
mixin-preset=webassembly
2492+
mixin-preset=webassembly-target
24882493
extra-cmake-options=
24892494
-DWASI_ICU_URL:STRING="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
24902495
-DWASI_ICU_MD5:STRING="25943864ebbfff15cf5aee8d9d5cc4d7"
@@ -2496,15 +2501,3 @@ extra-cmake-options=
24962501
-DSWIFT_BUILD_SYNTAXPARSERLIB=FALSE
24972502
-DCMAKE_AR='/usr/local/opt/llvm/bin/llvm-ar'
24982503
-DCMAKE_RANLIB='/usr/local/opt/llvm/bin/llvm-ranlib'
2499-
2500-
[preset: webassembly-linux-installable]
2501-
2502-
mixin-preset=
2503-
webassembly-linux
2504-
webassembly-installable
2505-
2506-
[preset: webassembly-macos-installable]
2507-
2508-
mixin-preset=
2509-
webassembly-macos
2510-
webassembly-installable

utils/webassembly/build-swiftpm.sh

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

utils/webassembly/build-toolchain.sh

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ WASI_SDK_PATH=$SOURCE_PATH/wasi-sdk
99
case $(uname -s) in
1010
Darwin)
1111
OS_SUFFIX=osx
12-
PRESET_NAME=webassembly-macos-installable
12+
PRESET_NAME=webassembly-macos
1313
;;
1414
Linux)
1515
OS_SUFFIX=linux
16-
PRESET_NAME=webassembly-linux-installable
16+
PRESET_NAME=webassembly-linux
1717
;;
1818
*)
1919
echo "Unrecognised platform $(uname -s)"
@@ -35,47 +35,50 @@ BUNDLE_IDENTIFIER="swiftwasm.${YEAR}${MONTH}${DAY}"
3535
DISPLAY_NAME_SHORT="Swift for WebAssembly Development Snapshot"
3636
DISPLAY_NAME="${DISPLAY_NAME_SHORT} ${YEAR}-${MONTH}-${DAY}"
3737

38-
$SOURCE_PATH/swift/utils/build-script --preset=$PRESET_NAME \
38+
HOST_TOOLCHAIN_DESTDIR=$SOURCE_PATH/host-toolchain-sdk
39+
HOST_TOOLCHAIN_SDK=$HOST_TOOLCHAIN_DESTDIR/$TOOLCHAIN_NAME
40+
41+
# Build the host toolchain and SDK first.
42+
$SOURCE_PATH/swift/utils/build-script --preset=webassembly-host \
43+
INSTALL_DESTDIR="$HOST_TOOLCHAIN_DESTDIR" \
44+
TOOLCHAIN_NAME="$TOOLCHAIN_NAME" \
45+
C_CXX_LAUNCHER="$(which sccache)"
46+
47+
# Clean up the host toolchain build directory so that the next
48+
# `build-script` invocation doesn't pick up wrong CMake config files.
49+
# For some reason passing `--reconfigure` to `build-script` won't do this.
50+
rm -rf $SOURCE_PATH/build/Ninja-ReleaseAssert/swift-macosx-x86_64
51+
52+
# build the cross-compilled toolchain
53+
$SOURCE_PATH/swift/utils/build-script \
54+
--preset=$PRESET_NAME \
55+
INSTALL_DESTDIR="$SOURCE_PATH/install" \
3956
SOURCE_PATH="$SOURCE_PATH" \
40-
INSTALLABLE_PACKAGE="$INSTALLABLE_PACKAGE" \
4157
BUNDLE_IDENTIFIER="${BUNDLE_IDENTIFIER}" \
4258
DISPLAY_NAME="${DISPLAY_NAME}" \
4359
DISPLAY_NAME_SHORT="${DISPLAY_NAME_SHORT}" \
4460
TOOLCHAIN_NAME="${TOOLCHAIN_NAME}" \
4561
TOOLCHAIN_VERSION="${TOOLCHAIN_VERSION}" \
4662
C_CXX_LAUNCHER="$(which sccache)"
4763

48-
49-
NIGHTLY_TOOLCHAIN=$SOURCE_PATH/swift-nightly-toolchain
50-
if [ ! -e $NIGHTLY_TOOLCHAIN ]; then
51-
$UTILS_PATH/install-nightly-toolchain.sh
52-
fi
53-
54-
TMP_DIR=$(mktemp -d)
55-
cd $TMP_DIR
56-
tar xfz $INSTALLABLE_PACKAGE $TOOLCHAIN_NAME
57-
cd $TMP_DIR/$TOOLCHAIN_NAME
58-
59-
# Merge wasi-sdk and toolchain
60-
cp -r $WASI_SDK_PATH/lib/clang usr/lib
61-
cp -a $WASI_SDK_PATH/bin/{*ld,llvm-ar} usr/bin
62-
cp -r $WASI_SDK_PATH/share/wasi-sysroot usr/share
63-
64-
# Build SwiftPM and install it into toolchain
65-
$UTILS_PATH/build-swiftpm.sh $TMP_DIR/$TOOLCHAIN_NAME
64+
# Merge wasi-sdk and the toolchain
65+
cp -a $WASI_SDK_PATH/lib/clang $HOST_TOOLCHAIN_SDK/usr/lib
66+
cp -a $WASI_SDK_PATH/bin/{clang*,*ld,llvm-ar} $HOST_TOOLCHAIN_SDK/usr/bin
67+
cp -r $WASI_SDK_PATH/share/wasi-sysroot $HOST_TOOLCHAIN_SDK/usr/share
6668

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

70-
# Copy nightly-toolchain's host environment stdlib into toolchain
72+
# Copy host environment stdlib into toolchain
7173

7274
if [[ "$(uname)" == "Linux" ]]; then
73-
# Avoid to copy usr/lib/swift/clang because our toolchain's one is a directory
74-
# but nightly's one is symbolic link, so fail to merge them.
75-
rsync -a $NIGHTLY_TOOLCHAIN/usr/lib/ $TMP_DIR/$TOOLCHAIN_NAME/usr/lib/ --exclude 'swift/clang'
75+
# Avoid copying usr/lib/swift/clang because our toolchain's one is a directory
76+
# but nightly's one is symbolic link. A simple copy fails to merge them.
77+
rsync -a $SOURCE_PATH/install/$TOOLCHAIN_NAME/usr/lib $HOST_TOOLCHAIN_SDK/usr/lib/ --exclude 'swift/clang'
7678
else
77-
cp -r $NIGHTLY_TOOLCHAIN/usr/lib/swift/macosx $TMP_DIR/$TOOLCHAIN_NAME/usr/lib/swift
79+
cp -a $SOURCE_PATH/install/$TOOLCHAIN_NAME/usr/lib/swift_static $HOST_TOOLCHAIN_SDK/usr/lib/swift_static
80+
cp -a $SOURCE_PATH/install/$TOOLCHAIN_NAME/usr/lib/swift/wasi $HOST_TOOLCHAIN_SDK/usr/lib/swift
7881
fi
7982

80-
cd $TMP_DIR
83+
cd $HOST_TOOLCHAIN_DESTDIR
8184
tar cfz $PACKAGE_ARTIFACT $TOOLCHAIN_NAME

0 commit comments

Comments
 (0)