From 32da3a5a347bbf1edb25a78c8b6c3fd384b12412 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Tue, 11 Feb 2025 17:08:06 +0000 Subject: [PATCH 01/14] Enable `_Concurrency` for Wasm in Embedded Swift --- stdlib/public/Concurrency/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/public/Concurrency/CMakeLists.txt b/stdlib/public/Concurrency/CMakeLists.txt index a38f4230192ad..6c1969f786e5a 100644 --- a/stdlib/public/Concurrency/CMakeLists.txt +++ b/stdlib/public/Concurrency/CMakeLists.txt @@ -245,7 +245,7 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC set(extra_c_compile_flags) set(extra_swift_compile_flags) elseif (SWIFT_HOST_VARIANT STREQUAL "macosx") - if(NOT "${mod}" MATCHES "-macos$") + if((NOT "${mod}" MATCHES "-macos$") AND (NOT "${arch}" MATCHES "^wasm")) continue() endif() if("${mod}" MATCHES "riscv") From 55f047b18a084d92fb5ef8e912a21e3e2db356d6 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 12 Feb 2025 12:56:00 +0000 Subject: [PATCH 02/14] Enable embedded concurrency for Wasm on Linux hosts --- stdlib/public/Concurrency/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/public/Concurrency/CMakeLists.txt b/stdlib/public/Concurrency/CMakeLists.txt index 6c1969f786e5a..2ab18194911a4 100644 --- a/stdlib/public/Concurrency/CMakeLists.txt +++ b/stdlib/public/Concurrency/CMakeLists.txt @@ -239,7 +239,7 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC list(GET list 2 triple) if (SWIFT_HOST_VARIANT STREQUAL "linux") - if(NOT "${mod}" MATCHES "-linux-gnu$") + if((NOT "${mod}" MATCHES "-linux-gnu$") AND (NOT "${arch}" MATCHES "^wasm")) continue() endif() set(extra_c_compile_flags) From 375187d5e7d0ea057926df79fd097072ba021762 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 12 Mar 2025 12:05:27 +0000 Subject: [PATCH 03/14] Build embedded stdlib for `wasm32-unknown-wasip1-wasm` triple This allows creation of small binaries without Swift runtime included, while still maintaining WASI 0.1 ABI and access to libc/libc++ APIs and headers. (cherry picked from commit 440a869b724150f93fb9332036ee31969d3265f2) --- stdlib/public/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/public/CMakeLists.txt b/stdlib/public/CMakeLists.txt index db3e3c13b6b71..a4dca2a9a0711 100644 --- a/stdlib/public/CMakeLists.txt +++ b/stdlib/public/CMakeLists.txt @@ -218,6 +218,7 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB_CROSS_COMPILING) if("WebAssembly" IN_LIST LLVM_TARGETS_TO_BUILD) list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES "wasm32 wasm32-unknown-none-wasm wasm32-unknown-none-wasm" + "wasm32 wasm32-unknown-wasip1-wasm wasm32-unknown-wasip1-wasm" "wasm64 wasm64-unknown-none-wasm wasm64-unknown-none-wasm" ) endif() @@ -226,7 +227,7 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB_CROSS_COMPILING) list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES "avr avr-none-none-elf avr-none-none-elf" ) - endif() + endif() endif() if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB) From 5a3626bfd74d3ec6fe09b30c8dfea4b69d32d395 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 12 Mar 2025 18:27:34 +0000 Subject: [PATCH 04/14] Pass `SWIFT_WASI_SYSROOT_PATH` in `Concurrency/CMakeLists.txt` --- stdlib/public/Concurrency/CMakeLists.txt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/stdlib/public/Concurrency/CMakeLists.txt b/stdlib/public/Concurrency/CMakeLists.txt index de072fee3b165..89bcb20097e58 100644 --- a/stdlib/public/Concurrency/CMakeLists.txt +++ b/stdlib/public/Concurrency/CMakeLists.txt @@ -245,13 +245,13 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC list(GET list 2 triple) if (SWIFT_HOST_VARIANT STREQUAL "linux") - if((NOT "${mod}" MATCHES "-linux-gnu$") AND (NOT "${arch}" MATCHES "^wasm")) + if((NOT "${mod}" MATCHES "-linux-gnu$") AND (NOT "${mod}" MATCHES "-wasip1")) continue() endif() set(extra_c_compile_flags) set(extra_swift_compile_flags) elseif (SWIFT_HOST_VARIANT STREQUAL "macosx") - if((NOT "${mod}" MATCHES "-macos$") AND (NOT "${arch}" MATCHES "^wasm")) + if((NOT "${mod}" MATCHES "-macos$") AND (NOT "${mod}" MATCHES "-wasip1")) continue() endif() if("${mod}" MATCHES "riscv") @@ -260,8 +260,11 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC if("${mod}" MATCHES "armv6m") continue() endif() - set(extra_c_compile_flags -D__MACH__ -D__APPLE__ -ffreestanding -stdlib=libc++) - set(extra_swift_compile_flags -Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding) + + if("${mod}" MATCHES "-macos$") + set(extra_c_compile_flags -D__MACH__ -D__APPLE__ -ffreestanding -stdlib=libc++) + set(extra_swift_compile_flags -Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding) + endif() endif() set(SWIFT_SDK_embedded_THREADING_PACKAGE none) @@ -304,7 +307,12 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC COMPONENT "stdlib" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) - set_property(TARGET embedded-concurrency-${mod} PROPERTY OSX_ARCHITECTURES "${arch}") + + if(NOT "${arch}" MATCHES "wasm32") + set_property(TARGET embedded-concurrency-${mod} PROPERTY OSX_ARCHITECTURES "${arch}") + elseif("${mod}" MATCHES "-wasip1$") + target_compile_options(embedded-concurrency-${mod} PRIVATE $<$:--sysroot=${SWIFT_WASI_SYSROOT_PATH}>) + endif() add_dependencies(embedded-concurrency embedded-concurrency-${mod}) # lib/swift/embedded//libswift_ConcurrencyDefaultExecutor.a From 8a11cdaccfe53618fe72a06464d08724856b65b7 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 13 Mar 2025 16:31:37 +0000 Subject: [PATCH 05/14] Pass `SWIFT_WASI_SYSROOT_PATH` to `swift_build_support/products/swift.py` --- CMakeLists.txt | 3 +++ stdlib/public/Concurrency/CMakeLists.txt | 6 +++-- utils/build-script-impl | 9 +------- .../swift_build_support/products/swift.py | 23 +++++++++++++++---- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb79821c76251..51eccd751ead6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -487,6 +487,9 @@ set(SWIFT_NATIVE_CLANG_TOOLS_PATH "" CACHE STRING set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "" CACHE STRING "Path to the directory that contains Swift tools that are executable on the build machine") +set(SWIFT_WASI_SYSROOT_PATH "" CACHE PATH + "Path to the directory that contains WASI Sysroot") + option(SWIFT_STDLIB_ENABLE_SIB_TARGETS "Should we generate sib targets for the stdlib or not?" FALSE) diff --git a/stdlib/public/Concurrency/CMakeLists.txt b/stdlib/public/Concurrency/CMakeLists.txt index 89bcb20097e58..65dccc719e334 100644 --- a/stdlib/public/Concurrency/CMakeLists.txt +++ b/stdlib/public/Concurrency/CMakeLists.txt @@ -265,6 +265,10 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC set(extra_c_compile_flags -D__MACH__ -D__APPLE__ -ffreestanding -stdlib=libc++) set(extra_swift_compile_flags -Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding) endif() + + if("${mod}" MATCHES "-wasip1") + set(extra_c_compile_flags "-I${SWIFT_WASI_SYSROOT_PATH}/include/c++/v1" "-I${SWIFT_WASI_SYSROOT_PATH}/include/wasm32-wasi") + endif() endif() set(SWIFT_SDK_embedded_THREADING_PACKAGE none) @@ -310,8 +314,6 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC if(NOT "${arch}" MATCHES "wasm32") set_property(TARGET embedded-concurrency-${mod} PROPERTY OSX_ARCHITECTURES "${arch}") - elseif("${mod}" MATCHES "-wasip1$") - target_compile_options(embedded-concurrency-${mod} PRIVATE $<$:--sysroot=${SWIFT_WASI_SYSROOT_PATH}>) endif() add_dependencies(embedded-concurrency embedded-concurrency-${mod}) diff --git a/utils/build-script-impl b/utils/build-script-impl index 06b54cc6c8eb2..ab0c488a861d5 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -1639,13 +1639,6 @@ for host in "${ALL_HOSTS[@]}"; do ) fi - if [[ ! "${SKIP_BUILD_WASM}" ]]; then - cmake_options=( - "${cmake_options[@]}" - -DSWIFT_WASI_SYSROOT_PATH:STRING="${WASI_SYSROOT}" - ) - fi - if [[ $(is_cross_tools_host ${host}) && "${host}" == "openbsd-"* && -n "${OPENBSD_USE_TOOLCHAIN_FILE}" ]]; then cmake_options=( "${cmake_options[@]}" @@ -2503,7 +2496,7 @@ for host in "${ALL_HOSTS[@]}"; do cmake_options=( -DENABLE_SWIFT=YES ${cmake_options[@]} - + -DCMAKE_BUILD_TYPE:STRING="${LIBDISPATCH_BUILD_TYPE}" -DCMAKE_C_COMPILER:PATH="${CLANG_BIN}/clang" -DCMAKE_CXX_COMPILER:PATH="${CLANG_BIN}/clang++" diff --git a/utils/swift_build_support/swift_build_support/products/swift.py b/utils/swift_build_support/swift_build_support/products/swift.py index 483be3b409d1c..0fdd2ab6bea55 100644 --- a/utils/swift_build_support/swift_build_support/products/swift.py +++ b/utils/swift_build_support/swift_build_support/products/swift.py @@ -10,6 +10,8 @@ # # ---------------------------------------------------------------------------- +import os + from build_swift.build_swift.constants import SWIFT_REPO_NAME from . import cmark @@ -18,6 +20,7 @@ from . import llvm from . import product from . import staticswiftlinux +from . import wasisysroot from ..cmake import CMakeOptions @@ -96,13 +99,13 @@ def __init__(self, args, toolchain, source_dir, build_dir): self.cmake_options.extend( self._swift_tools_ld64_lto_codegen_only_for_supporting_targets) - self.cmake_options.extend( - self._enable_experimental_parser_validation) + self.cmake_options.extend(self._enable_experimental_parser_validation) self._handle_swift_debuginfo_non_lto_args() - self.cmake_options.extend( - self._enable_new_runtime_build) + self.cmake_options.extend(self._enable_new_runtime_build) + + self.cmake_options.extend(self._wasi_sysroot_path) @classmethod def product_source_name(cls): @@ -296,6 +299,15 @@ def _enable_new_runtime_build(self): return [('SWIFT_ENABLE_NEW_RUNTIME_BUILD:BOOL', self.args.enable_new_runtime_build)] + @property + def _wasi_sysroot_path(self): + return [('SWIFT_WASI_SYSROOT_PATH:PATH', + self._get_wasi_sysroot_path("wasm32-wasi"))] + + def _get_wasi_sysroot_path(self, target_triple): + build_root = os.path.dirname(self.build_dir) + return wasisysroot.WASILibc.sysroot_install_path(build_root, target_triple) + def _handle_swift_debuginfo_non_lto_args(self): if ('swift_debuginfo_non_lto_args' not in self.args or self.args.swift_debuginfo_non_lto_args is None): @@ -314,4 +326,5 @@ def get_dependencies(cls): earlyswiftdriver.EarlySwiftDriver, llvm.LLVM, staticswiftlinux.StaticSwiftLinuxConfig, - libcxx.LibCXX] + libcxx.LibCXX, + wasisysroot.WASILibc,] From 431063b169277a46ecc90bac639a8c3cd88c365d Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Fri, 14 Mar 2025 13:24:52 +0000 Subject: [PATCH 06/14] Swift SDK build work in progress --- stdlib/public/CMakeLists.txt | 124 ++++++++++-------- stdlib/public/Concurrency/CMakeLists.txt | 17 ++- utils/build-presets.ini | 7 +- utils/build-script | 27 ++-- .../swift_build_support/products/swift.py | 11 -- .../products/wasmstdlib.py | 4 +- .../update-checkout-config.json | 10 +- 7 files changed, 108 insertions(+), 92 deletions(-) diff --git a/stdlib/public/CMakeLists.txt b/stdlib/public/CMakeLists.txt index a4dca2a9a0711..a1232d5829adb 100644 --- a/stdlib/public/CMakeLists.txt +++ b/stdlib/public/CMakeLists.txt @@ -155,7 +155,10 @@ option(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB_CROSS_COMPILING set(SWIFT_EMBEDDED_STDLIB_EXTRA_TARGET_TRIPLES "" CACHE STRING "List of extra target triples to build the embedded Swift standard library for") -if((NOT SWIFT_HOST_VARIANT STREQUAL "macosx") AND (NOT SWIFT_HOST_VARIANT STREQUAL "linux") AND (NOT SWIFT_HOST_VARIANT STREQUAL "windows")) +if((NOT SWIFT_HOST_VARIANT STREQUAL "macosx") AND + (NOT SWIFT_HOST_VARIANT STREQUAL "linux") AND + (NOT SWIFT_HOST_VARIANT STREQUAL "wasi") AND + (NOT SWIFT_HOST_VARIANT STREQUAL "windows")) set(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB FALSE) elseif(BOOTSTRAPPING_MODE STREQUAL "OFF") set(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB FALSE) @@ -168,69 +171,76 @@ endif() set(EMBEDDED_STDLIB_TARGET_TRIPLES) if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB_CROSS_COMPILING) - if("ARM" IN_LIST LLVM_TARGETS_TO_BUILD) + if(SWIFT_WASI_SYSROOT_PATH) + # Don't attempt to build any other Embedded Swift stdlib triples + # when building for WASI. list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES - # arch module_name target triple - "armv6 armv6-apple-none-macho armv6-apple-none-macho" - "armv6m armv6m-apple-none-macho armv6m-apple-none-macho" - "armv7 armv7-apple-none-macho armv7-apple-none-macho" - "armv7m armv7m-apple-none-macho armv7m-apple-none-macho" - "armv7em armv7em-apple-none-macho armv7em-apple-none-macho" - ) - endif() - if("AArch64" IN_LIST LLVM_TARGETS_TO_BUILD) - list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES - "arm64 arm64-apple-none-macho arm64-apple-none-macho" - "arm64e arm64e-apple-none-macho arm64e-apple-none-macho" - "arm64 arm64-apple-ios arm64-apple-ios18" - "arm64e arm64e-apple-ios arm64e-apple-ios18" - ) - endif() - - # the following are all ELF targets - if("ARM" IN_LIST LLVM_TARGETS_TO_BUILD) - list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES - "armv4t armv4t-none-none-eabi armv4t-none-none-eabi" - "armv6 armv6-none-none-eabi armv6-none-none-eabi" - "armv6m armv6m-none-none-eabi armv6m-none-none-eabi" - "armv7 armv7-none-none-eabi armv7-none-none-eabi" - "armv7em armv7em-none-none-eabi armv7em-none-none-eabi" - ) - endif() - if("AArch64" IN_LIST LLVM_TARGETS_TO_BUILD) - list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES - "aarch64 aarch64-none-none-elf aarch64-none-none-elf" - ) - endif() - if("RISCV" IN_LIST LLVM_TARGETS_TO_BUILD) - list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES - "riscv32 riscv32-none-none-eabi riscv32-none-none-eabi" - "riscv64 riscv64-none-none-eabi riscv64-none-none-eabi" - ) - endif() - if("X86" IN_LIST LLVM_TARGETS_TO_BUILD) - list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES - "i686 i686-unknown-none-elf i686-unknown-none-elf" - "x86_64 x86_64-unknown-none-elf x86_64-unknown-none-elf" - ) - endif() - - if("WebAssembly" IN_LIST LLVM_TARGETS_TO_BUILD) - list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES - "wasm32 wasm32-unknown-none-wasm wasm32-unknown-none-wasm" "wasm32 wasm32-unknown-wasip1-wasm wasm32-unknown-wasip1-wasm" - "wasm64 wasm64-unknown-none-wasm wasm64-unknown-none-wasm" ) - endif() + else() + if("ARM" IN_LIST LLVM_TARGETS_TO_BUILD) + list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES + # arch module_name target triple + "armv6 armv6-apple-none-macho armv6-apple-none-macho" + "armv6m armv6m-apple-none-macho armv6m-apple-none-macho" + "armv7 armv7-apple-none-macho armv7-apple-none-macho" + "armv7m armv7m-apple-none-macho armv7m-apple-none-macho" + "armv7em armv7em-apple-none-macho armv7em-apple-none-macho" + ) + endif() + if("AArch64" IN_LIST LLVM_TARGETS_TO_BUILD) + list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES + "arm64 arm64-apple-none-macho arm64-apple-none-macho" + "arm64e arm64e-apple-none-macho arm64e-apple-none-macho" + "arm64 arm64-apple-ios arm64-apple-ios18" + "arm64e arm64e-apple-ios arm64e-apple-ios18" + ) + endif() + + # the following are all ELF targets + if("ARM" IN_LIST LLVM_TARGETS_TO_BUILD) + list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES + "armv4t armv4t-none-none-eabi armv4t-none-none-eabi" + "armv6 armv6-none-none-eabi armv6-none-none-eabi" + "armv6m armv6m-none-none-eabi armv6m-none-none-eabi" + "armv7 armv7-none-none-eabi armv7-none-none-eabi" + "armv7em armv7em-none-none-eabi armv7em-none-none-eabi" + ) + endif() + if("AArch64" IN_LIST LLVM_TARGETS_TO_BUILD) + list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES + "aarch64 aarch64-none-none-elf aarch64-none-none-elf" + ) + endif() + if("RISCV" IN_LIST LLVM_TARGETS_TO_BUILD) + list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES + "riscv32 riscv32-none-none-eabi riscv32-none-none-eabi" + "riscv64 riscv64-none-none-eabi riscv64-none-none-eabi" + ) + endif() + if("X86" IN_LIST LLVM_TARGETS_TO_BUILD) + list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES + "i686 i686-unknown-none-elf i686-unknown-none-elf" + "x86_64 x86_64-unknown-none-elf x86_64-unknown-none-elf" + ) + endif() - if("AVR" IN_LIST LLVM_TARGETS_TO_BUILD) - list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES - "avr avr-none-none-elf avr-none-none-elf" - ) + if("WebAssembly" IN_LIST LLVM_TARGETS_TO_BUILD) + list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES + "wasm32 wasm32-unknown-none-wasm wasm32-unknown-none-wasm" + "wasm64 wasm64-unknown-none-wasm wasm64-unknown-none-wasm" + ) + endif() + + if("AVR" IN_LIST LLVM_TARGETS_TO_BUILD) + list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES + "avr avr-none-none-elf avr-none-none-elf" + ) + endif() endif() endif() -if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB) +if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND NOT SWIFT_WASI_SYSROOT_PATH) if (SWIFT_HOST_VARIANT STREQUAL "linux") list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES "${SWIFT_HOST_VARIANT_ARCH} ${SWIFT_HOST_VARIANT_ARCH}-unknown-linux-gnu ${SWIFT_HOST_VARIANT_ARCH}-unknown-linux-gnu" diff --git a/stdlib/public/Concurrency/CMakeLists.txt b/stdlib/public/Concurrency/CMakeLists.txt index 65dccc719e334..2db7587d9e9aa 100644 --- a/stdlib/public/Concurrency/CMakeLists.txt +++ b/stdlib/public/Concurrency/CMakeLists.txt @@ -224,6 +224,11 @@ elseif(BOOTSTRAPPING_MODE STREQUAL "OFF") elseif(SWIFT_HOST_VARIANT STREQUAL "windows") # For now, don't build embedded Concurrency on Windows set(SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENCY FALSE) endif() + +message(STATUS "SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB is ${SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB}") +message(STATUS "SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENCY is ${SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENCY}") +message(STATUS "EMBEDDED_STDLIB_TARGET_TRIPLES is ${EMBEDDED_STDLIB_TARGET_TRIPLES}") + if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENCY) add_custom_target(embedded-concurrency) add_dependencies(embedded-libraries embedded-concurrency) @@ -266,9 +271,19 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC set(extra_swift_compile_flags -Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding) endif() + elseif (SWIFT_HOST_VARIANT STREQUAL "wasi") + message(STATUS "SWIFT_WASI_SYSROOT_PATH is ${SWIFT_WASI_SYSROOT_PATH}") + message(STATUS "mod is ${mod}") if("${mod}" MATCHES "-wasip1") - set(extra_c_compile_flags "-I${SWIFT_WASI_SYSROOT_PATH}/include/c++/v1" "-I${SWIFT_WASI_SYSROOT_PATH}/include/wasm32-wasi") + set(extra_c_compile_flags "-I${SWIFT_WASI_SYSROOT_PATH}/include/c++/v1") + if(${SWIFT_WASI_SYSROOT_PATH} MATCHES "threads") + list(APPEND extra_c_compile_flags "-I${SWIFT_WASI_SYSROOT_PATH}/include/wasm32-wasip1-threads") + else() + list(APPEND extra_c_compile_flags "-I${SWIFT_WASI_SYSROOT_PATH}/include/wasm32-wasi") + endif() endif() + + message(STATUS "extra_c_compile_flags is ${extra_c_compile_flags}") endif() set(SWIFT_SDK_embedded_THREADING_PACKAGE none) diff --git a/utils/build-presets.ini b/utils/build-presets.ini index 488abd6896117..5d7cd8dabf515 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -1352,7 +1352,7 @@ release-debuginfo compiler-vendor=apple # Cross compile for Apple Silicon -infer-cross-compile-hosts-on-darwin +; infer-cross-compile-hosts-on-darwin lldb-use-system-debugserver lldb-build-type=Release @@ -1465,6 +1465,9 @@ mixin-preset= mixin_osx_package_test mixin_lightweight_assertions,no-stdlib-asserts +build-wasm-stdlib +skip-test-wasm-stdlib + # SKIP LLDB TESTS (67923799) skip-test-lldb skip-test-playgroundsupport @@ -1855,7 +1858,7 @@ skip-test-swift [preset: mixin_swiftpm_macos_platform] mixin-preset=mixin_swiftpm_base -infer-cross-compile-hosts-on-darwin +; infer-cross-compile-hosts-on-darwin # SwiftPM base [preset: mixin_swiftpm_linux_platform] diff --git a/utils/build-script b/utils/build-script index 81837e1fa1e9a..566a1ea9f5c1b 100755 --- a/utils/build-script +++ b/utils/build-script @@ -419,21 +419,18 @@ def apply_default_arguments(toolchain, args): args.extra_cmake_options.append( '-DSWIFT_DARWIN_MODULE_ARCHS:STRING={}'.format( args.swift_darwin_module_archs)) - if (args.infer_cross_compile_hosts_on_darwin and - platform.system() == "Darwin"): - args.cross_compile_hosts = _infer_cross_compile_hosts_on_darwin( - get_running_arch(args.dry_run)) - print("Inferred the following hosts for cross compilations: " - f"{args.cross_compile_hosts}") - sys.stdout.flush() - - -def _infer_cross_compile_hosts_on_darwin(arch_we_are_running_on): - if arch_we_are_running_on == "x86_64": - return ["macosx-arm64"] - else: - return ["macosx-x86_64"] - +# if (args.infer_cross_compile_hosts_on_darwin and +# platform.system() == "Darwin"): +# args.cross_compile_hosts = _infer_cross_compile_hosts_on_darwin( +# get_running_arch(args.dry_run)) +# print("Inferred the following hosts for cross compilations: " +# f"{args.cross_compile_hosts}") +# sys.stdout.flush() +# +# +# def _infer_cross_compile_hosts_on_darwin(arch_we_are_running_on): +# return ["macosx-arm64"] +# def get_running_arch(dry_run): # We can override the detected arch to support diff --git a/utils/swift_build_support/swift_build_support/products/swift.py b/utils/swift_build_support/swift_build_support/products/swift.py index 0fdd2ab6bea55..4756453e45dd5 100644 --- a/utils/swift_build_support/swift_build_support/products/swift.py +++ b/utils/swift_build_support/swift_build_support/products/swift.py @@ -105,8 +105,6 @@ def __init__(self, args, toolchain, source_dir, build_dir): self.cmake_options.extend(self._enable_new_runtime_build) - self.cmake_options.extend(self._wasi_sysroot_path) - @classmethod def product_source_name(cls): """product_source_name() -> str @@ -299,15 +297,6 @@ def _enable_new_runtime_build(self): return [('SWIFT_ENABLE_NEW_RUNTIME_BUILD:BOOL', self.args.enable_new_runtime_build)] - @property - def _wasi_sysroot_path(self): - return [('SWIFT_WASI_SYSROOT_PATH:PATH', - self._get_wasi_sysroot_path("wasm32-wasi"))] - - def _get_wasi_sysroot_path(self, target_triple): - build_root = os.path.dirname(self.build_dir) - return wasisysroot.WASILibc.sysroot_install_path(build_root, target_triple) - def _handle_swift_debuginfo_non_lto_args(self): if ('swift_debuginfo_non_lto_args' not in self.args or self.args.swift_debuginfo_non_lto_args is None): diff --git a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py index 70299e3788558..ba995a5622651 100644 --- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py @@ -141,7 +141,6 @@ def _build_stdlib(self, host_target, target_triple, llvm_cmake_dir): self.cmake_options.define('SWIFT_STDLIB_TRACING:BOOL', 'FALSE') self.cmake_options.define('SWIFT_STDLIB_HAS_ASLR:BOOL', 'FALSE') self.cmake_options.define('SWIFT_STDLIB_CONCURRENCY_TRACING:BOOL', 'FALSE') - self.cmake_options.define('SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB:BOOL', 'FALSE') self.cmake_options.define( 'SWIFT_STDLIB_INSTALL_PARENT_MODULE_FOR_SHIMS:BOOL', 'FALSE') self.cmake_options.define('SWIFT_RUNTIME_CRASH_REPORTER_CLIENT:BOOL', 'FALSE') @@ -165,6 +164,9 @@ def _build_stdlib(self, host_target, target_triple, llvm_cmake_dir): self.cmake_options.define('SWIFT_ENABLE_VOLATILE:BOOL', 'TRUE') self.cmake_options.define('SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL', 'TRUE') + self.cmake_options.define('SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB:BOOL', 'TRUE') + self.cmake_options.define('SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB_CROSS_COMPILING', 'TRUE') + self.add_extra_cmake_options() # Test configuration diff --git a/utils/update_checkout/update-checkout-config.json b/utils/update_checkout/update-checkout-config.json index ffce049ea3147..a3f39ae093080 100644 --- a/utils/update_checkout/update-checkout-config.json +++ b/utils/update_checkout/update-checkout-config.json @@ -15,7 +15,7 @@ "swift-async-algorithms": { "remote": { "id": "apple/swift-async-algorithms" } }, "swift-atomics": { - "remote": { "id": "apple/swift-atomics" } }, + "remote": { "id": "apple/swift-atomics" } }, "swift-collections": { "remote": { "id": "apple/swift-collections" } }, "swift-crypto": { @@ -29,7 +29,7 @@ "swift-log": { "remote": { "id": "apple/swift-log" } }, "swift-numerics": { - "remote": { "id": "apple/swift-numerics" } }, + "remote": { "id": "apple/swift-numerics" } }, "swift-toolchain-sqlite": { "remote": { "id": "swiftlang/swift-toolchain-sqlite" } }, "swift-tools-support-core": { @@ -47,9 +47,9 @@ "swift-corelibs-xctest": { "remote": { "id": "swiftlang/swift-corelibs-xctest" } }, "swift-corelibs-foundation": { - "remote": { "id": "swiftlang/swift-corelibs-foundation" } }, + "remote": { "id": "swiftlang/swift-corelibs-foundation" } }, "swift-foundation-icu": { - "remote": { "id": "swiftlang/swift-foundation-icu" } }, + "remote": { "id": "swiftlang/swift-foundation-icu" } }, "swift-foundation": { "remote": { "id": "swiftlang/swift-foundation" } }, "swift-corelibs-libdispatch": { @@ -158,7 +158,7 @@ "swift-corelibs-libdispatch": "main", "swift-integration-tests": "main", "swift-xcode-playground-support": "main", - "ninja": "v1.11.1", + "ninja": "v1.12.1", "cmake": "v3.30.2", "indexstore-db": "main", "sourcekit-lsp": "main", From 63d57f4d1c4a194b97c68794e93b1b8982c8b285 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Mon, 17 Mar 2025 10:45:27 +0000 Subject: [PATCH 07/14] Fix `Python/python_lint.swift` test --- utils/build-script | 27 ++++++++++--------- .../swift_build_support/products/swift.py | 2 -- .../products/wasmstdlib.py | 3 ++- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/utils/build-script b/utils/build-script index 566a1ea9f5c1b..81837e1fa1e9a 100755 --- a/utils/build-script +++ b/utils/build-script @@ -419,18 +419,21 @@ def apply_default_arguments(toolchain, args): args.extra_cmake_options.append( '-DSWIFT_DARWIN_MODULE_ARCHS:STRING={}'.format( args.swift_darwin_module_archs)) -# if (args.infer_cross_compile_hosts_on_darwin and -# platform.system() == "Darwin"): -# args.cross_compile_hosts = _infer_cross_compile_hosts_on_darwin( -# get_running_arch(args.dry_run)) -# print("Inferred the following hosts for cross compilations: " -# f"{args.cross_compile_hosts}") -# sys.stdout.flush() -# -# -# def _infer_cross_compile_hosts_on_darwin(arch_we_are_running_on): -# return ["macosx-arm64"] -# + if (args.infer_cross_compile_hosts_on_darwin and + platform.system() == "Darwin"): + args.cross_compile_hosts = _infer_cross_compile_hosts_on_darwin( + get_running_arch(args.dry_run)) + print("Inferred the following hosts for cross compilations: " + f"{args.cross_compile_hosts}") + sys.stdout.flush() + + +def _infer_cross_compile_hosts_on_darwin(arch_we_are_running_on): + if arch_we_are_running_on == "x86_64": + return ["macosx-arm64"] + else: + return ["macosx-x86_64"] + def get_running_arch(dry_run): # We can override the detected arch to support diff --git a/utils/swift_build_support/swift_build_support/products/swift.py b/utils/swift_build_support/swift_build_support/products/swift.py index 4756453e45dd5..56506f5fec7f8 100644 --- a/utils/swift_build_support/swift_build_support/products/swift.py +++ b/utils/swift_build_support/swift_build_support/products/swift.py @@ -10,8 +10,6 @@ # # ---------------------------------------------------------------------------- -import os - from build_swift.build_swift.constants import SWIFT_REPO_NAME from . import cmark diff --git a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py index ba995a5622651..e5652195f9950 100644 --- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py @@ -165,7 +165,8 @@ def _build_stdlib(self, host_target, target_triple, llvm_cmake_dir): self.cmake_options.define('SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL', 'TRUE') self.cmake_options.define('SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB:BOOL', 'TRUE') - self.cmake_options.define('SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB_CROSS_COMPILING', 'TRUE') + self.cmake_options.define( + 'SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB_CROSS_COMPILING', 'TRUE') self.add_extra_cmake_options() From a3e218d304e59e6b3b0f79dcf9b1ecaa86e6a522 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Mon, 17 Mar 2025 10:47:13 +0000 Subject: [PATCH 08/14] Remove unnecessary diff in `products/swift.py` --- .../swift_build_support/products/swift.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/swift_build_support/swift_build_support/products/swift.py b/utils/swift_build_support/swift_build_support/products/swift.py index 56506f5fec7f8..483be3b409d1c 100644 --- a/utils/swift_build_support/swift_build_support/products/swift.py +++ b/utils/swift_build_support/swift_build_support/products/swift.py @@ -18,7 +18,6 @@ from . import llvm from . import product from . import staticswiftlinux -from . import wasisysroot from ..cmake import CMakeOptions @@ -97,11 +96,13 @@ def __init__(self, args, toolchain, source_dir, build_dir): self.cmake_options.extend( self._swift_tools_ld64_lto_codegen_only_for_supporting_targets) - self.cmake_options.extend(self._enable_experimental_parser_validation) + self.cmake_options.extend( + self._enable_experimental_parser_validation) self._handle_swift_debuginfo_non_lto_args() - self.cmake_options.extend(self._enable_new_runtime_build) + self.cmake_options.extend( + self._enable_new_runtime_build) @classmethod def product_source_name(cls): @@ -313,5 +314,4 @@ def get_dependencies(cls): earlyswiftdriver.EarlySwiftDriver, llvm.LLVM, staticswiftlinux.StaticSwiftLinuxConfig, - libcxx.LibCXX, - wasisysroot.WASILibc,] + libcxx.LibCXX] From ee5d8d0b4186b7a9efadea1bae67cd4bfabd281a Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Mon, 17 Mar 2025 11:07:41 +0000 Subject: [PATCH 09/14] Revert changes to `build-presets.ini` --- utils/build-presets.ini | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/utils/build-presets.ini b/utils/build-presets.ini index 5d7cd8dabf515..488abd6896117 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -1352,7 +1352,7 @@ release-debuginfo compiler-vendor=apple # Cross compile for Apple Silicon -; infer-cross-compile-hosts-on-darwin +infer-cross-compile-hosts-on-darwin lldb-use-system-debugserver lldb-build-type=Release @@ -1465,9 +1465,6 @@ mixin-preset= mixin_osx_package_test mixin_lightweight_assertions,no-stdlib-asserts -build-wasm-stdlib -skip-test-wasm-stdlib - # SKIP LLDB TESTS (67923799) skip-test-lldb skip-test-playgroundsupport @@ -1858,7 +1855,7 @@ skip-test-swift [preset: mixin_swiftpm_macos_platform] mixin-preset=mixin_swiftpm_base -; infer-cross-compile-hosts-on-darwin +infer-cross-compile-hosts-on-darwin # SwiftPM base [preset: mixin_swiftpm_linux_platform] From f1b616fffb9cc8c2d54eb28685655362f26cfb9a Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Mon, 17 Mar 2025 11:08:51 +0000 Subject: [PATCH 10/14] Revert changes to `update-checkout-config.json` --- utils/update_checkout/update-checkout-config.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/update_checkout/update-checkout-config.json b/utils/update_checkout/update-checkout-config.json index a3f39ae093080..ffce049ea3147 100644 --- a/utils/update_checkout/update-checkout-config.json +++ b/utils/update_checkout/update-checkout-config.json @@ -15,7 +15,7 @@ "swift-async-algorithms": { "remote": { "id": "apple/swift-async-algorithms" } }, "swift-atomics": { - "remote": { "id": "apple/swift-atomics" } }, + "remote": { "id": "apple/swift-atomics" } }, "swift-collections": { "remote": { "id": "apple/swift-collections" } }, "swift-crypto": { @@ -29,7 +29,7 @@ "swift-log": { "remote": { "id": "apple/swift-log" } }, "swift-numerics": { - "remote": { "id": "apple/swift-numerics" } }, + "remote": { "id": "apple/swift-numerics" } }, "swift-toolchain-sqlite": { "remote": { "id": "swiftlang/swift-toolchain-sqlite" } }, "swift-tools-support-core": { @@ -47,9 +47,9 @@ "swift-corelibs-xctest": { "remote": { "id": "swiftlang/swift-corelibs-xctest" } }, "swift-corelibs-foundation": { - "remote": { "id": "swiftlang/swift-corelibs-foundation" } }, + "remote": { "id": "swiftlang/swift-corelibs-foundation" } }, "swift-foundation-icu": { - "remote": { "id": "swiftlang/swift-foundation-icu" } }, + "remote": { "id": "swiftlang/swift-foundation-icu" } }, "swift-foundation": { "remote": { "id": "swiftlang/swift-foundation" } }, "swift-corelibs-libdispatch": { @@ -158,7 +158,7 @@ "swift-corelibs-libdispatch": "main", "swift-integration-tests": "main", "swift-xcode-playground-support": "main", - "ninja": "v1.12.1", + "ninja": "v1.11.1", "cmake": "v3.30.2", "indexstore-db": "main", "sourcekit-lsp": "main", From a05560bbeee48bd40eaa1f91e04f5c5adcf76b87 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Mon, 17 Mar 2025 11:43:09 +0000 Subject: [PATCH 11/14] Remove unnecessary CMake `message(STATUS)` logging --- stdlib/public/Concurrency/CMakeLists.txt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/stdlib/public/Concurrency/CMakeLists.txt b/stdlib/public/Concurrency/CMakeLists.txt index 2db7587d9e9aa..0520f9c7c97d9 100644 --- a/stdlib/public/Concurrency/CMakeLists.txt +++ b/stdlib/public/Concurrency/CMakeLists.txt @@ -224,11 +224,6 @@ elseif(BOOTSTRAPPING_MODE STREQUAL "OFF") elseif(SWIFT_HOST_VARIANT STREQUAL "windows") # For now, don't build embedded Concurrency on Windows set(SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENCY FALSE) endif() - -message(STATUS "SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB is ${SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB}") -message(STATUS "SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENCY is ${SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENCY}") -message(STATUS "EMBEDDED_STDLIB_TARGET_TRIPLES is ${EMBEDDED_STDLIB_TARGET_TRIPLES}") - if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENCY) add_custom_target(embedded-concurrency) add_dependencies(embedded-libraries embedded-concurrency) @@ -272,8 +267,6 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC endif() elseif (SWIFT_HOST_VARIANT STREQUAL "wasi") - message(STATUS "SWIFT_WASI_SYSROOT_PATH is ${SWIFT_WASI_SYSROOT_PATH}") - message(STATUS "mod is ${mod}") if("${mod}" MATCHES "-wasip1") set(extra_c_compile_flags "-I${SWIFT_WASI_SYSROOT_PATH}/include/c++/v1") if(${SWIFT_WASI_SYSROOT_PATH} MATCHES "threads") @@ -282,8 +275,6 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC list(APPEND extra_c_compile_flags "-I${SWIFT_WASI_SYSROOT_PATH}/include/wasm32-wasi") endif() endif() - - message(STATUS "extra_c_compile_flags is ${extra_c_compile_flags}") endif() set(SWIFT_SDK_embedded_THREADING_PACKAGE none) From b9de71b621e147430cfd4155ae6660b1db1d7d6b Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 17 Mar 2025 14:12:47 +0000 Subject: [PATCH 12/14] Remove unreachable CMake code change from stdlib/public/Concurrency/CMakeLists.txt --- stdlib/public/Concurrency/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/public/Concurrency/CMakeLists.txt b/stdlib/public/Concurrency/CMakeLists.txt index 0520f9c7c97d9..38889b322922d 100644 --- a/stdlib/public/Concurrency/CMakeLists.txt +++ b/stdlib/public/Concurrency/CMakeLists.txt @@ -245,13 +245,13 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC list(GET list 2 triple) if (SWIFT_HOST_VARIANT STREQUAL "linux") - if((NOT "${mod}" MATCHES "-linux-gnu$") AND (NOT "${mod}" MATCHES "-wasip1")) + if(NOT "${mod}" MATCHES "-linux-gnu$") continue() endif() set(extra_c_compile_flags) set(extra_swift_compile_flags) elseif (SWIFT_HOST_VARIANT STREQUAL "macosx") - if((NOT "${mod}" MATCHES "-macos$") AND (NOT "${mod}" MATCHES "-wasip1")) + if(NOT "${mod}" MATCHES "-macos$") continue() endif() if("${mod}" MATCHES "riscv") From 59fbab85ad4dcb095b06f458e4de58111407b0c4 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 17 Mar 2025 14:33:51 +0000 Subject: [PATCH 13/14] CMake: Stop using `-I` for sysroot paths in the WASI stdlib --- stdlib/public/CMakeLists.txt | 2 +- stdlib/public/Concurrency/CMakeLists.txt | 10 ++-------- .../swift_build_support/products/wasmstdlib.py | 3 +++ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/stdlib/public/CMakeLists.txt b/stdlib/public/CMakeLists.txt index a1232d5829adb..0c479ae35085a 100644 --- a/stdlib/public/CMakeLists.txt +++ b/stdlib/public/CMakeLists.txt @@ -175,7 +175,7 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB_CROSS_COMPILING) # Don't attempt to build any other Embedded Swift stdlib triples # when building for WASI. list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES - "wasm32 wasm32-unknown-wasip1-wasm wasm32-unknown-wasip1-wasm" + "wasm32 wasm32-unknown-wasip1 wasm32-unknown-wasip1" ) else() if("ARM" IN_LIST LLVM_TARGETS_TO_BUILD) diff --git a/stdlib/public/Concurrency/CMakeLists.txt b/stdlib/public/Concurrency/CMakeLists.txt index 38889b322922d..86fa309b464da 100644 --- a/stdlib/public/Concurrency/CMakeLists.txt +++ b/stdlib/public/Concurrency/CMakeLists.txt @@ -267,14 +267,8 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC endif() elseif (SWIFT_HOST_VARIANT STREQUAL "wasi") - if("${mod}" MATCHES "-wasip1") - set(extra_c_compile_flags "-I${SWIFT_WASI_SYSROOT_PATH}/include/c++/v1") - if(${SWIFT_WASI_SYSROOT_PATH} MATCHES "threads") - list(APPEND extra_c_compile_flags "-I${SWIFT_WASI_SYSROOT_PATH}/include/wasm32-wasip1-threads") - else() - list(APPEND extra_c_compile_flags "-I${SWIFT_WASI_SYSROOT_PATH}/include/wasm32-wasi") - endif() - endif() + set(extra_c_compile_flags) + set(extra_swift_compile_flags) endif() set(SWIFT_SDK_embedded_THREADING_PACKAGE none) diff --git a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py index e5652195f9950..9cf73d3396d1d 100644 --- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py @@ -167,6 +167,9 @@ def _build_stdlib(self, host_target, target_triple, llvm_cmake_dir): self.cmake_options.define('SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB:BOOL', 'TRUE') self.cmake_options.define( 'SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB_CROSS_COMPILING', 'TRUE') + self.cmake_options.define( + 'SWIFT_SDK_embedded_ARCH_wasm32-unknown-wasip1_PATH:PATH', + self._wasi_sysroot_path("wasm32-wasi")) self.add_extra_cmake_options() From 220ab3022864038edac072780fd180e464f484fc Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 17 Mar 2025 15:04:05 +0000 Subject: [PATCH 14/14] build: Alias wasm32-wasip1 to wasm32-wasi in the sysroot for Embedded modules --- .../swift_build_support/products/wasisysroot.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/utils/swift_build_support/swift_build_support/products/wasisysroot.py b/utils/swift_build_support/swift_build_support/products/wasisysroot.py index 2f355760e2f1a..712a07e8377b4 100644 --- a/utils/swift_build_support/swift_build_support/products/wasisysroot.py +++ b/utils/swift_build_support/swift_build_support/products/wasisysroot.py @@ -62,6 +62,7 @@ def _build(self, host_target, thread_model='single', target_triple='wasm32-wasi' # check-symbols. The directory is required during sysroot installation step. os.makedirs(os.path.join(sysroot_build_dir, "share"), exist_ok=True) + sysroot_install_path = WASILibc.sysroot_install_path(build_root, target_triple) shell.call([ 'make', 'install', '-j', str(build_jobs), @@ -74,7 +75,7 @@ def _build(self, host_target, thread_model='single', target_triple='wasm32-wasi' '-C', self.source_dir, 'OBJDIR=' + os.path.join(self.build_dir, 'obj-' + thread_model), 'SYSROOT=' + sysroot_build_dir, - 'INSTALL_DIR=' + WASILibc.sysroot_install_path(build_root, target_triple), + 'INSTALL_DIR=' + sysroot_install_path, 'CC=' + os.path.join(clang_tools_path, 'clang'), 'AR=' + os.path.join(llvm_tools_path, 'llvm-ar'), 'NM=' + os.path.join(llvm_tools_path, 'llvm-nm'), @@ -82,6 +83,14 @@ def _build(self, host_target, thread_model='single', target_triple='wasm32-wasi' 'TARGET_TRIPLE=' + target_triple, ]) + if target_triple == "wasm32-wasi": + # Alias wasm32-wasip1 to wasm32-wasi as Embedded modules use + # wasm32-unknown-wasip1 as the target triple. + for subpath in ["lib", "include"]: + dest_path = os.path.join(sysroot_install_path, subpath, "wasm32-wasip1") + if not os.path.exists(dest_path): + shell.symlink("wasm32-wasi", dest_path) + @classmethod def get_dependencies(cls): return [llvm.LLVM]