From c81f3a579661fadd18dbea83b6cd9d1328d1ac83 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 18 Sep 2024 12:27:22 +0000 Subject: [PATCH 01/14] Update base tag for main to swift-DEVELOPMENT-SNAPSHOT-2024-09-17-a --- schemes/main/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemes/main/manifest.json b/schemes/main/manifest.json index 16ebb67c..492f3015 100644 --- a/schemes/main/manifest.json +++ b/schemes/main/manifest.json @@ -1,5 +1,5 @@ { - "base-tag": "swift-DEVELOPMENT-SNAPSHOT-2024-09-11-a", + "base-tag": "swift-DEVELOPMENT-SNAPSHOT-2024-09-17-a", "build-compiler": false, "icu4c": [ "https://github.com/swiftwasm/icu4c-wasi/releases/download/0.10.0/icu4c-wasm32-unknown-wasi.tar.xz", From 642844457abfa21e4d1d7829f1327cd62c4ace94 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 18 Sep 2024 14:47:29 +0000 Subject: [PATCH 02/14] Remove upstreamed patch --- .../main/swift-corelibs-foundation/5061.patch | 357 ------------------ 1 file changed, 357 deletions(-) delete mode 100644 schemes/main/swift-corelibs-foundation/5061.patch diff --git a/schemes/main/swift-corelibs-foundation/5061.patch b/schemes/main/swift-corelibs-foundation/5061.patch deleted file mode 100644 index 5304ae63..00000000 --- a/schemes/main/swift-corelibs-foundation/5061.patch +++ /dev/null @@ -1,357 +0,0 @@ -From 6a78203fc24702ed81a2b2bb2a9949168e694161 Mon Sep 17 00:00:00 2001 -From: Yuta Saito -Date: Thu, 8 Aug 2024 23:33:15 +0000 -Subject: [PATCH 1/3] [XMLParser] Use `TaskLocal` for storing the current - parser - -Instead of thread-local storage, use `TaskLocal` to store the current -parser. This solves three issues: - -1. If someone calls `XMLParser.parse()` with a new parser instance in - a delegate method call, it overwrote the current parser and wrote - it back after the call as `nil`, not the previous current parser. - This reentrancy issue can be a problem especially when someone uses - external entity resolving since the feature depends on the current - parser tracking. Using `TaskLocal` solves this issue since it tracks - values as a stack and restores the previous value at the end of the - `withValue` call. -2. Since jobs of different tasks can be scheduled on the same thread, - different tasks can refer to the same thread-local storage. This - wouldn't be a problem for now since the `parse()` method doesn't - have any suspention points and different tasks can't run on the same - thread during the parsing. However, it's better to use `TaskLocal` - to leverage the concurrency model of Swift. -3. The global variable `_currentParser` existed in the WASI platform - path but it's unsafe in the Swift concurrency model. It wouldn't be a - problem on WASI since it's always single-threaded, we should avoid - platform-specific assumption as much as possible. ---- - Sources/FoundationXML/XMLParser.swift | 85 ++++++++++----------------- - Tests/Foundation/TestXMLParser.swift | 43 +++++++++++++- - 2 files changed, 74 insertions(+), 54 deletions(-) - -diff --git a/Sources/FoundationXML/XMLParser.swift b/Sources/FoundationXML/XMLParser.swift -index d89d0ee1f4..e3d718a86f 100644 ---- a/Sources/FoundationXML/XMLParser.swift -+++ b/Sources/FoundationXML/XMLParser.swift -@@ -398,9 +398,7 @@ extension XMLParser : @unchecked Sendable { } - - open class XMLParser : NSObject { - private var _handler: _CFXMLInterfaceSAXHandler --#if !os(WASI) - internal var _stream: InputStream? --#endif - internal var _data: Data? - - internal var _chunkSize = Int(4096 * 32) // a suitably large number for a decent chunk size -@@ -469,33 +467,35 @@ open class XMLParser : NSObject { - open var externalEntityResolvingPolicy: ExternalEntityResolvingPolicy = .never - - open var allowedExternalEntityURLs: Set? -- --#if os(WASI) -- private static var _currentParser: XMLParser? --#endif - -- internal static func currentParser() -> XMLParser? { --#if os(WASI) -- return _currentParser --#else -- if let current = Thread.current.threadDictionary["__CurrentNSXMLParser"] { -- return current as? XMLParser -- } else { -- return nil -+ /// The current parser is stored in a task local variable to allow for -+ /// concurrent parsing in different tasks with different parsers. -+ /// -+ /// Rationale for `@unchecked Sendable`: -+ /// While the ``XMLParser`` class itself is not `Sendable`, `TaskLocal` -+ /// requires the value type to be `Sendable`. The sendability requirement -+ /// of `TaskLocal` is only for the "default" value and values set with -+ /// `withValue` will not be shared between tasks. -+ /// So as long as 1. the default value is safe to be shared between tasks -+ /// and 2. the `Sendable` conformance of `_CurrentParser` is not used -+ /// outside of `TaskLocal`, it is safe to mark it as `@unchecked Sendable`. -+ private struct _CurrentParser: @unchecked Sendable { -+ let parser: XMLParser? -+ -+ static var `default`: _CurrentParser { -+ return _CurrentParser(parser: nil) - } --#endif -+ } -+ -+ @TaskLocal -+ private static var _currentParser: _CurrentParser = .default -+ -+ internal static func currentParser() -> XMLParser? { -+ return _currentParser.parser - } - -- internal static func setCurrentParser(_ parser: XMLParser?) { --#if os(WASI) -- _currentParser = parser --#else -- if let p = parser { -- Thread.current.threadDictionary["__CurrentNSXMLParser"] = p -- } else { -- Thread.current.threadDictionary.removeObject(forKey: "__CurrentNSXMLParser") -- } --#endif -+ internal static func withCurrentParser(_ parser: XMLParser, _ body: () -> R) -> R { -+ return self.$_currentParser.withValue(_CurrentParser(parser: parser), operation: body) - } - - internal func _handleParseResult(_ parseResult: Int32) -> Bool { -@@ -569,7 +569,6 @@ open class XMLParser : NSObject { - return result - } - --#if !os(WASI) - internal func parseFrom(_ stream : InputStream) -> Bool { - var result = true - -@@ -598,37 +597,17 @@ open class XMLParser : NSObject { - - return result - } --#else -- internal func parse(from data: Data) -> Bool { -- var result = true -- var chunkStart = 0 -- var chunkEnd = min(_chunkSize, data.count) -- while result && chunkStart < chunkEnd { -- let chunk = data[chunkStart.. Bool { --#if os(WASI) -- return _data.map { parse(from: $0) } ?? false --#else -- XMLParser.setCurrentParser(self) -- defer { XMLParser.setCurrentParser(nil) } -- -- if _stream != nil { -- return parseFrom(_stream!) -- } else if _data != nil { -- return parseData(_data!, lastChunkOfData: true) -+ return Self.withCurrentParser(self) { -+ if _stream != nil { -+ return parseFrom(_stream!) -+ } else if _data != nil { -+ return parseData(_data!, lastChunkOfData: true) -+ } -+ return false - } -- -- return false --#endif - } - - // called by the delegate to stop the parse. The delegate will get an error message sent to it. -diff --git a/Tests/Foundation/TestXMLParser.swift b/Tests/Foundation/TestXMLParser.swift -index c98741eb38..df3685a82e 100644 ---- a/Tests/Foundation/TestXMLParser.swift -+++ b/Tests/Foundation/TestXMLParser.swift -@@ -198,5 +198,46 @@ class TestXMLParser : XCTestCase { - ElementNameChecker("noPrefix").check() - ElementNameChecker("myPrefix:myLocalName").check() - } -- -+ -+ func testExternalEntity() throws { -+ class Delegate: XMLParserDelegateEventStream { -+ override func parserDidStartDocument(_ parser: XMLParser) { -+ // Start a child parser, updating `currentParser` to the child parser -+ // to ensure that `currentParser` won't be reset to `nil`, which would -+ // ignore any external entity related configuration. -+ let childParser = XMLParser(data: "".data(using: .utf8)!) -+ XCTAssertTrue(childParser.parse()) -+ super.parserDidStartDocument(parser) -+ } -+ } -+ try withTemporaryDirectory { dir, _ in -+ let greetingPath = dir.appendingPathComponent("greeting.xml") -+ try Data("".utf8).write(to: greetingPath) -+ let xml = """ -+ -+ -+ ]> -+ &greeting; -+ """ -+ -+ let parser = XMLParser(data: xml.data(using: .utf8)!) -+ // Explicitly disable external entity resolving -+ parser.externalEntityResolvingPolicy = .never -+ let delegate = Delegate() -+ parser.delegate = delegate -+ // The parse result changes depending on the libxml2 version -+ // because of the following libxml2 commit (shipped in libxml2 2.9.10): -+ // https://gitlab.gnome.org/GNOME/libxml2/-/commit/eddfbc38fa7e84ccd480eab3738e40d1b2c83979 -+ // So we don't check the parse result here. -+ _ = parser.parse() -+ XCTAssertEqual(delegate.events, [ -+ .startDocument, -+ .didStartElement("doc", nil, nil, [:]), -+ // Should not have parsed the external entity -+ .didEndElement("doc", nil, nil), -+ .endDocument, -+ ]) -+ } -+ } - } - -From 7a6125f16e07bb9cdd15e8bee5e7e2c283da4205 Mon Sep 17 00:00:00 2001 -From: Yuta Saito -Date: Fri, 9 Aug 2024 01:51:50 +0000 -Subject: [PATCH 2/3] Remove unnecessary `#if os(WASI)` condition in - XMLParser.swift - ---- - Sources/FoundationXML/XMLParser.swift | 6 ------ - 1 file changed, 6 deletions(-) - -diff --git a/Sources/FoundationXML/XMLParser.swift b/Sources/FoundationXML/XMLParser.swift -index e3d718a86f..39eea6c3d8 100644 ---- a/Sources/FoundationXML/XMLParser.swift -+++ b/Sources/FoundationXML/XMLParser.swift -@@ -412,9 +412,6 @@ open class XMLParser : NSObject { - - // initializes the parser with the specified URL. - public convenience init?(contentsOf url: URL) { --#if os(WASI) -- return nil --#else - setupXMLParsing() - if url.isFileURL { - if let stream = InputStream(url: url) { -@@ -432,7 +429,6 @@ open class XMLParser : NSObject { - return nil - } - } --#endif - } - - // create the parser from data -@@ -448,7 +444,6 @@ open class XMLParser : NSObject { - _CFXMLInterfaceDestroyContext(_parserContext) - } - --#if !os(WASI) - //create a parser that incrementally pulls data from the specified stream and parses it. - public init(stream: InputStream) { - setupXMLParsing() -@@ -456,7 +451,6 @@ open class XMLParser : NSObject { - _handler = _CFXMLInterfaceCreateSAXHandler() - _parserContext = nil - } --#endif - - open weak var delegate: XMLParserDelegate? - - -From a4a80e1c2f6721b7e92e137d10dbf37dacb65be9 Mon Sep 17 00:00:00 2001 -From: Yuta Saito -Date: Fri, 23 Aug 2024 06:20:59 +0000 -Subject: [PATCH 3/3] Keep the current parser in TLS instead of TaskLocal - -TaskLocal storage is inherited by non-detached child tasks, which can -lead to the parser being shared between tasks. This is not our intention -and can lead to inconsistent state. Instead, we should keep the current -parser in thread-local storage. This should be safe as long as we don't -have any structured suspension points in `withCurrentParser` block. ---- - Sources/FoundationXML/XMLParser.swift | 65 ++++++++++++++++++--------- - 1 file changed, 44 insertions(+), 21 deletions(-) - -diff --git a/Sources/FoundationXML/XMLParser.swift b/Sources/FoundationXML/XMLParser.swift -index 39eea6c3d8..952c25cd58 100644 ---- a/Sources/FoundationXML/XMLParser.swift -+++ b/Sources/FoundationXML/XMLParser.swift -@@ -462,34 +462,57 @@ open class XMLParser : NSObject { - - open var allowedExternalEntityURLs: Set? - -- /// The current parser is stored in a task local variable to allow for -- /// concurrent parsing in different tasks with different parsers. -- /// -- /// Rationale for `@unchecked Sendable`: -- /// While the ``XMLParser`` class itself is not `Sendable`, `TaskLocal` -- /// requires the value type to be `Sendable`. The sendability requirement -- /// of `TaskLocal` is only for the "default" value and values set with -- /// `withValue` will not be shared between tasks. -- /// So as long as 1. the default value is safe to be shared between tasks -- /// and 2. the `Sendable` conformance of `_CurrentParser` is not used -- /// outside of `TaskLocal`, it is safe to mark it as `@unchecked Sendable`. -- private struct _CurrentParser: @unchecked Sendable { -- let parser: XMLParser? -- -- static var `default`: _CurrentParser { -- return _CurrentParser(parser: nil) -+ /// The current parser context for the current thread. -+ private class _CurrentParserContext { -+ var _stack: [XMLParser] = [] -+ var _current: XMLParser? { -+ return _stack.last - } - } - -- @TaskLocal -- private static var _currentParser: _CurrentParser = .default -+ #if os(WASI) -+ /// The current parser associated with the current thread. (assuming no multi-threading) -+ /// FIXME: Unify the implementation with the other platforms once we unlock `threadDictionary` -+ /// or migrate to `FoundationEssentials._ThreadLocal`. -+ private static nonisolated(unsafe) var _currentParserContext: _CurrentParserContext? -+ #else -+ /// The current parser associated with the current thread. -+ private static var _currentParserContext: _CurrentParserContext? { -+ get { -+ return Thread.current.threadDictionary["__CurrentNSXMLParser"] as? _CurrentParserContext -+ } -+ set { -+ Thread.current.threadDictionary["__CurrentNSXMLParser"] = newValue -+ } -+ } -+ #endif - -+ /// The current parser associated with the current thread. - internal static func currentParser() -> XMLParser? { -- return _currentParser.parser -+ if let ctx = _currentParserContext { -+ return ctx._current -+ } -+ return nil - } -- -+ -+ /// Execute the given closure with the current parser set to the given parser. - internal static func withCurrentParser(_ parser: XMLParser, _ body: () -> R) -> R { -- return self.$_currentParser.withValue(_CurrentParser(parser: parser), operation: body) -+ var ctx: _CurrentParserContext -+ if let current = _currentParserContext { -+ // Use the existing context if it exists -+ ctx = current -+ } else { -+ // Create a new context in TLS -+ ctx = _CurrentParserContext() -+ _currentParserContext = ctx -+ } -+ // Push the parser onto the stack -+ ctx._stack.append(parser) -+ defer { -+ // Pop the parser off the stack -+ ctx._stack.removeLast() -+ } -+ return body() - } - - internal func _handleParseResult(_ parseResult: Int32) -> Bool { From 66275e8b1f3da0d889e78e873fe52df97f8aac3e Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 18 Sep 2024 16:05:28 +0000 Subject: [PATCH 03/14] Remove unnecessary CMake variables from stdlib build It inverted a fix I made in swiftlang/swift https://github.com/swiftlang/swift/commit/0a304e172ca8d7470d1de3173405db1522cf2161 --- schemes/main/build/build-target-toolchain.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/schemes/main/build/build-target-toolchain.sh b/schemes/main/build/build-target-toolchain.sh index 45150107..f6ec3fa1 100755 --- a/schemes/main/build/build-target-toolchain.sh +++ b/schemes/main/build/build-target-toolchain.sh @@ -148,8 +148,6 @@ main() { -DSWIFT_STDLIB_CONCURRENCY_TRACING=NO \ -DSWIFT_RUNTIME_CRASH_REPORTER_CLIENT=NO \ -DSWIFT_STDLIB_INSTALL_PARENT_MODULE_FOR_SHIMS=NO \ - -DSWIFT_BUILD_DYNAMIC_SDK_OVERLAY=NO \ - -DSWIFT_BUILD_STATIC_SDK_OVERLAY=NO \ " \ --llvm-cmake-options="\ -DCROSS_TOOLCHAIN_FLAGS_LLVM_NATIVE='-DCMAKE_C_COMPILER=clang;-DCMAKE_CXX_COMPILER=clang++' \ From 7d9e45b34557cc831eb8904f63617154adf22f5c Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 18 Sep 2024 17:13:38 +0000 Subject: [PATCH 04/14] Attempt to fix cross-compilation on macOS host machine --- ...ss-compilation-on-macOS-host-machine.patch | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 schemes/main/swift/0001-wasm-Fix-cross-compilation-on-macOS-host-machine.patch diff --git a/schemes/main/swift/0001-wasm-Fix-cross-compilation-on-macOS-host-machine.patch b/schemes/main/swift/0001-wasm-Fix-cross-compilation-on-macOS-host-machine.patch new file mode 100644 index 00000000..26635d6c --- /dev/null +++ b/schemes/main/swift/0001-wasm-Fix-cross-compilation-on-macOS-host-machine.patch @@ -0,0 +1,29 @@ +From 7c3bf8e91d8fd74c496e0051139bc542887b3327 Mon Sep 17 00:00:00 2001 +From: Yuta Saito +Date: Wed, 18 Sep 2024 17:11:23 +0000 +Subject: [PATCH] [wasm] Fix cross-compilation on macOS host machine + +We didn't set the CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR when +cross-compiling stdlib for WASI. This caused the build to fail on macOS +host machines as the build system was trying to build some overlays +assuming the target is macOS. +--- + .../swift_build_support/products/wasmstdlib.py | 2 ++ + 1 file changed, 2 insertions(+) + +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 4d8beeaae8a..d042fc38038 100644 +--- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py ++++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +@@ -44,6 +44,8 @@ class WasmStdlib(cmake_product.CMakeProduct): + def _build(self, host_target, target_triple): + self.cmake_options.define('CMAKE_INSTALL_PREFIX:PATH', '/usr') + self.cmake_options.define('CMAKE_BUILD_TYPE:STRING', self._build_variant) ++ self.cmake_options.define('CMAKE_SYSTEM_NAME:STRING', 'WASI') ++ self.cmake_options.define('CMAKE_SYSTEM_PROCESSOR:STRING', 'wasm32') + self.cmake_options.define( + 'SWIFT_STDLIB_BUILD_TYPE:STRING', self._build_variant) + +-- +2.46.0 + From fc3bd5e0bfbf8d28fb5af5acddb40281b16ed4e8 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 18 Sep 2024 17:24:16 +0000 Subject: [PATCH 05/14] Fix macOS host build patch --- ...ss-compilation-on-macOS-host-machine.patch | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/schemes/main/swift/0001-wasm-Fix-cross-compilation-on-macOS-host-machine.patch b/schemes/main/swift/0001-wasm-Fix-cross-compilation-on-macOS-host-machine.patch index 26635d6c..023ac3fc 100644 --- a/schemes/main/swift/0001-wasm-Fix-cross-compilation-on-macOS-host-machine.patch +++ b/schemes/main/swift/0001-wasm-Fix-cross-compilation-on-macOS-host-machine.patch @@ -1,4 +1,4 @@ -From 7c3bf8e91d8fd74c496e0051139bc542887b3327 Mon Sep 17 00:00:00 2001 +From 59cda3636a7fddb6e68e7c87f5737c6d127c98c8 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 18 Sep 2024 17:11:23 +0000 Subject: [PATCH] [wasm] Fix cross-compilation on macOS host machine @@ -7,10 +7,27 @@ We didn't set the CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR when cross-compiling stdlib for WASI. This caused the build to fail on macOS host machines as the build system was trying to build some overlays assuming the target is macOS. +Additionally, add a default "SWIFT_HOST_VARIANT_SDK" for WASI target +even though we don't support it as a host system yet because it's +required anyway. --- + CMakeLists.txt | 2 ++ .../swift_build_support/products/wasmstdlib.py | 2 ++ - 1 file changed, 2 insertions(+) + 2 files changed, 4 insertions(+) +diff --git a/CMakeLists.txt b/CMakeLists.txt +index edee1dd58e6..f04243464be 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -155,6 +155,8 @@ else() + set(SWIFT_HOST_VARIANT_SDK_default "ANDROID") + elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") + set(SWIFT_HOST_VARIANT_SDK_default "OSX") ++ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "WASI") ++ set(SWIFT_HOST_VARIANT_SDK_default "WASI") + else() + message(FATAL_ERROR "Unable to detect SDK for host system: ${CMAKE_SYSTEM_NAME}") + endif() 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 4d8beeaae8a..d042fc38038 100644 --- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py From fa5ef82c30a15fea8a1f6f0475f5c3e5a0cb731f Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 04:50:03 +0000 Subject: [PATCH 06/14] Update macOS cross-compilation patch for Swift stdlib --- ...ss-compilation-on-macOS-host-machine.patch | 2 +- ...LVM-for-WebAssembly-target-independe.patch | 112 ++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch diff --git a/schemes/main/swift/0001-wasm-Fix-cross-compilation-on-macOS-host-machine.patch b/schemes/main/swift/0001-wasm-Fix-cross-compilation-on-macOS-host-machine.patch index 023ac3fc..f6c627ca 100644 --- a/schemes/main/swift/0001-wasm-Fix-cross-compilation-on-macOS-host-machine.patch +++ b/schemes/main/swift/0001-wasm-Fix-cross-compilation-on-macOS-host-machine.patch @@ -1,7 +1,7 @@ From 59cda3636a7fddb6e68e7c87f5737c6d127c98c8 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 18 Sep 2024 17:11:23 +0000 -Subject: [PATCH] [wasm] Fix cross-compilation on macOS host machine +Subject: [PATCH 1/2] [wasm] Fix cross-compilation on macOS host machine We didn't set the CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR when cross-compiling stdlib for WASI. This caused the build to fail on macOS diff --git a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch new file mode 100644 index 00000000..4388bb46 --- /dev/null +++ b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch @@ -0,0 +1,112 @@ +From b361f701dbc9c50732b2b32dc4e2bc42e02149c1 Mon Sep 17 00:00:00 2001 +From: Yuta Saito +Date: Thu, 19 Sep 2024 04:45:51 +0000 +Subject: [PATCH 2/2] [wasm] Configure LLVM for WebAssembly target + independently from the native LLVM build + +We have been using the host LLVM build directory to configure the Wasm +Swift stdlib. This has been working fine so far as the stdlib build is +configured with `CMAKE_SYSTEM_NAME` having host system name. However, +we fixed the stdlib build to use `WASI` as the system name properly in +the previous commit. This exposed the issue that the host LLVM build +directory is not suitable for configuring the stdlib build. +--- + .../products/wasmstdlib.py | 49 ++++++++++++++++--- + 1 file changed, 43 insertions(+), 6 deletions(-) + +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 d042fc38038..8a81103f561 100644 +--- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py ++++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +@@ -17,6 +17,8 @@ from . import llvm + from . import swift + from . import wasisysroot + from . import wasmkit ++from .. import cmake ++from .. import shell + + + class WasmStdlib(cmake_product.CMakeProduct): +@@ -39,13 +41,48 @@ class WasmStdlib(cmake_product.CMakeProduct): + return self.args.test_wasmstdlib + + def build(self, host_target): +- self._build(host_target, 'wasm32-wasi') ++ self._build(host_target, 'wasm32-wasi', 'wasi-wasm32') + +- def _build(self, host_target, target_triple): ++ def _build(self, host_target, target_triple, short_triple): ++ llvm_build_dir = self._configure_llvm(target_triple, short_triple) ++ llvm_cmake_dir = os.path.join(llvm_build_dir, 'lib', 'cmake', 'llvm') ++ self._build_stdlib(host_target, target_triple, llvm_cmake_dir) ++ ++ def _configure_llvm(self, target_triple, short_triple): ++ # Configure LLVM for WebAssembly target independently ++ # from the native LLVM build to turn off zlib and libxml2 ++ build_root = os.path.dirname(self.build_dir) ++ build_dir = os.path.join( ++ build_root, 'llvm-%s' % short_triple) ++ llvm_source_dir = os.path.join( ++ os.path.dirname(self.source_dir), 'llvm-project', 'llvm') ++ cmake_options = cmake.CMakeOptions() ++ cmake_options.define('CMAKE_BUILD_TYPE:STRING', self._build_variant) ++ cmake_options.define('CMAKE_SYSTEM_NAME:STRING', 'WASI') ++ cmake_options.define('CMAKE_SYSTEM_PROCESSOR:STRING', 'wasm32') ++ cmake_options.define('UNIX:BOOL', 'TRUE') ++ cmake_options.define('LLVM_ENABLE_ZLIB:BOOL', 'FALSE') ++ cmake_options.define('LLVM_ENABLE_LIBXML2:BOOL', 'FALSE') ++ ++ llvm_cmake = cmake.CMake( ++ self.args, self.toolchain, prefer_native_toolchain=True) ++ # Only configure LLVM, not build it because we just need ++ # LLVM CMake functionalities ++ shell.call(["env", self.toolchain.cmake, "-B", build_dir] ++ + list(llvm_cmake.common_options(self)) ++ + list(cmake_options) ++ + [llvm_source_dir]) ++ return build_dir ++ ++ def _build_stdlib(self, host_target, target_triple, llvm_cmake_dir): + self.cmake_options.define('CMAKE_INSTALL_PREFIX:PATH', '/usr') + self.cmake_options.define('CMAKE_BUILD_TYPE:STRING', self._build_variant) ++ # Teach about the WebAssembly target. UNIX is explicitly set to TRUE ++ # as CMake still doesn't recognize WASI as a UNIX platform and the ++ # variable is used in LLVM CMake configuration. + self.cmake_options.define('CMAKE_SYSTEM_NAME:STRING', 'WASI') + self.cmake_options.define('CMAKE_SYSTEM_PROCESSOR:STRING', 'wasm32') ++ self.cmake_options.define('UNIX:BOOL', 'TRUE') + self.cmake_options.define( + 'SWIFT_STDLIB_BUILD_TYPE:STRING', self._build_variant) + +@@ -71,9 +108,6 @@ class WasmStdlib(cmake_product.CMakeProduct): + self.cmake_options.define('SWIFT_WASI_SYSROOT_PATH:STRING', + self._wasi_sysroot_path(target_triple)) + +- # It's ok to use the host LLVM build dir just for CMake functionalities +- llvm_cmake_dir = os.path.join(self._host_llvm_build_dir( +- host_target), 'lib', 'cmake', 'llvm') + self.cmake_options.define('LLVM_DIR:PATH', llvm_cmake_dir) + + # Standalone stdlib configuration +@@ -90,6 +124,9 @@ class WasmStdlib(cmake_product.CMakeProduct): + self.cmake_options.define('SWIFT_BUILD_STATIC_STDLIB:BOOL', 'TRUE') + self.cmake_options.define('SWIFT_BUILD_DYNAMIC_STDLIB:BOOL', 'FALSE') + self.cmake_options.define('SWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL', 'TRUE') ++ # TODO: Turn off library evolution once we establish a good way to teach ++ # libraries including swift-testing whether to use the stable ABI. ++ self.cmake_options.define('SWIFT_STDLIB_STABLE_ABI:BOOL', 'TRUE') + 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') +@@ -200,7 +237,7 @@ class WasmStdlib(cmake_product.CMakeProduct): + + class WasmThreadsStdlib(WasmStdlib): + def build(self, host_target): +- self._build(host_target, 'wasm32-wasip1-threads') ++ self._build(host_target, 'wasm32-wasip1-threads', 'wasip1-threads-wasm32') + + def should_test_executable(self): + # TODO(katei): Enable tests once WasmKit supports WASI threads +-- +2.46.0 + From e1773ad4b5f411e974283ec806f4715a6679fc54 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 06:13:57 +0000 Subject: [PATCH 07/14] Use FileCheck built by build-script --- schemes/main/build/run-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemes/main/build/run-test.sh b/schemes/main/build/run-test.sh index e8d89efd..a7f56671 100755 --- a/schemes/main/build/run-test.sh +++ b/schemes/main/build/run-test.sh @@ -6,4 +6,4 @@ SOURCE_PATH="$(cd "$(dirname "$0")/../../../.." && pwd)" TARGET_BUILD_ROOT="$SOURCE_PATH/build/WebAssembly" HOST_SUFFIX=$(find "$TARGET_BUILD_ROOT" -name "wasmstdlib-*" -exec basename {} \; | sed 's/wasmstdlib-//') -env "LIT_FILTER_OUT=(IRGen/|embedded/)" ninja check-swift-wasi-wasm32-custom -C "$TARGET_BUILD_ROOT/wasmstdlib-$HOST_SUFFIX" +env "PATH=$TARGET_BUILD_ROOT/llvm-$HOST_SUFFIX/bin:$PATH" "LIT_FILTER_OUT=(IRGen/|embedded/)" ninja check-swift-wasi-wasm32-custom -C "$TARGET_BUILD_ROOT/wasmstdlib-$HOST_SUFFIX" From be42ace55a63cd06cf8aad15f9233aaf181301fc Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 06:18:44 +0000 Subject: [PATCH 08/14] Skip compiler health check --- ...LVM-for-WebAssembly-target-independe.patch | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch index 4388bb46..8858d20b 100644 --- a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch +++ b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch @@ -1,4 +1,4 @@ -From b361f701dbc9c50732b2b32dc4e2bc42e02149c1 Mon Sep 17 00:00:00 2001 +From 574c78452bf15a8c801c2c1e5c53d60192528a79 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 04:45:51 +0000 Subject: [PATCH 2/2] [wasm] Configure LLVM for WebAssembly target @@ -11,11 +11,11 @@ we fixed the stdlib build to use `WASI` as the system name properly in the previous commit. This exposed the issue that the host LLVM build directory is not suitable for configuring the stdlib build. --- - .../products/wasmstdlib.py | 49 ++++++++++++++++--- - 1 file changed, 43 insertions(+), 6 deletions(-) + .../products/wasmstdlib.py | 53 ++++++++++++++++--- + 1 file changed, 47 insertions(+), 6 deletions(-) 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 d042fc38038..8a81103f561 100644 +index d042fc38038..2e780a0453b 100644 --- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py @@ -17,6 +17,8 @@ from . import llvm @@ -27,7 +27,7 @@ index d042fc38038..8a81103f561 100644 class WasmStdlib(cmake_product.CMakeProduct): -@@ -39,13 +41,48 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -39,13 +41,52 @@ class WasmStdlib(cmake_product.CMakeProduct): return self.args.test_wasmstdlib def build(self, host_target): @@ -53,6 +53,10 @@ index d042fc38038..8a81103f561 100644 + cmake_options.define('CMAKE_SYSTEM_NAME:STRING', 'WASI') + cmake_options.define('CMAKE_SYSTEM_PROCESSOR:STRING', 'wasm32') + cmake_options.define('UNIX:BOOL', 'TRUE') ++ # compiler-rt for WebAssembly target is not installed in the host toolchain ++ # so skip compiler health checks here. ++ cmake_options.define('CMAKE_C_COMPILER_WORKS:BOOL', 'TRUE') ++ cmake_options.define('CMAKE_CXX_COMPILER_WORKS:BOOL', 'TRUE') + cmake_options.define('LLVM_ENABLE_ZLIB:BOOL', 'FALSE') + cmake_options.define('LLVM_ENABLE_LIBXML2:BOOL', 'FALSE') + @@ -78,7 +82,7 @@ index d042fc38038..8a81103f561 100644 self.cmake_options.define( 'SWIFT_STDLIB_BUILD_TYPE:STRING', self._build_variant) -@@ -71,9 +108,6 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -71,9 +112,6 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_WASI_SYSROOT_PATH:STRING', self._wasi_sysroot_path(target_triple)) @@ -88,7 +92,7 @@ index d042fc38038..8a81103f561 100644 self.cmake_options.define('LLVM_DIR:PATH', llvm_cmake_dir) # Standalone stdlib configuration -@@ -90,6 +124,9 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -90,6 +128,9 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_BUILD_STATIC_STDLIB:BOOL', 'TRUE') self.cmake_options.define('SWIFT_BUILD_DYNAMIC_STDLIB:BOOL', 'FALSE') self.cmake_options.define('SWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL', 'TRUE') @@ -98,7 +102,7 @@ index d042fc38038..8a81103f561 100644 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') -@@ -200,7 +237,7 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -200,7 +241,7 @@ class WasmStdlib(cmake_product.CMakeProduct): class WasmThreadsStdlib(WasmStdlib): def build(self, host_target): From 13a200a159681add2fdc7ca8410a51594179229d Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 06:50:26 +0000 Subject: [PATCH 09/14] Skip llvm compiler checks --- ...-LLVM-for-WebAssembly-target-independe.patch | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch index 8858d20b..9480dc28 100644 --- a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch +++ b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch @@ -1,4 +1,4 @@ -From 574c78452bf15a8c801c2c1e5c53d60192528a79 Mon Sep 17 00:00:00 2001 +From 8b7f1aaa735d1d0b994fc9ac9009f4bc9805a142 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 04:45:51 +0000 Subject: [PATCH 2/2] [wasm] Configure LLVM for WebAssembly target @@ -11,11 +11,11 @@ we fixed the stdlib build to use `WASI` as the system name properly in the previous commit. This exposed the issue that the host LLVM build directory is not suitable for configuring the stdlib build. --- - .../products/wasmstdlib.py | 53 ++++++++++++++++--- - 1 file changed, 47 insertions(+), 6 deletions(-) + .../products/wasmstdlib.py | 54 ++++++++++++++++--- + 1 file changed, 48 insertions(+), 6 deletions(-) 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 d042fc38038..2e780a0453b 100644 +index d042fc38038..09d90be7fe9 100644 --- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py @@ -17,6 +17,8 @@ from . import llvm @@ -27,7 +27,7 @@ index d042fc38038..2e780a0453b 100644 class WasmStdlib(cmake_product.CMakeProduct): -@@ -39,13 +41,52 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -39,13 +41,53 @@ class WasmStdlib(cmake_product.CMakeProduct): return self.args.test_wasmstdlib def build(self, host_target): @@ -57,6 +57,7 @@ index d042fc38038..2e780a0453b 100644 + # so skip compiler health checks here. + cmake_options.define('CMAKE_C_COMPILER_WORKS:BOOL', 'TRUE') + cmake_options.define('CMAKE_CXX_COMPILER_WORKS:BOOL', 'TRUE') ++ cmake_options.define('LLVM_COMPILER_CHECKED:BOOL', 'TRUE') + cmake_options.define('LLVM_ENABLE_ZLIB:BOOL', 'FALSE') + cmake_options.define('LLVM_ENABLE_LIBXML2:BOOL', 'FALSE') + @@ -82,7 +83,7 @@ index d042fc38038..2e780a0453b 100644 self.cmake_options.define( 'SWIFT_STDLIB_BUILD_TYPE:STRING', self._build_variant) -@@ -71,9 +112,6 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -71,9 +113,6 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_WASI_SYSROOT_PATH:STRING', self._wasi_sysroot_path(target_triple)) @@ -92,7 +93,7 @@ index d042fc38038..2e780a0453b 100644 self.cmake_options.define('LLVM_DIR:PATH', llvm_cmake_dir) # Standalone stdlib configuration -@@ -90,6 +128,9 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -90,6 +129,9 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_BUILD_STATIC_STDLIB:BOOL', 'TRUE') self.cmake_options.define('SWIFT_BUILD_DYNAMIC_STDLIB:BOOL', 'FALSE') self.cmake_options.define('SWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL', 'TRUE') @@ -102,7 +103,7 @@ index d042fc38038..2e780a0453b 100644 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') -@@ -200,7 +241,7 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -200,7 +242,7 @@ class WasmStdlib(cmake_product.CMakeProduct): class WasmThreadsStdlib(WasmStdlib): def build(self, host_target): From 893de78d2a4e7e64e44a5ce9dae43e52ea25bc4b Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 07:38:11 +0000 Subject: [PATCH 10/14] Configure LLVM for host target for now --- ...LVM-for-WebAssembly-target-independe.patch | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch index 9480dc28..0def0055 100644 --- a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch +++ b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch @@ -1,4 +1,4 @@ -From 8b7f1aaa735d1d0b994fc9ac9009f4bc9805a142 Mon Sep 17 00:00:00 2001 +From 724d3056fae124c059a15563a0ed1e55799cdf81 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 04:45:51 +0000 Subject: [PATCH 2/2] [wasm] Configure LLVM for WebAssembly target @@ -11,11 +11,11 @@ we fixed the stdlib build to use `WASI` as the system name properly in the previous commit. This exposed the issue that the host LLVM build directory is not suitable for configuring the stdlib build. --- - .../products/wasmstdlib.py | 54 ++++++++++++++++--- - 1 file changed, 48 insertions(+), 6 deletions(-) + .../products/wasmstdlib.py | 50 ++++++++++++++++--- + 1 file changed, 44 insertions(+), 6 deletions(-) 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 d042fc38038..09d90be7fe9 100644 +index d042fc38038..03a24a85fae 100644 --- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py @@ -17,6 +17,8 @@ from . import llvm @@ -27,7 +27,7 @@ index d042fc38038..09d90be7fe9 100644 class WasmStdlib(cmake_product.CMakeProduct): -@@ -39,13 +41,53 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -39,13 +41,49 @@ class WasmStdlib(cmake_product.CMakeProduct): return self.args.test_wasmstdlib def build(self, host_target): @@ -49,10 +49,6 @@ index d042fc38038..09d90be7fe9 100644 + llvm_source_dir = os.path.join( + os.path.dirname(self.source_dir), 'llvm-project', 'llvm') + cmake_options = cmake.CMakeOptions() -+ cmake_options.define('CMAKE_BUILD_TYPE:STRING', self._build_variant) -+ cmake_options.define('CMAKE_SYSTEM_NAME:STRING', 'WASI') -+ cmake_options.define('CMAKE_SYSTEM_PROCESSOR:STRING', 'wasm32') -+ cmake_options.define('UNIX:BOOL', 'TRUE') + # compiler-rt for WebAssembly target is not installed in the host toolchain + # so skip compiler health checks here. + cmake_options.define('CMAKE_C_COMPILER_WORKS:BOOL', 'TRUE') @@ -83,7 +79,7 @@ index d042fc38038..09d90be7fe9 100644 self.cmake_options.define( 'SWIFT_STDLIB_BUILD_TYPE:STRING', self._build_variant) -@@ -71,9 +113,6 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -71,9 +109,6 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_WASI_SYSROOT_PATH:STRING', self._wasi_sysroot_path(target_triple)) @@ -93,7 +89,7 @@ index d042fc38038..09d90be7fe9 100644 self.cmake_options.define('LLVM_DIR:PATH', llvm_cmake_dir) # Standalone stdlib configuration -@@ -90,6 +129,9 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -90,6 +125,9 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_BUILD_STATIC_STDLIB:BOOL', 'TRUE') self.cmake_options.define('SWIFT_BUILD_DYNAMIC_STDLIB:BOOL', 'FALSE') self.cmake_options.define('SWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL', 'TRUE') @@ -103,7 +99,7 @@ index d042fc38038..09d90be7fe9 100644 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') -@@ -200,7 +242,7 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -200,7 +238,7 @@ class WasmStdlib(cmake_product.CMakeProduct): class WasmThreadsStdlib(WasmStdlib): def build(self, host_target): From 27d133857f6c1a15db8f2167eacb14b49cea14dd Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 07:59:55 +0000 Subject: [PATCH 11/14] Restore CMAKE_BUILD_TYPE --- ...-LLVM-for-WebAssembly-target-independe.patch | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch index 0def0055..93b7cae8 100644 --- a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch +++ b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch @@ -1,4 +1,4 @@ -From 724d3056fae124c059a15563a0ed1e55799cdf81 Mon Sep 17 00:00:00 2001 +From 061b9339c6c76064e3930ee81811be058ca853fc Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 04:45:51 +0000 Subject: [PATCH 2/2] [wasm] Configure LLVM for WebAssembly target @@ -11,11 +11,11 @@ we fixed the stdlib build to use `WASI` as the system name properly in the previous commit. This exposed the issue that the host LLVM build directory is not suitable for configuring the stdlib build. --- - .../products/wasmstdlib.py | 50 ++++++++++++++++--- - 1 file changed, 44 insertions(+), 6 deletions(-) + .../products/wasmstdlib.py | 51 ++++++++++++++++--- + 1 file changed, 45 insertions(+), 6 deletions(-) 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 d042fc38038..03a24a85fae 100644 +index d042fc38038..053756139d5 100644 --- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py @@ -17,6 +17,8 @@ from . import llvm @@ -27,7 +27,7 @@ index d042fc38038..03a24a85fae 100644 class WasmStdlib(cmake_product.CMakeProduct): -@@ -39,13 +41,49 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -39,13 +41,50 @@ class WasmStdlib(cmake_product.CMakeProduct): return self.args.test_wasmstdlib def build(self, host_target): @@ -49,6 +49,7 @@ index d042fc38038..03a24a85fae 100644 + llvm_source_dir = os.path.join( + os.path.dirname(self.source_dir), 'llvm-project', 'llvm') + cmake_options = cmake.CMakeOptions() ++ cmake_options.define('CMAKE_BUILD_TYPE:STRING', self._build_variant) + # compiler-rt for WebAssembly target is not installed in the host toolchain + # so skip compiler health checks here. + cmake_options.define('CMAKE_C_COMPILER_WORKS:BOOL', 'TRUE') @@ -79,7 +80,7 @@ index d042fc38038..03a24a85fae 100644 self.cmake_options.define( 'SWIFT_STDLIB_BUILD_TYPE:STRING', self._build_variant) -@@ -71,9 +109,6 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -71,9 +110,6 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_WASI_SYSROOT_PATH:STRING', self._wasi_sysroot_path(target_triple)) @@ -89,7 +90,7 @@ index d042fc38038..03a24a85fae 100644 self.cmake_options.define('LLVM_DIR:PATH', llvm_cmake_dir) # Standalone stdlib configuration -@@ -90,6 +125,9 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -90,6 +126,9 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_BUILD_STATIC_STDLIB:BOOL', 'TRUE') self.cmake_options.define('SWIFT_BUILD_DYNAMIC_STDLIB:BOOL', 'FALSE') self.cmake_options.define('SWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL', 'TRUE') @@ -99,7 +100,7 @@ index d042fc38038..03a24a85fae 100644 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') -@@ -200,7 +238,7 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -200,7 +239,7 @@ class WasmStdlib(cmake_product.CMakeProduct): class WasmThreadsStdlib(WasmStdlib): def build(self, host_target): From 599bacff8e1316cdf77dc9ec9b4c32761a06c7bc Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 08:21:14 +0000 Subject: [PATCH 12/14] Skip compiler checks in stdlib too --- ...LVM-for-WebAssembly-target-independe.patch | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch index 93b7cae8..10ae408a 100644 --- a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch +++ b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch @@ -1,4 +1,4 @@ -From 061b9339c6c76064e3930ee81811be058ca853fc Mon Sep 17 00:00:00 2001 +From 8105c1de468d1962c7aacd0aaf31ec2dc90121c0 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 04:45:51 +0000 Subject: [PATCH 2/2] [wasm] Configure LLVM for WebAssembly target @@ -11,11 +11,11 @@ we fixed the stdlib build to use `WASI` as the system name properly in the previous commit. This exposed the issue that the host LLVM build directory is not suitable for configuring the stdlib build. --- - .../products/wasmstdlib.py | 51 ++++++++++++++++--- - 1 file changed, 45 insertions(+), 6 deletions(-) + .../products/wasmstdlib.py | 57 +++++++++++++++++-- + 1 file changed, 51 insertions(+), 6 deletions(-) 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 d042fc38038..053756139d5 100644 +index d042fc38038..f87cd87d41c 100644 --- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py @@ -17,6 +17,8 @@ from . import llvm @@ -80,17 +80,23 @@ index d042fc38038..053756139d5 100644 self.cmake_options.define( 'SWIFT_STDLIB_BUILD_TYPE:STRING', self._build_variant) -@@ -71,9 +110,6 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -71,9 +110,12 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_WASI_SYSROOT_PATH:STRING', self._wasi_sysroot_path(target_triple)) - # It's ok to use the host LLVM build dir just for CMake functionalities - llvm_cmake_dir = os.path.join(self._host_llvm_build_dir( - host_target), 'lib', 'cmake', 'llvm') ++ # compiler-rt for WebAssembly target is not installed in the host toolchain ++ # so skip compiler health checks here. ++ self.cmake_options.define('CMAKE_C_COMPILER_WORKS:BOOL', 'TRUE') ++ self.cmake_options.define('CMAKE_CXX_COMPILER_WORKS:BOOL', 'TRUE') ++ self.cmake_options.define('LLVM_COMPILER_CHECKED:BOOL', 'TRUE') ++ self.cmake_options.define('LLVM_DIR:PATH', llvm_cmake_dir) # Standalone stdlib configuration -@@ -90,6 +126,9 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -90,6 +132,9 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_BUILD_STATIC_STDLIB:BOOL', 'TRUE') self.cmake_options.define('SWIFT_BUILD_DYNAMIC_STDLIB:BOOL', 'FALSE') self.cmake_options.define('SWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL', 'TRUE') @@ -100,7 +106,7 @@ index d042fc38038..053756139d5 100644 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') -@@ -200,7 +239,7 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -200,7 +245,7 @@ class WasmStdlib(cmake_product.CMakeProduct): class WasmThreadsStdlib(WasmStdlib): def build(self, host_target): From 8a8c999a00d419ec079b471b8dba1656e0e19f66 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 08:44:19 +0000 Subject: [PATCH 13/14] Add CMAKE_Swift_COMPILER_WORKS --- ...re-LLVM-for-WebAssembly-target-independe.patch | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch index 10ae408a..09667ce5 100644 --- a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch +++ b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch @@ -1,4 +1,4 @@ -From 8105c1de468d1962c7aacd0aaf31ec2dc90121c0 Mon Sep 17 00:00:00 2001 +From 173de308e35d9cb7dcd65b0726ccd86bc2e0eb9b Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 04:45:51 +0000 Subject: [PATCH 2/2] [wasm] Configure LLVM for WebAssembly target @@ -11,11 +11,11 @@ we fixed the stdlib build to use `WASI` as the system name properly in the previous commit. This exposed the issue that the host LLVM build directory is not suitable for configuring the stdlib build. --- - .../products/wasmstdlib.py | 57 +++++++++++++++++-- - 1 file changed, 51 insertions(+), 6 deletions(-) + .../products/wasmstdlib.py | 58 +++++++++++++++++-- + 1 file changed, 52 insertions(+), 6 deletions(-) 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 d042fc38038..f87cd87d41c 100644 +index d042fc38038..3c93a7a679f 100644 --- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py @@ -17,6 +17,8 @@ from . import llvm @@ -80,7 +80,7 @@ index d042fc38038..f87cd87d41c 100644 self.cmake_options.define( 'SWIFT_STDLIB_BUILD_TYPE:STRING', self._build_variant) -@@ -71,9 +110,12 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -71,9 +110,13 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_WASI_SYSROOT_PATH:STRING', self._wasi_sysroot_path(target_triple)) @@ -91,12 +91,13 @@ index d042fc38038..f87cd87d41c 100644 + # so skip compiler health checks here. + self.cmake_options.define('CMAKE_C_COMPILER_WORKS:BOOL', 'TRUE') + self.cmake_options.define('CMAKE_CXX_COMPILER_WORKS:BOOL', 'TRUE') ++ self.cmake_options.define('CMAKE_Swift_COMPILER_WORKS:BOOL', 'TRUE') + self.cmake_options.define('LLVM_COMPILER_CHECKED:BOOL', 'TRUE') + self.cmake_options.define('LLVM_DIR:PATH', llvm_cmake_dir) # Standalone stdlib configuration -@@ -90,6 +132,9 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -90,6 +133,9 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_BUILD_STATIC_STDLIB:BOOL', 'TRUE') self.cmake_options.define('SWIFT_BUILD_DYNAMIC_STDLIB:BOOL', 'FALSE') self.cmake_options.define('SWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL', 'TRUE') @@ -106,7 +107,7 @@ index d042fc38038..f87cd87d41c 100644 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') -@@ -200,7 +245,7 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -200,7 +246,7 @@ class WasmStdlib(cmake_product.CMakeProduct): class WasmThreadsStdlib(WasmStdlib): def build(self, host_target): From 77bbc7c1f54f365a77ee69f9be2b7d41a6147ab8 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 09:11:41 +0000 Subject: [PATCH 14/14] Disable libedit and terminfo in LLVM --- ...LLVM-for-WebAssembly-target-independe.patch | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch index 09667ce5..eca2c256 100644 --- a/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch +++ b/schemes/main/swift/0002-wasm-Configure-LLVM-for-WebAssembly-target-independe.patch @@ -1,4 +1,4 @@ -From 173de308e35d9cb7dcd65b0726ccd86bc2e0eb9b Mon Sep 17 00:00:00 2001 +From 24bd384f841df8f357fe35c6cc890cd7b15a4114 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 19 Sep 2024 04:45:51 +0000 Subject: [PATCH 2/2] [wasm] Configure LLVM for WebAssembly target @@ -11,11 +11,11 @@ we fixed the stdlib build to use `WASI` as the system name properly in the previous commit. This exposed the issue that the host LLVM build directory is not suitable for configuring the stdlib build. --- - .../products/wasmstdlib.py | 58 +++++++++++++++++-- - 1 file changed, 52 insertions(+), 6 deletions(-) + .../products/wasmstdlib.py | 60 +++++++++++++++++-- + 1 file changed, 54 insertions(+), 6 deletions(-) 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 d042fc38038..3c93a7a679f 100644 +index d042fc38038..70299e37885 100644 --- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py @@ -17,6 +17,8 @@ from . import llvm @@ -27,7 +27,7 @@ index d042fc38038..3c93a7a679f 100644 class WasmStdlib(cmake_product.CMakeProduct): -@@ -39,13 +41,50 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -39,13 +41,52 @@ class WasmStdlib(cmake_product.CMakeProduct): return self.args.test_wasmstdlib def build(self, host_target): @@ -57,6 +57,8 @@ index d042fc38038..3c93a7a679f 100644 + cmake_options.define('LLVM_COMPILER_CHECKED:BOOL', 'TRUE') + cmake_options.define('LLVM_ENABLE_ZLIB:BOOL', 'FALSE') + cmake_options.define('LLVM_ENABLE_LIBXML2:BOOL', 'FALSE') ++ cmake_options.define('LLVM_ENABLE_LIBEDIT:BOOL', 'FALSE') ++ cmake_options.define('LLVM_ENABLE_TERMINFO:BOOL', 'FALSE') + + llvm_cmake = cmake.CMake( + self.args, self.toolchain, prefer_native_toolchain=True) @@ -80,7 +82,7 @@ index d042fc38038..3c93a7a679f 100644 self.cmake_options.define( 'SWIFT_STDLIB_BUILD_TYPE:STRING', self._build_variant) -@@ -71,9 +110,13 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -71,9 +112,13 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_WASI_SYSROOT_PATH:STRING', self._wasi_sysroot_path(target_triple)) @@ -97,7 +99,7 @@ index d042fc38038..3c93a7a679f 100644 self.cmake_options.define('LLVM_DIR:PATH', llvm_cmake_dir) # Standalone stdlib configuration -@@ -90,6 +133,9 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -90,6 +135,9 @@ class WasmStdlib(cmake_product.CMakeProduct): self.cmake_options.define('SWIFT_BUILD_STATIC_STDLIB:BOOL', 'TRUE') self.cmake_options.define('SWIFT_BUILD_DYNAMIC_STDLIB:BOOL', 'FALSE') self.cmake_options.define('SWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL', 'TRUE') @@ -107,7 +109,7 @@ index d042fc38038..3c93a7a679f 100644 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') -@@ -200,7 +246,7 @@ class WasmStdlib(cmake_product.CMakeProduct): +@@ -200,7 +248,7 @@ class WasmStdlib(cmake_product.CMakeProduct): class WasmThreadsStdlib(WasmStdlib): def build(self, host_target):