@@ -9,11 +9,13 @@ WASI_SDK_PATH=$SOURCE_PATH/wasi-sdk
9
9
case $( uname -s) in
10
10
Darwin)
11
11
OS_SUFFIX=osx
12
- PRESET_NAME=webassembly-macos-installable
12
+ HOST_PRESET=webassembly-host
13
+ TARGET_PRESET=webassembly-macos-target
13
14
;;
14
15
Linux)
15
16
OS_SUFFIX=linux
16
- PRESET_NAME=webassembly-linux-installable
17
+ HOST_PRESET=webassembly-linux-host
18
+ TARGET_PRESET=webassembly-linux-target
17
19
;;
18
20
* )
19
21
echo " Unrecognised platform $( uname -s) "
@@ -35,49 +37,52 @@ BUNDLE_IDENTIFIER="swiftwasm.${YEAR}${MONTH}${DAY}"
35
37
DISPLAY_NAME_SHORT=" Swift for WebAssembly Development Snapshot"
36
38
DISPLAY_NAME=" ${DISPLAY_NAME_SHORT} ${YEAR} -${MONTH} -${DAY} "
37
39
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
40
42
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" \
42
62
SOURCE_PATH=" $SOURCE_PATH " \
43
- INSTALLABLE_PACKAGE=" $INSTALLABLE_PACKAGE " \
44
63
BUNDLE_IDENTIFIER=" ${BUNDLE_IDENTIFIER} " \
45
64
DISPLAY_NAME=" ${DISPLAY_NAME} " \
46
65
DISPLAY_NAME_SHORT=" ${DISPLAY_NAME_SHORT} " \
47
66
TOOLCHAIN_NAME=" ${TOOLCHAIN_NAME} " \
48
67
TOOLCHAIN_VERSION=" ${TOOLCHAIN_VERSION} " \
49
68
C_CXX_LAUNCHER=" $( which sccache) "
50
69
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
69
74
70
75
# 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
72
77
73
- # Copy nightly-toolchain's host environment stdlib into toolchain
78
+ # Copy the target environment stdlib into the toolchain
74
79
75
80
# 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'
78
83
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
81
86
82
- cd $TMP_DIR
87
+ cd $HOST_TOOLCHAIN_DESTDIR
83
88
tar cfz $PACKAGE_ARTIFACT $TOOLCHAIN_NAME
0 commit comments