@@ -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
- BUILD_SCRIPT=$UTILS_PATH /build-mac.sh
12
+ HOST_PRESET=webassembly-host
13
+ TARGET_PRESET=webassembly-macos-target
13
14
;;
14
15
Linux)
15
16
OS_SUFFIX=linux
16
- BUILD_SCRIPT=$UTILS_PATH /build-linux.sh
17
+ HOST_PRESET=webassembly-linux-host
18
+ TARGET_PRESET=webassembly-linux-target
17
19
;;
18
20
* )
19
21
echo " Unrecognised platform $( uname -s) "
@@ -35,51 +37,52 @@ BUNDLE_IDENTIFIER="swiftwasm.5.3-${YEAR}${MONTH}${DAY}"
35
37
DISPLAY_NAME_SHORT=" Swift for WebAssembly 5.3 Snapshot"
36
38
DISPLAY_NAME=" ${DISPLAY_NAME_SHORT} ${YEAR} -${MONTH} -${DAY} "
37
39
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
74
74
75
75
# 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
77
77
78
- # Copy nightly-toolchain's host environment stdlib into toolchain
78
+ # Copy the target environment stdlib into the toolchain
79
79
80
80
# 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'
83
83
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
85
88
tar cfz $PACKAGE_ARTIFACT $TOOLCHAIN_NAME
0 commit comments