Skip to content

Commit a361bba

Browse files
committed
Switch to WASI
1 parent 2961563 commit a361bba

File tree

16 files changed

+21
-61
lines changed

16 files changed

+21
-61
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ if(swift_build_windows AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
785785
configure_sdk_windows("Windows" "msvc" "${SWIFT_SDK_WINDOWS_ARCHITECTURES}")
786786
endif()
787787

788-
# Should we cross-compile the standard library for WebAssembly (Emscripten)?
788+
# Should we cross-compile the standard library for WebAssembly (WASI)?
789789
is_sdk_requested(WASM swift_build_wasm)
790790
if(swift_build_wasm AND NOT "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASM")
791791
#if ("${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")

cmake/modules/AddSwift.cmake

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ include(SwiftList)
22
include(SwiftXcodeSupport)
33
include(SwiftWindowsSupport)
44
include(SwiftAndroidSupport)
5-
include(SwiftWasmSupport)
65

76
# SWIFTLIB_DIR is the directory in the build tree where Swift resource files
87
# should be placed. Note that $CMAKE_CFG_INTDIR expands to "." for
@@ -316,12 +315,6 @@ function(_add_variant_c_compile_flags)
316315
foreach(path ${${CFLAGS_ARCH}_INCLUDE})
317316
list(APPEND result "\"${CMAKE_INCLUDE_FLAG_C}${path}\"")
318317
endforeach()
319-
elseif(CFLAGS_SDK STREQUAL WASM)
320-
list(APPEND result "-D__EMSCRIPTEN__=1")
321-
swift_wasm_include_for_arch(${CFLAGS_ARCH} ${CFLAGS_ARCH}_INCLUDE)
322-
foreach(path ${${CFLAGS_ARCH}_INCLUDE})
323-
list(APPEND result "\"${CMAKE_INCLUDE_FLAG_C}${path}\"")
324-
endforeach()
325318
endif()
326319

327320
set(ICU_UC_INCLUDE_DIR ${SWIFT_${CFLAGS_SDK}_${CFLAGS_ARCH}_ICU_UC_INCLUDE})
@@ -376,11 +369,6 @@ function(_add_variant_swift_compile_flags
376369
foreach(path IN LISTS ${arch}_swift_include)
377370
list(APPEND result "\"${CMAKE_INCLUDE_FLAG_C}${path}\"")
378371
endforeach()
379-
elseif("${sdk}" STREQUAL "WASM")
380-
swift_wasm_include_for_arch(${arch} ${arch}_swift_include)
381-
foreach(path IN LISTS ${arch}_swift_include)
382-
list(APPEND result "\"${CMAKE_INCLUDE_FLAG_C}${path}\"")
383-
endforeach()
384372
endif()
385373

386374
if(NOT BUILD_STANDALONE)
@@ -493,10 +481,7 @@ function(_add_variant_link_flags)
493481
list(APPEND library_search_directories ${path})
494482
endforeach()
495483
elseif("${LFLAGS_SDK}" STREQUAL "WASM")
496-
swift_wasm_lib_for_arch(${LFLAGS_ARCH} ${LFLAGS_ARCH}_LIB)
497-
foreach(path IN LISTS ${LFLAGS_ARCH}_LIB)
498-
list(APPEND library_search_directories ${path})
499-
endforeach()
484+
# No extra libraries needed.
500485
else()
501486
# If lto is enabled, we need to add the object path flag so that the LTO code
502487
# generator leaves the intermediate object file in a place where it will not

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set(SWIFT_CONFIGURED_SDKS)
77

88
include(SwiftWindowsSupport)
99
include(SwiftAndroidSupport)
10-
include(SwiftWasmSupport)
1110

1211
# Report the given SDK to the user.
1312
function(_report_sdk prefix)
@@ -36,14 +35,6 @@ function(_report_sdk prefix)
3635
message(STATUS " ${arch} INCLUDE: ${${arch}_INCLUDE}")
3736
message(STATUS " ${arch} LIB: ${${arch}_LIB}")
3837
endforeach()
39-
elseif("${prefix}" STREQUAL "WASM")
40-
message(STATUS " Emscripten Dir: $ENV{SWIFT_WASM_EMSCRIPTEN_PATH}")
41-
foreach(arch ${SWIFT_SDK_${prefix}_ARCHITECTURES})
42-
swift_wasm_include_for_arch(${arch} ${arch}_INCLUDE)
43-
swift_wasm_lib_for_arch(${arch} ${arch}_LIB)
44-
message(STATUS " ${arch} INCLUDE: ${${arch}_INCLUDE}")
45-
message(STATUS " ${arch} LIB: ${${arch}_LIB}")
46-
endforeach()
4738
else()
4839
foreach(arch ${SWIFT_SDK_${prefix}_ARCHITECTURES})
4940
message(STATUS " ${arch} Path: ${SWIFT_SDK_${prefix}_ARCH_${arch}_PATH}")
@@ -247,8 +238,8 @@ macro(configure_sdk_unix name architectures)
247238
if(NOT arch STREQUAL wasm32)
248239
message(FATAL_ERROR "unsupported arch for WebAssembly: ${arch}")
249240
endif()
250-
# FIXME: this is actually wrong: emscripten doesn't use sysroot.
251-
set(SWIFT_SDK_WASM_ARCH_wasm32_PATH "${SWIFT_WASM_EMSCRIPTEN_PATH}/system")
241+
set(SWIFT_SDK_WASM_ARCH_wasm32_PATH "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot")
242+
# fixme: Wasi is wasm32-unknown-wasi-musl. This LLVM doesn't have it yet.
252243
set(SWIFT_SDK_WASM_ARCH_wasm32_TRIPLE "wasm32-unknown-unknown-wasm")
253244
else()
254245
message(FATAL_ERROR "unknown Unix OS: ${prefix}")

cmake/modules/SwiftWasmSupport.cmake

Lines changed: 0 additions & 16 deletions
This file was deleted.

include/swift/Runtime/Mutex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <type_traits>
2222

23-
#if (defined(__APPLE__) || defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__HAIKU__) || defined(__EMSCRIPTEN__))
23+
#if (defined(__APPLE__) || defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__HAIKU__) || defined(__wasi__))
2424
#include "swift/Runtime/MutexPThread.h"
2525
#elif defined(_WIN32)
2626
#include "swift/Runtime/MutexWin32.h"

include/swift/Runtime/MutexPThread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef pthread_cond_t ConditionHandle;
2626
typedef pthread_mutex_t MutexHandle;
2727
typedef pthread_rwlock_t ReadWriteLockHandle;
2828

29-
#if defined(__CYGWIN__) || defined(__ANDROID__) || defined(__HAIKU__) || defined(__EMSCRIPTEN__)
29+
#if defined(__CYGWIN__) || defined(__ANDROID__) || defined(__HAIKU__) || defined(__wasi__)
3030
// At the moment CYGWIN pthreads implementation doesn't support the use of
3131
// constexpr for static allocation versions. The way they define things
3232
// results in a reinterpret_cast which violates constexpr. Similarly, Android's

lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ Driver::buildToolChain(const llvm::opt::InputArgList &ArgList) {
286286
case llvm::Triple::Haiku:
287287
return llvm::make_unique<toolchains::GenericUnix>(*this, target);
288288
case llvm::Triple::UnknownOS:
289-
// newer LLVM actually has an OS value for Emscripten; should we use it?
289+
// WebAssembly: hack: WASI isn't defined in this LLVM version yet
290290
if (target.isOSBinFormatWasm())
291291
return llvm::make_unique<toolchains::GenericUnix>(*this, target);
292292
LLVM_FALLTHROUGH;

stdlib/public/SwiftShims/LibcShims.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef __swift_uint32_t __swift_mode_t;
4343
typedef __swift_uint16_t __swift_mode_t;
4444
#elif defined(_WIN32)
4545
typedef __swift_int32_t __swift_mode_t;
46-
#elif defined(__EMSCRIPTEN__)
46+
#elif defined(__wasi__)
4747
typedef __swift_uint32_t __swift_mode_t;
4848
#else // just guessing
4949
typedef __swift_uint16_t __swift_mode_t;
@@ -107,7 +107,7 @@ static inline __swift_size_t _swift_stdlib_malloc_size(const void *ptr) {
107107
return malloc_size(ptr);
108108
}
109109
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__ANDROID__) \
110-
|| defined(__HAIKU__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__)
110+
|| defined(__HAIKU__) || defined(__FreeBSD__) || defined(__wasi__)
111111
static inline __swift_size_t _swift_stdlib_malloc_size(const void *ptr) {
112112
#if defined(__ANDROID__)
113113
#if __ANDROID_API__ >= 17

stdlib/public/runtime/Errors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#if defined(__CYGWIN__) || defined(__ANDROID__) || defined(__HAIKU__) || defined(__EMSCRIPTEN__)
17+
#if defined(__CYGWIN__) || defined(__ANDROID__) || defined(__HAIKU__) || defined(__wasi__)
1818
#define SWIFT_SUPPORTS_BACKTRACE_REPORTING 0
1919
#else
2020
#define SWIFT_SUPPORTS_BACKTRACE_REPORTING 1

stdlib/public/runtime/Heap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ using namespace swift;
4242
#elif defined(_WIN32)
4343
# define MALLOC_ALIGN_MASK 7
4444

45-
#elif defined(__EMSCRIPTEN__)
45+
#elif defined(__wasi__)
4646
// Musl malloc is 4*sizeof(size_t), so 16 bytes on 32-bit?
4747
// For some reason the unknown alignment code fails because std::max isn't constexpr?
4848
# define MALLOC_ALIGN_MASK 15

stdlib/public/runtime/ThreadLocalStorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ typedef int __swift_thread_key_t;
7676
typedef unsigned long __swift_thread_key_t;
7777
# elif defined(__HAIKU__)
7878
typedef int __swift_thread_key_t;
79-
# elif defined(__EMSCRIPTEN__)
79+
# elif defined(__wasi__)
8080
typedef unsigned int __swift_thread_key_t;
8181
# else
8282
typedef unsigned long __swift_thread_key_t;

stdlib/public/stubs/LibcShims.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include <stdio.h>
2525
#include <sys/types.h>
26-
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__EMSCRIPTEN__)
26+
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__wasi__)
2727
#include <unistd.h>
2828
#endif
2929

utils/build-script

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,14 @@ class BuildScriptInvocation(object):
345345
"must be specified")
346346

347347
if args.wasm:
348-
if args.wasm_emscripten is None or \
348+
if args.wasm_wasi_sdk is None or \
349349
args.wasm_icu_uc is None or \
350350
args.wasm_icu_uc_include is None or \
351351
args.wasm_icu_i18n is None or \
352352
args.wasm_icu_i18n_include is None or \
353353
args.wasm_icu_data is None:
354354
diagnostics.fatal(
355-
"when building for WebAssembly, --wasm-emscripten, "
355+
"when building for WebAssembly, --wasm-wasi-sdk, "
356356
"--wasm-icu-uc, "
357357
"--wasm-icu-uc-include, --wasm-icu-i18n, "
358358
"--wasm-icu-i18n-include, and --wasm-icu-data "
@@ -777,7 +777,7 @@ class BuildScriptInvocation(object):
777777

778778
if args.wasm:
779779
impl_args += [
780-
"--wasm-emscripten", args.wasm_emscripten,
780+
"--wasm-wasi-sdk", args.wasm_wasi_sdk,
781781
"--wasm-icu-uc", args.wasm_icu_uc,
782782
"--wasm-icu-uc-include", args.wasm_icu_uc_include,
783783
"--wasm-icu-i18n", args.wasm_icu_i18n,

utils/build-script-impl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ KNOWN_SETTINGS=(
258258
android-icu-data "" "Path to libicudata.so"
259259
android-deploy-device-path "" "Path on an Android device to which built Swift stdlib products will be deployed"
260260
android-arch "armv7" "The Android target architecture when building for Android"
261-
wasm-emscripten "" "An absolute path to the Emscripten that will be used as a libc implementation for Wasm builds"
261+
wasm-wasi-sdk "" "An absolute path to the WASI SDK that will be used as a libc implementation for Wasm builds"
262262
wasm-icu-uc "" "Path to libicuuc.so"
263263
wasm-icu-uc-include "" "Path to a directory containing headers for libicuuc"
264264
wasm-icu-i18n "" "Path to libicui18n.so"
@@ -2292,7 +2292,7 @@ for host in "${ALL_HOSTS[@]}"; do
22922292
if [[ ! "${SKIP_BUILD_WASM}" ]]; then
22932293
cmake_options=(
22942294
"${cmake_options[@]}"
2295-
-DSWIFT_WASM_EMSCRIPTEN_PATH:STRING="${WASM_EMSCRIPTEN}"
2295+
-DSWIFT_WASM_WASI_SDK_PATH:STRING="${WASM_WASI_SDK}"
22962296
-DSWIFT_WASM_wasm32_ICU_UC:STRING="${WASM_ICU_UC}"
22972297
-DSWIFT_WASM_wasm32_ICU_UC_INCLUDE:STRING="${WASM_ICU_UC_INCLUDE}"
22982298
-DSWIFT_WASM_wasm32_ICU_I18N:STRING="${WASM_ICU_I18N}"

utils/build_swift/driver_arguments.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,8 @@ def create_argument_parser():
10021002

10031003
in_group('Build settings for Android')
10041004

1005-
option('--wasm-emscripten', store_path,
1006-
help='An absolute path to Emscripten that will be used as a libc '
1005+
option('--wasm-wasi-sdk', store_path,
1006+
help='An absolute path to WASI SDK that will be used as a libc '
10071007
'implementation for Wasm builds')
10081008

10091009
option('--wasm-icu-uc', store_path,

vvv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
utils/build-script --release-debuginfo --wasm \
22
--llvm-targets-to-build "X86;ARM;AArch64;PowerPC;SystemZ;WebAssembly" \
33
--llvm-max-parallel-lto-link-jobs 1 --swift-tools-max-parallel-lto-link-jobs 1 \
4-
--wasm-emscripten "/home/zhuowei/Documents/emsdk/emscripten/1.38.30" \
4+
--wasm-wasi-sdk "/home/zhuowei/Downloads/wasi-sdk-3.0-linux/wasi-sdk-3.0/opt/wasi-sdk" \
55
--wasm-icu-uc "todo" \
66
--wasm-icu-uc-include "$PWD/NO" \
77
--wasm-icu-i18n "todo" \

0 commit comments

Comments
 (0)