Skip to content

Commit 9877f28

Browse files
committed
Revert "Merge pull request #1024 from swiftwasm/maxd/build-host-toolchain"
This reverts commit 88fd32c, reversing changes made to 04c8aba.
1 parent 627df41 commit 9877f28

File tree

4 files changed

+173
-88
lines changed

4 files changed

+173
-88
lines changed

utils/build-presets.ini

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,67 +2437,39 @@ no-assertions
24372437

24382438
[preset: webassembly]
24392439

2440+
wasm
24402441
release
2442+
verbose
24412443
cmake-c-launcher=%(C_CXX_LAUNCHER)s
24422444
cmake-cxx-launcher=%(C_CXX_LAUNCHER)s
24432445
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-
extra-cmake-options=
2455-
-DSWIFT_BUILD_SOURCEKIT=FALSE
2456-
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE
2457-
-DSWIFT_BUILD_SYNTAXPARSERLIB=FALSE
2458-
2459-
llbuild
2460-
swiftpm
2461-
2462-
install-swift
2463-
install-llbuild
2464-
install-swiftpm
2465-
2466-
[preset: webassembly-linux-host]
2467-
2468-
mixin-preset=webassembly-host
2469-
2470-
libdispatch
2471-
libicu
2472-
foundation
2473-
xctest
2474-
2475-
install-libicu
2476-
install-foundation
2477-
install-libdispatch
2478-
install-xctest
2479-
2480-
skip-test-libicu
2481-
skip-test-foundation
2482-
skip-test-libdispatch
2483-
skip-test-xctest
2484-
2485-
[preset: webassembly-target]
2486-
2487-
mixin-preset=webassembly
2488-
wasm
2489-
verbose
24902446
build-stdlib-deployment-targets=wasi-wasm32
24912447
build-swift-dynamic-sdk-overlay=false
24922448
build-swift-dynamic-stdlib=false
24932449
build-swift-static-sdk-overlay
24942450
build-swift-static-stdlib
2451+
llvm-targets-to-build=X86;WebAssembly
24952452
stdlib-deployment-targets=wasi-wasm32
24962453
wasi-sdk=%(SOURCE_PATH)s/wasi-sdk
24972454

2498-
[preset: webassembly-linux-target]
2455+
[preset: webassembly-installable]
24992456

2500-
mixin-preset=webassembly-target
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+
2470+
[preset: webassembly-linux]
2471+
2472+
mixin-preset=webassembly
25012473
extra-cmake-options=
25022474
-DWASI_ICU_URL:STRING="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
25032475
-DWASI_ICU_MD5:STRING="25943864ebbfff15cf5aee8d9d5cc4d7"
@@ -2510,9 +2482,9 @@ extra-cmake-options=
25102482
-DCMAKE_AR="%(SOURCE_PATH)s/wasi-sdk/bin/llvm-ar"
25112483
-DCMAKE_RANLIB="%(SOURCE_PATH)s/wasi-sdk/bin/llvm-ranlib"
25122484

2513-
[preset: webassembly-macos-target]
2485+
[preset: webassembly-macos]
25142486

2515-
mixin-preset=webassembly-target
2487+
mixin-preset=webassembly
25162488
extra-cmake-options=
25172489
-DWASI_ICU_URL:STRING="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
25182490
-DWASI_ICU_MD5:STRING="25943864ebbfff15cf5aee8d9d5cc4d7"
@@ -2524,3 +2496,15 @@ extra-cmake-options=
25242496
-DSWIFT_BUILD_SYNTAXPARSERLIB=FALSE
25252497
-DCMAKE_AR='/usr/local/opt/llvm/bin/llvm-ar'
25262498
-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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -e
3+
DESTINATION_TOOLCHAIN=$1
4+
SOURCE_PATH="$(cd "$(dirname $0)/../../.." && pwd)"
5+
NIGHTLY_TOOLCHAIN=${SOURCE_PATH}/swift-nightly-toolchain
6+
7+
export PATH=$NIGHTLY_TOOLCHAIN/usr/bin:$PATH
8+
9+
SWIFT_BUILD_FLAGS="-c release"
10+
SWIFT_BUILD=${NIGHTLY_TOOLCHAIN}/usr/bin/swift-build
11+
12+
build_swiftpm() {
13+
local build_flags=$SWIFT_BUILD_FLAGS
14+
if [[ "$(uname)" == "Darwin" ]]; then
15+
rpath_prefix='@executable_path/../lib/swift/macosx'
16+
else
17+
rpath_prefix='$ORIGIN/../lib/swift/linux'
18+
fi
19+
build_flags="${build_flags} -Xlinker -rpath -Xlinker ${rpath_prefix}"
20+
cd ${SOURCE_PATH}/swiftpm
21+
${SWIFT_BUILD} ${build_flags}
22+
}
23+
24+
install_binary() {
25+
local src=$1
26+
local dest=${DESTINATION_TOOLCHAIN}/usr/bin
27+
echo "Installing ${src} to ${dest}"
28+
cp ${src} ${dest}
29+
}
30+
31+
install_runtime_file() {
32+
local src=$1
33+
local dest=${DESTINATION_TOOLCHAIN}/usr/lib/swift/pm
34+
echo "Installing ${src} to ${dest}/{4,4_2}"
35+
for runtime in "4" "4_2"
36+
do
37+
mkdir -p ${dest}/${runtime}
38+
cp ${src} ${dest}/${runtime}
39+
done
40+
}
41+
42+
install_swiftpm() {
43+
cd ${SOURCE_PATH}/swiftpm
44+
local bin_path=$(${SWIFT_BUILD} ${SWIFT_BUILD_FLAGS} --show-bin-path)
45+
for binary in ${bin_path}/{swift-build,swift-test,swift-run,swift-package}
46+
do
47+
install_binary ${binary}
48+
done
49+
50+
if [[ "$(uname)" == "Linux" ]]; then
51+
install_runtime_file "${bin_path}/libPackageDescription.so"
52+
else
53+
install_runtime_file "${bin_path}/libPackageDescription.dylib"
54+
fi
55+
install_runtime_file "${bin_path}/PackageDescription.swiftmodule"
56+
install_runtime_file "${bin_path}/PackageDescription.swiftdoc"
57+
}
58+
59+
build_swiftpm
60+
install_swiftpm

utils/webassembly/build-toolchain.sh

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ WASI_SDK_PATH=$SOURCE_PATH/wasi-sdk
99
case $(uname -s) in
1010
Darwin)
1111
OS_SUFFIX=osx
12-
HOST_PRESET=webassembly-host
13-
TARGET_PRESET=webassembly-macos-target
12+
PRESET_NAME=webassembly-macos-installable
1413
;;
1514
Linux)
1615
OS_SUFFIX=linux
17-
HOST_PRESET=webassembly-linux-host
18-
TARGET_PRESET=webassembly-linux-target
16+
PRESET_NAME=webassembly-linux-installable
1917
;;
2018
*)
2119
echo "Unrecognised platform $(uname -s)"
@@ -37,54 +35,47 @@ BUNDLE_IDENTIFIER="swiftwasm.${YEAR}${MONTH}${DAY}"
3735
DISPLAY_NAME_SHORT="Swift for WebAssembly Development Snapshot"
3836
DISPLAY_NAME="${DISPLAY_NAME_SHORT} ${YEAR}-${MONTH}-${DAY}"
3937

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" \
38+
$SOURCE_PATH/swift/utils/build-script --preset=$PRESET_NAME \
6239
SOURCE_PATH="$SOURCE_PATH" \
40+
INSTALLABLE_PACKAGE="$INSTALLABLE_PACKAGE" \
6341
BUNDLE_IDENTIFIER="${BUNDLE_IDENTIFIER}" \
6442
DISPLAY_NAME="${DISPLAY_NAME}" \
6543
DISPLAY_NAME_SHORT="${DISPLAY_NAME_SHORT}" \
6644
TOOLCHAIN_NAME="${TOOLCHAIN_NAME}" \
6745
TOOLCHAIN_VERSION="${TOOLCHAIN_VERSION}" \
6846
C_CXX_LAUNCHER="$(which sccache)"
6947

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
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
7466

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

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

8072
if [[ "$(uname)" == "Linux" ]]; then
81-
# Avoid copying usr/lib/swift/clang because our toolchain's one is a directory
82-
# but nightly's one is symbolic link. A simple copy fails to merge them.
83-
rsync -v -a $SOURCE_PATH/install/$TOOLCHAIN_NAME/usr/lib/ $HOST_TOOLCHAIN_SDK/usr/lib/ --exclude 'swift/clang'
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'
8476
else
85-
cp -v -a $SOURCE_PATH/install/$TOOLCHAIN_NAME/usr/lib/swift_static $HOST_TOOLCHAIN_SDK/usr/lib/swift_static
86-
cp -v -a $SOURCE_PATH/install/$TOOLCHAIN_NAME/usr/lib/swift/wasi $HOST_TOOLCHAIN_SDK/usr/lib/swift
77+
cp -r $NIGHTLY_TOOLCHAIN/usr/lib/swift/macosx $TMP_DIR/$TOOLCHAIN_NAME/usr/lib/swift
8778
fi
8879

89-
cd $HOST_TOOLCHAIN_DESTDIR
80+
cd $TMP_DIR
9081
tar cfz $PACKAGE_ARTIFACT $TOOLCHAIN_NAME
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
set -x
2+
3+
SOURCE_DIR="$(cd "$(dirname $0)/../../.." && pwd)"
4+
DESTINATION="${SOURCE_DIR}/swift-nightly-toolchain"
5+
6+
mkdir -p $DESTINATION
7+
8+
install_linux() {
9+
WORKSPACE=$(mktemp -d)
10+
11+
pushd ${WORKSPACE}
12+
13+
BASE_URL=https://swift.org/builds/development/ubuntu1804
14+
export $(/usr/bin/curl ${BASE_URL}/latest-build.yml | grep 'download:' | sed 's/:[^:\/\/]/=/g')
15+
16+
DOWNLOAD_DIR=$(echo $download | sed "s/-ubuntu18.04.tar.gz//g")
17+
DOWNLOAD_URL=${BASE_URL}/${DOWNLOAD_DIR}/${download}
18+
/usr/bin/curl ${BASE_URL}/${DOWNLOAD_DIR}/${download} > ${WORKSPACE}/latest_toolchain.tar.gz
19+
20+
mkdir -p ${WORKSPACE}/latest_toolchain
21+
tar xzf ${WORKSPACE}/latest_toolchain.tar.gz -C ${WORKSPACE}/latest_toolchain
22+
mv ${WORKSPACE}/latest_toolchain/${DOWNLOAD_DIR}-ubuntu18.04/usr ${DESTINATION}/usr
23+
24+
popd
25+
}
26+
27+
install_macos() {
28+
WORKSPACE=$(mktemp -d)
29+
30+
pushd ${WORKSPACE}
31+
32+
BASE_URL=https://swift.org/builds/development/
33+
export $(/usr/bin/curl --silent ${BASE_URL}/xcode/latest-build.yml | grep 'download:' | sed 's/:[^:\/\/]/=/g')
34+
35+
DOWNLOAD_DIR=$(echo $download | sed "s/-osx.pkg//g")
36+
DOWNLOAD_URL=${BASE_URL}/xcode/${DOWNLOAD_DIR}/${download}
37+
38+
/usr/bin/curl --silent ${DOWNLOAD_URL} > ${WORKSPACE}/latest_xcode_toolchain.pkg
39+
pkgutil --expand ${WORKSPACE}/latest_xcode_toolchain.pkg ${WORKSPACE}/latest_xcode_toolchain
40+
tar xf latest_xcode_toolchain/${DOWNLOAD_DIR}-osx-package.pkg/Payload
41+
mv ${WORKSPACE}/usr ${DESTINATION}/usr
42+
43+
popd
44+
}
45+
46+
if [[ "$(uname)" == "Linux" ]]; then
47+
install_linux
48+
else
49+
install_macos
50+
fi

0 commit comments

Comments
 (0)