Skip to content
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

[WASM] [BuildScript] Initial Support for building WASI toolchain #29465

Closed
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
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ set(SWIFT_ANDROID_DEPLOY_DEVICE_PATH "" CACHE STRING
"Path on an Android device where build products will be pushed. These are used when running the test suite against the device")

#
# User-configurable ICU specific options for Android, FreeBSD, Linux and Haiku.
# User-configurable ICU specific options for Android, FreeBSD, Linux, Haiku, and WebAssembly/WASI.
#

foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS;HAIKU)
foreach(arch aarch64;armv6;armv7;i686;powerpc64;powerpc64le;s390x;x86_64)
foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS;HAIKU;WASI)
foreach(arch aarch64;armv6;armv7;i686;powerpc64;powerpc64le;s390x;wasm32;x86_64)
set(SWIFT_${sdk}_${arch}_ICU_UC "" CACHE STRING
"Path to a directory containing the icuuc library for ${sdk}")
set(SWIFT_${sdk}_${arch}_ICU_UC_INCLUDE "" CACHE STRING
Expand Down Expand Up @@ -599,6 +599,8 @@ else()
set(SWIFT_HOST_VARIANT_ARCH_default "powerpc64le")
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
set(SWIFT_HOST_VARIANT_ARCH_default "s390x")
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "wasm32")
set(SWIFT_HOST_VARIANT_ARCH_default "wasm32")
# FIXME: Only matches v6l/v7l - by far the most common variants
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
set(SWIFT_HOST_VARIANT_ARCH_default "armv6")
Expand Down Expand Up @@ -783,6 +785,14 @@ if(swift_build_windows AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
configure_sdk_windows("Windows" "msvc" "${SWIFT_SDK_WINDOWS_ARCHITECTURES}")
endif()

is_sdk_requested(WASI swift_build_wasi)
if(swift_build_wasi AND NOT "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASI")
if("${SWIFT_SDK_WASI_ARCHITECTURES}" STREQUAL "")
set(SWIFT_SDK_WASI_ARCHITECTURES wasm32)
endif()
configure_sdk_unix("WASI" "${SWIFT_SDK_WASI_ARCHITECTURES}")
endif()

if("${SWIFT_SDKS}" STREQUAL "")
set(SWIFT_SDKS "${SWIFT_CONFIGURED_SDKS}")
endif()
Expand Down
10 changes: 10 additions & 0 deletions cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ macro(configure_sdk_unix name architectures)
set(SWIFT_SDK_${prefix}_ARCHITECTURES "${architectures}")
if("${prefix}" STREQUAL "CYGWIN")
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "COFF")
elseif("${prefix}" STREQUAL "WASI")
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "WASM")
else()
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "ELF")
endif()
Expand Down Expand Up @@ -330,6 +332,14 @@ macro(configure_sdk_unix name architectures)
message(FATAL_ERROR "unsupported arch for Haiku: ${arch}")
endif()
set(SWIFT_SDK_HAIKU_ARCH_x86_64_TRIPLE "x86_64-unknown-haiku")
elseif("${prefix}" STREQUAL "WASI")
if(NOT arch STREQUAL wasm32)
message(FATAL_ERROR "unsupported arch for WASI: ${arch}")
endif()
set(SWIFT_SDK_WASI_ARCH_wasm32_PATH "${SWIFT_WASI_SYSROOT}")
set(SWIFT_SDK_WASI_ARCH_wasm32_TRIPLE "wasm32-unknown-wasi")
set(SWIFT_SDK_WASI_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASI_SYSROOT}/include")
set(SWIFT_SDK_WASI_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY "${SWIFT_WASI_SYSROOT}/include")
else()
message(FATAL_ERROR "unknown Unix OS: ${prefix}")
endif()
Expand Down
3 changes: 2 additions & 1 deletion cmake/modules/SwiftSetIfArchBitness.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function(set_if_arch_bitness var_name)
"${SIA_ARCH}" STREQUAL "armv6" OR
"${SIA_ARCH}" STREQUAL "armv7" OR
"${SIA_ARCH}" STREQUAL "armv7k" OR
"${SIA_ARCH}" STREQUAL "armv7s")
"${SIA_ARCH}" STREQUAL "armv7s" OR
"${SIA_ARCH}" STREQUAL "wasm32")
set("${var_name}" "${SIA_CASE_32_BIT}" PARENT_SCOPE)
elseif("${SIA_ARCH}" STREQUAL "x86_64" OR
"${SIA_ARCH}" STREQUAL "arm64" OR
Expand Down
1 change: 1 addition & 0 deletions stdlib/private/SwiftPrivateThreadExtras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_swift_target_library(swiftSwiftPrivateThreadExtras ${SWIFT_STDLIB_LIBRARY_BU
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
SWIFT_MODULE_DEPENDS_CYGWIN Glibc
SWIFT_MODULE_DEPENDS_HAIKU Glibc
SWIFT_MODULE_DEPENDS_WASI Glibc
SWIFT_MODULE_DEPENDS_WINDOWS MSVCRT WinSDK
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
TARGET_SDKS ALL_APPLE_PLATFORMS CYGWIN FREEBSD HAIKU LINUX WINDOWS ANDROID
Expand Down
3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ function(get_test_dependencies SDK result_var_name)
("${SDK}" STREQUAL "FREEBSD") OR
("${SDK}" STREQUAL "ANDROID") OR
("${SDK}" STREQUAL "WINDOWS") OR
("${SDK}" STREQUAL "HAIKU"))
("${SDK}" STREQUAL "HAIKU") OR
("${SDK}" STREQUAL "WASI"))
# No extra dependencies.
else()
message(FATAL_ERROR "Unknown SDK: ${SDK}")
Expand Down
12 changes: 12 additions & 0 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ def apply_default_arguments(toolchain, args):
args.stdlib_deployment_targets.append(
StdlibDeploymentTarget.Android.aarch64.name)

if args.wasi:
args.build_swift_static_stdlib = True
args.build_dynamic_stdlib = False
args.build_swift_static_sdk_overlay = True
args.build_swift_dynamic_sdk_overlay = False
args.stdlib_deployment_targets.append(
StdlibDeploymentTarget.WASI.wasm32.name)

# Infer platform flags from manually-specified configure targets.
# This doesn't apply to Darwin platforms, as they are
# already configured. No building without the platform flag, though.
Expand Down Expand Up @@ -588,6 +596,8 @@ class BuildScriptInvocation(object):
impl_args += ["--skip-build-watchos-simulator"]
if not args.build_android:
impl_args += ["--skip-build-android"]
if not args.build_wasi:
impl_args += ["--skip-build-wasi"]
if not args.build_clang_tools_extra:
impl_args += ["--skip-build-clang-tools-extra"]

Expand Down Expand Up @@ -629,6 +639,8 @@ class BuildScriptInvocation(object):
impl_args += ["--skip-test-android"]
if not args.test_android_host:
impl_args += ["--skip-test-android-host"]
if not args.test_wasi:
impl_args += ["--skip-test-wasi"]
if args.build_runtime_with_host_compiler:
impl_args += ["--build-runtime-with-host-compiler"]
if args.validation_test:
Expand Down
1 change: 1 addition & 0 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ KNOWN_SETTINGS=(
skip-test-osx "" "set to skip testing Swift stdlibs for OS X"
skip-test-tvos-host "" "set to skip testing the host parts of the tvOS toolchain"
skip-test-tvos-simulator "" "set to skip testing Swift stdlibs for tvOS simulators (i.e. test devices only)"
skip-test-wasi "" "set to skip testing Swift stdlibs for WebAssembly/WASI"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should there be a matching skip-build-wasi somewhere as well?

skip-test-watchos-host "" "set to skip testing the host parts of the watchOS toolchain"
skip-test-watchos-simulator "" "set to skip testing Swift stdlibs for Apple watchOS simulators (i.e. test devices only)"
skip-test-benchmarks "" "set to skip running Swift Benchmark Suite"
Expand Down
22 changes: 21 additions & 1 deletion utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def _apply_default_arguments(args):
if not args.android or not args.build_android:
args.build_android = False

if not args.wasi or not args.build_wasi:
args.build_wasi = False

# --test-paths implies --test and/or --validation-test
# depending on what directories/files have been specified.
if args.test_paths:
Expand Down Expand Up @@ -183,6 +186,7 @@ def _apply_default_arguments(args):
args.test_tvos = False
args.test_watchos = False
args.test_android = False
args.test_wasi = False
args.test_swiftpm = False
args.test_swiftsyntax = False
args.test_indexstoredb = False
Expand Down Expand Up @@ -233,6 +237,12 @@ def _apply_default_arguments(args):
if not args.test_android:
args.test_android_host = False

if not args.build_wasi:
args.test_wasi = False

if not args.test_wasi:
args.test_wasi = False

if not args.host_test:
args.test_ios_host = False
args.test_tvos_host = False
Expand Down Expand Up @@ -326,6 +336,9 @@ def create_argument_parser():
option('--android', toggle_true,
help='also build for Android')

option('--wasi', toggle_true,
help='also build for WebAssembly/WASI')

option('--swift-analyze-code-coverage', store,
choices=['false', 'not-merged', 'merged'],
# so CMake can see the inert mode as a false value
Expand Down Expand Up @@ -932,6 +945,9 @@ def create_argument_parser():
option('--skip-build-android', toggle_false('build_android'),
help='skip building Swift stdlibs for Android')

option('--skip-build-wasi', toggle_false('build_wasi'),
help='skip building Swift stdlibs for WebAssembly/WASI')

option('--skip-build-benchmarks', toggle_false('build_benchmarks'),
help='skip building Swift Benchmark Suite')

Expand Down Expand Up @@ -988,6 +1004,10 @@ def create_argument_parser():
help='skip testing Android device targets on the host machine (the '
'phone itself)')

option('--skip-test-wasi',
toggle_false('test_wasi'),
help='skip testing all WebAssembly/WASI targets.')

option('--skip-test-swiftpm', toggle_false('test_swiftpm'),
help='skip testing swiftpm')
option('--skip-test-swiftsyntax', toggle_false('test_swiftsyntax'),
Expand All @@ -1011,7 +1031,7 @@ def create_argument_parser():
in_group('Build settings specific for LLVM')

option('--llvm-targets-to-build', store,
default='X86;ARM;AArch64;PowerPC;SystemZ;Mips',
default='X86;ARM;AArch64;PowerPC;SystemZ;Mips;WebAssembly',
help='LLVM target generators to build')

# -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ def __platforms_to_skip_test(self, args):
StdlibDeploymentTarget.AppleWatchSimulator)
if not args.test_android:
platforms_to_skip_test.add(StdlibDeploymentTarget.Android)
if not args.test_wasi:
platforms_to_skip_test.add(StdlibDeploymentTarget.WASI)

return platforms_to_skip_test

Expand Down
9 changes: 8 additions & 1 deletion utils/swift_build_support/swift_build_support/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ class StdlibDeploymentTarget(object):

Haiku = Platform("haiku", archs=["x86_64"])

WASI = Platform("wasi", archs=["wasm32"])

# The list of known platforms.
known_platforms = [
OSX,
Expand All @@ -169,7 +171,8 @@ class StdlibDeploymentTarget(object):
Cygwin,
Android,
Windows,
Haiku]
Haiku,
WASI]

# Cache of targets by name.
_targets_by_name = dict((target.name, target)
Expand Down Expand Up @@ -233,6 +236,10 @@ def host_target():
if machine == 'x86_64':
return StdlibDeploymentTarget.Haiku.x86_64

elif system == 'WASI':
if machine == 'wasm32':
return StdlibDeploymentTarget.WASI.wasm32

raise NotImplementedError('System "%s" with architecture "%s" is not '
'supported' % (system, machine))

Expand Down