From 06b88ded9b5a646fcd6664695e812b6cf6b24a37 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 3 Jan 2023 03:43:48 +0000 Subject: [PATCH 1/3] [wasm] update wasi-sysroot version from 14 to 16 --- utils/webassembly/install-build-sdk.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/webassembly/install-build-sdk.sh b/utils/webassembly/install-build-sdk.sh index f147c1abcfc1a..e6508674da329 100755 --- a/utils/webassembly/install-build-sdk.sh +++ b/utils/webassembly/install-build-sdk.sh @@ -21,7 +21,7 @@ install_icu() { } 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" + WASI_SYSROOT_URL="https://github.com/swiftwasm/wasi-sdk-build/releases/download/wasi-sdk-16%2Bswiftwasm-2023-01-03/wasi-sysroot.tar.gz" curl -L "$WASI_SYSROOT_URL" | tar xz From bb10148a672607e01077b9c88c8b4e933a9713cb Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 3 Jan 2023 04:09:52 +0000 Subject: [PATCH 2/3] [wasm] remove unnecessary c++ modulemap hacks --- utils/webassembly/install-build-sdk.sh | 2 - ...disable_part_modules_for_cxx_interop.patch | 75 ------------------- 2 files changed, 77 deletions(-) delete mode 100644 utils/webassembly/patches/wasi-sysroot/disable_part_modules_for_cxx_interop.patch diff --git a/utils/webassembly/install-build-sdk.sh b/utils/webassembly/install-build-sdk.sh index e6508674da329..ef60bf6640ee0 100755 --- a/utils/webassembly/install-build-sdk.sh +++ b/utils/webassembly/install-build-sdk.sh @@ -4,7 +4,6 @@ set -eux SOURCE_PATH="$( cd "$(dirname "$0")/../../../" && pwd )" BUILD_SDK_PATH="$SOURCE_PATH/build-sdk" -PATCHES="$(cd "$(dirname "$0")/patches" && pwd)" install_libxml2() { LIBXML2_URL="https://github.com/swiftwasm/libxml2-wasm/releases/download/1.0.0/libxml2-wasm32-unknown-wasi.tar.gz" @@ -26,7 +25,6 @@ install_wasi-sysroot() { curl -L "$WASI_SYSROOT_URL" | tar xz mv "wasi-sysroot" "$BUILD_SDK_PATH/wasi-sysroot" - patch -p1 -d "$BUILD_SDK_PATH/wasi-sysroot" < "$PATCHES/wasi-sysroot"/*.patch } workdir=$(mktemp -d) diff --git a/utils/webassembly/patches/wasi-sysroot/disable_part_modules_for_cxx_interop.patch b/utils/webassembly/patches/wasi-sysroot/disable_part_modules_for_cxx_interop.patch deleted file mode 100644 index 4995a60369ee6..0000000000000 --- a/utils/webassembly/patches/wasi-sysroot/disable_part_modules_for_cxx_interop.patch +++ /dev/null @@ -1,75 +0,0 @@ -Author: Yuta Saito -Date: Thu Dec 29 10:50:33 2022 +0000 - - Without this patch, Cxx.swiftmodule build fails on macOS host environments - -diff --git a/include/c++/v1/module.modulemap b/include/c++/v1/module.modulemap -index b5781b0..af10440 100644 ---- a/include/c++/v1/module.modulemap -+++ b/include/c++/v1/module.modulemap -@@ -44,10 +44,12 @@ module std [system] { - header "math.h" - export * - } -+ /* XXX(swiftwasm): setjmp.h is unavailable in wasi-libc - module setjmp_h { - header "setjmp.h" - export * - } -+ */ - // FIXME: is missing. - // provided by C library. - // provided by compiler. -@@ -153,10 +155,12 @@ module std [system] { - header "cmath" - export * - } -+ /* XXX(swiftwasm): setjmp.h is unavailable in wasi-libc - module csetjmp { - header "csetjmp" - export * - } -+ */ - module csignal { - header "csignal" - export * -@@ -384,10 +388,12 @@ module std [system] { - header "execution" - export * - } -+ /* XXX(swiftwasm): wasi-sdk configures with LIBCXX_ENABLE_FILESYSTEM=OFF - module filesystem { - header "filesystem" - export * - } -+ */ - module format { - header "format" - export * -@@ -645,11 +651,13 @@ module std [system] { - header "scoped_allocator" - export * - } -+ /* XXX(swiftwasm): semaphore is unavailable due to lack of thread - module semaphore { - requires cplusplus14 - header "semaphore" - export * - } -+ */ - module set { - header "set" - export initializer_list -@@ -816,10 +824,12 @@ module std [system] { - header "experimental/deque" - export * - } -+ /* XXX(swiftwasm): wasi-sdk configures with LIBCXX_ENABLE_FILESYSTEM=OFF - module filesystem { - header "experimental/filesystem" - export * - } -+ */ - module forward_list { - header "experimental/forward_list" - export * From ffb5d2ad0edd5274f15e2f995b1dfbfc6674dfc6 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 3 Jan 2023 05:17:40 +0000 Subject: [PATCH 3/3] [wasm] support __main_argc_argv entry point --- include/swift/Basic/LangOptions.h | 4 +++- lib/AST/ASTContext.cpp | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/swift/Basic/LangOptions.h b/include/swift/Basic/LangOptions.h index 8b400f2dbe398..ab382061991fe 100644 --- a/include/swift/Basic/LangOptions.h +++ b/include/swift/Basic/LangOptions.h @@ -153,7 +153,9 @@ namespace swift { llvm::VersionTuple MinimumInliningTargetVersion; /// The alternate name to use for the entry point instead of main. - std::string entryPointFunctionName = "main"; + /// A value of 'None' means the default entry point name (usually main) + /// should be used. + Optional entryPointFunctionName; /// /// Language features diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 8f607acfd632d..c0d92b143a656 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -5811,7 +5811,19 @@ ASTContext::SILTransformCtors ASTContext::getIRGenSILTransforms() const { } std::string ASTContext::getEntryPointFunctionName() const { - return LangOpts.entryPointFunctionName; + // If -entry-point-function-name was specified, use that. + if (auto entryPointName = LangOpts.entryPointFunctionName) + return entryPointName.getValue(); + + // Otherwise, use the platform-specific default entry point name. + switch (LangOpts.Target.getArch()) { + case llvm::Triple::wasm32: + // The WebAssembly entry point with argc/argv is distinguished from `int main(void)` by name + // https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md#user-entrypoint + return "__main_argc_argv"; + default: + return "main"; + } } SILLayout *SILLayout::get(ASTContext &C,