Skip to content

Commit d5d7a1c

Browse files
authored
Merge pull request #1387 from swiftwasm/maxd/build-host
Build both host and target toolchains on CI Both `libPackageDescription.dylib` and `swiftc` used to compile package manifests should come from the same toolchain for SwiftPM to work on macOS. This is resolved here by re-reverting the previous change #1024 to build both host and target toolchain in one go on CI. I'm wary of the disk space/time limit constraints, but I think those should be resolved separately when they appear, otherwise SwiftPM is completely broken on macOS currently. Resolves #1365.
2 parents 8013451 + 98d9c47 commit d5d7a1c

File tree

4 files changed

+87
-176
lines changed

4 files changed

+87
-176
lines changed

utils/build-presets.ini

+51-35
Original file line numberDiff line numberDiff line change
@@ -2461,40 +2461,68 @@ no-assertions
24612461

24622462
[preset: webassembly]
24632463

2464-
wasm
24652464
release
2466-
verbose
24672465
cmake-c-launcher=%(C_CXX_LAUNCHER)s
24682466
cmake-cxx-launcher=%(C_CXX_LAUNCHER)s
24692467
skip-build-benchmarks
2468+
llvm-targets-to-build=X86;WebAssembly
2469+
install-destdir=%(INSTALL_DESTDIR)s
2470+
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
2471+
llvm-install-components=clang
2472+
install-swift
2473+
install-prefix=/%(TOOLCHAIN_NAME)s/usr
2474+
2475+
[preset: webassembly-host]
2476+
2477+
mixin-preset=webassembly
2478+
extra-cmake-options=
2479+
-DSWIFT_BUILD_SOURCEKIT=FALSE
2480+
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE
2481+
-DSWIFT_BUILD_SYNTAXPARSERLIB=FALSE
2482+
2483+
llbuild
2484+
swiftpm
2485+
2486+
install-llvm
2487+
install-swift
2488+
install-llbuild
2489+
install-swiftpm
2490+
2491+
[preset: webassembly-linux-host]
2492+
2493+
mixin-preset=webassembly-host
2494+
2495+
libdispatch
2496+
libicu
2497+
foundation
2498+
xctest
2499+
2500+
install-libicu
2501+
install-foundation
2502+
install-libdispatch
2503+
install-xctest
2504+
2505+
skip-test-libicu
2506+
skip-test-foundation
2507+
skip-test-libdispatch
2508+
skip-test-xctest
2509+
2510+
[preset: webassembly-target]
2511+
2512+
mixin-preset=webassembly
2513+
wasm
2514+
verbose
24702515
build-stdlib-deployment-targets=wasi-wasm32
24712516
build-swift-dynamic-sdk-overlay=false
24722517
build-swift-dynamic-stdlib=false
24732518
build-swift-static-sdk-overlay
24742519
build-swift-static-stdlib
2475-
llvm-targets-to-build=X86;WebAssembly
24762520
stdlib-deployment-targets=wasi-wasm32
24772521
wasi-sdk=%(SOURCE_PATH)s/wasi-sdk
24782522

2479-
[preset: webassembly-installable]
2480-
2481-
install-destdir=%(SOURCE_PATH)s/install
2482-
installable-package=%(INSTALLABLE_PACKAGE)s
2483-
install-prefix=/%(TOOLCHAIN_NAME)s/usr
2484-
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
2485-
llvm-install-components=clang
2486-
install-swift
2487-
install-llvm
2488-
darwin-toolchain-bundle-identifier=%(BUNDLE_IDENTIFIER)s
2489-
darwin-toolchain-display-name=%(DISPLAY_NAME)s
2490-
darwin-toolchain-display-name-short=%(DISPLAY_NAME_SHORT)s
2491-
darwin-toolchain-name=%(TOOLCHAIN_NAME)s
2492-
darwin-toolchain-version=%(TOOLCHAIN_VERSION)s
2493-
darwin-toolchain-alias=swift
2523+
[preset: webassembly-linux-target]
24942524

2495-
[preset: webassembly-linux]
2496-
2497-
mixin-preset=webassembly
2525+
mixin-preset=webassembly-target
24982526
extra-cmake-options=
24992527
-DWASI_ICU_URL:STRING="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
25002528
-DWASI_ICU_MD5:STRING="25943864ebbfff15cf5aee8d9d5cc4d7"
@@ -2507,9 +2535,9 @@ extra-cmake-options=
25072535
-DCMAKE_AR="%(SOURCE_PATH)s/wasi-sdk/bin/llvm-ar"
25082536
-DCMAKE_RANLIB="%(SOURCE_PATH)s/wasi-sdk/bin/llvm-ranlib"
25092537

2510-
[preset: webassembly-macos]
2538+
[preset: webassembly-macos-target]
25112539

2512-
mixin-preset=webassembly
2540+
mixin-preset=webassembly-target
25132541
extra-cmake-options=
25142542
-DWASI_ICU_URL:STRING="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
25152543
-DWASI_ICU_MD5:STRING="25943864ebbfff15cf5aee8d9d5cc4d7"
@@ -2521,15 +2549,3 @@ extra-cmake-options=
25212549
-DSWIFT_BUILD_SYNTAXPARSERLIB=FALSE
25222550
-DCMAKE_AR='/usr/local/opt/llvm/bin/llvm-ar'
25232551
-DCMAKE_RANLIB='/usr/local/opt/llvm/bin/llvm-ranlib'
2524-
2525-
[preset: webassembly-linux-installable]
2526-
2527-
mixin-preset=
2528-
webassembly-linux
2529-
webassembly-installable
2530-
2531-
[preset: webassembly-macos-installable]
2532-
2533-
mixin-preset=
2534-
webassembly-macos
2535-
webassembly-installable

utils/webassembly/build-swiftpm.sh

-60
This file was deleted.

utils/webassembly/build-toolchain.sh

+36-31
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-
PRESET_NAME=webassembly-macos-installable
12+
HOST_PRESET=webassembly-host
13+
TARGET_PRESET=webassembly-macos-target
1314
;;
1415
Linux)
1516
OS_SUFFIX=linux
16-
PRESET_NAME=webassembly-linux-installable
17+
HOST_PRESET=webassembly-linux-host
18+
TARGET_PRESET=webassembly-linux-target
1719
;;
1820
*)
1921
echo "Unrecognised platform $(uname -s)"
@@ -35,49 +37,52 @@ BUNDLE_IDENTIFIER="swiftwasm.${YEAR}${MONTH}${DAY}"
3537
DISPLAY_NAME_SHORT="Swift for WebAssembly Development Snapshot"
3638
DISPLAY_NAME="${DISPLAY_NAME_SHORT} ${YEAR}-${MONTH}-${DAY}"
3739

38-
# Make sure Clang headers install dir exists to avoid broken symlinks
39-
mkdir -p $SOURCE_PATH/install/$TOOLCHAIN_NAME/usr/lib/clang/10.0.0
40+
HOST_TOOLCHAIN_DESTDIR=$SOURCE_PATH/host-toolchain-sdk
41+
HOST_TOOLCHAIN_SDK=$HOST_TOOLCHAIN_DESTDIR/$TOOLCHAIN_NAME
4042

41-
$SOURCE_PATH/swift/utils/build-script --preset=$PRESET_NAME \
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" \
4262
SOURCE_PATH="$SOURCE_PATH" \
43-
INSTALLABLE_PACKAGE="$INSTALLABLE_PACKAGE" \
4463
BUNDLE_IDENTIFIER="${BUNDLE_IDENTIFIER}" \
4564
DISPLAY_NAME="${DISPLAY_NAME}" \
4665
DISPLAY_NAME_SHORT="${DISPLAY_NAME_SHORT}" \
4766
TOOLCHAIN_NAME="${TOOLCHAIN_NAME}" \
4867
TOOLCHAIN_VERSION="${TOOLCHAIN_VERSION}" \
4968
C_CXX_LAUNCHER="$(which sccache)"
5069

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

7075
# Replace absolute sysroot path with relative path
71-
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
7277

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

7580
# Avoid copying usr/lib/swift/clang because our toolchain's one is a directory
76-
# but nightly's one is symbolic link, simple copy fails to merge them.
77-
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'
7883

79-
$UTILS_PATH/build-foundation.sh $TMP_DIR/$TOOLCHAIN_NAME
80-
$UTILS_PATH/build-xctest.sh $TMP_DIR/$TOOLCHAIN_NAME
84+
$UTILS_PATH/build-foundation.sh $HOST_TOOLCHAIN_SDK
85+
$UTILS_PATH/build-xctest.sh $HOST_TOOLCHAIN_SDK
8186

82-
cd $TMP_DIR
87+
cd $HOST_TOOLCHAIN_DESTDIR
8388
tar cfz $PACKAGE_ARTIFACT $TOOLCHAIN_NAME

utils/webassembly/install-nightly-toolchain.sh

-50
This file was deleted.

0 commit comments

Comments
 (0)