Skip to content

Build host toolchain w/o copying it from snapshots #1024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 50 additions & 34 deletions utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2437,39 +2437,67 @@ no-assertions

[preset: webassembly]

wasm
release
verbose
cmake-c-launcher=%(C_CXX_LAUNCHER)s
cmake-cxx-launcher=%(C_CXX_LAUNCHER)s
skip-build-benchmarks
llvm-targets-to-build=X86;WebAssembly
install-destdir=%(INSTALL_DESTDIR)s
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
llvm-install-components=clang
install-swift
install-prefix=/%(TOOLCHAIN_NAME)s/usr

[preset: webassembly-host]

mixin-preset=webassembly
extra-cmake-options=
-DSWIFT_BUILD_SOURCEKIT=FALSE
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE
-DSWIFT_BUILD_SYNTAXPARSERLIB=FALSE

llbuild
swiftpm

install-swift
install-llbuild
install-swiftpm

[preset: webassembly-linux-host]

mixin-preset=webassembly-host

libdispatch
libicu
foundation
xctest

install-libicu
install-foundation
install-libdispatch
install-xctest

skip-test-libicu
skip-test-foundation
skip-test-libdispatch
skip-test-xctest

[preset: webassembly-target]

mixin-preset=webassembly
wasm
verbose
build-stdlib-deployment-targets=wasi-wasm32
build-swift-dynamic-sdk-overlay=false
build-swift-dynamic-stdlib=false
build-swift-static-sdk-overlay
build-swift-static-stdlib
llvm-targets-to-build=X86;WebAssembly
stdlib-deployment-targets=wasi-wasm32
wasi-sdk=%(SOURCE_PATH)s/wasi-sdk

[preset: webassembly-installable]
[preset: webassembly-linux-target]

install_destdir=%(SOURCE_PATH)s/install
installable_package=%(INSTALLABLE_PACKAGE)s
install-prefix=/%(TOOLCHAIN_NAME)s/usr
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
llvm-install-components=clang
install-swift
darwin-toolchain-bundle-identifier=%(BUNDLE_IDENTIFIER)s
darwin-toolchain-display-name=%(DISPLAY_NAME)s
darwin-toolchain-display-name-short=%(DISPLAY_NAME_SHORT)s
darwin-toolchain-name=%(TOOLCHAIN_NAME)s
darwin-toolchain-version=%(TOOLCHAIN_VERSION)s
darwin-toolchain-alias=swift

[preset: webassembly-linux]

mixin-preset=webassembly
mixin-preset=webassembly-target
extra-cmake-options=
-DWASI_ICU_URL:STRING="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
-DWASI_ICU_MD5:STRING="25943864ebbfff15cf5aee8d9d5cc4d7"
Expand All @@ -2482,9 +2510,9 @@ extra-cmake-options=
-DCMAKE_AR="%(SOURCE_PATH)s/wasi-sdk/bin/llvm-ar"
-DCMAKE_RANLIB="%(SOURCE_PATH)s/wasi-sdk/bin/llvm-ranlib"

[preset: webassembly-macos]
[preset: webassembly-macos-target]

mixin-preset=webassembly
mixin-preset=webassembly-target
extra-cmake-options=
-DWASI_ICU_URL:STRING="https://github.com/swiftwasm/icu4c-wasi/releases/download/0.5.0/icu4c-wasi.tar.xz"
-DWASI_ICU_MD5:STRING="25943864ebbfff15cf5aee8d9d5cc4d7"
Expand All @@ -2496,15 +2524,3 @@ extra-cmake-options=
-DSWIFT_BUILD_SYNTAXPARSERLIB=FALSE
-DCMAKE_AR='/usr/local/opt/llvm/bin/llvm-ar'
-DCMAKE_RANLIB='/usr/local/opt/llvm/bin/llvm-ranlib'

[preset: webassembly-linux-installable]

mixin-preset=
webassembly-linux
webassembly-installable

[preset: webassembly-macos-installable]

mixin-preset=
webassembly-macos
webassembly-installable
60 changes: 0 additions & 60 deletions utils/webassembly/build-swiftpm.sh

This file was deleted.

67 changes: 38 additions & 29 deletions utils/webassembly/build-toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ WASI_SDK_PATH=$SOURCE_PATH/wasi-sdk
case $(uname -s) in
Darwin)
OS_SUFFIX=osx
PRESET_NAME=webassembly-macos-installable
HOST_PRESET=webassembly-host
TARGET_PRESET=webassembly-macos-target
;;
Linux)
OS_SUFFIX=linux
PRESET_NAME=webassembly-linux-installable
HOST_PRESET=webassembly-linux-host
TARGET_PRESET=webassembly-linux-target
;;
*)
echo "Unrecognised platform $(uname -s)"
Expand All @@ -35,47 +37,54 @@ BUNDLE_IDENTIFIER="swiftwasm.${YEAR}${MONTH}${DAY}"
DISPLAY_NAME_SHORT="Swift for WebAssembly Development Snapshot"
DISPLAY_NAME="${DISPLAY_NAME_SHORT} ${YEAR}-${MONTH}-${DAY}"

$SOURCE_PATH/swift/utils/build-script --preset=$PRESET_NAME \
HOST_TOOLCHAIN_DESTDIR=$SOURCE_PATH/host-toolchain-sdk
HOST_TOOLCHAIN_SDK=$HOST_TOOLCHAIN_DESTDIR/$TOOLCHAIN_NAME

# Avoid clang headers symlink issues
mkdir -p $HOST_TOOLCHAIN_SDK/usr/lib/clang/10.0.0

# Build the host toolchain and SDK first.
$SOURCE_PATH/swift/utils/build-script \
--preset=$HOST_PRESET \
INSTALL_DESTDIR="$HOST_TOOLCHAIN_DESTDIR" \
TOOLCHAIN_NAME="$TOOLCHAIN_NAME" \
C_CXX_LAUNCHER="$(which sccache)"

# Clean up the host toolchain build directory so that the next
# `build-script` invocation doesn't pick up wrong CMake config files.
# For some reason passing `--reconfigure` to `build-script` won't do this.
rm -rf $SOURCE_PATH/build/Ninja-ReleaseAssert/swift-*

# build the cross-compilled toolchain
$SOURCE_PATH/swift/utils/build-script \
--preset=$TARGET_PRESET \
INSTALL_DESTDIR="$SOURCE_PATH/install" \
SOURCE_PATH="$SOURCE_PATH" \
INSTALLABLE_PACKAGE="$INSTALLABLE_PACKAGE" \
BUNDLE_IDENTIFIER="${BUNDLE_IDENTIFIER}" \
DISPLAY_NAME="${DISPLAY_NAME}" \
DISPLAY_NAME_SHORT="${DISPLAY_NAME_SHORT}" \
TOOLCHAIN_NAME="${TOOLCHAIN_NAME}" \
TOOLCHAIN_VERSION="${TOOLCHAIN_VERSION}" \
C_CXX_LAUNCHER="$(which sccache)"


NIGHTLY_TOOLCHAIN=$SOURCE_PATH/swift-nightly-toolchain
if [ ! -e $NIGHTLY_TOOLCHAIN ]; then
$UTILS_PATH/install-nightly-toolchain.sh
fi

TMP_DIR=$(mktemp -d)
cd $TMP_DIR
tar xfz $INSTALLABLE_PACKAGE $TOOLCHAIN_NAME
cd $TMP_DIR/$TOOLCHAIN_NAME

# Merge wasi-sdk and toolchain
cp -r $WASI_SDK_PATH/lib/clang usr/lib
cp -a $WASI_SDK_PATH/bin/{*ld,llvm-ar} usr/bin
cp -r $WASI_SDK_PATH/share/wasi-sysroot usr/share

# Build SwiftPM and install it into toolchain
$UTILS_PATH/build-swiftpm.sh $TMP_DIR/$TOOLCHAIN_NAME
# Merge wasi-sdk and the toolchain
cp -a $WASI_SDK_PATH/lib/clang $HOST_TOOLCHAIN_SDK/usr/lib
cp -a $WASI_SDK_PATH/bin/{*ld,llvm-ar} $HOST_TOOLCHAIN_SDK/usr/bin
cp -r $WASI_SDK_PATH/share/wasi-sysroot $HOST_TOOLCHAIN_SDK/usr/share

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

# Copy nightly-toolchain's host environment stdlib into toolchain
# Copy the target environment stdlib into the toolchain

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

cd $TMP_DIR
cd $HOST_TOOLCHAIN_DESTDIR
tar cfz $PACKAGE_ARTIFACT $TOOLCHAIN_NAME
50 changes: 0 additions & 50 deletions utils/webassembly/install-nightly-toolchain.sh

This file was deleted.