Skip to content

Update wasi-sdk to 4 to 14.0 #4360

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 3 commits into from
Mar 14, 2022
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
3 changes: 2 additions & 1 deletion .github/workflows/build-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ jobs:
restore-keys: |
${{ matrix.target }}-sccache-v11-

- name: Clean stdlib build directory
- name: Clean build directory
if: ${{ matrix.clean_build_dir }}
run: |
rm -rf ${{ github.workspace }}/target-build \
${{ github.workspace }}/host-build \
${{ github.workspace }}/build-sdk \
${{ github.workspace }}/host-toolchain-sdk \
${{ github.workspace }}/dist-toolchain-sdk

Expand Down
5 changes: 4 additions & 1 deletion lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,10 @@ importer::getNormalInvocationArguments(
}

if (triple.isOSWASI()) {
invocationArgStrs.insert(invocationArgStrs.end(), {"-D_WASI_EMULATED_MMAN"});
invocationArgStrs.insert(invocationArgStrs.end(),
{"-D_WASI_EMULATED_MMAN",
"-D_WASI_EMULATED_SIGNAL",
"-D_WASI_EMULATED_PROCESS_CLOCKS"});
SmallString<128> buffer;
if (auto path = getWasiLibcModuleMapPath(searchPathOpts, triple, buffer)) {
invocationArgStrs.push_back((Twine("-fmodule-map-file=") + *path).str());
Expand Down
6 changes: 1 addition & 5 deletions stdlib/cmake/modules/AddSwiftStdlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ function(_add_target_variant_c_compile_flags)
endif()

if("${CFLAGS_SDK}" STREQUAL "WASI")
list(APPEND result "-D_WASI_EMULATED_MMAN")
list(APPEND result "-D_WASI_EMULATED_MMAN" "-D_WASI_EMULATED_SIGNAL" "-D_WASI_EMULATED_PROCESS_CLOCKS")
endif()

if("${CFLAGS_SDK}" STREQUAL "LINUX")
Expand All @@ -298,10 +298,6 @@ function(_add_target_variant_c_compile_flags)
endif()
endif()

if("${CFLAGS_SDK}" STREQUAL "WASI")
list(APPEND result "-D_WASI_EMULATED_MMAN")
endif()

if(NOT SWIFT_STDLIB_ENABLE_OBJC_INTEROP)
list(APPEND result "-DSWIFT_OBJC_INTEROP=0")
endif()
Expand Down
2 changes: 1 addition & 1 deletion stdlib/cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function(_add_target_variant_swift_compile_flags
endif()

if("${sdk}" STREQUAL "WASI")
list(APPEND result "-Xcc" "-D_WASI_EMULATED_MMAN")
list(APPEND result "-Xcc" "-D_WASI_EMULATED_MMAN" "-Xcc" "-D_WASI_EMULATED_SIGNAL" "-Xcc" "-D_WASI_EMULATED_PROCESS_CLOCKS")
endif()

if(NOT BUILD_STANDALONE)
Expand Down
1 change: 1 addition & 0 deletions utils/webassembly/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ install-prefix=/usr
[preset: webassembly-host]

mixin-preset=webassembly
sccache
extra-cmake-options=
-DSWIFT_BUILD_SOURCEKIT=FALSE
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE
Expand Down
5 changes: 2 additions & 3 deletions utils/webassembly/build-toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ SOURCE_PATH="$(cd "$(dirname "$0")/../../.." && pwd)"
UTILS_PATH="$(cd "$(dirname "$0")" && pwd)"

BUILD_SDK_PATH="$SOURCE_PATH/build-sdk"
WASI_SDK_PATH="$BUILD_SDK_PATH/wasi-sdk"
WASI_SYSROOT_PATH="$WASI_SDK_PATH/share/wasi-sysroot"
WASI_SYSROOT_PATH="$BUILD_SDK_PATH/wasi-sysroot"

case $(uname -s) in
Darwin)
Expand Down Expand Up @@ -155,7 +154,7 @@ build_target_toolchain() {

embed_wasi_sysroot() {
# Merge wasi-sdk and the toolchain
cp -r "$WASI_SDK_PATH/share/wasi-sysroot" "$DIST_TOOLCHAIN_SDK/usr/share"
cp -r "$WASI_SYSROOT_PATH" "$DIST_TOOLCHAIN_SDK/usr/share"

# Replace absolute sysroot path with relative path
sed -i.bak -e "s@\".*/include@\"../../../../share/wasi-sysroot/include@g" "$DIST_TOOLCHAIN_SDK/usr/lib/swift/wasi/wasm32/wasi.modulemap"
Expand Down
20 changes: 6 additions & 14 deletions utils/webassembly/install-build-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@ install_icu() {
mv icu_out "$BUILD_SDK_PATH/icu"
}

install_wasi-sdk() {
# We only use wasi-sysroot and do not use binaries in wasi-sdk,
# so build machine's os and wasi-sdk's host os don't have to be matched
WASI_SDK_URL="https://github.com/swiftwasm/wasi-sdk/releases/download/0.2.2-swiftwasm/dist-ubuntu-18.04.zip"
install_wasi-sysroot() {
WASI_SYSROOT_URL="https://github.com/swiftwasm/wasi-sdk-build/releases/download/wasi-sdk-14%2Bswiftwasm-2022-03-13/wasi-sysroot.tar.gz"

curl -L -o dist-wasi-sdk.zip "$WASI_SDK_URL"
unzip -u dist-wasi-sdk.zip -d .
curl -L "$WASI_SYSROOT_URL" | tar xz

WASI_SDK_TAR_PATH=$(find . -type f -name "wasi-sdk-*")
WASI_SDK_FULL_NAME=$(basename "$WASI_SDK_TAR_PATH" -linux.tar.gz)
tar xfz "$WASI_SDK_TAR_PATH"

rm -rf "$BUILD_SDK_PATH/wasi-sdk"
mv "$WASI_SDK_FULL_NAME" "$BUILD_SDK_PATH/wasi-sdk"
mv "wasi-sysroot" "$BUILD_SDK_PATH/wasi-sysroot"
}

workdir=$(mktemp -d)
Expand All @@ -48,6 +40,6 @@ if [ ! -e "$BUILD_SDK_PATH/icu" ]; then
install_icu
fi

if [ ! -e "$BUILD_SDK_PATH/wasi-sdk" ]; then
install_wasi-sdk
if [ ! -e "$BUILD_SDK_PATH/wasi-sysroot" ]; then
install_wasi-sysroot
fi
3 changes: 2 additions & 1 deletion utils/webassembly/static-executable-args.lnk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
-lstdc++
-lm
-lwasi-emulated-mman
-lwasi-emulated-signal
-lwasi-emulated-process-clocks
-Xlinker --error-limit=0
-Xlinker --no-gc-sections
-Xlinker --threads=1
-D_WASI_EMULATED_MMAN